Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bin/oref0-html.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ if (!module.parent) {

//console.log("<!-- ");
console.log( bgnow + requestedtemp.tick + " " + bgTime + ", "
+ iob + "U -> " + requestedtemp.eventualBG + "-" + requestedtemp.snoozeBG + ", "
+ iob + "U -> " + requestedtemp.eventualBG + ", "
+ tempstring + "U/hr @ " + temp_time
+ " " + reqtempstring
+ ", " + requestedtemp.reason + ", "
Expand All @@ -157,7 +157,7 @@ console.log("<body>");
console.log("<h1>");
console.log( bgnow + " " + tick + " at " + bgTime );
console.log("<br>");
console.log( "IOB: " + iob + "U, eventually " + requestedtemp.eventualBG + "-" + requestedtemp.snoozeBG + " mg/dL" );
console.log( "IOB: " + iob + "U, eventually " + requestedtemp.eventualBG + " mg/dL" );
console.log("<br>");
//+ "Act: " + enactedstring
//+ " at " + enactedat + "\n"
Expand Down
3 changes: 2 additions & 1 deletion bin/oref0-pebble.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ if (!module.parent) {

var pebble = {
"content" : "" + bgnow + requestedtemp.tick + " " + bgTime + "\n"
+ iob + "U->" + requestedtemp.eventualBG + "-" + requestedtemp.snoozeBG + "\n"
//+ iob + "U->" + requestedtemp.eventualBG + "-" + requestedtemp.snoozeBG + "\n"
+ iob + "U->" + requestedtemp.eventualBG + "\n"
//+ "Act: " + enactedstring
//+ " at " + enactedat + "\n"
+ tempstring
Expand Down
29 changes: 15 additions & 14 deletions bin/oref0-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ case $i in
current_basal_safety_multiplier="${i#*=}"
shift # past argument=value
;;
-bdd=*|--bolussnooze_dia_divisor=*)
bolussnooze_dia_divisor="${i#*=}"
shift # past argument=value
;;
#-bdd=*|--bolussnooze_dia_divisor=*)
#bolussnooze_dia_divisor="${i#*=}"
#shift # past argument=value
#;;
-m5c=*|--min_5m_carbimpact=*)
min_5m_carbimpact="${i#*=}"
shift # past argument=value
Expand Down Expand Up @@ -425,9 +425,9 @@ fi
if [[ ! -z "$current_basal_safety_multiplier" ]]; then
echo -n ", current_basal_safety_multiplier $current_basal_safety_multiplier";
fi
if [[ ! -z "$bolussnooze_dia_divisor" ]]; then
echo -n ", bolussnooze_dia_divisor $bolussnooze_dia_divisor";
fi
#if [[ ! -z "$bolussnooze_dia_divisor" ]]; then
#echo -n ", bolussnooze_dia_divisor $bolussnooze_dia_divisor";
#fi
if [[ ! -z "$min_5m_carbimpact" ]]; then
echo -n ", min_5m_carbimpact $min_5m_carbimpact";
fi
Expand Down Expand Up @@ -462,9 +462,9 @@ fi
if [[ ! -z "$current_basal_safety_multiplier" ]]; then
echo -n " --current_basal_safety_multiplier=$current_basal_safety_multiplier" | tee -a $OREF0_RUNAGAIN
fi
if [[ ! -z "$bolussnooze_dia_divisor" ]]; then
echo -n " --bolussnooze_dia_divisor=$bolussnooze_dia_divisor" | tee -a $OREF0_RUNAGAIN
fi
#if [[ ! -z "$bolussnooze_dia_divisor" ]]; then
#echo -n " --bolussnooze_dia_divisor=$bolussnooze_dia_divisor" | tee -a $OREF0_RUNAGAIN
#fi
if [[ ! -z "$min_5m_carbimpact" ]]; then
echo -n " --min_5m_carbimpact=$min_5m_carbimpact" | tee -a $OREF0_RUNAGAIN
fi
Expand Down Expand Up @@ -581,7 +581,8 @@ if [[ $REPLY =~ ^[Yy]$ ]]; then
#fi

cd $directory || die "Can't cd $directory"
if [[ "$max_iob" == "0" && -z "$max_daily_safety_multiplier" && -z "$current_basal_safety_multiplier" && -z "$bolussnooze_dia_divisor" && -z "$min_5m_carbimpact" ]]; then
#if [[ "$max_iob" == "0" && -z "$max_daily_safety_multiplier" && -z "$current_basal_safety_multiplier" && -z "$bolussnooze_dia_divisor" && -z "$min_5m_carbimpact" ]]; then
if [[ "$max_iob" == "0" && -z "$max_daily_safety_multiplier" && -z "$current_basal_safety_multiplier" && -z "$min_5m_carbimpact" ]]; then
oref0-get-profile --exportDefaults > preferences.json || die "Could not run oref0-get-profile"
else
preferences_from_args=()
Expand All @@ -594,9 +595,9 @@ if [[ $REPLY =~ ^[Yy]$ ]]; then
if [[ ! -z "$current_basal_safety_multiplier" ]]; then
preferences_from_args+="\"current_basal_safety_multiplier\":$current_basal_safety_multiplier "
fi
if [[ ! -z "$bolussnooze_dia_divisor" ]]; then
preferences_from_args+="\"bolussnooze_dia_divisor\":$bolussnooze_dia_divisor "
fi
#if [[ ! -z "$bolussnooze_dia_divisor" ]]; then
#preferences_from_args+="\"bolussnooze_dia_divisor\":$bolussnooze_dia_divisor "
#fi
if [[ ! -z "$min_5m_carbimpact" ]]; then
preferences_from_args+="\"min_5m_carbimpact\":$min_5m_carbimpact "
fi
Expand Down
4 changes: 2 additions & 2 deletions bin/peb-urchin-status.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ if [[ $(jq .urchin_loop_status pancreoptions.json) = "true" ]]; then
echo {"\"message\": "\"loop status at "'$(date +%-I:%M%P)'": Running\"} > upload/urchin-status.json
fi
if [[ $(jq .urchin_iob pancreoptions.json) = "true" ]]; then
echo {"\"message\": "\""$(date +%R)": IOB: $(jq .openaps.iob.iob upload/ns-status.json) - BasalIOB: $(jq .openaps.iob.basaliob upload/ns-status.json)\"} > upload/urchin-status.json
echo {"\"message\": "\""$(date +%R)": IOB: $(jq .openaps.iob.iob upload/ns-status.json)\"} > upload/urchin-status.json
fi
if [[ $(jq .urchin_temp_rate pancreoptions.json) = "true" ]]; then
echo {"\"message\": "\""$(date +%-I:%M%P)": Basel: $(jq .rate monitor/temp_basal.json) U/hr for $(jq .duration monitor/temp_basal.json) mins\"} > upload/urchin-status.json
echo {"\"message\": "\""$(date +%-I:%M%P)": Basal: $(jq .rate monitor/temp_basal.json) U/hr for $(jq .duration monitor/temp_basal.json) mins\"} > upload/urchin-status.json
fi

#Notification Status
Expand Down
85 changes: 40 additions & 45 deletions lib/determine-basal/determine-basal.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,11 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_
// and adjust it for the deviation above
var eventualBG = naive_eventualBG + deviation;
// calculate what portion of that is due to bolussnooze
var bolusContrib = iob_data.bolussnooze * sens;
//var bolusContrib = iob_data.bolussnooze * sens;
// and add it back in to get snoozeBG, plus another 50% to avoid low-temping at mealtime
var naive_snoozeBG = round( naive_eventualBG + 1.5 * bolusContrib );
//var naive_snoozeBG = round( naive_eventualBG + 1.5 * bolusContrib );
// adjust that for deviation like we did eventualBG
var snoozeBG = naive_snoozeBG + deviation;
//var snoozeBG = naive_snoozeBG + deviation;

// adjust target BG range if needed to safely bring down high BG faster without causing lows
if ( bg > max_bg && profile.adv_target_adjustments && ! profile.temptargetSet ) {
Expand Down Expand Up @@ -238,17 +238,12 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_
, 'bg': bg
, 'tick': tick
, 'eventualBG': eventualBG
, 'snoozeBG': snoozeBG
//, 'snoozeBG': snoozeBG
, 'insulinReq': 0
, 'reservoir' : reservoir_data // The expected reservoir volume at which to deliver the microbolus (the reservoir volume from right before the last pumphistory run)
, 'deliverAt' : deliverAt // The time at which the microbolus should be delivered
};

var basaliob = iob_data.basaliob;
//if (iob_data.basaliob) { basaliob = iob_data.basaliob; }
//else { basaliob = iob_data.iob - iob_data.bolussnooze; }
var bolusiob = iob_data.iob - basaliob;

// generate predicted future BGs based on IOB, COB, and current absorption rate

var COBpredBGs = [];
Expand All @@ -270,7 +265,7 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_
} else if (profile.enableSMB_always) {
enableSMB=true;
// enable SMB/UAM (if enabled in preferences) for DIA hours after bolus
} else if (profile.enableSMB_with_bolus && bolusiob > 0.1) {
} else if (profile.enableSMB_always) {
enableSMB=true;
// enable SMB/UAM (if enabled in preferences) while we have COB
} else if (profile.enableSMB_with_COB && meal_data.mealCOB) {
Expand All @@ -283,8 +278,8 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_
} else if (profile.enableSMB_after_carbs && meal_data.carbs) {
enableSMB=true;
}
// enable UAM (if enabled in preferences) for DIA hours after bolus, or if SMB is enabled
var enableUAM=(profile.enableUAM && (bolusiob > 0.1 || enableSMB));
// enable UAM (if enabled in preferences) if SMB is enabled
var enableUAM=(profile.enableUAM && enableSMB);


//console.error(meal_data);
Expand Down Expand Up @@ -601,10 +596,10 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_
minPredBG = Math.min(minPredBG, maxCOBPredBG);
}
// set snoozeBG to minPredBG if it's higher
if (minPredBG < 999) {
snoozeBG = round(Math.max(snoozeBG,minPredBG));
}
rT.snoozeBG = snoozeBG;
//if (minPredBG < 999) {
//snoozeBG = round(Math.max(snoozeBG,minPredBG));
//}
//rT.snoozeBG = snoozeBG;
//console.error(minPredBG, minIOBPredBG, minUAMPredBG, minCOBPredBG, maxCOBPredBG, snoozeBG);

rT.COB=meal_data.mealCOB;
Expand Down Expand Up @@ -720,31 +715,32 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_
}

// if we've bolused recently, we can snooze until the bolus IOB decays (at double speed)
if (snoozeBG > min_bg) { // if adding back in the bolus contribution BG would be above min
//if (snoozeBG > min_bg) { // if adding back in the bolus contribution BG would be above min
// If we're not in SMB mode with COB, or lastCOBpredBG > target_bg, bolus snooze
if (! (microBolusAllowed && rT.COB) || lastCOBpredBG > target_bg) {
rT.reason += ", bolus snooze: eventual BG range " + convert_bg(eventualBG, profile) + "-" + convert_bg(snoozeBG, profile);
//if (! (microBolusAllowed && rT.COB) || lastCOBpredBG > target_bg) {
//rT.reason += ", bolus snooze: eventual BG range " + convert_bg(eventualBG, profile) + "-" + convert_bg(snoozeBG, profile);
//console.error(currenttemp, basal );
if (currenttemp.duration > 15 && (round_basal(basal, profile) === round_basal(currenttemp.rate, profile))) {
rT.reason += ", temp " + currenttemp.rate + " ~ req " + basal + "U/hr. ";
return rT;
} else {
rT.reason += "; setting current basal of " + basal + " as temp. ";
return tempBasalFunctions.setTempBasal(basal, 30, profile, rT, currenttemp);
}
}
} else {
//if (currenttemp.duration > 15 && (round_basal(basal, profile) === round_basal(currenttemp.rate, profile))) {
//rT.reason += ", temp " + currenttemp.rate + " ~ req " + basal + "U/hr. ";
//return rT;
//} else {
//rT.reason += "; setting current basal of " + basal + " as temp. ";
//return tempBasalFunctions.setTempBasal(basal, 30, profile, rT, currenttemp);
//}
//}
//} else {
// calculate 30m low-temp required to get projected BG up to target
// use snoozeBG to more gradually ramp in any counteraction of the user's boluses
// multiply by 2 to low-temp faster for increased hypo safety
var insulinReq = 2 * Math.min(0, (snoozeBG - target_bg) / sens);
//var insulinReq = 2 * Math.min(0, (snoozeBG - target_bg) / sens);
var insulinReq = 2 * Math.min(0, (eventualBG - target_bg) / sens);
insulinReq = round( insulinReq , 2);
// calculate naiveInsulinReq based on naive_eventualBG
var naiveInsulinReq = Math.min(0, (naive_eventualBG - target_bg) / sens);
naiveInsulinReq = round( naiveInsulinReq , 2);
if (minDelta < 0 && minDelta > expectedDelta) {
// if we're barely falling, newinsulinReq should be barely negative
rT.reason += ", Snooze BG " + convert_bg(snoozeBG, profile);
//rT.reason += ", Snooze BG " + convert_bg(snoozeBG, profile);
var newinsulinReq = round(( insulinReq * (minDelta / expectedDelta) ), 2);
//console.error("Increasing insulinReq from " + insulinReq + " to " + newinsulinReq);
insulinReq = newinsulinReq;
Expand All @@ -766,7 +762,7 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_
return rT;
} else {
// calculate a long enough zero temp to eventually correct back up to target
if ( rate < 0 ) {
if ( rate <=0 ) {
var bgUndershoot = target_bg - naive_eventualBG;
var worstCaseInsulinReq = bgUndershoot / sens;
var durationReq = round(60*worstCaseInsulinReq / profile.current_basal);
Expand All @@ -788,7 +784,7 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_
}
return tempBasalFunctions.setTempBasal(rate, 30, profile, rT, currenttemp);
}
}
//}
}

// if eventual BG is above min but BG is falling faster than expected Delta
Expand All @@ -809,11 +805,11 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_
}
}
}
// eventualBG, snoozeBG, or minPredBG is below max_bg
if (Math.min(eventualBG,snoozeBG,minPredBG) < max_bg) {
// eventualBG or minPredBG is below max_bg
if (Math.min(eventualBG,minPredBG) < max_bg) {
// if in SMB mode, don't cancel SMB zero temp
if (! (microBolusAllowed && enableSMB )) {
rT.reason += convert_bg(eventualBG, profile)+"-"+convert_bg(Math.min(minPredBG,snoozeBG), profile)+" in range: bolus snooze, no temp required";
rT.reason += convert_bg(eventualBG, profile)+"-"+convert_bg(minPredBG, profile)+" in range: no temp required";
if (currenttemp.duration > 15 && (round_basal(basal, profile) === round_basal(currenttemp.rate, profile))) {
rT.reason += ", temp " + currenttemp.rate + " ~ req " + basal + "U/hr. ";
return rT;
Expand All @@ -826,8 +822,6 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_

// eventual BG is at/above target (or bolus snooze disabled for SMB)
// if iob is over max, just cancel any temps
if (iob_data.basaliob) { basaliob = iob_data.basaliob; }
else { basaliob = iob_data.iob - iob_data.bolussnooze; }
// if we're not here because of SMB, eventual BG is at/above target
if (! (microBolusAllowed && rT.COB)) {
rT.reason += "Eventual BG " + convert_bg(eventualBG, profile) + " >= " + convert_bg(max_bg, profile) + ", ";
Expand All @@ -845,7 +839,8 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_

// insulinReq is the additional insulin required to get minPredBG down to target_bg
//console.error(minPredBG,snoozeBG,eventualBG);
var insulinReq = round( (Math.min(minPredBG,snoozeBG,eventualBG) - target_bg) / sens, 2);
//var insulinReq = round( (Math.min(minPredBG,snoozeBG,eventualBG) - target_bg) / sens, 2);
var insulinReq = round( (Math.min(minPredBG,eventualBG) - target_bg) / sens, 2);
// when dropping, but not as fast as expected, reduce insulinReq proportionally
// to the what fraction of expectedDelta we're dropping at
if (minDelta < 0 && minDelta > expectedDelta) {
Expand Down Expand Up @@ -893,9 +888,9 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_
var durationReq = round(60*worstCaseInsulinReq / profile.current_basal);

// if no microBolus required, snoozeBG > target_bg, and lastCOBpredBG > target_bg, don't set a zero temp
if (microBolus < 0.1 && snoozeBG > target_bg && lastCOBpredBG > target_bg) {
durationReq = 0;
}
//if (microBolus < 0.1 && snoozeBG > target_bg && lastCOBpredBG > target_bg) {
//durationReq = 0;
//}

var smbLowTempReq = 0;
if (durationReq <= 0) {
Expand Down Expand Up @@ -940,10 +935,10 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_
}

// if insulinReq is negative, snoozeBG > target_bg, and lastCOBpredBG > target_bg, set a neutral temp
if (insulinReq < 0 && snoozeBG > target_bg && lastCOBpredBG > target_bg) {
rT.reason += "; SMB bolus snooze: setting current basal of " + basal + " as temp. ";
return tempBasalFunctions.setTempBasal(basal, 30, profile, rT, currenttemp);
}
//if (insulinReq < 0 && snoozeBG > target_bg && lastCOBpredBG > target_bg) {
//rT.reason += "; SMB bolus snooze: setting current basal of " + basal + " as temp. ";
//return tempBasalFunctions.setTempBasal(basal, 30, profile, rT, currenttemp);
//}
}

var maxSafeBasal = tempBasalFunctions.getMaxSafeBasal(profile);
Expand Down
6 changes: 3 additions & 3 deletions lib/iob/calculate.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ function iobCalc(treatment, time, dia, profile) {
activityContrib = treatment.insulin * (S / Math.pow(tau, 2)) * t * (1 - t / td) * Math.exp(-t / tau);
iobContrib = treatment.insulin * (1 - S * (1 - a) * ((Math.pow(t, 2) / (tau * td * (1 - a)) - t / tau - 1) * Math.exp(-t / tau) + 1));
// calculate bolus snooze insulin in the same pass
t = t * profile.bolussnooze_dia_divisor;
biobContrib = treatment.insulin * (1 - S * (1 - a) * ((Math.pow(t, 2) / (tau * td * (1 - a)) - t / tau - 1) * Math.exp(-t / tau) + 1));
//t = t * profile.bolussnooze_dia_divisor;
//biobContrib = treatment.insulin * (1 - S * (1 - a) * ((Math.pow(t, 2) / (tau * td * (1 - a)) - t / tau - 1) * Math.exp(-t / tau) + 1));

//console.error('DIA: ' + dia + ' t: ' + t + ' td: ' + td + ' tp: ' + tp + ' tau: ' + tau + ' a: ' + a + ' S: ' + S + ' activityContrib: ' + activityContrib + ' iobContrib: ' + iobContrib);

Expand All @@ -147,7 +147,7 @@ function iobCalc(treatment, time, dia, profile) {
results = {
iobContrib: iobContrib,
activityContrib: activityContrib,
biobContrib: biobContrib
//biobContrib: biobContrib
};

return results;
Expand Down
Loading