Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1455: Don’t cancel a <10m old high temp due to lack of BG data #1456

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from
2 changes: 1 addition & 1 deletion bin/oref0-pushover.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/usr/bin/env bash

source $(dirname $0)/oref0-bash-common-functions.sh || (echo "ERROR: Failed to run oref0-bash-common-functions.sh. Is oref0 correctly installed?"; exit 1)

Expand Down
13 changes: 12 additions & 1 deletion lib/determine-basal/determine-basal.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,14 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_
}
}

var lastTempAge;
if (typeof iob_data.lastTemp !== 'undefined' ) {
lastTempAge = round(( new Date(systemTime).getTime() - iob_data.lastTemp.date ) / 60000); // in minutes
} else if (typeof currenttemp.duration !== 'undefined' ) {
// the second % 30 converts any lastTempAge of 30 to 0
lastTempAge = (30 - currenttemp.duration % 30) % 30;
}

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 changing less than 1 mg/dL/5m for 45m, cancel any high temps and shorten any long zero temps
Expand All @@ -195,7 +203,10 @@ 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 ((minAgo > 12 || minAgo < -5) && lastTempAge < 10) {
rT.reason += ", but lastTempAge of " + lastTempAge + " < 10m; doing nothing. ";
return rT;
} else if (bg <= 10 || bg === 38 || noise >= 3 || minAgo > 12 || minAgo < -5 || 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