Commit aa7e2a8c authored by Julius Metz's avatar Julius Metz

first plot generator basics, datetime added to data

parent cae10365
import plotly.io as pio
import datetime
def cpu_plot(values, title=None):
def cpu_plot(values, title=None, xtitle=None, ytitle=None):
plot = {
'data': [],
'layout': {
......@@ -9,15 +10,24 @@ def cpu_plot(values, title=None):
'title': {
'text': title
},
'xaxis': {
'title': xtitle,
},
'yaxis': {
'title': ytitle,
},
},
}
for cmd, cmd_data in values.items():
CPU = cmd_data.get('CPU', [])
if not any(elem != '0' for elem in CPU):
continue
plot['data'].append(
{
'type': 'scatter',
'mode': 'markers',
'x': cmd_data.get('Time', []),
'x': cmd_data.get('datetime', []),
'y': cmd_data.get('CPU', []),
'name': cmd,
}
......
import subprocess
from pathlib import Path
import time
import datetime
import click
import plots_generators
HEAD_BLACKLIST = ['Time', 'Date']
CONFIG = {
'cpu_plot':{
'title': 'CPU load',
'xtitle': 'Date',
'ytitle': 'CPU load',
}
}
def datestr2date(datestr):
return datetime.date(
int(datestr[:4]),
int(datestr[4:6]),
int(datestr[6:8]),
)
def parse_file(path, collectl):
process = subprocess.run([collectl, '-P', '-p', path, '-sZ'], capture_output=True)
output = process.stdout.decode().splitlines()
head = output.pop(0).split(' ')
head[0] = head[0][1:]
entrys_data = {}
tmp_date = None
tmp_time = None
for entry in output:
splited_entry = entry.split(' ', len(head))
cmd = splited_entry[-1]
if not cmd in entrys_data:
entrys_data[cmd] = {head_elem : [] for head_elem in head[:-1]}
entrys_data[cmd] = {
head_elem : [] for head_elem in head[:-1] if head_elem not in HEAD_BLACKLIST
}
entrys_data[cmd]['datetime'] = []
for i, head_elem in enumerate(head[:-1]):
entrys_data[cmd][head_elem].append(splited_entry[i])
if head_elem == 'Date':
tmp_date = datestr2date(splited_entry[i])
if head_elem == 'Time':
tmp_time = datetime.time.fromisoformat(splited_entry[i])
if not head_elem in HEAD_BLACKLIST:
entrys_data[cmd][head_elem].append(splited_entry[i])
entrys_data[cmd]['datetime'].append(
datetime.datetime.combine(tmp_date, tmp_time),
)
return entrys_data
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment