From 7b9936334c557f60cc876d95b78430ccf2356d64 Mon Sep 17 00:00:00 2001 From: Alban Bronisz Date: Wed, 3 Mar 2021 20:22:47 +0100 Subject: [PATCH] Read all field (not only first day) --- display/render.py | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/display/render.py b/display/render.py index 4f3e286..2c7512e 100644 --- a/display/render.py +++ b/display/render.py @@ -21,10 +21,24 @@ def parse_args(): return args.stats, args.web +def extract_names(data: list): + names = set() + for d in data: + for field in d: + name = name_from_field(field) + names.update([name]) + return names + + def name_from_field(field: str) -> str : if field.startswith("onlyoffice-"): return "onlyoffice" - return field.split("_")[0] + name = field.split("_")[0] + + name = name.replace("org-caracals-", "") + name = name.replace(".caracals.org", "") + return name + def main(): stats_fn, web_render = parse_args() @@ -37,23 +51,27 @@ def load_data(stats_fn: str): with open(stats_fn) as stats_f: data = json.load(stats_f) - data_dict = {name_from_field(field): [0]*len(data) for field in data[0]} - print("Found", len(data), "points") + data_dict = {name_from_field(field): [0]*len(data) for field in extract_names(data)} + print("Found", len(data), "points") + print(" keys:", data_dict.keys()) for t_i, stat in enumerate(data): for field in stat: if field == "date": # date - data_dict[field][t_i] = datetime.strptime(stat[field], "%Y-%m-%dT%H:%M:%S%z") + date_ = stat[field].replace("+01:00", "+0000") + data_dict[field][t_i] = datetime.strptime(date_, "%Y-%m-%dT%H:%M:%S%z") else: # float value = stat[field].split(" ")[0] value = value.replace("MiB", "e3") + value = value.replace("GiB", "e6") data_dict[name_from_field(field)][t_i] += float(value) / 1000 # values are in MiB return data_dict def render(data: dict, web_render:bool=False): - bar_chart = pygal.StackedBar(height=400, legend_box_size=5, x_label_rotation=25) + style = pygal.style.Style(value_label_font_size=5, value_font_size=5, label_font_size=5, legend_font_size=5) + bar_chart = pygal.StackedBar(height=400, x_label_rotation=25, style=style, legend_box_size=5) labels = [d.strftime("%B %d %H:%M") for d in data["date"]] bar_chart.x_labels = labels for k in data: