LoopKit / Loop

An automated insulin delivery app for iOS, built on LoopKit
https://loopdocs.org
Other
1.51k stars 1.3k forks source link

Enhanced Activity Mode Idea #593

Closed rsilvers129 closed 5 years ago

rsilvers129 commented 7 years ago

Yesterday I mountain biked for 4:20:00 in 92 degree weather, I once did a Marathon, and I have done 100+ mile road bike rides-so I get to use activity modes a lot. With a plain pump, I can do great simply by turning basal to 15-20% my normal rate. If I don't do this, I must eat about 30 grams of carb an hour, and that also works, but sometimes I just don't feel like eating/drinking or carrying so much food.

With OpenAPS and Loop, I set an activity-mode target to about 140. Problem is, those modes have never really worked for me unless I eat / drink non-stop. Yesterday for my 4:20 of riding, I had to eat 14 cookies to keep from going low during the ride. That amounts to one Oreo cookie every 20 minutes, or about 30 grams of carb per hour - the same as if I had a pump and did nothing to the settings. So while the activity mode gave me some extra margin of safety, it never really addressed the root problem.

My idea is for Loop to have a new configuration setting where you tell it what percentage of normal basal you want for when activity mode is active. It should accept a value from 0-100%, and I will set mine to 20%. It then reduces basal to this whenever activity mode is on.

eszcloud commented 7 years ago

This response addresses utilizing Loop during long aerobic activities rather than implementation of your idea. (As a reference, Saturday I rode 75 mi with nearly 8k ft of climbing.)

I've had good results by changing insulin sensitivity when I ride, run, hike, etc. in addition to setting a workout target. For cycling, I make my ISF more sensitive to insulin by about 250 %, e.g. 1 u drops by 110 mg/dL instead of 45 mg/dL. For activities such as hiking, I modify ISF less. Changing ISF alone has yielded sufficiently good results for me to focus on cycling, running, hiking, etc., which is where I want my focus to be, rather than tinkering with insulin dosing or ingesting gu to correct.

In this paradigm for cycling specifically, I bolus for some carbs but don't enter all of them and consider the context of what is happening next, e.g. bolusing before a descent > 25 min long but not before or mid-climb.

One note about this approach is that when I have finished the activity, I have nearly no insulin on board, probably some carbs still coming on board, and am also going into a period of decreased insulin sensitivity due to standard post-workout physiology. This combination of effects can lead to very high glucose levels post-workout. To deal with this lack of IOB, I input the number of carbs I've eaten throughout the day (~150 g CHO but often more) and immediately bolus for a portion of that. Not bolusing for everything lets Loop modulate insulin delivery in response to glucose and consequently mitigates post-workout lows.

rsilvers129 commented 7 years ago

I will try that. It sounds like you agree that an activity-mode that changes the target is not going to work. Maybe activity mode should do four things:

Lower basals to W percent of normal. Raise ISF to X times normal. Raise carb ratio to Y times normal. Change target to Z mg/dl.

scottleibrand commented 7 years ago

That sounds very similar to an idea based on a discussion I had with @tepidjuice in https://gitter.im/openaps/oref0, which is to proactively set the autosens ratio used for prospective dosing decisions (but not for retrospective IOB calculations) for the duration of the activity. That effectively sets 1/W == X == Y, and sets Z proportionally as well (as is already done in oref0 if enabled in preferences).

rsilvers129 commented 7 years ago

Great Scott.

1/W == X == Y sounds good to me. It would just come down to which method to describe it to the user. Perhaps one of these two methods:

"Reduce insulin during activity by factor of: (1.0 to 10.0)" 5

or

"Percentage of normal insulin needs during activity (0-100%):" 20

Maybe have both a moderate and heavy activity mode.

Ideally OpenAPS and Loop would do it the same way, and once this is in place, it is one step closer to a movement or HR sensor allowing an automatic mode.

scottleibrand commented 7 years ago

In OpenAPS we use the "% of basal" side of the equation for the autosens ratio, such that a 0.7 (the lowest it'll go automatically by default) represents 70% of normal basal, and 1.2 (the default maximum) represents 120%.

The code for adjusting target based on autosens ratio is https://github.com/openaps/oref0/blob/master/lib/determine-basal/determine-basal.js#L105-L123, so if you wanted to do a ratio of 20% (0.2) for your activity, that would adjust a normal target of 100 to a new_target_bg of 260 (which OpenAPS would then proceed to cap at 200). So more likely if you were adjusting all four things, a bit higher ratio would work better, to get the high temp target to work in tandem with the lower baseline basal to set temp basals near 20%. A ratio of 0.4, for example, would set a target of 160 on a 40% basal.

tepidjuice commented 7 years ago

I've written some, terrible, code which seems to behave as I outlined in https://github.com/openaps/oref0/issues/588. However I've only one rig so I haven't been able to properly test it.

For me at least this method seems to be very effective at controlling bgls during exercise. As it both raises the target and reduces the control action to reach that target.

Currently I manually set autosens.json and the auto_sens_max variable in preferences.json. For example, yesterday, I had roughly three hours of intense activity. I sey autosens.json to 0.4, to drop my IOB more quickly, and the auto_sens_max to 0.7. I stayed between 4.9 mmol/L -- 6.6 mmol/L the entire time.

rsilvers129 commented 7 years ago

Today I tried this concept. I did the following:

  1. Set activity mode, which turned on target of 140.
  2. changed my ISF from 70 to 350.
  3. Changed my carb ratio from 7.5 to 37.5.
  4. Changed my basals from 0.600 to 0.120.
  5. Drank can of V8 (14 grams carb).
  6. Did a bolus. It only gave me 0.2 units.
  7. Went running.
  8. Changed all settings back.

The run and food had no big swings with my glucose.

screen shot 2017-09-27 at 10 39 04 am
jessiepusateri commented 7 years ago

I also wanted to weigh in and say that I have also tried Loop's exercise mode target and it has been very hit and miss.

Yesterday, before working out my blood sugar was 80. I had my exercise target range set to 150-170 and ate 20g before 90 minutes of cardio. I proceeded to skyrocket to 300 and then 4 hours later I was 48. (See the screenshot below.)

However, on Saturday I went on a 5 hour bike ride using exercise mode and things went really well. (I only needed to stop and eat some raisins one time and Loop even corrected to keep me in range when I ate too many.)

I'm sure something must have been up with my sensitivity but I have no idea how I would go about implementing those changes without completing guessing.

screen shot 2017-09-27 at 5 20 32 pm

davidmlb commented 7 years ago

@rsilvers129, I post a new issue with the same idea, i close it now and put here.

Hi, exercise time is something difficult to manage with loop, i Have two options; 1 is open loop and put a temp basal for the exercise time and another is to put a workout mode for the time.

But in fact the exercise time affect the time you’re doing exercise and depending of the exercise several hours after it.

If I open the loop I have not control and if I put the workout mode I have the same sensitivity and the same basal, if I eat something to increase the bg and the Workout mode target is 120-150, the bg begin to rise, but when the bg is in 120 loop put my basal, and probably I need less basal, if I reach loop correct with my current sensitivity and probably is to much…also for the coming hour after exercise.

How do you think is the best way to manage it?

Could be possible to have a Exercise/illness Mode?

could be some screen like that: extime

ps2 commented 7 years ago

It seems to me that implementing a temporary sensitivity scale factor, that would apply to ISF, carb ratios, and basal rates might work better than just a simple target change.

francesc0-cgm commented 7 years ago

Agree

rsilvers129 commented 7 years ago

Those kind of changes worked much better in my test.

elnjensen commented 7 years ago

@jessiepusateri I've found big differences between settings I need for long sustained exercise (distance running) and for more intense, shorter bursts (ultimate frisbee, which has more sprinting interspersed with slower jogging or breaks between points). The latter produces some adrenaline, which keeps BG up more. So that could be part of the difference between your two cases. An activity mode like what's described here would be great, but may work best for sustained workouts (or perhaps could work for both, but with a milder scaling for high-intensity workouts).

rsilvers129 commented 7 years ago

You will just end up finding a scaling factor that works for the kind of workout you do.

eszcloud commented 7 years ago

@rsilvers129 I'm glad that modifying ISF and other values worked well for you!

eszcloud commented 7 years ago

One thing that I've found in all my trials is that timing is critical for getting this approach to work, and the mismatch in the times for these events means that workout mode isn't a one-button event.

I have tried varying the timing to enact the changes and the magnitude of the changes (e.g. implementing both changes at the same time in between the two times here, moving temp target start time earlier/later, moving the change in ISF earlier/later), and this combination was by far the most reliable and successful for me:

 - 1-1.25 h before workout begins:  set temp target  
 - as workout begins:  change ISF to 2.5x(standard ISF)

The window for changing ISF is very small in my experience. Setting it more than 10 min before I leave results in a high that can persist. Setting it much after I leave (>10 min) means that bg will drop (or may be low depending on starting bg, carbs eaten before, etc.). Changing ISF at the start of a workout without having set a temp target in advance is insufficient for mitigating lows in my experience.

Because of the rigidity for modifying ISF, I wouldn't want its to be implemented automatically based on the timing of a temp target because leaving more than 10 min late is a common enough occurrence (e.g. riding buddies hit traffic, there is only one restroom at the start and so a long line ensues, etc.) that I wouldn't want to risk the extreme highs that are difficult to get to drop that result in implementing ISF too soon. As much as I would like to have a single action to do for working out, based on my experience, temporary changes to ISF and carb ratios would need to be separate from enacting temp targets.

rsilvers129 commented 7 years ago

Setting basal to 15-20% of my normal has worked over and over. I have never tested changing carb ratio until today. I ate 100 grams of carb in pancakes before a 1.5 hours bike ride. Instead of telling Loop it was 100 grams of carb, I told it it was 20 grams. It worked. Had it told it 100, I would have needed lots and lots of extra carb to not go low.

So, I am really hoping this feature can go in because now when I run or bike, I do the following:

  1. Activate Activity Mode to raise my target to 140.
  2. Change my basal from 0.650 to 0.1
  3. Change my carb ratio from 7.5 to 50
  4. Change my sensitivity from 75 to 500

Then I have to change everything back.

scottleibrand commented 7 years ago

@jessiepusateri brought this up at the Seattle meetup last night, and it sounds like she might be interested in helping code it up.

It seems like everyone is converging on letting the user configure a temporary sensitivity scale factor, which would function as described above and adjust basals (primarily for IOB calculation), ISF, and CR accordingly while active. Not sure if we’ve discussed whether such a scale factor, if configured, should apply automatically when Workout mode is active, or if it should be a separate toggle.

FWIW, the sensitivityRatio I’ve implemented in oref0 0.6.0-dev since this issue was opened is working well. The main difference would be in the UX for setting the scale factor and activating it. In OpenAPS that is done by setting a high temp target, but in Loop could be configured more directly.

rsilvers129 commented 7 years ago

Oh great. OpenAPS already has this.

Loop could also just activate it when activity mode is on, and for people who don't want this behavior, they could leave the ratio field on the settings page at the default.

eszcloud commented 7 years ago

For implementation, I think it's imperative that enacting a scaling ratio have its own enact button separate from the temp target button and that it be visible on the main page of Loop. That way when looking down at Loop, it's easy to see what Loop's status is, e.g. whether a scaling ratio, temp target, or both are enacted. Having separate buttons would also enable distinct timing to enact or deactivate the settings. I would find this beneficial as the most successful strategy I have found is implementing the changes at different times, e.g. enacting the temp target 1 h in advance of a workout and the scaling factor when a workout commences.

If the scaling button is in the settings page, enacting a temp target and a scaling ratio at separate times would require going into the settings page twice per workout (e.g. once to change it for the workout and then again to change it back to 100 % at the end in preparation for the next workout). Having the implementation of the scaling factor on Loop's home screen and separate from temp targets would mean that it's one less thing to forget or have to keep track of.

Additionally, a distinct button means that the scaling ratio could be used in conjunction with either temp target or on its own. For example, using the scaling ratio with a lower temp target would be useful while flying, taking a medication that temporarily decreases sensitivity, or any number of other events that decrease sensitivity for a period of time. Having a separate button lets people combine temp targets and scaling ratios in combinations and timings that work for them in whatever combination that might be.

jessiepusateri commented 7 years ago

@eszcloud I think that's a good point. Since we're considering a single scaling factor that affects ISF, carb ratios, and basal rates, perhaps we could add a status in the HUD and then have a button at the bottom that leads to a small action menu that is similar to the bolus menu where you can enter the factor and the duration that you want the factor to be active.

I made a mock-up below. (Not sure if we decided upon percentage or decimal for the factor so I just made it decimal for now.)

Also, if we add automatic sensitivity detection (autosens), the "calculated" scaling factor could display in that same HUD section when a user-entered sensitivity isn't active.

Main Page Action Menu
scottleibrand commented 7 years ago

1.0 would be neutral, so I would default it to that when the user first opens the screen. It might also be useful to label it, either on this screen or a confirmation screen. I usually describe it based on the % of normal basal that would be considered neutral.

jessiepusateri commented 7 years ago

Definitely, @scottleibrand. Some explanation like this would make sense.

scottleibrand commented 7 years ago

The challenge is that basals and ISF/CR are adjusted in opposite directions. You have to explain whether the ratio being used is multiplied by basals or by ISF. That’s why I prefer the “percent of basal” framing: ISF is an intuitively “backwards” (or at least confusing) metric.

rsilvers129 commented 7 years ago

The wheel and everything looks good.

Scott put a lot of thought into how to scale it, and it would be good to keep it consistent with OpenAps’s terminology. Plus it is a good way of doing it.

jessiepusateri commented 7 years ago

@scottleibrand Oh right, I forgot that they were inverses. 😛

You're right, the metrics are a little counterintuitive because you'd think if you were "decreasing" your sensitivity factor from 100, you'd be less sensitive but maybe that's unavoidably confusing?

Maybe a visual diagram like this that updates whenever the user inputs a different factor would help?

rsilvers129 commented 7 years ago

I like that. Then people can really see what it is doing.

Need a way to trigger temp target at same time. Maybe two begin buttons. One will begin with existing target. The other will begin and also trigger activity target.

Or one begin button and a checkbox that will toggle on activity target.

rsilvers129 commented 7 years ago

Needs a cancel button also.

mpangburn commented 7 years ago

@jessiepusateri Looks good! I like the display of the basal/ISF/carb ratio changes; it makes the effect really clear. My two cents on some UI stuff to be cohesive with the rest of Loop:

eszcloud commented 7 years ago

@jessiepusateri, nice!

I think that for the duration, it would make sense to have the setup be consistent with the temp target time options of 1 h, 2 h, and indefinitely.

eszcloud commented 7 years ago

For the implementation, if there is a straightforward way to choose which variables the scaling factor will affect (e.g. ISF, carb ratios, and/or basal rates), I recommend making that relatively easy (at least in the code before compiling if not in the settings themselves as is done now, for example, for tailoring the prefilled bolus value on the watch). In the case of working out, I find that basal rates and carb ratios scale quite differently from ISF. In contrast, my experience with a dramatic change in sensitivity due to a medication affected all three variables by the same the scaling factor.

elnjensen commented 7 years ago

@eszcloud Looking at the nice mockup UI from @jessiepusateri above, perhaps there could be little checkbox toggles below each of the three factors along the bottom row there, to indicate whether the changes applied would affect that particular variable. And maybe you have to have them checked in order to edit that factor (greyed out if not) so it would be clear which thing(s) you're changing when enabling this mode.

GlennCoco commented 6 years ago

This is a fantastic idea, well done! Is this something that would be applicable to openAPS as well? I would very much like to be able to do the same thing for different exercise acivitities.

rsilvers129 commented 6 years ago

I think @scottleibrand said OpenAPS already has this. Everyone has their own ideas on what is the most important thing needed, but for me, I would love this enhanced activity mode, and for Loop to better adapt to changing sensitivity needs automatically - like OpenAPS's autosens.

GlennCoco commented 6 years ago

@scottleibrand can you point me in the right direction to use this function? I would like to add it to the docs as well or is this dev branch only?

Kdisimone commented 6 years ago

@glenncoco you should probably ask in the Gitter channel for OpenAPS or Fb Group, as it’s outside the scope of this Loop issue discussion on suggestions for Loop app in particular.

GlennCoco commented 6 years ago

Thanks @Kdisimone, I just realised I was asking in the wrong forum, Cheers.

rsilvers129 commented 6 years ago

Once a way to change sensitivity is internally implemented, then it could be auto-adjusted based on heart rate. Check out how this app does prediction based on HR:

https://itunes.apple.com/us/app/diabits/id965600611?mt=8

rustymonkey commented 6 years ago

Deleted.

kparisella commented 6 years ago

What’s the status of this idea/feature in Loop? Has it been implemented by anyone? Absolutely essential! :)

kparisella commented 6 years ago

If anyone has implemented it or has an interest in it, I’d love to try it or help with developing it if needed.

davidmlb commented 6 years ago

After several tests, best solution for my 9 years old son and 1,5 hours of exercise

0-eat 15-30 Ch gr without inform to loop. 1- change the minimum bg from 75 to 90 2-workout mode fro 100-110 to 110-150 3-change the max basal from 3 to 0.6 ( his basals are aprox from 0,3 to 0.8)

beached commented 6 years ago

I would like profiles with the timing option(Use profile x for 1,2,4,8hrs, indefinite). For me with aerobic, if I do not go to a temp basal/bolus/correction where basal is 1/10 of normal I often find myself dropping 1-2mmol/L in 5min. I would need around 100g CHO just to cover it. Currently I disable loop and use the pump's basal profile and manually adjust other things if I need to eat. This covers it most times but it depends on other factors like glycogen levels. Doing it based on current body movements or HR would not work. I need to plan this at 5hrs and at 2hrs prior or else be in the danger zone.

tqb43 commented 6 years ago

It would be very cool if Loop could take activity tracker data into consideration for ISF. So if Loop saw an increase in activity activity It could automatically adjust the ISF for a certain amount of time after the time of the increased heart rate.

kparisella commented 6 years ago

Yes, an automated adjustment of ISP (and Carb Ratio and Basal) would be ideal. However, since these adjustments should really be made in advance, I’m not quite sure how that would work.

Anyhow, I see that months ago (above) there was a detailed discussion about making a manual % adjustment of all three settings, but I’m not sure if anybody implemented that idea (maybe in their own fork).

After a couple months using Loop, it’s more and more clear to me that I need this feature both for best glucose control and so that the “actual carbs absorbed” calculation in Loop is accurate.

If anybody has implemented this feature somehow, or there’s other progress on it, please let me know.

beached commented 6 years ago

For me, using activity data would be about 2-2.5hrs too late.

diggabyte commented 6 years ago

Edit: Just realized that someone else had already posted about using activity data. Great idea. But yeah, perhaps dynamic changes based on activity are too late to be useful?

shainey commented 6 years ago

Hello all, I am new to Loop and GitHub over the last few months. I was wondering if there are any active efforts to incorporate something like the Apple/Samsung Health Active Energy/Calorie Burn data within the Loop basal adjustment calculations and found this string. For those of us who wear smartwatches to assist in computing the calorie burn off exercising, steps, heart rate, etc. it seems like this would be another valuable element to continue improving this close loop delivery process. A number of apps now have auto detect exercising so it doesn't need to be manually entered too. Here are a couple images of the Apple Health Active Data and a Power BI report I started pulling together to review this type of data for myself. It would be a nice enhancement to have it part of the close loop apps as a proactive process instead of a reactive reviewing of reports which will probably still be needed for parameter adjustment feedback. Any thoughts on this for this group? apple health calorie burn pbi ns and calorie burn

diggabyte commented 6 years ago

@shainey this has been discussed quite a bit. The biggest challenge we've seen (and why this really hasn't been pursued much further) is that by the time activity data is available and we know you are exercising, reducing insulin delivery or raising bg targets is often far too late due to the existing IOB. Most people have to make adjustments 1-2hrs ahead of activity time for any meaningful effect.

We have discussed the possibility of a "carbs predicted" alert that takes activity into account along with all the other factors to recognize an impending low (or rather, then necessity of carbs to offset the trajectory). But that concept hasn't gained a lot of momentum thus far.

shainey commented 6 years ago

@diggabyte What you mention is correct. That being said, it would also be helpful to have these different major glucose impacting elements within the app screen & Nightscout reports to share with parents, Endos, and others to determine better methods to address different exercise types in the future. With a combination of this information, individuals could understand when & how they would need to reduce the basal upfront before exercising depending on the amount of insulin onboard for the user. Lots of math their depending on numerous factors which systems do much better than the typical human guestimates.