From 9c1eb7d4ce15f0f9c933dabd8b249e9103eb2bf6 Mon Sep 17 00:00:00 2001 From: Scott Leibrand Date: Thu, 17 Aug 2023 18:35:45 -0700 Subject: [PATCH] =?UTF-8?q?#1455:=20Don=E2=80=99t=20cancel=20a=20high=20te?= =?UTF-8?q?mp=20due=20to=20lack=20of=20BG=20data=20if=20the=20temp=20has?= =?UTF-8?q?=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;