From bb201c83b5323ac8f73b006a34febc286e1a03aa Mon Sep 17 00:00:00 2001 From: Alban Bronisz Date: Wed, 7 Apr 2021 22:38:44 +0200 Subject: [PATCH] Generate plotly html --- display/generate_html.py | 21 +++++++++++++++++++++ display/requirements.txt | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 display/generate_html.py diff --git a/display/generate_html.py b/display/generate_html.py new file mode 100644 index 0000000..2d2c533 --- /dev/null +++ b/display/generate_html.py @@ -0,0 +1,21 @@ +import sqlite3 +import pandas as pd +import plotly.express as px + +TABLE_NAME = "stats" + +INTERVAL = 20 # on cron interval is 10min + + +# Create your connection. +cnx = sqlite3.connect('data.sqlite') + +df = pd.read_sql_query(f"SELECT * FROM {TABLE_NAME}", cnx) +df = df.set_index("date") +df = df[::INTERVAL] +print(f"Find {len(df)} items") + + +fig = px.area(df, title="Wide-Form Input") +fig.for_each_trace(lambda trace: trace.update(fillcolor = trace.line.color)) +fig.write_html("stats.html", include_plotlyjs="cdn") diff --git a/display/requirements.txt b/display/requirements.txt index d11ec07..a0a9f33 100644 --- a/display/requirements.txt +++ b/display/requirements.txt @@ -1,5 +1,5 @@ - +plotly pygal