Skip to content
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