Add TIR bar/threshold lines, Dagoverzicht charts, and hypo/hyper Level-1 charts to PDF export

Closes gitea #14 (PDF part), #15 (PDF part), #16, #17, #18.
This commit is contained in:
2026-08-01 22:33:45 +02:00
parent 00fb81b283
commit 441bb84212
2 changed files with 197 additions and 4 deletions
+52 -1
View File
@@ -2,7 +2,14 @@ from datetime import date
import pandas as pd
from pdf_export import SECTION_AGP, SECTION_EVENTS, SECTION_SUMMARY, build_report_pdf
from pdf_export import (
DAGOVERZICHT_MAX_DAYS,
SECTION_AGP,
SECTION_DAGOVERZICHT,
SECTION_EVENTS,
SECTION_SUMMARY,
build_report_pdf,
)
def _sample_glucose():
@@ -10,6 +17,15 @@ def _sample_glucose():
return pd.DataFrame({"timestamp": timestamps, "mmol": [6.0 + (i % 5) for i in range(48)]})
def _glucose_with_hypo_and_hyper_events():
"""3 dagen data met een echte hypo- (<3.9, >=15 min) en hyperepisode (>10.0)."""
timestamps = pd.date_range("2026-01-01", periods=3 * 24 * 12, freq="5min")
values = [7.0] * len(timestamps)
values[10:15] = [3.0] * 5 # 25 min hypo
values[100:106] = [12.0] * 6 # 30 min hyper
return pd.DataFrame({"timestamp": timestamps, "mmol": values})
def test_build_report_pdf_produces_valid_pdf_bytes():
glucose = _sample_glucose()
events_summary = {
@@ -39,3 +55,38 @@ def test_build_report_pdf_handles_no_sections_selected():
glucose = _sample_glucose()
pdf_bytes = build_report_pdf([], glucose, {}, date(2026, 1, 1), date(2026, 1, 2))
assert pdf_bytes.startswith(b"%PDF")
def test_build_report_pdf_includes_dagoverzicht_section():
glucose = _sample_glucose()
pdf_bytes = build_report_pdf(
[SECTION_DAGOVERZICHT], glucose, {}, date(2026, 1, 1), date(2026, 1, 2)
)
assert pdf_bytes.startswith(b"%PDF")
assert len(pdf_bytes) > 500
def test_build_report_pdf_caps_dagoverzicht_at_max_days():
timestamps = pd.date_range("2026-01-01", periods=(DAGOVERZICHT_MAX_DAYS + 10) * 24, freq="1h")
glucose = pd.DataFrame({"timestamp": timestamps, "mmol": [7.0] * len(timestamps)})
pdf_bytes = build_report_pdf(
[SECTION_DAGOVERZICHT],
glucose,
{},
timestamps[0].date(),
timestamps[-1].date(),
)
assert pdf_bytes.startswith(b"%PDF")
def test_build_report_pdf_draws_hypo_and_hyper_charts_when_events_present():
glucose = _glucose_with_hypo_and_hyper_events()
events_summary = {
"Hypo Level 1": {"count": 1, "avg_duration_minutes": 25.0, "events_per_week": 2.3},
"Hyper Level 1": {"count": 1, "avg_duration_minutes": 30.0, "events_per_week": 2.3},
}
pdf_bytes = build_report_pdf(
[SECTION_EVENTS], glucose, events_summary, date(2026, 1, 1), date(2026, 1, 4)
)
assert pdf_bytes.startswith(b"%PDF")
assert len(pdf_bytes) > 500