Update determine-basal.js and basal-set-temp.js from Current oref0 dev.

This commit is contained in:
Paul Andrel 2017-09-12 15:03:48 -04:00 committed by Paul Andrel
parent 1a8edc8372
commit 936184be60

View file

@ -63,7 +63,7 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_
basal = profile.current_basal * autosens_data.ratio; basal = profile.current_basal * autosens_data.ratio;
basal = round_basal(basal, profile); basal = round_basal(basal, profile);
if (basal != profile_current_basal) { if (basal != profile_current_basal) {
console.error("Autosens adjusting basal from "+profile.current_basal+" to "+basal+"; "); console.error("Autosens adjusting basal from "+profile_current_basal+" to "+basal+"; ");
} else { } else {
console.error("Basal unchanged: "+basal+"; "); console.error("Basal unchanged: "+basal+"; ");
} }
@ -105,14 +105,16 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_
// adjust min, max, and target BG for sensitivity, such that 50% increase in ISF raises target from 100 to 120 // adjust min, max, and target BG for sensitivity, such that 50% increase in ISF raises target from 100 to 120
if (typeof autosens_data !== 'undefined' && profile.autosens_adjust_targets) { if (typeof autosens_data !== 'undefined' && profile.autosens_adjust_targets) {
if (profile.temptargetSet) { if (profile.temptargetSet) {
console.error("Temp Target set, not adjusting with autosens"); console.error("Temp Target set, not adjusting with autosens; ");
} else { } else {
// with a target of 100, default 0.7-1.2 autosens min/max range would allow a 93-117 target range // with a target of 100, default 0.7-1.2 autosens min/max range would allow a 93-117 target range
min_bg = round((min_bg - 60) / autosens_data.ratio) + 60; min_bg = round((min_bg - 60) / autosens_data.ratio) + 60;
max_bg = round((max_bg - 60) / autosens_data.ratio) + 60; max_bg = round((max_bg - 60) / autosens_data.ratio) + 60;
new_target_bg = round((target_bg - 60) / autosens_data.ratio) + 60; new_target_bg = round((target_bg - 60) / autosens_data.ratio) + 60;
// don't allow target_bg below 80
new_target_bg = Math.max(80, new_target_bg);
if (target_bg == new_target_bg) { if (target_bg == new_target_bg) {
console.error("target_bg unchanged:", new_target_bg); console.error("target_bg unchanged: "+new_target_bg+"; ");
} else { } else {
console.error("target_bg from "+target_bg+" to "+new_target_bg+"; "); console.error("target_bg from "+target_bg+" to "+new_target_bg+"; ");
} }
@ -261,15 +263,19 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_
// disable SMB when a high temptarget is set // disable SMB when a high temptarget is set
if (profile.temptargetSet && target_bg > 100) { if (profile.temptargetSet && target_bg > 100) {
enableSMB=false; enableSMB=false;
// enable SMB (if enabled in preferences) for DIA hours after bolus // 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_with_bolus && bolusiob > 0.1) {
enableSMB=true; enableSMB=true;
// enable SMB (if enabled in preferences) while we have COB // enable SMB/UAM (if enabled in preferences) while we have COB
} else if (profile.enableSMB_with_COB && meal_data.mealCOB) { } else if (profile.enableSMB_with_COB && meal_data.mealCOB) {
enableSMB=true; enableSMB=true;
// enable SMB (if enabled in preferences) if a low temptarget is set // enable SMB/UAM (if enabled in preferences) if a low temptarget is set
} else if (profile.enableSMB_with_temptarget && (profile.temptargetSet && target_bg < 100)) { } else if (profile.enableSMB_with_temptarget && (profile.temptargetSet && target_bg < 100)) {
enableSMB=true; enableSMB=true;
// enable SMB/UAM (if enabled in preferences) for a full 6 hours after any carb entry
// (6 hours is defined in carbWindow in lib/meal/total.js)
} 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 // enable UAM (if enabled in preferences) for DIA hours after bolus, or if SMB is enabled
var enableUAM=(profile.enableUAM && (bolusiob > 0.1 || enableSMB)); var enableUAM=(profile.enableUAM && (bolusiob > 0.1 || enableSMB));
@ -567,7 +573,9 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_
rT.reason += "BG " + convert_bg(bg, profile) + "<" + convert_bg(threshold, profile); rT.reason += "BG " + convert_bg(bg, profile) + "<" + convert_bg(threshold, profile);
if ((glucose_status.delta <= 0 && minDelta <= 0) || (glucose_status.delta < expectedDelta && minDelta < expectedDelta) || bg < 60 ) { if ((glucose_status.delta <= 0 && minDelta <= 0) || (glucose_status.delta < expectedDelta && minDelta < expectedDelta) || bg < 60 ) {
// BG is still falling / rising slower than predicted // BG is still falling / rising slower than predicted
if ( minDelta < expectedDelta ) {
rT.reason += ", minDelta " + minDelta + " < " + "expectedDelta " + expectedDelta + "; "; rT.reason += ", minDelta " + minDelta + " < " + "expectedDelta " + expectedDelta + "; ";
}
return tempBasalFunctions.setTempBasal(0, 30, profile, rT, currenttemp); return tempBasalFunctions.setTempBasal(0, 30, profile, rT, currenttemp);
} }
if (glucose_status.delta > minDelta) { if (glucose_status.delta > minDelta) {
@ -787,12 +795,12 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_
rT.minPredBG = minPredBG; rT.minPredBG = minPredBG;
//console.error(iob_data.lastBolusTime); //console.error(iob_data.lastBolusTime);
// minutes since last bolus // minutes since last bolus
var lastBolusAge = round(( new Date().getTime() - meal_data.lastBolusTime ) / 60000,1); var lastBolusAge = round(( new Date().getTime() - iob_data.lastBolusTime ) / 60000,1);
//console.error(lastBolusAge); //console.error(lastBolusAge);
//console.error(profile.temptargetSet, target_bg, rT.COB); //console.error(profile.temptargetSet, target_bg, rT.COB);
// only allow microboluses with COB or low temp targets, or within DIA hours of a bolus // only allow microboluses with COB or low temp targets, or within DIA hours of a bolus
// only microbolus if 0.1U SMB represents 20m or less of basal (0.3U/hr or higher) // only microbolus if 0.1U SMB represents 20m or less of basal (0.3U/hr or higher)
if (microBolusAllowed && enableSMB && profile.current_basal >= 0.3) { if (microBolusAllowed && enableSMB && profile.current_basal >= 0.3 && bg > threshold) {
// never bolus more than 30m worth of basal // never bolus more than 30m worth of basal
maxBolus = round(profile.current_basal/2,1); maxBolus = round(profile.current_basal/2,1);
// bolus 1/3 the insulinReq, up to maxBolus // bolus 1/3 the insulinReq, up to maxBolus
@ -834,7 +842,7 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_
rT.reason += "Microbolusing " + microBolus + "U. "; rT.reason += "Microbolusing " + microBolus + "U. ";
} }
} else { } else {
rT.reason += "Waiting " + nextBolusMins + "m to microbolus again(" + microBolus + "). "; rT.reason += "Waiting " + nextBolusMins + "m to microbolus again. ";
} }
//rT.reason += ". "; //rT.reason += ". ";