Posted By

narkisr on 01/27/09


Tagged

sparkline haskell


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

keigoi


Haskell hackage uploads sparkline script


 / Published in: Java
 

An Haskell script that generate sparkline graphs of hackage uploads (http://donsbot.wordpress.com/2008/06/24/daily-haskell-download-and-analyse-logs-then-generate-sparklines/).

  1. --------------------------------------------------------------------
  2. -- |
  3. -- Module : Generate sparkline graphs of hackage uploads
  4. -- Copyright : (c) Don Stewart 2008
  5. -- License : BSD3
  6. --
  7. -- Maintainer: Don Stewart <dons@galois.com>
  8. -- Stability : provisional
  9. -- Portability:
  10. --
  11. --------------------------------------------------------------------
  12.  
  13. import Data.List
  14. import Data.Maybe
  15. import Graphics.Rendering.HSparklines
  16. import System.Locale
  17. import System.Time
  18. import System.Time.Parse
  19. import System.Directory
  20. import System.FilePath
  21. import Text.HTML.Download
  22.  
  23. url = "http://hackage.haskell.org/packages/archive/log"
  24.  
  25. png1 = "hackage-monthly.png"
  26. png2 = "hackage-daily.png"
  27.  
  28. main :: IO ()
  29. main = do
  30. pwd <- getCurrentDirectory
  31. src <- openURL url
  32. let dates = catMaybes . sort . map parse . lines $ src
  33.  
  34. -- uploads per year
  35. let permonth = groupBy month dates
  36. graph <- make ((barSpark {bgColor = rgb 0xee 0xee 0xee}) ) (map genericLength permonth)
  37. savePngFile png1 graph
  38. putStrLn $ "Wrote: " ++ pwd </> png1
  39.  
  40. -- print uploads this month
  41. let today = last dates
  42. thismonth = groupBy day . filter (month today) $ dates
  43. graph <- make ((barSpark {bgColor = rgb 0xee 0xee 0xee
  44. , limits = (0,20)} )) (map genericLength thismonth)
  45. savePngFile png2 graph
  46. putStrLn $ "Wrote: " ++ pwd </> png2
  47.  
  48. where
  49. parse = parseCalendarTime defaultTimeLocale "%c"
  50. month a b = ctYear a == ctYear b && ctMonth a == ctMonth b
  51. day a b = month a b && ctDay a == ctDay b

Report this snippet  

You need to login to post a comment.