Skip to content
Merged
Changes from all 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
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