-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathplotter.py
61 lines (48 loc) · 1.51 KB
/
plotter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import pygal
fig_pygal="""
<figure>
<!-- Pygal render() result: -->
{a}
<!-- End of Pygal render() result: -->
</figure>
"""
def to_html_fig(chart):
plot_html_fig = fig_pygal.format(a=chart.render(is_unicode=True))
return plot_html_fig
previous = []
def plot(data, statement, append=False):
if type(data) is str:
return f"ERROR OCCURRED: {data}"
global previous
style = Style(background="#FFFFFF")
line_chart = pygal.Line(fill=True, truncate_legend=7, style=style)
line_chart.x_labels = [d[0] for d in data]
try:
if append:
previous.append((statement, data))
for statement, data in previous:
line_chart.add(statement, list(map(lambda y: int(y) if y is not None else None, [d[1] for d in data])))
else:
line_chart.title = f'Result evolution among Delta Lake versions\n{statement}'
line_chart.add(None, list(map(lambda y: int(y) if y is not None else None, [d[1] for d in data])))
previous = []
previous.append((statement, data))
return to_html_fig(line_chart)
except Exception as e:
return f"ERROR OCCURRED: {str(e)}"
html_pygal="""
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://kozea.github.com/pygal.js/latest/pygal-tooltips.min.js"></script>
<!-- ... -->
</head>
<body>
<figure>
<!-- Pygal render() result: -->
{a}
<!-- End of Pygal render() result: -->
</figure>
</body>
</html>
"""