Skip to content

Commit

Permalink
Merge pull request #112 from mddub/neutral-temps-preference
Browse files Browse the repository at this point in the history
Make neutral temp basals configurable
  • Loading branch information
scottleibrand committed May 15, 2016
2 parents e491328 + c079319 commit 40bad10
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
3 changes: 2 additions & 1 deletion bin/oref0-get-profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ if (!module.parent) {
}
var basalprofile_data = require(cwd + '/' + basalprofile_input);

var preferences = { max_iob: 0 };
var preferences = {};
if (typeof preferences_input != 'undefined') {
preferences = require(cwd + '/' + preferences_input);
}
Expand Down Expand Up @@ -97,6 +97,7 @@ if (!module.parent) {
, basals: basalprofile_data
, isf: isf_data
, max_iob: preferences.max_iob || 0
, skip_neutral_temps: preferences.skip_neutral_temps || false
, carbratio: carbratio_data
};

Expand Down
33 changes: 29 additions & 4 deletions lib/basal-set-temp.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var setTempBasal = function (rate, duration, profile, rT, currenttemp) {
maxSafeBasal = Math.min(profile.max_basal, 3 * profile.max_daily_basal, 4 * profile.current_basal);
var maxSafeBasal = Math.min(profile.max_basal, 3 * profile.max_daily_basal, 4 * profile.current_basal);

if (rate < 0) {
rate = 0;
Expand All @@ -13,9 +13,34 @@ var setTempBasal = function (rate, duration, profile, rT, currenttemp) {
return rT;
}

rT.duration = duration;
rT.rate = Math.round((Math.round(rate / 0.05) * 0.05)*100)/100;
return rT;
var suggestedRate = Math.round((Math.round(rate / 0.05) * 0.05)*100)/100;
if (suggestedRate === profile.current_basal) {
if (profile.skip_neutral_temps) {
if (typeof(currenttemp) !== 'undefined' && typeof(currenttemp.duration) !== 'undefined' && currenttemp.duration > 0) {
reason(rT, 'Suggested rate is same as profile rate, a temp basal is active, canceling current temp');
rT.duration = 0;
rT.rate = 0;
return rT;
} else {
reason(rT, 'Suggested rate is same as profile rate, no temp basal is active, doing nothing');
return rT;
}
} else {
reason(rT, 'Setting neutral temp basal of ' + profile.current_basal + 'U/hr');
rT.duration = duration;
rT.rate = suggestedRate;
return rT;
}
} else {
rT.duration = duration;
rT.rate = suggestedRate;
return rT;
}
};

function reason(rT, msg) {
rT.reason = (rT.reason ? rT.reason + '. ' : '') + msg;
console.error(msg);
}

module.exports = setTempBasal;
1 change: 1 addition & 0 deletions lib/profile/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ function generate (inputs, opts) {
if (inputs.max_iob) {
profile.max_iob = inputs.max_iob;
}
profile.skip_neutral_temps = inputs.skip_neutral_temps;

profile.current_basal = basal.basalLookup(inputs.basals);
profile.max_daily_basal = basal.maxDailyBasal(inputs);
Expand Down

0 comments on commit 40bad10

Please sign in to comment.