openaps / oref0

oref0: The open reference implementation of the OpenAPS reference design.
http://www.OpenAPS.org
MIT License
428 stars 396 forks source link

skip_neutral_temps prevents SMB's before full hour? #1451

Open mountrcg opened 1 year ago

mountrcg commented 1 year ago

Not really a bug, just a question for clarification. It seems that this part of the code also disables all insReq calculations and hence SMB's every hour at xx:55 until the hour has passed? Is this intended?

mountrcg commented 1 year ago

With people striving for full closed loops, situations like this

2 loop cycles would not administer SMB's due to skip_neutral_temps. May be this can be changed without invalidating the original purpose Set neutral temp basals By default Medtronic pumps beep on the hour when a temporary basal rate is active. Enabling this option can help reduce the number of beeps heard by interupting a temporary basal at the hour change in order to supress the beep. of this option, which at the moment would have to be switched off.

scottleibrand commented 1 year ago

The reason for skip_neutral_temps was to stop the pump beeping or vibrating from them. Every SMB causes a vibration/beep, so the original intended reason to use skip_neutral_temps doesn’t apply with SMB.

What is your use case for it?

mountrcg commented 1 year ago

What we see is that between :55 and :00 every loop cycle skips to calculate insulin required, and therefore cannot issue an SMB, if above option is enabled. So wouldn’t it be better to run the full calculation, in order to get necessary SMBs and than skip neutral temps. At the moment the loop is basically stopped, right?

scottleibrand commented 1 year ago

Why do you care? AFAICT skip_neutral_temps is approximately useless with SMB, so you shouldn’t have it enabled.

mountrcg commented 1 year ago

I just saw one user report it for autoISF branch in iAPS, he has a medtronic and had this option enabled not knowing it has such an impact. if I see a setting that might have a huge impact, which is not really seen from the description of the variable – I just think something needs to be fixed. Oref is just too good to not make it better.

scottleibrand commented 1 year ago

Gotcha. If you want to change the behavior, I would suggest writing a PR to disable skip_neutral_temps when SMB is enabled.

mountrcg commented 1 year ago

wouldn't it make more senso to move the conditional here?

scottleibrand commented 1 year ago

If you want to make the two functions work together, that might be sufficient, but it'd require some testing. I don't see any reason why anyone would want them to work together, so I'd rather disable skip_neutral_temps if SMB is enabled and not have to think about the interaction effects. But if you have a use case for using both, please feel free to test out that potential solution, and please also describe what the scenario is where both are needed.

mountrcg commented 1 year ago

I don’t have a medtronic so no experience with it at all.

But if skipNT‘s is just a cosmetic function to prevent beeping, then why should this „cosmetic function“ not work together with the real stuff? In other words, why is there a use case without SMB for skipNT and not a use case with SMB four you @scottleibrand - or am I missing something about skipNT?

scottleibrand commented 1 year ago

If it’s important enough to you to keep your MDT completely silent, you have to turn off SMBs, because every bolus makes the pump beep or vibrate. Once you’ve done that, you can further eliminate the beeps and vibrations caused by temp basals running at the top of the hour by using the SNT feature. Doing the latter without doing the former doesn’t really make any sense to me.

mountrcg commented 1 year ago

ok, then I put your first suggestion in motion. Thanks Scott.

mountrcg commented 1 year ago

So I suggest just the following:

    // if not in LGS mode, cancel temps before the top of the hour to reduce beeping/vibration
    // console.error(profile.skip_neutral_temps, rT.deliverAt.getMinutes());
    if ( profile.skip_neutral_temps && !enableSMB && rT.deliverAt.getMinutes() >= 55 ) {
        rT.reason += "; Canceling temp at " + (60 - rT.deliverAt.getMinutes()) + "min before turn of the hour to avoid beeping of MDT. SMB disabled anyways.";
        return tempBasalFunctions.setTempBasal(0, 0, profile, rT, currenttemp);
    }

I have enabled sNT

Screenshot 2023-06-26 at 12 57 12

When disabling SMB or the algo disables SMB's sNT kicks in at xx:55 o'clock. I missed screenshotting the clock:

Screenshot 2023-06-26 at 12 55 58

with logoutput (here you see the time), see rT.reason in 4th last log line:

2023-06-26 12:55:12.061311+0200 FreeAPS[50894:17361867] [OpenAPS] JavaScriptWorker.swift - createContext() - 23 DEV: JavaScript log: currenttemp:2 lastTempAge:1m, tempModulus:0m
2023-06-26 12:55:12.061695+0200 FreeAPS[50894:17361867] [OpenAPS] JavaScriptWorker.swift - createContext() - 23 DEV: JavaScript log: profile.sens:54, sens:54, CSF:5.4
2023-06-26 12:55:12.062048+0200 FreeAPS[50894:17361867] [OpenAPS] JavaScriptWorker.swift - createContext() - 23 DEV: JavaScript log: Carb Impact:-3mg/dL per 5m; CI Duration:0hours; remaining CI (1.5h peak):,0mg/dL per 5m
2023-06-26 12:55:12.062787+0200 FreeAPS[50894:17361867] [OpenAPS] JavaScriptWorker.swift - createContext() - 23 DEV: JavaScript log: UAM Impact:-3mg/dL per 5m; UAM Duration:0hours
2023-06-26 12:55:12.063223+0200 FreeAPS[50894:17361867] [OpenAPS] JavaScriptWorker.swift - createContext() - 23 DEV: JavaScript log: minPredBG: 171 minIOBPredBG: 171 minZTGuardBG: 187
2023-06-26 12:55:12.063595+0200 FreeAPS[50894:17361867] [OpenAPS] JavaScriptWorker.swift - createContext() - 23 DEV: JavaScript log:  avgPredBG:187 COB/Carbs:0/0
2023-06-26 12:55:12.064029+0200 FreeAPS[50894:17361867] [OpenAPS] JavaScriptWorker.swift - createContext() - 23 DEV: JavaScript log: autoISF disabled, don't adjust SMB Delivery Ratio
2023-06-26 12:55:12.064399+0200 FreeAPS[50894:17361867] [OpenAPS] JavaScriptWorker.swift - createContext() - 23 DEV: JavaScript log: maxDelta threshold for BG-Jump to allow SMB's set to: 30%
2023-06-26 12:55:12.064757+0200 FreeAPS[50894:17361867] [OpenAPS] JavaScriptWorker.swift - createContext() - 23 DEV: JavaScript log: BG projected to remain above 100 for 240minutes
2023-06-26 12:55:12.065106+0200 FreeAPS[50894:17361867] [OpenAPS] JavaScriptWorker.swift - createContext() - 23 DEV: JavaScript log: naive_eventualBG: 187, bgUndershoot: -117, zeroTempDuration: 240, zeroTempEffect: 443, carbsReq: -104
2023-06-26 12:55:12.065850+0200 FreeAPS[50894:17361867] [OpenAPS] OpenAPS.swift - determineBasal(currentTemp:clock:) - 77 DEV: SUGGESTED: {
    "temp": "absolute",
    "bg": 187,
    "tick": -3,
    "eventualBG": 164,
    "insulinReq": 0,
    "reservoir": 72.28434399902787,
    "deliverAt": "2023-06-26T10:55:12.052Z",
    "sensitivityRatio": 1,
    "TDD": 0.1,
    "insulin": {
        "TDD": 0.1,
        "bolus": 0,
        "temp_basal": 0.1,
        "scheduled_basal": 0
    },
    "predBGs": {
        "IOB": [
            187,
            184,
            182,
            180,
            178,
            176,
            174,
            173,
            172,
            171,
            171,
            171,
            171
        ],
        "ZT": [
            187,
            187,
            187,
            187,
            187,
            188,
            188
        ]
    },
    "COB": 0,
    "IOB": 0,
    "BGI": 0,
    "insulinForManualBolus": 0,
    "deviation": -23,
    "dura_ISFratio": 1,
    "bg_ISFratio": 1,
    "delta_ISFratio": 1,
    "pp_ISFratio": 1,
    "acce_ISFratio": 1,
    "auto_ISFratio": 1,
    "ISF": 54,
    "CR": 10,
    "TDDytd": 43.7,
    "TDD7d": 33.8,
    "target_bg": 100,
    "SMBratio": 0.5,
    "reason": "SMB Del.Ratio:, 0.5, autoISF, disabled, Standard, COB: 0, Dev: -23, BGI: 0, ISF: 54, CR: 10, Target: 100, minPredBG 171, minGuardBG 171, IOBpredBG 171, TDD: Not enough pumpData (< 21h); ; Canceling temp at 5min before turn of the hour to avoid beeping of MDT. SMB disabled anyways.",
    "duration": 0,
    "rate": 0
}

Once SMB is enabled, the regular SMB gets calculated and enacted:

Screenshot 2023-06-26 at 12 56 43

With the following log: "reason": "SMB Del.Ratio:, 0.5, autoISF, disabled, Standard, COB: 0, Dev: -23, BGI: 0, ISF: 54, CR: 10, Target: 100, minPredBG 171, minGuardBG 171, IOBpredBG 171, TDD: Not enough pumpData (< 21h); ; Canceling temp at 5min before turn of the hour to avoid beeping of MDT. SMB disabled anyways.",

mountrcg commented 1 year ago

I cannot test on rigs. If someone else could, this would be great!