add Samenvatting and AGP Profiel pages (FR2, FR3, FR9)
Wires reporting.py's stats into two new pages: a summary panel (data completeness, GMI, %CV, 5-band time-in-range vs. consensus targets) and the standard AGP percentile chart (5th-95th and 25th-75th bands plus median, aggregated by time-of-day across the selected period). Co-Authored-By: Claude Sonnet 5 <[email protected]>
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
import requests
|
||||
import streamlit as st
|
||||
|
||||
from auth import require_auth
|
||||
from nightscout_client import NightscoutConfigError
|
||||
from reporting import (
|
||||
gmi_percent,
|
||||
percent_cv,
|
||||
sensor_active_percent,
|
||||
tir_breakdown_5band,
|
||||
)
|
||||
from ui_common import load_range_data, select_period_days
|
||||
|
||||
st.set_page_config(page_title="Glucose dashboard — Samenvatting", page_icon="📊", layout="wide")
|
||||
require_auth()
|
||||
|
||||
st.title("Samenvatting")
|
||||
st.caption("AGP-stijl samenvattingsstatistieken over een gekozen periode (FR2, FR9).")
|
||||
|
||||
start, end, days = select_period_days(default_label="90 dagen")
|
||||
|
||||
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()
|
||||
|
||||
active_pct = sensor_active_percent(glucose, start, end)
|
||||
if active_pct < 70:
|
||||
st.warning(
|
||||
f"Slechts {active_pct:.0f}% sensordekking in deze periode (streefwaarde ≥70%). "
|
||||
"De onderstaande cijfers zijn mogelijk minder betrouwbaar door de vele hiaten."
|
||||
)
|
||||
|
||||
mean_mmol = glucose["mmol"].mean()
|
||||
gmi = gmi_percent(mean_mmol)
|
||||
cv = percent_cv(glucose)
|
||||
tir = tir_breakdown_5band(glucose)
|
||||
|
||||
st.subheader("Kerncijfers")
|
||||
col1, col2, col3, col4 = st.columns(4)
|
||||
col1.metric("Sensordekking", f"{active_pct:.0f}%", help="Streefwaarde: ≥70%")
|
||||
col2.metric("Gemiddelde glucose", f"{mean_mmol:.1f} mmol/L")
|
||||
col3.metric("Geschat HbA1c (GMI)", f"{gmi:.1f}%", help="Bergenstal et al. 2018 — geen labwaarde")
|
||||
col4.metric("Variabiliteit (%CV)", f"{cv:.0f}%", help="Streefwaarde: ≤36%")
|
||||
|
||||
st.subheader("Tijd in bereik (5 klinische banden)")
|
||||
band_labels = {
|
||||
"very_low": "Zeer laag (<3.0)",
|
||||
"low": "Laag (3.0-3.9)",
|
||||
"in_range": "In bereik (3.9-10.0)",
|
||||
"high": "Hoog (10.0-13.9)",
|
||||
"very_high": "Zeer hoog (>13.9)",
|
||||
}
|
||||
band_targets = {
|
||||
"very_low": "<1%",
|
||||
"low": "<4% (samen met zeer laag)",
|
||||
"in_range": ">70%",
|
||||
"high": "<25% (samen met zeer hoog)",
|
||||
"very_high": "<5%",
|
||||
}
|
||||
cols = st.columns(5)
|
||||
for col, band in zip(cols, band_labels, strict=True):
|
||||
col.metric(band_labels[band], f"{tir[band]:.0f}%", help=f"Streefwaarde: {band_targets[band]}")
|
||||
|
||||
st.caption(
|
||||
f"Periode: {start.strftime('%d-%m-%Y')} t/m {end.strftime('%d-%m-%Y')} "
|
||||
f"({len(glucose)} metingen) · streefwaarden volgens Battelino et al. 2019"
|
||||
)
|
||||
@@ -0,0 +1,100 @@
|
||||
import plotly.graph_objects as go
|
||||
import requests
|
||||
import streamlit as st
|
||||
|
||||
from auth import require_auth
|
||||
from data_processing import TARGET_HIGH, TARGET_LOW
|
||||
from nightscout_client import NightscoutConfigError
|
||||
from reporting import agp_percentile_bands
|
||||
from ui_common import get_colors, hex_to_rgba, load_range_data, select_period_days
|
||||
|
||||
st.set_page_config(page_title="Glucose dashboard — AGP profiel", page_icon="📊", layout="wide")
|
||||
require_auth()
|
||||
|
||||
st.title("AGP profiel")
|
||||
st.caption(
|
||||
"Percentielgrafiek over een samengesteld 24-uursbeeld (FR3) — de 5e/25e/50e/75e/"
|
||||
"95e percentiel van alle metingen op elk tijdstip van de dag in de gekozen periode."
|
||||
)
|
||||
|
||||
start, end, days = select_period_days(default_label="90 dagen")
|
||||
|
||||
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()
|
||||
|
||||
bands = agp_percentile_bands(glucose, bin_minutes=30)
|
||||
colors = get_colors()
|
||||
|
||||
hours = bands["minute_of_day"] / 60
|
||||
|
||||
fig = go.Figure()
|
||||
fig.add_hrect(y0=TARGET_LOW, y1=TARGET_HIGH, fillcolor=colors["band"], line_width=0, layer="below")
|
||||
|
||||
# 5e-95e percentiel als brede, lichte band.
|
||||
fig.add_trace(
|
||||
go.Scatter(x=hours, y=bands["p95"], mode="lines", line={"width": 0}, showlegend=False, hoverinfo="skip")
|
||||
)
|
||||
fig.add_trace(
|
||||
go.Scatter(
|
||||
x=hours,
|
||||
y=bands["p5"],
|
||||
mode="lines",
|
||||
line={"width": 0},
|
||||
fill="tonexty",
|
||||
fillcolor=colors["band"],
|
||||
name="5e-95e percentiel",
|
||||
hoverinfo="skip",
|
||||
)
|
||||
)
|
||||
# 25e-75e percentiel als smallere, donkerdere band.
|
||||
fig.add_trace(
|
||||
go.Scatter(x=hours, y=bands["p75"], mode="lines", line={"width": 0}, showlegend=False, hoverinfo="skip")
|
||||
)
|
||||
fig.add_trace(
|
||||
go.Scatter(
|
||||
x=hours,
|
||||
y=bands["p25"],
|
||||
mode="lines",
|
||||
line={"width": 0},
|
||||
fill="tonexty",
|
||||
fillcolor=hex_to_rgba(colors["glucose"], 0.3),
|
||||
name="25e-75e percentiel",
|
||||
hoverinfo="skip",
|
||||
)
|
||||
)
|
||||
# Mediaan.
|
||||
fig.add_trace(
|
||||
go.Scatter(
|
||||
x=hours,
|
||||
y=bands["p50"],
|
||||
mode="lines",
|
||||
line={"color": colors["glucose"], "width": 2},
|
||||
name="Mediaan",
|
||||
hovertemplate="%{x:.0f}u · %{y:.1f} mmol/L<extra></extra>",
|
||||
)
|
||||
)
|
||||
|
||||
fig.update_layout(
|
||||
paper_bgcolor="rgba(0,0,0,0)",
|
||||
plot_bgcolor="rgba(0,0,0,0)",
|
||||
font_color=colors["text"],
|
||||
legend={"orientation": "h", "yanchor": "bottom", "y": 1.02, "xanchor": "left", "x": 0},
|
||||
margin={"l": 10, "r": 10, "t": 10, "b": 10},
|
||||
height=480,
|
||||
yaxis={"title": "mmol/L", "gridcolor": colors["grid"], "zeroline": False},
|
||||
xaxis={"title": "Uur van de dag", "gridcolor": colors["grid"], "tickmode": "linear", "dtick": 2},
|
||||
)
|
||||
st.plotly_chart(fig, width="stretch")
|
||||
st.caption(
|
||||
f"Periode: {start.strftime('%d-%m-%Y')} t/m {end.strftime('%d-%m-%Y')} ({len(glucose)} metingen)"
|
||||
)
|
||||
Reference in New Issue
Block a user