Skip to content

feat(core): explainable glucose metrics pack + dashboard patterns - #6

Open
shroominic wants to merge 1 commit into
feat/sim-demo-modefrom
feat/metrics-pack
Open

feat(core): explainable glucose metrics pack + dashboard patterns#6
shroominic wants to merge 1 commit into
feat/sim-demo-modefrom
feat/metrics-pack

Conversation

@shroominic

Copy link
Copy Markdown
Owner

Summary

Implements the explainable metrics pack (TASK-012): pure-Dart glucose analytics plus a wellness-framed dashboard "Patterns" section.

Stacked on #4 (feat/sim-demo-mode). Rebase to main after #4 merges.

Analytics (packages/cgm_core/lib/src/glucose_analytics.dart)

Pure-Dart functions over List<CgmReading>, exported via cgm_core.dart:

  • Time in range / below / above — bucketed against configurable GlucoseRangeBounds (default 70-180 mg/dL ~ 3.9-10 mmol/L)
  • Average (mean mg/dL)
  • Standard deviation (population) + CV (variability %)
  • Estimated GMI — GMI-style indicator from mean (3.31 + 0.02392 * mean), hedged as a rough self-experimentation value, not a lab result
  • Spike count — upward crossings of the high bound, ordered by timestamp
  • Timeframes — 24h / 7d / 14d windowing (readingsInTimeframe, summarize)
  • min / max, null-safe empty results

Dashboard (openhealth/lib/src/metrics_section.dart)

New MetricsSection widget rendering each metric with a one-line plain-language explanation, a 24h/7d/14d segmented selector, and mg/dL <-> mmol/L unit-pref-aware formatting. Insertion into main.dart is minimal and clearly delimited (another wave touches the dashboard). dashboard_chart.dart, demo_driver.dart, and settings untouched.

Wellness framing

Section titled "Patterns" with subtitle "Observations for self-experimentation, not medical metrics." No diagnostic/treatment language; estimated GMI explicitly flagged as not a lab result.

Tests

packages/cgm_core/test/glucose_analytics_test.dart — thorough synthetic-reading unit tests (windowing, average/SD/CV with known-answer series, GMI, spike counting incl. ordering & custom bounds, TIR bucketing & boundary inclusivity, empty/preFiltered paths). All cgm_core + app tests pass; flutter analyze clean for changed files.

Verification

Ran on iPhone 15 Pro simulator with --dart-define=OG_DEMO=true. Screenshot: /tmp/og-metrics.png — shows TIR 100%, below/above 0%/0%, average 118 mg/dL, CV 10% (SD 12 mg/dL), estimated GMI ~6.1%, spikes 0, with the timeframe selector and disclaimer.

Refs: TASK-012

🤖 Generated with Claude Code

Add pure-Dart glucose analytics in cgm_core (glucose_analytics.dart):
time-in-range / below / above, average, SD, CV, estimated GMI-style
indicator, and spike count over 24h/7d/14d windows with configurable
range bounds (default 70-180 mg/dL). Fully unit-tested with synthetic
readings.

Render these in a new explainable, wellness-framed "Patterns" section
on the dashboard (metrics_section.dart) with a timeframe selector, a
one-line plain-language explanation per metric, and unit-pref-aware
formatting. Edits to main.dart are minimal and clearly delimited.

Wellness/self-experimentation framing only: observations and patterns,
not medical metrics or diagnosis.

Refs: TASK-012

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant