-
Notifications
You must be signed in to change notification settings - Fork 394
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
halfBasalExerciseTarget and lowTT settings can lead to negative ISF and Basal #1401
Comments
There are several possibilities to arrive at denominator of 0 in marked formula. |
Following the comment of OpenAPS not allowing TTs lower than 80, updated the example numbers |
I've confirmed the behavior described. The half_basal_exercise_target was never intended to be set that low, nor tested at such low values. I would prefer that we set a hard-coded minimum value for half_basal_exercise_target. Since the minimum temp target is hard-coded to 80 mg/dL, and the normalTarget is hard-coded to 100 mg/dL, a minimum value of >120 mg/dL for half_basal_exercise_target is required. If it's set lower than that, should we automatically bump it up to 130 or 125 mg/dL? |
@scottleibrand I'm using halfBasal of 110 and TT of 144 to get sensitivity ratio down to ~20% |
alternatively we can do |
Feel free to submit an alternative PR if you have specific code tweaks you think would work better. |
getting multiplication less or equal to 0 means that we have a really low target with a really low halfBasalTarget with low TT and lowTTlowersSensitivity we need autosens_max as a value we use multiplication instead of the division to avoid "division by zero error"
I've added my PR as I'm using a low halfBasal to be able to get to even lower ratio than 50% without using a really high TT when workout |
@scottleibrand, hello! result of halfBasalTarget 100 with normalTarget 100 in a browser console: result of halfBasalTarget 110 with normalTarget 100 in a browser console: We can see, that sensitivityRatio is 1.2. My prefrences.json on openaps: The result with target_bg 80, halfBasalTarget 100 on openaps log: I can not see dividing by zero. |
Is #1403 your preferred solution, or is there another change you'd rather make? |
getting multiplication less or equal to 0 means that we have a really low target with a really low halfBasalTarget with low TT and lowTTlowersSensitivity we need autosens_max as a value we use multiplication instead of the division to avoid "division by zero error"
When we set halfBasalExerciseTarget to (for example) 110 and lowTempTarget of 80, the sensitivityRatio is negative
halfBasal of 100 leads to sensitivity of 0
the code with the calculations is in determine-basal.js:
https://github.com/openaps/oref0/blob/master/lib/determine-basal/determine-basal.js#L209
formula is (halfBasalTarget - 100) / (halfBasalTarget - 100 + target - 100)
in the situation mentioned above we get (110 - 100) / (110 - 100 + 80 - 100) = 10 / (-10) = -1
that leads to negative basal and ISF and calculations are all wrong
setting halfBasal to 100 leads to ratio = 0.0 and thus when we calculate ISF, we divide the original ISF by the ratio, so divide by zero
this can happen only on low TT because the numerator is almost guaranteed to be above 0 and with the denominator of
halfBasalTarget + target - 200 we get negative results only with low targets
and low TT usually require low sensitivity, so we may set it as a max available value in preferences
I suggest we add the check after the
sensitivityRatio = Math.min(sensitivityRatio, profile.autosens_max);
as follows:if (sensitivityRatio <= 0.0) sensitivityRatio = profile.autosens_max;
To Reproduce
Steps to reproduce the behavior:
the second issue:
Expected behavior
With low TT the ratio needs to be high
Smartphone (please complete the following information):
Setup Information (please complete the following information):
The text was updated successfully, but these errors were encountered: