From 9c1eb7d4ce15f0f9c933dabd8b249e9103eb2bf6 Mon Sep 17 00:00:00 2001 From: Scott Leibrand Date: Thu, 17 Aug 2023 18:35:45 -0700 Subject: [PATCH 1/5] =?UTF-8?q?#1455:=20Don=E2=80=99t=20cancel=20a=20high?= =?UTF-8?q?=20temp=20due=20to=20lack=20of=20BG=20data=20if=20the=20temp=20?= =?UTF-8?q?has=20been=20running=20for=20less=20than=2010m?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/determine-basal/determine-basal.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/determine-basal/determine-basal.js b/lib/determine-basal/determine-basal.js index 5e3ee78b8..9ada05bbf 100644 --- a/lib/determine-basal/determine-basal.js +++ b/lib/determine-basal/determine-basal.js @@ -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 ) { @@ -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; From 5fd2ad03fe82eb412463a8ee1e011331692f46c4 Mon Sep 17 00:00:00 2001 From: Scott Leibrand Date: Thu, 17 Aug 2023 19:04:25 -0700 Subject: [PATCH 2/5] don't modify temp if lastTempAge < 10, just print why not --- lib/determine-basal/determine-basal.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/determine-basal/determine-basal.js b/lib/determine-basal/determine-basal.js index 9ada05bbf..1c68e8208 100644 --- a/lib/determine-basal/determine-basal.js +++ b/lib/determine-basal/determine-basal.js @@ -189,7 +189,7 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_ 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 + 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 } else if ( tooflat ) { @@ -200,7 +200,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) && lastTempAge >= 10) || tooflat ) { + if ((minAgo > 12 || minAgo < -5) && lastTempAge < 10) { + rT.reason += "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; @@ -224,7 +227,6 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_ return rT; } } - // Get configured target, and return if unable to do so. // This should occur after checking that we're not in one of the CGM-data-related error conditions handled above, // and before using target_bg to adjust sensitivityRatio below. From faba83c34b1cdd74abd1fa1fd0acb83f9d8fcea5 Mon Sep 17 00:00:00 2001 From: Scott Date: Sat, 19 Aug 2023 19:30:57 -0700 Subject: [PATCH 3/5] remove suprious BOM introduced in #1443 causing /usr/bin/env: No such file --- bin/oref0-pushover.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/oref0-pushover.sh b/bin/oref0-pushover.sh index 5820b39c6..2df11e33b 100755 --- a/bin/oref0-pushover.sh +++ b/bin/oref0-pushover.sh @@ -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) From 2a0386af9b8ee671695da8a216abd0bc7eba16fa Mon Sep 17 00:00:00 2001 From: Scott Leibrand Date: Sat, 19 Aug 2023 19:54:06 -0700 Subject: [PATCH 4/5] add ', but' to make reason more readable --- lib/determine-basal/determine-basal.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/determine-basal/determine-basal.js b/lib/determine-basal/determine-basal.js index 1c68e8208..7215c7c40 100644 --- a/lib/determine-basal/determine-basal.js +++ b/lib/determine-basal/determine-basal.js @@ -201,7 +201,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 ((minAgo > 12 || minAgo < -5) && lastTempAge < 10) { - rT.reason += "lastTempAge of " + lastTempAge + " < 10m; doing nothing. "; + 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 @@ -227,6 +227,7 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_ return rT; } } + // Get configured target, and return if unable to do so. // This should occur after checking that we're not in one of the CGM-data-related error conditions handled above, // and before using target_bg to adjust sensitivityRatio below. From 61f5b188796647304a298492b5aff8dc487204e3 Mon Sep 17 00:00:00 2001 From: Scott Leibrand Date: Sat, 19 Aug 2023 20:44:45 -0700 Subject: [PATCH 5/5] if iob_data.lastTemp is undefined, calculate lastTempAge from currenttemp.duration % 30 --- lib/determine-basal/determine-basal.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/determine-basal/determine-basal.js b/lib/determine-basal/determine-basal.js index 7215c7c40..2447a6df4 100644 --- a/lib/determine-basal/determine-basal.js +++ b/lib/determine-basal/determine-basal.js @@ -184,9 +184,12 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_ } } - var lastTempAge = 0; + 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