2021-04-07 20:38:44 +00:00
|
|
|
import sqlite3
|
|
|
|
import pandas as pd
|
|
|
|
import plotly.express as px
|
|
|
|
|
|
|
|
TABLE_NAME = "stats"
|
|
|
|
|
2021-04-07 21:45:52 +00:00
|
|
|
INTERVALS = [50, 100, 1000] # on cron interval is 10min
|
2021-04-07 20:38:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
# 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")
|
|
|
|
|
2021-04-07 21:45:52 +00:00
|
|
|
df["granu"] = 1
|
2021-04-07 20:38:44 +00:00
|
|
|
|
2021-04-07 21:45:52 +00:00
|
|
|
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")
|
2021-04-07 20:38:44 +00:00
|
|
|
fig.for_each_trace(lambda trace: trace.update(fillcolor = trace.line.color))
|
2021-04-07 21:45:52 +00:00
|
|
|
fig["layout"].pop("updatemenus") # optional, drop animation buttons
|
|
|
|
fig.update_layout(transition = {'duration': 1e12})
|
2021-04-07 20:38:44 +00:00
|
|
|
fig.write_html("stats.html", include_plotlyjs="cdn")
|