Skip to content

Commit

Permalink
Merge pull request #1064 from scottleibrand/fix-delayedCarbs
Browse files Browse the repository at this point in the history
Fix delayed carbs
  • Loading branch information
jasoncalabrese committed Sep 21, 2015
2 parents 0412d03 + 26ebe88 commit ec74763
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 5 additions & 2 deletions lib/plugins/cob.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ function init() {
return {};
}

var liverSensRatio = 1;
// TODO: figure out the liverSensRatio that gives the most accurate purple line predictions
var liverSensRatio = 8;
var totalCOB = 0;
var lastCarbs = null;

Expand All @@ -51,10 +52,12 @@ function init() {
var cCalc = cob.cobCalc(treatment, profile, lastDecayedBy, time);
var decaysin_hr = (cCalc.decayedBy - time) / 1000 / 60 / 60;
if (decaysin_hr > -10) {
// units: BG
var actStart = iob.calcTotal(treatments, profile, lastDecayedBy).activity;
var actEnd = iob.calcTotal(treatments, profile, cCalc.decayedBy).activity;
var avgActivity = (actStart + actEnd) / 2;
var delayedCarbs = avgActivity * liverSensRatio * profile.getSensitivity(treatment.mills) / profile.getCarbRatio(treatment.mills);
// units: g = BG * scalar / BG / U * g / U
var delayedCarbs = ( avgActivity * liverSensRatio / profile.getSensitivity(treatment.mills) ) * profile.getCarbRatio(treatment.mills);
var delayMinutes = Math.round(delayedCarbs / profile.getCarbAbsorptionRate(treatment.mills) * 60);
if (delayMinutes > 0) {
cCalc.decayedBy.setMinutes(cCalc.decayedBy.getMinutes() + delayMinutes);
Expand Down
4 changes: 3 additions & 1 deletion lib/plugins/iob.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ function init() {
lastBolus = treatment;
}
if (tIOB && tIOB.iobContrib) { totalIOB += tIOB.iobContrib; }
// units: BG (mg/dL or mmol/L)
if (tIOB && tIOB.activityContrib) { totalActivity += tIOB.activityContrib; }
}
});
Expand Down Expand Up @@ -76,6 +77,7 @@ function init() {
if (minAgo < peak) {
var x1 = minAgo / 5 + 1;
result.iobContrib = treatment.insulin * (1 - 0.001852 * x1 * x1 + 0.001852 * x1);
// units: BG (mg/dL) = (BG/U) * U insulin * scalar
result.activityContrib = sens * treatment.insulin * (2 / dia / 60 / peak) * minAgo;

} else if (minAgo < 180) {
Expand Down Expand Up @@ -113,4 +115,4 @@ function init() {

}

module.exports = init;
module.exports = init;

0 comments on commit ec74763

Please sign in to comment.