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:
@@ -22,6 +22,7 @@ from fpdf.enums import XPos, YPos
|
||||
|
||||
from reporting import (
|
||||
agp_percentile_bands,
|
||||
completeness_warning,
|
||||
gmi_percent,
|
||||
percent_cv,
|
||||
sensor_active_percent,
|
||||
@@ -64,6 +65,13 @@ def _add_summary_section(pdf: FPDF, glucose: pd.DataFrame, start, end) -> None:
|
||||
|
||||
pdf.set_font("Helvetica", "B", 13)
|
||||
pdf.cell(0, 8, "Samenvatting", **_LINE_KWARGS)
|
||||
|
||||
warning = completeness_warning(glucose, start, end)
|
||||
if warning:
|
||||
pdf.set_font("Helvetica", "BI", 10)
|
||||
pdf.multi_cell(0, 5, warning)
|
||||
pdf.ln(2)
|
||||
|
||||
pdf.set_font("Helvetica", "", 11)
|
||||
pdf.cell(0, 6, f"Sensordekking: {active_pct:.0f}%", **_LINE_KWARGS)
|
||||
pdf.cell(0, 6, f"Gemiddelde glucose: {mean_mmol:.1f} mmol/L", **_LINE_KWARGS)
|
||||
|
||||
Reference in New Issue
Block a user