-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinteractive-plots.py
63 lines (50 loc) · 1.46 KB
/
interactive-plots.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
62
63
"""
Interactive plot of stats usage.
"""
from copy import deepcopy
from pathlib import Path
from string import Template
import pandas as pd
import plotly.express as px
main_dir = Path.cwd()
html_dir = main_dir / 'htmls'
summary_dir = main_dir / 'summaries'
namespaces = ['ai4eosc', 'imagine', 'ai4life']
labels = {
'cpu_num': 'CPU cores',
'cpu_MHz': 'CPU frequency (MHz)',
'memory_MB': 'RAM memory (MB)',
'disk_MB': 'Disk memory (MB)',
'gpu_num': ' Number of GPUs',
'running': 'Jobs running',
'queued': 'Jobs queued',
}
# Load html template
with open(html_dir / 'template.html', 'r') as f:
html_template = Template(f.read())
# Generate plots
for namespace in namespaces:
df = pd.read_csv(
summary_dir / f'{namespace}-timeseries.csv',
sep=';',
)
with open(html_dir / f'{namespace}.html', 'w') as f:
html = deepcopy(html_template)
divs = {}
for k in labels.keys():
fig = px.area(
x=df['date'],
y=df[k],
title=labels[k],
labels={
'x': 'Dates',
# 'y': labels[k],
'y': '',
},
width=800, height=400,
)
divs[k] = fig.to_html( # retrieve html code of the plot
full_html=False,
include_plotlyjs='cdn',
)
f.write(html.safe_substitute(divs)) # replace in template