Skip to content

Commit

Permalink
Merge branch '0.6.0-dev' into responsive-remainingCI
Browse files Browse the repository at this point in the history
Conflicts:
	lib/determine-basal/determine-basal.js
  • Loading branch information
scottleibrand committed Sep 7, 2017
2 parents a845590 + 8cfd6a7 commit 5ed9685
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
5 changes: 3 additions & 2 deletions lib/determine-basal/determine-basal.js
Original file line number Diff line number Diff line change
Expand Up @@ -477,9 +477,11 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_
minUAMPredBG = Math.max(39,minUAMPredBG);
minPredBG = round(minIOBPredBG);

var fractionCarbsLeft = meal_data.mealCOB/meal_data.carbs;
// if we have COB and UAM is enabled, average all three
if ( minUAMPredBG < 400 && minCOBPredBG < 400 ) {
avgPredBG = round( (IOBpredBG + UAMpredBG + COBpredBG)/3 );
// weight COBpredBG vs. UAMpredBG based on how many carbs remain as COB
avgPredBG = round( (IOBpredBG/3 + (1-fractionCarbsLeft)*UAMpredBG*2/3 + fractionCarbsLeft*COBpredBG*2/3) );
// if UAM is disabled, average IOB and COB
} else if ( minCOBPredBG < 400 ) {
avgPredBG = round( (IOBpredBG + COBpredBG)/2 );
Expand Down Expand Up @@ -508,7 +510,6 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_
// if we have COB, use minCOBPredBG, or blendedMinPredBG if it's higher
} else if ( minCOBPredBG < 400 ) {
// calculate blendedMinPredBG based on how many carbs remain as COB
fractionCarbsLeft = meal_data.mealCOB/meal_data.carbs;
blendedMinPredBG = fractionCarbsLeft*minCOBPredBG + (1-fractionCarbsLeft)*avgMinPredBG;
// if blendedMinPredBG > minCOBPredBG, use that instead
minPredBG = round(Math.max(minIOBPredBG, minCOBPredBG, blendedMinPredBG));
Expand Down
15 changes: 10 additions & 5 deletions lib/meal/total.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ function recentCarbs(opts, time) {
var glucose_data = opts.glucose;
}
var carbs = 0;
var boluses = 0;
var carbDelay = 20 * 60 * 1000;
var maxCarbs = 0;
var mealCarbTime = time.getTime();
Expand All @@ -35,6 +34,7 @@ function recentCarbs(opts, time) {
return bDate.getTime() - aDate.getTime();
});

var carbsToRemove = 0;
treatments.forEach(function(treatment) {
var now = time.getTime();
// consider carbs from up to 6 hours ago in calculating COB
Expand All @@ -49,13 +49,19 @@ function recentCarbs(opts, time) {
var myCarbsAbsorbed = calcMealCOB(COB_inputs).carbsAbsorbed;
var myMealCOB = Math.max(0, carbs - myCarbsAbsorbed);
mealCOB = Math.max(mealCOB, myMealCOB);
//console.error(myMealCOB, mealCOB, carbs);
if (myMealCOB < mealCOB) {
carbsToRemove += parseFloat(treatment.carbs);
} else {
carbsToRemove = 0;
}
//console.error(carbs, carbsToRemove);
//console.error("COB:",mealCOB);
}
if (treatment.bolus >= 0.1) {
boluses += parseFloat(treatment.bolus);
}
}
});
// only include carbs actually used in calculating COB
carbs -= carbsToRemove;

// calculate the current deviation and steepest deviation downslope over the last hour
COB_inputs.ciTime = time.getTime();
Expand All @@ -80,7 +86,6 @@ function recentCarbs(opts, time) {

return {
carbs: Math.round( carbs * 1000 ) / 1000
, boluses: Math.round( boluses * 1000 ) / 1000
, mealCOB: Math.round( mealCOB )
, currentDeviation: Math.round( c.currentDeviation * 100 ) / 100
, maxDeviation: Math.round( c.maxDeviation * 100 ) / 100
Expand Down

0 comments on commit 5ed9685

Please sign in to comment.