Skip to content

Commit

Permalink
add unannounced meal detection to autotune
Browse files Browse the repository at this point in the history
  • Loading branch information
scottleibrand committed Mar 9, 2017
1 parent c2cfc8f commit 42c6141
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions lib/autotune-prep/categorize.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ function categorizeBGDatums(opts) {
}
//console.error(treatments);
absorbing = 0;
uam = 0; // unannounced meal
mealCOB = 0;
mealCarbs = 0;
var type="";
Expand Down Expand Up @@ -215,11 +216,28 @@ function categorizeBGDatums(opts) {
//if (i == 0) { glucoseDatum.mealAbsorption = "end"; }
CSFGlucoseData.push(glucoseDatum);
} else {
// check previous "type" value, and if it was csf, set a mealAbsorption end flag
if ( type === "csf" ) {
CSFGlucoseData[CSFGlucoseData.length-1].mealAbsorption = "end";
console.error(CSFGlucoseData[CSFGlucoseData.length-1].mealAbsorption,"carb absorption");
// check previous "type" value, and if it was csf, set a mealAbsorption end flag
if ( type === "csf" ) {
CSFGlucoseData[CSFGlucoseData.length-1].mealAbsorption = "end";
console.error(CSFGlucoseData[CSFGlucoseData.length-1].mealAbsorption,"carb absorption");
}

if (iob.iob > currentBasal || uam) {
if (deviation > 0) {
uam = 1;
} else {
uam = 0;
}
if ( type != "uam" ) {
glucoseDatum.uamAbsorption = "start";
console.error(glucoseDatum.uamAbsorption,"uannnounced meal absorption");
}
type="uam";
} else {
if ( type === "uam" ) {
console.error("end unannounced meal absorption");
}


// Go through the remaining time periods and divide them into periods where scheduled basal insulin activity dominates. This would be determined by calculating the BG impact of scheduled basal insulin (for example 1U/hr * 48 mg/dL/U ISF = 48 mg/dL/hr = 5 mg/dL/5m), and comparing that to BGI from bolus and net basal insulin activity.
// When BGI is positive (insulin activity is negative), we want to use that data to tune basals
Expand Down Expand Up @@ -248,9 +266,12 @@ function categorizeBGDatums(opts) {
ISFGlucoseData.push(glucoseDatum);
}
}
}
}
// debug line to print out all the things
console.error(absorbing.toString(),"mealCOB:",mealCOB.toFixed(1),"mealCarbs:",mealCarbs,"basalBGI:",basalBGI.toFixed(1),"BGI:",BGI.toFixed(1),"at",BGDate,"dev:",deviation,"avgDelta:",avgDelta,type);
BGDateArray = BGDate.toString().split(" ");
BGTime = BGDateArray[4];
console.error(absorbing.toString(),"mealCOB:",mealCOB.toFixed(1),"mealCarbs:",mealCarbs,"basalBGI:",basalBGI.toFixed(1),"BGI:",BGI.toFixed(1),"IOB:",iob.iob.toFixed(1),"at",BGTime,"dev:",deviation,"avgDelta:",avgDelta,type);
}

return {
Expand Down

0 comments on commit 42c6141

Please sign in to comment.