1 from __future__ import print_function
8 from crunchstat_summary import logger
11 class ChartJS(object):
12 JSLIB = 'https://cdnjs.cloudflare.com/ajax/libs/canvasjs/1.7.0/canvasjs.min.js'
14 def __init__(self, label, summarizers):
16 self.summarizers = summarizers
19 return '''<!doctype html><html><head>
20 <title>{} stats</title>
21 <script type="text/javascript" src="{}"></script>
22 <script type="text/javascript">{}</script>
23 </head><body></body></html>
24 '''.format(cgi.escape(self.label), self.JSLIB, self.js())
27 return 'var sections = {};\n{}'.format(
28 json.dumps(self.sections()),
29 pkg_resources.resource_string('crunchstat_summary', 'chartjs.js'))
34 'label': s.long_label(),
35 'charts': self.charts(s.label, s.tasks),
37 for s in self.summarizers]
39 def _axisY(self, tasks, stat):
41 for task in tasks.itervalues():
42 for pt in task.series[stat]:
43 ymax = max(ymax, pt[1])
44 ytick = math.exp((1+math.floor(math.log(ymax, 2)))*math.log(2))/4
46 'gridColor': '#cccccc',
51 'valueFormatString': "''",
54 def charts(self, label, tasks):
57 'axisY': self._axisY(tasks=tasks, stat=stat),
62 'dataPoints': self._datapoints(
63 label=uuid, task=task, series=task.series[stat]),
65 for uuid, task in tasks.iteritems()
68 'text': '{}: {} {}'.format(label, stat[0], stat[1]),
72 for stat in (('cpu', 'user+sys__rate'),
74 ('net:eth0', 'tx+rx__rate'),
75 ('net:keep0', 'tx+rx__rate'))]
77 def _datapoints(self, label, task, series):
79 {'x': pt[0].total_seconds(), 'y': pt[1]}
82 points[-1]['markerType'] = 'cross'
83 points[-1]['markerSize'] = 12