Add rolling-average trend line to meal statistics chart#34
Open
Sjoerd-Bo3 wants to merge 5 commits into
Open
Conversation
Overlay the same centered rolling-average trend line on the Macro Nutrients bar chart in Statistics > Meals, reusing the helpers added for the insulin charts. The line tracks total carbs, or carbs + fat + protein when FPU conversion is enabled, and a Rolling average legend entry is added.
Add a debug-only slider on the Statistics insulin and meal tabs to adjust the rolling-average window live, so the smoothing can be tuned on TestFlight builds without rebuilding. - Persist the override via @AppStorage under a shared key in StatChartUtils (0 = automatic per-interval default, 1 = no smoothing, higher = smoother). - Add an override-aware rollingAverageWindow(for:override:) helper and route the TDD, bolus, and meal charts through it. - Show a labelled debug card with the slider on the insulin and meal tabs. Note: the control is intentionally always visible (there is no UI to toggle the app's developer options) and should be gated or removed before merging to the release branch.
Address correctness and stability issues with the rolling-average trend line: - Time-windowed average: window is now defined in calendar time (not array index), so gaps (days with no bolus/meal) no longer distort the result. Previously it averaged data points, over-counting active days. - Switch interpolation catmullRom -> monotone to stop the line overshooting past the data into misleading bumps. - Add debug toggles (Statistics insulin/meal tabs) to compare live on TestFlight: rolling median vs mean (outlier robustness), counting empty days as zero (true per-day average), and a carry-over lead-in. - Carry-over: persist a per-metric summary of the oldest retained days and use it to pad the leading edge so the average isn't one-sided at the 90-day purge boundary. Refreshed whenever stats are recomputed; never drawn as a bar. Note: the debug toggles are intentionally always visible for Build testing and should be gated or removed before merging to the release branch.
The Stat module uses explicit Xcode file references (not a synchronized group), so the standalone RollingAverageCarryOver.swift was never compiled, causing 'no member updateMealCarryOver / tddCarryOverValue' archive errors. Move the carry-over extension into StatStateModel.swift, which is already referenced by the project.
Sjoerd-Bo3
force-pushed
the
claude/insulin-charts-rolling-average-bbc2sb
branch
from
June 16, 2026 10:32
d14e669 to
64aca90
Compare
Sjoerd-Bo3
force-pushed
the
claude/meals-chart-rolling-average
branch
from
June 16, 2026 10:32
912d79c to
06d5510
Compare
Sjoerd-Bo3
pushed a commit
that referenced
this pull request
Jun 16, 2026
Sync the Build branch up to upstream nightscout/Trio dev (0.8.2.1), while preserving the fork-specific features and the rolling-average trend-line work (insulin + meal charts, debug slider, gap-correct/robust averaging, carry-over lead-in) already on Build. Resolved one conflict in Localizable.xcstrings (kept the fork's extra string keys). The Statistics feature files are identical to the rebased PR branches #33 and #34.
- Selection popovers (TDD, bolus, meal) now also show the rolling-average (trend) value at the scrubbed point, matching the dashed line. Each chart computes its rolling-average points once (shared by the line and the popover), and RollingAveragePoint carries its original bar date so the value at the scrubbed bar can be looked up via StatChartUtils.rollingAverageValue(at:). - Default the rolling-average window to 21 days for the week/month/3M charts (day view keeps 3 hours), computed over the full retained daily series for a smoother trend. - Raise the debug smoothing-window slider max from 21 to 60.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Extends the rolling-average trend line to the Macro Nutrients chart in Statistics → Meals, matching the insulin charts.
The dashed line tracks total carbs, or carbs + fat + protein when FPU conversion is enabled (so it stays consistent with the stacked bars actually shown), plus a "Rolling average" legend entry.
This PR is stacked on top of #33 (
claude/insulin-charts-rolling-average-bbc2sb) because it reuses theStatChartUtilsrolling-average helpers introduced there. Its base branch is set to that branch so the diff shows only the Meals change.Merge #33 first, then this PR (GitHub will auto-retarget it to
dev). Alternatively, if you'd prefer this as a single combined PR with #33, let me know and I'll consolidate.What changed
MealStatsView: overlay the dashedLineMark(catmullRom interpolation,Color.primary) over the macro bars, and add a "Rolling average" entry to the legend.No data-layer or helper changes — it relies entirely on the helpers added in #33.
Test plan
🤖 Generated with Claude Code
Generated by Claude Code