Skip to content

Commit

Permalink
#1455: Don’t cancel a high temp due to lack of BG data if the temp ha…
Browse files Browse the repository at this point in the history
…s been running for less than 10m
  • Loading branch information
scottleibrand committed Aug 18, 2023
1 parent 10f9e27 commit 9c1eb7d
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/determine-basal/determine-basal.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,12 @@ 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
var lastTempAge = 0;
if (typeof iob_data.lastTemp !== 'undefined' ) {
lastTempAge = round(( new Date(systemTime).getTime() - iob_data.lastTemp.date ) / 60000); // in minutes
}

if ((minAgo > 12 || minAgo < -5) && lastTempAge >= 10) { // 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 changing less than 1 mg/dL/5m for 45m, cancel any high temps and shorten any long zero temps
} else if ( tooflat ) {
Expand All @@ -195,7 +200,7 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_
}
}
// Then, for all such error conditions, cancel any running high temp or shorten any long zero temp, and return.
if (bg <= 10 || bg === 38 || noise >= 3 || minAgo > 12 || minAgo < -5 || tooflat ) {
if (bg <= 10 || bg === 38 || noise >= 3 || ((minAgo > 12 || minAgo < -5) && lastTempAge >= 10) || tooflat ) {
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;
Expand Down

0 comments on commit 9c1eb7d

Please sign in to comment.