From 4d0a0250011d2777d9baf32eb78714472edd6d6c Mon Sep 17 00:00:00 2001 From: Alban Bronisz Date: Wed, 7 Apr 2021 23:45:52 +0200 Subject: [PATCH] Add animation slider --- display/generate_html.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/display/generate_html.py b/display/generate_html.py index 2d2c533..72880da 100644 --- a/display/generate_html.py +++ b/display/generate_html.py @@ -4,7 +4,7 @@ import plotly.express as px TABLE_NAME = "stats" -INTERVAL = 20 # on cron interval is 10min +INTERVALS = [50, 100, 1000] # on cron interval is 10min # Create your connection. @@ -12,10 +12,19 @@ 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") +df["granu"] = 1 -fig = px.area(df, title="Wide-Form Input") +dfs = pd.DataFrame() +for i in INTERVALS: + dfi = df[::i].copy() + dfi["granu"] = i + dfs = dfs.append(dfi) + +print(f"Find {len(dfs)} items") +fig = px.area(dfs, title="Wide-Form Input", animation_frame="granu") fig.for_each_trace(lambda trace: trace.update(fillcolor = trace.line.color)) +fig["layout"].pop("updatemenus") # optional, drop animation buttons +fig.update_layout(transition = {'duration': 1e12}) fig.write_html("stats.html", include_plotlyjs="cdn")