-------------------------------------------------------------------- -- | -- Module : Generate sparkline graphs of hackage uploads -- Copyright : (c) Don Stewart 2008 -- License : BSD3 -- -- Maintainer: Don Stewart -- Stability : provisional -- Portability: -- -------------------------------------------------------------------- import Data.List import Data.Maybe import Graphics.Rendering.HSparklines import System.Directory import System.FilePath import System.Locale import System.Time import System.Time.Parse import Text.HTML.Download url = "http://hackage.haskell.org/packages/archive/log" png1 = "hackage-monthly.png" png2 = "hackage-daily.png" graph = barSpark -- { bgColor = rgb 0xEE 0xEE 0xEE } main :: IO () main = do pwd <- getCurrentDirectory src <- openURL url let dates = catMaybes . sort . map parse . lines $ src let today = last dates permonth = groupBy month dates thismonth = groupBy day . filter (month today) $ dates monthlies = map genericLength permonth dailies = map genericLength thismonth top = maximum monthlies graph1 <- make (graph { limits = (0,round top) }) monthlies graph2 <- make (graph { limits = (0,20) }) dailies savePngFile png1 graph1 savePngFile png2 graph2 putStrLn $ "Wrote: " ++ pwd png1 putStrLn $ "Wrote: " ++ pwd png2 where parse = parseCalendarTime defaultTimeLocale "%c" month a b = ctYear a == ctYear b && ctMonth a == ctMonth b day a b = month a b && ctDay a == ctDay b