Do not pipe into `grep -q`, because that stops reading as soon as a
[arvados.git] / tools / crunchstat-summary / crunchstat_summary / dygraphs.py
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 import crunchstat_summary.webchart
6
7
8 class DygraphsChart(crunchstat_summary.webchart.WebChart):
9     CSS = 'https://cdnjs.cloudflare.com/ajax/libs/dygraph/2.0.0/dygraph.min.css'
10     JSLIB = 'https://cdnjs.cloudflare.com/ajax/libs/dygraph/2.0.0/dygraph.min.js'
11     JSASSETS = ['synchronizer.js','dygraphs.js']
12
13     def headHTML(self):
14         return '<link rel="stylesheet" href="{}">\n'.format(self.CSS)
15
16     def chartdata(self, label, tasks, stats):
17         '''For Crunch2, label is the name of container request,
18         tasks is the top level container and
19         stats is index by a tuple of (category, metric).
20         '''
21         return {
22             'data': self._collate_data(tasks, stats),
23             'options': {
24                 'legend': 'always',
25                 'connectSeparatedPoints': True,
26                 'labels': ['elapsed'] +  stats[1],
27                 'title': '{}: {}'.format(label, stats[0]),
28             },
29         }
30
31     def _collate_data(self, tasks, stats):
32         data = []
33         nulls = []
34         # uuid is category for crunch2
35         for uuid, task in tasks.items():
36             # All stats in a category are assumed to have the same time base and same number of samples
37             category = stats[0]
38             series_names = stats[1]
39             sn0 = series_names[0]
40             series = task.series[(category,sn0)]
41             for i in range(len(series)):
42                 pt = series[i]
43                 vals = [task.series[(category,stat)][i][1] for stat in series_names[1:]]
44                 data.append([pt[0].total_seconds()] + nulls + [pt[1]] + vals)
45             nulls.append(None)
46         return sorted(data)