Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
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
2 changes: 2 additions & 0 deletions lib/determine-basal/autosens.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ function detectSensitivity(inputs) {
avgDelta = avgDelta.toFixed(2);
iob_inputs.clock=bgTime;
iob_inputs.profile.current_basal = basal.basalLookup(basalprofile, bgTime);
// make sure autosens doesn't use temptarget-adjusted insulin calculations
iob_inputs.profile.temptargetSet = false;
//console.log(JSON.stringify(iob_inputs.profile));
//console.error("Before: ", new Date().getTime());
var iob = get_iob(iob_inputs, true, treatments)[0];
Expand Down
42 changes: 27 additions & 15 deletions lib/determine-basal/determine-basal.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,6 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_
}
var profile_current_basal = round_basal(profile.current_basal, profile);
var basal = profile_current_basal;
if (typeof autosens_data !== 'undefined' ) {
basal = profile.current_basal * autosens_data.ratio;
basal = round_basal(basal, profile);
if (basal != profile_current_basal) {
process.stderr.write("Autosens adjusting basal from "+profile_current_basal+" to "+basal+"; ");
} else {
process.stderr.write("Basal unchanged: "+basal+"; ");
}
}

var bg = glucose_status.glucose;
if (bg < 39) { //Dexcom is in ??? mode or calibrating
Expand Down Expand Up @@ -102,10 +93,31 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_
return rT;
}

var sensitivityRatio;
if (profile.temptargetSet && target_bg > 110) {
// w/ target 100, temp target 110 = .89, 120 = 0.8, 140 = 0.67, 160 = .57, and 200 = .44
// e.g.: Sensitivity ratio set to 0.8 based on temp target of 120; Adjusting basal from 1.65 to 1.35; ISF from 58.9 to 73.6
sensitivityRatio = 2/(2+(target_bg-100)/40);
sensitivityRatio = round(sensitivityRatio,2);
process.stderr.write("Sensitivity ratio set to "+sensitivityRatio+" based on temp target of "+target_bg+"; ");
} else if (typeof autosens_data !== 'undefined' ) {
sensitivityRatio = autosens_data.ratio;
process.stderr.write("Autosens ratio: "+sensitivityRatio+"; ");
}
if (sensitivityRatio) {
basal = profile.current_basal * sensitivityRatio;
basal = round_basal(basal, profile);
if (basal != profile_current_basal) {
process.stderr.write("Adjusting basal from "+profile_current_basal+" to "+basal+"; ");
} else {
process.stderr.write("Basal unchanged: "+basal+"; ");
}
}

// 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 (profile.temptargetSet) {
process.stderr.write("Temp Target set, not adjusting with autosens; ");
//process.stderr.write("Temp Target set, not adjusting with autosens; ");
} else {
// 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;
Expand Down Expand Up @@ -152,14 +164,14 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_
var profile_sens = round(profile.sens,1)
var sens = profile.sens;
if (typeof autosens_data !== 'undefined' ) {
sens = profile.sens / autosens_data.ratio;
sens = profile.sens / sensitivityRatio;
sens = round(sens, 1);
if (sens != profile_sens) {
process.stderr.write("sens from "+profile_sens+" to "+sens);
process.stderr.write("ISF from "+profile_sens+" to "+sens);
} else {
process.stderr.write("sens unchanged: "+sens);
process.stderr.write("ISF unchanged: "+sens);
}
process.stderr.write(" (autosens ratio "+autosens_data.ratio+")");
//process.stderr.write(" (autosens ratio "+sensitivityRatio+")");
}
console.error("");

Expand Down Expand Up @@ -682,7 +694,7 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_
if (eventualBG < min_bg) { // if eventual BG is below target:
rT.reason += "Eventual BG " + convert_bg(eventualBG, profile) + " < " + convert_bg(min_bg, profile);
// if 5m or 30m avg BG is rising faster than expected delta
if (minDelta > expectedDelta && minDelta > 0) {
if ( minDelta > expectedDelta && minDelta > 0 && !carbsReq ) {
// if naive_eventualBG < 40, set a 30m zero temp (oref0-pump-loop will let any longer SMB zero temp run)
if (naive_eventualBG < 40) {
rT.reason += ", naive_eventualBG < 40. ";
Expand Down
9 changes: 8 additions & 1 deletion lib/iob/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,18 @@ function calcTempTreatments (inputs) {
if (currentItem.duration > 0) {

var currentRate = profile_data.current_basal;

if (!_.isEmpty(profile_data.basalprofile)) {
currentRate = basalprofile.basalLookup(profile_data.basalprofile,new Date(currentItem.timestamp));
}

if (typeof profile_data.min_bg !== 'undefined' && typeof profile_data.max_bg !== 'undefined') {
target_bg = (profile_data.min_bg + profile_data.max_bg) / 2;
}
if (profile_data.temptargetSet && target_bg > 110) {
sensitivityRatio = 2/(2+(target_bg-100)/40);
currentRate = profile_data.current_basal * sensitivityRatio;
}

var netBasalRate = currentItem.rate - currentRate;
if (netBasalRate < 0) { tempBolusSize = -0.05; }
else { tempBolusSize = 0.05; }
Expand Down