docker-stats-histo/display/generate_html.py

31 lines
807 B
Python

import sqlite3
import pandas as pd
import plotly.express as px
TABLE_NAME = "stats"
INTERVALS = [50, 100, 1000] # 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")
print(f"Find {len(df)} items")
df["granu"] = 1
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")