Fix bolus/basal insulin categorization: split SMB from manual corrections, add basal calc
AndroidAPS records an automatic SMB micro-bolus as eventType "Correction Bolus" with type "SMB", not as its own eventType. bolus_stats() was grouping by eventType alone, so every SMB was silently counted as a manual correction bolus. Verified against production data: 100% of "Correction Bolus" treatments over 90 days were actually type=SMB. Also adds basal_stats(), computing delivered basal directly from Temp Basal treatments (rate x duration) without needing the pump profile. Closes gitea #20.
This commit is contained in:
+17
-9
@@ -6,6 +6,7 @@ from auth import require_auth
|
||||
from data_processing import classify_treatments
|
||||
from nightscout_client import NightscoutConfigError
|
||||
from reporting import (
|
||||
basal_stats,
|
||||
bolus_stats,
|
||||
day_of_week_pattern,
|
||||
gmi_percent,
|
||||
@@ -93,18 +94,25 @@ if not weekday_plot.empty:
|
||||
)
|
||||
st.plotly_chart(fig, width="stretch")
|
||||
|
||||
# --- FR8: bolus-insuline --------------------------------------------------
|
||||
st.subheader("Bolus-insuline")
|
||||
# --- FR8: insuline (basaal + bolus-uitsplitsing) ---------------------------
|
||||
st.subheader("Insuline")
|
||||
st.caption(
|
||||
"Alleen bolusinsuline (maaltijd/correctie/combo/SMB) — basaalinsuline vereist "
|
||||
"profielgegevens en is hier niet in verwerkt (zie docs/design-reporting.md)."
|
||||
"Basaal berekend uit Temp Basal-treatments (snelheid x duur), zonder pompprofiel "
|
||||
"nodig — een ondergrens bij periodes zonder actieve temp basal. Boluses "
|
||||
"opgesplitst naar voeding, handmatige correctie en automatische SMB-microbolus "
|
||||
"(gitea #20)."
|
||||
)
|
||||
bolus = bolus_stats(treatments)
|
||||
col1, col2 = st.columns(2)
|
||||
col1.metric("Totaal bolus", f"{bolus['total_units']:.1f} E")
|
||||
col2.metric("Aantal boluses", bolus["count"])
|
||||
if bolus["by_type"]:
|
||||
st.table({"type": list(bolus["by_type"].keys()), "eenheden": list(bolus["by_type"].values())})
|
||||
basal = basal_stats(treatments, days)
|
||||
total_units = bolus["total_units"] + basal["total_units"]
|
||||
col1, col2, col3 = st.columns(3)
|
||||
col1.metric("Totaal insuline", f"{total_units:.1f} E")
|
||||
col2.metric("Gem. per dag", f"{total_units / days:.1f} E")
|
||||
col3.metric("Aantal boluses", bolus["count"])
|
||||
|
||||
breakdown = {"Basaal": basal["total_units"], **bolus["by_type"]}
|
||||
if any(breakdown.values()):
|
||||
st.table({"Categorie": list(breakdown.keys()), "Eenheden": list(breakdown.values())})
|
||||
|
||||
# --- FR8: pompsite-leeftijd vs. glucose/insuline ---------------------------
|
||||
st.subheader("Pompsite-leeftijd vs. glucose en insuline")
|
||||
|
||||
Reference in New Issue
Block a user