add Dagoverzicht, Hypo Events, and Hyper Events pages (FR4, FR5, FR6)
Dagoverzicht stacks one glucose trace per calendar day (small multiples via a shared 0-24h x-axis). The two event pages share a new render_event_level() helper in ui_common.py so Level 1/Level 2 hypo and hyper are rendered identically: count/avg/longest/events-per-week metrics, a time-of-day histogram, and a table of individual events. Co-Authored-By: Claude Sonnet 5 <[email protected]>
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
import plotly.graph_objects as go
|
||||
import requests
|
||||
import streamlit as st
|
||||
from plotly.subplots import make_subplots
|
||||
|
||||
from auth import require_auth
|
||||
from data_processing import TARGET_HIGH, TARGET_LOW
|
||||
from nightscout_client import NightscoutConfigError
|
||||
from ui_common import get_colors, load_range_data, select_period_days
|
||||
|
||||
st.set_page_config(page_title="Glucose dashboard — Dagoverzicht", page_icon="📊", layout="wide")
|
||||
require_auth()
|
||||
|
||||
st.title("Dagoverzicht")
|
||||
st.caption("Eén glucosegrafiek per kalenderdag (FR4).")
|
||||
|
||||
start, end, days = select_period_days(default_label="14 dagen")
|
||||
if days > 31:
|
||||
st.info(
|
||||
"Bij langere periodes wordt de pagina lang en kan laden traag zijn — "
|
||||
"voor het bekijken van individuele dagen is 14 of 30 dagen prettiger."
|
||||
)
|
||||
|
||||
try:
|
||||
glucose, _treatments = load_range_data(start, end)
|
||||
except NightscoutConfigError as exc:
|
||||
st.error(str(exc))
|
||||
st.stop()
|
||||
except (requests.RequestException, ValueError) as exc:
|
||||
st.error(f"Kon geen data ophalen van Nightscout: {exc}")
|
||||
st.stop()
|
||||
|
||||
if glucose.empty:
|
||||
st.info("Geen glucosemetingen gevonden in deze periode.")
|
||||
st.stop()
|
||||
|
||||
colors = get_colors()
|
||||
glucose = glucose.copy()
|
||||
glucose["date"] = glucose["timestamp"].dt.date
|
||||
glucose["hour"] = glucose["timestamp"].dt.hour + glucose["timestamp"].dt.minute / 60
|
||||
|
||||
dates = sorted(glucose["date"].unique())
|
||||
row_height = 150
|
||||
fig = make_subplots(
|
||||
rows=len(dates),
|
||||
cols=1,
|
||||
shared_xaxes=True,
|
||||
subplot_titles=[d.strftime("%A %d-%m-%Y") for d in dates],
|
||||
vertical_spacing=min(0.4 / max(len(dates) - 1, 1), 0.05),
|
||||
)
|
||||
|
||||
for i, day in enumerate(dates, start=1):
|
||||
day_df = glucose[glucose["date"] == day]
|
||||
fig.add_hrect(
|
||||
y0=TARGET_LOW, y1=TARGET_HIGH, fillcolor=colors["band"], line_width=0, layer="below", row=i, col=1
|
||||
)
|
||||
fig.add_trace(
|
||||
go.Scatter(
|
||||
x=day_df["hour"],
|
||||
y=day_df["mmol"],
|
||||
mode="lines",
|
||||
line={"color": colors["glucose"], "width": 2},
|
||||
showlegend=False,
|
||||
hovertemplate="%{y:.1f} mmol/L<extra></extra>",
|
||||
),
|
||||
row=i,
|
||||
col=1,
|
||||
)
|
||||
fig.update_yaxes(title_text="mmol/L", gridcolor=colors["grid"], row=i, col=1)
|
||||
|
||||
fig.update_xaxes(title_text="Uur van de dag", range=[0, 24], dtick=4, gridcolor=colors["grid"])
|
||||
fig.update_layout(
|
||||
paper_bgcolor="rgba(0,0,0,0)",
|
||||
plot_bgcolor="rgba(0,0,0,0)",
|
||||
font_color=colors["text"],
|
||||
height=row_height * len(dates),
|
||||
showlegend=False,
|
||||
margin={"l": 10, "r": 10, "t": 30, "b": 10},
|
||||
)
|
||||
st.plotly_chart(fig, width="stretch")
|
||||
st.caption(f"{len(dates)} dagen · {len(glucose)} metingen")
|
||||
Reference in New Issue
Block a user