diff --git a/bin/oref0-autosens-loop.sh b/bin/oref0-autosens-loop.sh index 4534668cf..a811d68e3 100755 --- a/bin/oref0-autosens-loop.sh +++ b/bin/oref0-autosens-loop.sh @@ -13,7 +13,7 @@ main() { autosens 2>&1 touch /tmp/autosens-completed - echo Completed oref0-autons-loop at $(date) + echo Completed oref0-autosens-loop at $(date) } usage "$@" < 12) { + console.error("Found at least 1h of carb absorption: assuming all meals were announced, and categorizing UAM data as basal."); basalGlucoseData = basalGlucoseData.concat(UAMGlucoseData); } else { if (2*basalLength < UAMLength) { diff --git a/lib/determine-basal/determine-basal.js b/lib/determine-basal/determine-basal.js index 2c12ad2fb..599dd8abe 100644 --- a/lib/determine-basal/determine-basal.js +++ b/lib/determine-basal/determine-basal.js @@ -439,14 +439,22 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_ ci = round((minDelta - bgi),1); var uci = round((minDelta - bgi),1); // ISF (mg/dL/U) / CR (g/U) = CSF (mg/dL/g) - if (profile.temptargetSet) { + + // TODO: remove commented-out code for old behavior + //if (profile.temptargetSet) { // if temptargetSet, use unadjusted profile.sens to allow activity mode sensitivityRatio to adjust CR - var csf = profile.sens / profile.carb_ratio; - } else { + //var csf = profile.sens / profile.carb_ratio; + //} else { // otherwise, use autosens-adjusted sens to counteract autosens meal insulin dosing adjustments // so that autotuned CR is still in effect even when basals and ISF are being adjusted by autosens - csf = sens / profile.carb_ratio; - } + //var csf = sens / profile.carb_ratio; + //} + // use autosens-adjusted sens to counteract autosens meal insulin dosing adjustments so that + // autotuned CR is still in effect even when basals and ISF are being adjusted by TT or autosens + // this avoids overdosing insulin for large meals when low temp targets are active + csf = sens / profile.carb_ratio; + console.error("profile.sens:",profile.sens,"sens:",sens,"CSF:",csf); + var maxCarbAbsorptionRate = 30; // g/h; maximum rate to assume carbs will absorb if no CI observed // limit Carb Impact to maxCarbAbsorptionRate * csf in mg/dL per 5m var maxCI = round(maxCarbAbsorptionRate*csf*5/60,1)