Skip to content

Conversation

@scottleibrand
Copy link
Contributor

@scottleibrand scottleibrand commented Sep 7, 2017

Currently autotune categorizes glucose deviations data into buckets based on what is impacting things the most: basals, carbs, or insulin. It uses the mealtime data to calculate CSF, the IOB-without-COB data to calculate ISF, and then the remainder to adjust basals. This works fairly well, but due to the fuzzy line between carb-dominated and insulin-dominated deviations after a meal, it tends to overestimate ISF. CR is calculated as ISF/CSF, so that tends to be overestimated as well.

As an alternative, this change calculates CR directly. To do so, we use the BG and IOB at the time of carb entry, the BG and IOB after COB==0 and IOB is back down to low level, the total amount of carbs given, and the total amount of insulin given over the meal period. After adjusting for the BG and IOB changes, that allows a direct calculation of carb ratio as total carbs / total insulin at mealtime.

Additionally, this change adds some more error checking around bad carb ratios (falling back to the pump profile carb ratio if needed), and avoids setting new ISF, CSF, or CRs unless the new ones are valid. These should help with the occasional situation where someone's autotune gets messed up and their rig stops looping just after midnight.

@scottleibrand scottleibrand added this to the 0.6.0 milestone Sep 7, 2017
@scottleibrand
Copy link
Contributor Author

Additionally, some hours of the day rarely have data to tune basals due to meals.
When we don't have any data to tune a particular hour's basals, we should adjust it slightly toward the average of the surrounding periods that do have data. This smooths out the big fluctuations we otherwise see in mealtime basals and ensures that they are tuned based on the best data we have from non-meal times before and afterward.

@scottleibrand scottleibrand changed the title Autotune: calculate CR directly, and use CR*CSF to help calculate ISF Autotune: calculate CR directly Sep 10, 2017
@scottleibrand scottleibrand merged commit 9e78f10 into 0.6.0-dev Sep 10, 2017
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.

2 participants