Sfoglia il codice sorgente

Adjustments (trio-oref and TCD)
* TCD: Remove enableDynamicCR setting from TCD
* TCD: Allow carb ratio to begin at 1.0 g/U
* trio-oref: Always add minPredBG to rT object
* trio-oref: Remove dynamicCR
* trio-oref: Lower min carb ratio to 1g/U (down from 3)
* Pull in changes to trio-oref via webpack re-bundling of JS sources

Deniz Cengiz 1 anno fa
parent
commit
8a51609663

File diff suppressed because it is too large
+ 1 - 1
Trio/Resources/javascript/bundle/autosens.js


File diff suppressed because it is too large
+ 1 - 1
Trio/Resources/javascript/bundle/autotune-core.js


File diff suppressed because it is too large
+ 1 - 1
Trio/Resources/javascript/bundle/autotune-prep.js


File diff suppressed because it is too large
+ 1 - 1
Trio/Resources/javascript/bundle/basal-set-temp.js


File diff suppressed because it is too large
+ 1 - 1
Trio/Resources/javascript/bundle/determine-basal.js


File diff suppressed because it is too large
+ 1 - 1
Trio/Resources/javascript/bundle/iob.js


File diff suppressed because it is too large
+ 1 - 1
Trio/Resources/javascript/bundle/meal.js


File diff suppressed because it is too large
+ 1 - 1
Trio/Resources/javascript/bundle/profile.js


+ 0 - 1
Trio/Resources/json/defaults/preferences.json

@@ -43,7 +43,6 @@
   "adjustmentFactor" : 0.8,
   "adjustmentFactorSigmoid" : 0.5,
   "sigmoid" : false,
-  "enableDynamicCR" : false,
   "useNewFormula" : false,
   "useWeightedAverage" : false,
   "weightPercentage" : 0.35,

+ 0 - 7
Trio/Sources/Models/Preferences.swift

@@ -45,7 +45,6 @@ struct Preferences: JSON, Equatable {
     var adjustmentFactor: Decimal = 0.8
     var adjustmentFactorSigmoid: Decimal = 0.5
     var sigmoid: Bool = false
-    var enableDynamicCR: Bool = false
     var useNewFormula: Bool = false
     var useWeightedAverage: Bool = false
     var weightPercentage: Decimal = 0.35
@@ -101,7 +100,6 @@ extension Preferences {
         case adjustmentFactor
         case adjustmentFactorSigmoid
         case sigmoid
-        case enableDynamicCR
         case useNewFormula
         case useWeightedAverage
         case weightPercentage
@@ -298,11 +296,6 @@ extension Preferences: Decodable {
             preferences.sigmoid = sigmoid
         }
 
-        // FIXME: remove this at a later release; hard code it to false for now
-        if let enableDynamicCR = try? container.decode(Bool.self, forKey: .enableDynamicCR) {
-            preferences.enableDynamicCR = false
-        }
-
         if let useNewFormula = try? container.decode(Bool.self, forKey: .useNewFormula) {
             preferences.useNewFormula = useNewFormula
         }

+ 1 - 1
Trio/Sources/Modules/CarbRatioEditor/CarbRatioEditorStateModel.swift

@@ -9,7 +9,7 @@ extension CarbRatioEditor {
 
         let timeValues = stride(from: 0.0, to: 1.days.timeInterval, by: 30.minutes.timeInterval).map { $0 }
 
-        let rateValues = stride(from: 30.0, to: 501.0, by: 1.0).map { ($0.decimal ?? .zero) / 10 }
+        let rateValues = stride(from: 10.0, to: 501.0, by: 1.0).map { ($0.decimal ?? .zero) / 10 }
 
         var canAdd: Bool {
             guard let lastItem = items.last else { return true }

+ 13 - 3
oref0_source_version.txt

@@ -1,13 +1,23 @@
-oref0 branch: removeTDDCalc - git version: 73d6d6c
+oref0 branch: tcd-fixes - git version: ffb9374
 
 Last commits:
-73d6d6c webpack for Trio-dev
-5c6ce4b remove TDD calculation
+ffb9374 Always add minPredBG to rT object
+814b629 Remove dynamicCR
+4b62fe2 Lower min carb ratio to 1 g/U (down from 3)
+33d6b02 Merge pull request #39 from mountrcg/removeTDDCalc
+a4e46fc Merge pull request #42 from kingst/fix-date-undefined
+9a39c57 var -> let in tests
+ad3b5bb Fixes an incorrect undefined check
+ae14e0d Merge pull request #38 from kingst/profile-carbs-fix
+9df2270 Merge pull request #40 from mountrcg/maxAbsorptionTime
 a542ed3 use guarded maxAbsorptionTime
 4c77757 Revert "reduce dynISF logging"
 1567c76 use variable name maxMealAbsorptionTime
+bdcdf69 also remove insulin distribution and fix sonarcloud issue
 61b4f85 reduce dynISF logging
 0fe81c1 introduce maxAbsorptionTime to orefmaxAbsorptionTime
+5c6ce4b remove TDD calculation
+c8e7b32 Always check for bad carb ratios in profile
 ade267d Merge pull request #37 from mountrcg/tdd-pumpdataCheck
 46deecb remove dynisf check on pumpdata calc
 2f258b2 Merge pull request #36 from mountrcg/fixTDDcheck

+ 1 - 1
trio-oref/lib/autotune/index.js

@@ -412,7 +412,7 @@ function tuneAllTheThings (inputs) {
     var maxCR = pumpCarbRatio * autotuneMax;
     if (maxCR > 150) { maxCR = 150 }
     var minCR = pumpCarbRatio * autotuneMin;
-    if (minCR < 1) { minCR = 3 }
+    if (minCR < 1) { minCR = 1 }
     // safety cap fullNewCR
     if (typeof(pumpCarbRatio) !== 'undefined') {
         if (fullNewCR > maxCR) {

+ 18 - 47
trio-oref/lib/determine-basal/determine-basal.js

@@ -156,6 +156,10 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_
     const cr_ = oref2_variables.cr;
     const smbMinutes = oref2_variables.smbMinutes;
     const uamMinutes = oref2_variables.uamMinutes;
+    // tdd past 24 hour
+    let tdd = oref2_variables.currentTDD;
+    var logOutPut = "";
+    var tddReason = "";
 
     var dynISFenabled = preferences.useNewFormula
 
@@ -168,10 +172,7 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_
         systemTime = new Date(currentTime);
     }
 
-    // tdd past 24 hours
-    var logOutPut = "";
-    var tddReason = "";
-    var tdd = oref2_variables.currentTDD;
+
 
     const weightedAverage = oref2_variables.weightedAverage;
     var overrideFactor = 1;
@@ -202,7 +203,6 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_
 
     // Dynamic ratios
     const BG = glucose_status.glucose;
-    const useDynamicCR = preferences.enableDynamicCR;
     const adjustmentFactor = preferences.adjustmentFactor;
     const adjustmentFactorSigmoid = preferences.adjustmentFactorSigmoid;
     const enable_sigmoid = preferences.sigmoid;
@@ -319,18 +319,15 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_
             const sigmoid_factor = autosens_interval / (1 + Math.exp(-exponent)) + as_min;
             newRatio = sigmoid_factor;
             formula = ", Sigmoid function";
-            // Dynamic CR will be processed further down
         }
     }
 
-    var cr = carbRatio;
-    const cr_before = round(carbRatio, 1);
-    var log_isfCR = "";
+    var dynamicISFLog = "";
     var limitLog = "";
 
     if (dynISFenabled && tdd > 0) {
 
-        log_isfCR = ", Dynamic ISF/CR: On/";
+        dynamicISFLog = ", Dynamic ISF: On";
 
         // Respect autosens.max and autosens.min limitLogs
         if (newRatio > maxLimitChris) {
@@ -343,53 +340,30 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_
             newRatio = minLimitChris;
         }
 
-        // Dynamic CR (Test)
-        if (useDynamicCR) {
-            log_isfCR += "On";
-            var dynCR = newRatio;
-
-            /*
-            // Lessen the ratio used by half, if newRatio > 1.
-            if (newRatio > 1) {
-                dynCR = (newRatio - 1) / 2 + 1;
-            }
-
-            cr = round(cr/dynCR, 2);
-            var logCR = " CR: " + cr + " g/U";
-            carbRatio = cr;
-            */
-            carbRatio /= dynCR;
-            var logCR = ". New Dynamic CR: " + round(carbRatio, 1) + " g/U";
-
-        } else {
-            logCR = " CR: " + cr + " g/U";
-            log_isfCR += "Off";
-        }
-
         const isf = sensitivity / newRatio;
 
          // Set the new ratio
          autosens_data.ratio = newRatio;
 
-        sigmoidLog = ". Using Sigmoid function, the autosens ratio has been adjusted with sigmoid factor to: " + round(autosens_data.ratio, 2) + ". New ISF = " + round(isf, 2) + " mg/dl (" + round(0.0555 * isf, 2) + " (mmol/l)" + ". CR adjusted from " + round(cr_before,2) + " to " + round(carbRatio,2);
+        sigmoidLog = ". Using Sigmoid function, the autosens ratio has been adjusted with sigmoid factor to: " + round(autosens_data.ratio, 2) + ". New ISF = " + round(isf, 2) + " mg/dl (" + round(0.0555 * isf, 2) + " (mmol/l).";
 
         if (!enable_sigmoid) {
             log += ", Dynamic autosens.ratio set to " + round(newRatio,2) + " with ISF: " + isf.toPrecision(3) + " mg/dl/U (" + (isf * 0.0555).toPrecision(3) + " mmol/l/U)";
         } else { log += sigmoidLog }
 
 
-        logOutPut += startLog + bgLog + afLog + formula + log + log_isfCR + logCR + weightLog;
+        logOutPut += startLog + bgLog + afLog + formula + log + dynamicISFLog + weightLog;
 
     } else { logOutPut += startLog + "Dynamic Settings disabled"; }
 
     console.log(logOutPut);
 
-    if (!dynISFenabled && !useDynamicCR) {
+    if (!dynISFenabledR) {
         tddReason += "";
     } else if (dynISFenabled && profile.tddAdjBasal) {
-        tddReason += log_isfCR + formula + limitLog + afLog + basal_ratio_log;
+        tddReason += dynamicISFLog + formula + limitLog + afLog + basal_ratio_log;
     }
-    else if (dynISFenabled && !profile.tddAdjBasal) { tddReason += log_isfCR + formula + limitLog + afLog; }
+    else if (dynISFenabled && !profile.tddAdjBasal) { tddReason += dynamicISFLog + formula + limitLog + afLog; }
 
     if (0.5 !== profile.smb_delivery_ratio) {
         tddReason += ", SMB Ratio: " + Math.min(profile.smb_delivery_ratio, 1);
@@ -909,7 +883,7 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_
     var minUAMGuardBG = 999;
     var minIOBGuardBG = 999;
     var minZTGuardBG = 999;
-    //var minPredBG;
+    var minPredBG;
     var avgPredBG;
     var IOBpredBG = eventualBG;
     var maxIOBPredBG = bg;
@@ -1189,13 +1163,7 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_
     rT.CR=round(carbRatio, 1);
     rT.target_bg=convert_bg(target_bg, profile);
     rT.current_target=round(target_bg, 0);
-
-    var cr_log = rT.CR;
-    if (cr_before != rT.CR) {
-        cr_log = cr_before + "\u2192" + rT.CR;
-    }
-
-    rT.reason = isfreason + ", COB: " + rT.COB + ", Dev: " + rT.deviation + ", BGI: " + rT.BGI + ", CR: " + cr_log + ", Target: " + targetLog + ", minPredBG " + convert_bg(minPredBG, profile) + ", minGuardBG " + convert_bg(minGuardBG, profile) + ", IOBpredBG " + convert_bg(lastIOBpredBG, profile);
+    rT.reason = isfreason + ", COB: " + rT.COB + ", Dev: " + rT.deviation + ", BGI: " + rT.BGI + ", CR: " + rT.CR + ", Target: " + targetLog + ", minPredBG " + convert_bg(minPredBG, profile) + ", minGuardBG " + convert_bg(minGuardBG, profile) + ", IOBpredBG " + convert_bg(lastIOBpredBG, profile);
     if (lastCOBpredBG > 0) {
         rT.reason += ", COBpredBG " + convert_bg(lastCOBpredBG, profile);
     }
@@ -1461,8 +1429,11 @@ var maxDelta_bg_threshold;
         if (minPredBG < min_bg && eventualBG > min_bg) {
             rT.manualBolusErrorString = 6;
             rT.insulinForManualBolus = round((rT.eventualBG - rT.target_bg) / sens, 2);
-            rT.minPredBG = minPredBG;
         }
+
+        // Moving this out of the if condition in L1429, so that minPredBG is becomes always available in rT object (aka Trio's determination)
+        rT.minPredBG = minPredBG;
+
         // if in SMB mode, don't cancel SMB zero temp
         if (! (microBolusAllowed && enableSMB )) {
             rT.reason += convert_bg(eventualBG, profile)+ "-" + convert_bg(minPredBG, profile) + " in range: no temp required";

+ 10 - 7
trio-oref/lib/profile/carbs.js

@@ -1,8 +1,10 @@
 
 var getTime = require('../medtronic-clock');
 
-function carbRatioLookup (inputs, profile) {
-    var now = new Date();
+function carbRatioLookup (inputs, profile, now) {
+    if (typeof(now) === 'undefined') {
+        now = new Date();
+    }
     var carbratio_data = inputs.carbratio;
     if (typeof(carbratio_data) !== "undefined" && typeof(carbratio_data.schedule) !== "undefined") {
         var carbRatio;
@@ -13,14 +15,15 @@ function carbRatioLookup (inputs, profile) {
             for (var i = 0; i < carbratio_data.schedule.length - 1; i++) {
                 if ((now >= getTime(carbratio_data.schedule[i].offset)) && (now < getTime(carbratio_data.schedule[i + 1].offset))) {
                     carbRatio = carbratio_data.schedule[i];
-                    // disallow impossibly high/low carbRatios due to bad decoding
-                    if (carbRatio < 3 || carbRatio > 150) {
-                        console.error("Error: carbRatio of " + carbRatio + " out of bounds.");
-                        return;
-                    }
                     break;
                 }
             }
+            // disallow impossibly high/low carbRatios due to bad decoding
+            if (carbRatio.ratio < 1 || carbRatio.ratio > 150) {
+                console.error("Error: carbRatio of " + carbRatio.ratio + " out of bounds.");
+                return;
+            }
+
             if (carbratio_data.units === "exchanges") {
                 carbRatio.ratio = 12 / carbRatio.ratio
             }