fix: Nightscout API silently truncated multi-day fetches to ~3-4 days
_entries_since/_treatments_since requested a single page via `count`, but Nightscout's /api/v1/entries and /api/v1/treatments ignore a large `count` and cap the response around ~1150/~700 documents regardless of how far back the requested period goes. Every report page relying on fetch_entries_range/fetch_treatments_range (7/14/30/90-day selectors) was silently only getting the most recent ~3-4 days, no matter the selected period. Fixed by paginating with `find[date][$lte]` cursors in a new _paginated_get(), walking back until the requested `since` boundary is reached or the server returns a short/empty page (= genuinely no more data, confirmed by manually paginating against the real instance: entries go back 50+ days, treatments only ~4 days on this install). Also added reporting.completeness_warning(), shared by the interactive pages (via ui_common.render_completeness_warning) and the PDF export, that distinguishes "a structural gap at the start of the period" (data wasn't fetched/available) from "scattered gaps below the clinical AGP coverage threshold" (Danne et al. 2017) — the previous single generic "X% sensor coverage" message read as a CGM/sensor problem even when the real cause was this fetch bug.
This commit is contained in:
@@ -9,7 +9,7 @@ from reporting import (
|
||||
sensor_active_percent,
|
||||
tir_breakdown_5band,
|
||||
)
|
||||
from ui_common import load_range_data, select_period_days
|
||||
from ui_common import load_range_data, render_completeness_warning, select_period_days
|
||||
|
||||
st.set_page_config(page_title="Glucose dashboard — Samenvatting", page_icon="📊", layout="wide")
|
||||
require_auth()
|
||||
@@ -32,12 +32,8 @@ if glucose.empty:
|
||||
st.info("Geen glucosemetingen gevonden in deze periode.")
|
||||
st.stop()
|
||||
|
||||
render_completeness_warning(glucose, start, end)
|
||||
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)
|
||||
|
||||
@@ -6,7 +6,13 @@ 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
|
||||
from ui_common import (
|
||||
get_colors,
|
||||
hex_to_rgba,
|
||||
load_range_data,
|
||||
render_completeness_warning,
|
||||
select_period_days,
|
||||
)
|
||||
|
||||
st.set_page_config(page_title="Glucose dashboard — AGP profiel", page_icon="📊", layout="wide")
|
||||
require_auth()
|
||||
@@ -32,6 +38,8 @@ if glucose.empty:
|
||||
st.info("Geen glucosemetingen gevonden in deze periode.")
|
||||
st.stop()
|
||||
|
||||
render_completeness_warning(glucose, start, end)
|
||||
|
||||
bands = agp_percentile_bands(glucose, bin_minutes=30)
|
||||
colors = get_colors()
|
||||
|
||||
|
||||
@@ -6,7 +6,12 @@ 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
|
||||
from ui_common import (
|
||||
get_colors,
|
||||
load_range_data,
|
||||
render_completeness_warning,
|
||||
select_period_days,
|
||||
)
|
||||
|
||||
st.set_page_config(page_title="Glucose dashboard — Dagoverzicht", page_icon="📊", layout="wide")
|
||||
require_auth()
|
||||
@@ -34,6 +39,8 @@ if glucose.empty:
|
||||
st.info("Geen glucosemetingen gevonden in deze periode.")
|
||||
st.stop()
|
||||
|
||||
render_completeness_warning(glucose, start, end)
|
||||
|
||||
colors = get_colors()
|
||||
glucose = glucose.copy()
|
||||
glucose["date"] = glucose["timestamp"].dt.date
|
||||
|
||||
@@ -7,6 +7,7 @@ from reporting import LOW, VERY_LOW
|
||||
from ui_common import (
|
||||
get_colors,
|
||||
load_range_data,
|
||||
render_completeness_warning,
|
||||
render_event_level,
|
||||
select_period_days,
|
||||
)
|
||||
@@ -36,6 +37,8 @@ if glucose.empty:
|
||||
st.info("Geen glucosemetingen gevonden in deze periode.")
|
||||
st.stop()
|
||||
|
||||
render_completeness_warning(glucose, start, end)
|
||||
|
||||
colors = get_colors()
|
||||
|
||||
render_event_level(glucose, LOW, "below", f"Level 1 (<{LOW} mmol/L)", days, colors)
|
||||
|
||||
@@ -7,6 +7,7 @@ from reporting import HIGH, VERY_HIGH
|
||||
from ui_common import (
|
||||
get_colors,
|
||||
load_range_data,
|
||||
render_completeness_warning,
|
||||
render_event_level,
|
||||
select_period_days,
|
||||
)
|
||||
@@ -35,6 +36,8 @@ if glucose.empty:
|
||||
st.info("Geen glucosemetingen gevonden in deze periode.")
|
||||
st.stop()
|
||||
|
||||
render_completeness_warning(glucose, start, end)
|
||||
|
||||
colors = get_colors()
|
||||
|
||||
render_event_level(glucose, HIGH, "above", f"Level 1 (>{HIGH} mmol/L)", days, colors)
|
||||
|
||||
+8
-1
@@ -12,7 +12,12 @@ from reporting import (
|
||||
overnight_daytime_split,
|
||||
site_interval_stats,
|
||||
)
|
||||
from ui_common import get_colors, load_range_data, select_period_days
|
||||
from ui_common import (
|
||||
get_colors,
|
||||
load_range_data,
|
||||
render_completeness_warning,
|
||||
select_period_days,
|
||||
)
|
||||
|
||||
st.set_page_config(page_title="Glucose dashboard — Trends", page_icon="📊", layout="wide")
|
||||
require_auth()
|
||||
@@ -35,6 +40,8 @@ if glucose.empty:
|
||||
st.info("Geen glucosemetingen gevonden in deze periode.")
|
||||
st.stop()
|
||||
|
||||
render_completeness_warning(glucose, start, end)
|
||||
|
||||
colors = get_colors()
|
||||
events = classify_treatments(treatments)
|
||||
|
||||
|
||||
+3
-1
@@ -5,7 +5,7 @@ from auth import require_auth
|
||||
from nightscout_client import NightscoutConfigError
|
||||
from pdf_export import AVAILABLE_SECTIONS, SECTION_EVENTS, build_report_pdf
|
||||
from reporting import HIGH, LOW, VERY_HIGH, VERY_LOW, detect_events, summarize_events
|
||||
from ui_common import load_range_data, select_period_days
|
||||
from ui_common import load_range_data, render_completeness_warning, select_period_days
|
||||
|
||||
st.set_page_config(page_title="Glucose dashboard — Export", page_icon="📊", layout="wide")
|
||||
require_auth()
|
||||
@@ -29,6 +29,8 @@ if glucose.empty:
|
||||
st.info("Geen glucosemetingen gevonden in deze periode.")
|
||||
st.stop()
|
||||
|
||||
render_completeness_warning(glucose, start, end)
|
||||
|
||||
events_summary = {}
|
||||
if SECTION_EVENTS in sections:
|
||||
levels = {
|
||||
|
||||
Reference in New Issue
Block a user