Skip to content
Merged
Show file tree
Hide file tree
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
14 changes: 7 additions & 7 deletions lib/determine-basal/determine-basal.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,21 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_
}
if (minAgo > 12 || minAgo < -5) { // Dexcom data is too old, or way in the future
rT.reason = "If current system time "+systemTime+" is correct, then BG data is too old. The last BG data was read "+minAgo+"m ago at "+bgTime;
// if BG is too old/noisy, or is completely unchanging, cancel any high temps and shorten any long zero temps
} else if ( glucose_status.short_avgdelta === 0 && glucose_status.long_avgdelta === 0 ) {
// if BG is too old/noisy, or is changing less than 1 mg/dL/5m for 45m, cancel any high temps and shorten any long zero temps
} else if ( bg > 60 && glucose_status == 0 && glucose_status.short_avgdelta > -1 && glucose_status.short_avgdelta < 1 && glucose_status.long_avgdelta > -1 && glucose_status.long_avgdelta < 1 ) {
if ( glucose_status.last_cal && glucose_status.last_cal < 3 ) {
rT.reason = "CGM was just calibrated";
} else {
rT.reason = "Error: CGM data is unchanged for the past ~45m";
}
}
if (bg <= 10 || bg === 38 || noise >= 3 || minAgo > 12 || minAgo < -5 || ( glucose_status.short_avgdelta === 0 && glucose_status.long_avgdelta === 0 ) ) {
if (currenttemp.rate >= basal) { // high temp is running
rT.reason += ". Canceling high temp basal of "+currenttemp.rate;
if (bg <= 10 || bg === 38 || noise >= 3 || minAgo > 12 || minAgo < -5 || ( bg > 60 && glucose_status == 0 && glucose_status.short_avgdelta > -1 && glucose_status.short_avgdelta < 1 && glucose_status.long_avgdelta > -1 && glucose_status.long_avgdelta < 1 ) ) {
if (currenttemp.rate > basal) { // high temp is running
rT.reason += ". Replacing high temp basal of "+currenttemp.rate+" with neutral temp of "+basal;
rT.deliverAt = deliverAt;
rT.temp = 'absolute';
rT.duration = 0;
rT.rate = 0;
rT.duration = 30;
rT.rate = basal;
return rT;
//return tempBasalFunctions.setTempBasal(basal, 30, profile, rT, currenttemp);
} else if ( currenttemp.rate === 0 && currenttemp.duration > 30 ) { //shorten long zero temps to 30m
Expand Down
17 changes: 11 additions & 6 deletions tests/determine-basal.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ describe('determine-basal', function ( ) {
//function determine_basal(glucose_status, currenttemp, iob_data, profile)

// standard initial conditions for all determine-basal test cases unless overridden
var glucose_status = {"delta":0,"glucose":115,"long_avgdelta":0.1,"short_avgdelta":0};
var glucose_status = {"delta":0,"glucose":115,"long_avgdelta":1.1,"short_avgdelta":0};
var currenttemp = {"duration":0,"rate":0,"temp":"absolute"};
var iob_data = {"iob":0,"activity":0,"bolussnooze":0};
var autosens = {"ratio":1.0};
Expand Down Expand Up @@ -126,7 +126,7 @@ describe('determine-basal', function ( ) {
it('should do nothing when low and rising w/o IOB', function () {
var glucose_status = {"delta":6,"glucose":75,"long_avgdelta":6,"short_avgdelta":6};
var output = determine_basal(glucose_status, currenttemp, iob_data, profile, autosens, meal_data, tempBasalFunctions);
console.log(output);
//console.log(output);
output.rate.should.equal(0.9);
output.duration.should.equal(30);
//output.reason.should.match(/75<80.*setting current basal/);
Expand Down Expand Up @@ -248,27 +248,30 @@ describe('determine-basal', function ( ) {
});

it('should temp to 0 when LOW w/ positive IOB', function () {
var glucose_status = {"delta":0,"glucose":39,"long_avgdelta":0.1,"short_avgdelta":0};
var glucose_status = {"delta":0,"glucose":39,"long_avgdelta":-1.1,"short_avgdelta":0};
var iob_data = {"iob":1,"activity":0.01,"bolussnooze":0.5};
var output = determine_basal(glucose_status, currenttemp, iob_data, profile, autosens, meal_data, tempBasalFunctions);
//console.log(output);
output.rate.should.equal(0);
output.duration.should.be.above(29);
//output.reason.should.match(/BG 39<80/);
});

it('should low temp when LOW w/ negative IOB', function () {
var glucose_status = {"delta":0,"glucose":39,"long_avgdelta":0.1,"short_avgdelta":0};
var glucose_status = {"delta":0,"glucose":39,"long_avgdelta":-1.1,"short_avgdelta":0};
var iob_data = {"iob":-2.5,"activity":-0.03,"bolussnooze":0};
var output = determine_basal(glucose_status, currenttemp, iob_data, profile, autosens, meal_data, tempBasalFunctions);
//console.log(output);
output.rate.should.be.below(0.8);
output.duration.should.be.above(29);
//output.reason.should.match(/BG 39<80/);
});

it('should temp to 0 when LOW w/ no IOB', function () {
var glucose_status = {"delta":0,"glucose":39,"long_avgdelta":0.1,"short_avgdelta":0};
var glucose_status = {"delta":0,"glucose":39,"long_avgdelta":-1.1,"short_avgdelta":0};
var iob_data = {"iob":0,"activity":0,"bolussnooze":0};
var output = determine_basal(glucose_status, currenttemp, iob_data, profile, autosens, meal_data, tempBasalFunctions);
//console.log(output);
output.rate.should.equal(0);
output.duration.should.be.above(29);
//output.reason.should.match(/BG 39<80/);
Expand Down Expand Up @@ -476,7 +479,7 @@ describe('determine-basal', function ( ) {
var output = determine_basal({glucose:10},currenttemp, iob_data, profile, autosens, meal_data, tempBasalFunctions);
//console.log(output);
output.rate.should.be.below(1);
output.reason.should.match(/Canceling high temp/);
output.reason.should.match(/Replacing high temp/);
});

it('profile should contain min_bg,max_bg', function () {
Expand Down Expand Up @@ -725,6 +728,7 @@ describe('determine-basal', function ( ) {
profile.current_basal = 0.825;
profile.model = "523";
var output = determine_basal(glucose_status, currenttemp, iob_data, profile, autosens, meal_data, tempBasalFunctions);
//console.log(output);
//output.rate.should.equal(0);
//output.duration.should.equal(0);
output.rate.should.equal(0.825);
Expand All @@ -738,6 +742,7 @@ describe('determine-basal', function ( ) {
profile.current_basal = 0.875;
profile.model = "522";
var output = determine_basal(glucose_status, currenttemp, iob_data, profile, autosens, meal_data, tempBasalFunctions);
//console.log(output);
//output.rate.should.equal(0);
//output.duration.should.equal(0);
output.rate.should.equal(0.9);
Expand Down