import json import numpy as np d = json.loads(open('/tmp/wunderlist-2014015-12-49-55.json').read()) # extract the id of the category "Future Blog Posts" cat_id = [x['id'] for x in d['lists'] if x['title'].startswith('Future blog posts')][0] # convert datetimes into epoc milliseconds from datetime import datetime to_epoc = lambda x: int(datetime.strptime(x['created_at'], '%Y-%m-%dT%H:%M:%SZ').strftime('%s'))*1000 # list of pairs (time, val) where val is 1 iff the task belongs to the category under analysis time_indicator = sorted([[to_epoc(x), x['list_id'] == cat_id and 1 or 0] for x in d['tasks']]) times, indicator = zip(*time_indicator) # prepare the JSON for nvd3 data = [] data.append({'key': 'All other lists', 'values' : zip(times, [int(x) for x in np.cumsum([1-x for x in indicator])])}) data.append({'key': 'Future posts', 'values' : zip(times, [int(x) for x in np.cumsum(indicator)])}) f = open('../data/wunderlist.json', 'w') f.write(json.dumps(data)) f.close() %%bash cat ../_includes/bladh/wunderlist_infographic.html