#!/usr/bin/env python # coding: utf-8 # In[1]: import cPickle as pickle with open('result.db') as f: data = f.read() RES = pickle.loads(data) # In[2]: from IPython.display import HTML from collections import defaultdict SERIES = [] options = ('', '-i', '-v') commands = ('grep', 'ack', 'ag') xns = ('en', 'cn') for xn in xns: for word in RES[xn]: for option in options: series = [] for command in commands: _res = {} w_value = RES[xn][word] for size in w_value: res = w_value[size] _r = res[command][option] _res[size] = _r v = [i[1] for i in sorted( _res.iteritems(), key=lambda x:int(x[0])) ] series.append({ 'name': command, 'data': v }) subtitle = '{0} {1} {2}'.format(xn, word, option) SERIES.append((subtitle, series)) # In[3]: div_tmpl = '
' div = '\n'.join([div_tmpl.format("chart%d" % index) for index in range(len(SERIES))]) js_tmpl = 'setTimeout("do_chart(\'{0}\', \'{1}\', {2})", 50)' js = ';\n'.join([js_tmpl.format("chart%d" % index, series[0], series[1]) for index, series in enumerate(SERIES)]) # In[5]: HTML(''' %s ''' % (div, js)) # In[ ]: