diff --git a/bin/oref0-autotune.sh b/bin/oref0-autotune.sh index 407b89391..e9894b93b 100755 --- a/bin/oref0-autotune.sh +++ b/bin/oref0-autotune.sh @@ -252,7 +252,12 @@ do fi else # Copy tuned profile produced by autotune to profile.json for use with next day of data - cp newprofile.$i.json profile.json + if cat newprofile.$i.json | jq . | grep -q start; then + cp newprofile.$i.json profile.json + else + jq -c newprofile.$i.json + die "newprofile.$i.json invalid" + fi fi 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)