Repository navigation
Show daily insulin totals and the usual amount by this time of day - #2601
Merged
Merged
Conversation
People ask for total daily dose stats, and some check in the morning whether the day is running ahead of their usual insulin. The Statistics page gains a Daily Insulin section: average per day, basal and bolus (with the automatic part and the scheduled basal total), today so far, and a chart of each calendar day stacked by basal, automatic bolus and manual bolus. The Insulin Delivery Log adds "usually X U by <time>" under the total since midnight. The usual amount is the median of the last 14 days, each measured from midnight to the same clock time, so meals and dawn-phenomenon basal compare like with like. It needs at least 3 days of history. InsulinDeliveryHistory computes all of these from normalized doses, counting uncovered time at the scheduled basal rate. Today's total now uses it too: the old calculation kept the full volume of any zero-duration bolus in the fetch window, so a logged dose from yesterday evening counted toward today.
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.
People have asked for total daily dose stats in Loop, and some check in the morning whether the day is running ahead of their usual insulin.
Statistics page: new Daily Insulin section
Insulin Delivery Log
How the usual amount works
Calculation
InsulinDeliveryHistorycomputes all of these from normalized doses. Time not covered by a basal record counts at the scheduled basal rate, as the existing total does.totalDeliveredToday()) now uses it too. The old calculation trimmed each dose individually and kept the full volume of zero-duration boluses. A dose logged yesterday evening was still in the display fetch window, so it counted toward today. This may account for some of the Loop-higher-than-Apple-Health reports.Tests: 9 new
InsulinDeliveryHistoryTests:Screenshots are from the simulator with seeded history (the generator overdoses, hence ~64 U/day):