Created
June 18, 2009 12:44
-
-
Save jberkel/131886 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys | |
import csv | |
from datetime import timedelta, datetime | |
from graphication import FileOutput, Series, SeriesSet, Label, SimpleScale, css, default_css as style | |
from graphication.scales.date import AutoWeekDateScale, AutoDateScale | |
from graphication.wavegraph import WaveGraph | |
def colorgen(colours): | |
while 1: | |
for c in colours: yield c | |
colour_loop = colorgen( | |
("#4D8963", | |
"#69A583", | |
"#E1B378", | |
"#E0CC97", | |
"#EC799A", | |
"#9F0251") | |
) | |
series_set = SeriesSet() | |
for filename in sys.argv[1:]: | |
data = {} | |
for row in csv.reader(open(filename)): | |
name, date, count = row[0], datetime.strptime(row[1] + "0", '%Y%W%w'), int(row[2]) | |
if name not in data: | |
data[name] = [] | |
data[name].append((date, count)) | |
for k in data.keys(): | |
series_set.add_series(Series(k, dict(data[k]), colour_loop.next())) | |
output = FileOutput() | |
scale = AutoWeekDateScale(series_set) | |
#scale = AutoDateScale(series_set) | |
wg = WaveGraph(series_set, scale, None, label_curves=True) | |
#lb = Label(', '.join(map(lambda x: x.title, series_set)), None) | |
width = 20*len(series_set.keys()) | |
#output.add_item(lb, x=10, y=5, width=width-20, height=20) | |
output.add_item(wg, x=0, y=30, width=width, height=500) | |
filename = "trends" | |
output.write("png", ("%s.png" % filename)) | |
output.write("pdf", ("%s.pdf" % filename)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment