Sfoglia il codice sorgente

Update oref0 for #114 Add separate setting for sigmoid adjustment factor

and brings in "tddAdjBasal pop-up correction" https://github.com/nightscout/open-iaps-oref/pull/22

oref0 branch: dev - git version: fa373c9

Last commits:
fa373c9 Merge pull request 22 from nightscout/tmhastings-tddAdjBasal
fc0ae69 tddAdjBasal pop-up correction
487bcbb Merge pull request 21 from MikePlante1/separate_adjustment_factors
bjornoleh 2 anni fa
parent
commit
fb3b099582

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


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


+ 31 - 28
open-iaps-oref/lib/determine-basal/determine-basal.js

@@ -569,6 +569,8 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_
     const BG = glucose_status.glucose;
     const BG = glucose_status.glucose;
     const useDynamicCR = preferences.enableDynamicCR;
     const useDynamicCR = preferences.enableDynamicCR;
     const adjustmentFactor = preferences.adjustmentFactor;
     const adjustmentFactor = preferences.adjustmentFactor;
+    const adjustmentFactorSigmoid = preferences.adjustmentFactorSigmoid;
+    const enable_sigmoid = preferences.sigmoid;
     const currentMinTarget = profileTarget;
     const currentMinTarget = profileTarget;
     var exerciseSetting = false;
     var exerciseSetting = false;
     var log = "";
     var log = "";
@@ -610,7 +612,7 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_
     }
     }
 
 
     var startLog = ", Dynamic ratios log: ";
     var startLog = ", Dynamic ratios log: ";
-    var afLog = ", AF: " + adjustmentFactor;
+    var afLog = ", AF: " + (enable_sigmoid ? adjustmentFactorSigmoid : adjustmentFactor);
     var bgLog = "BG: " + BG + " mg/dl (" + (BG * 0.0555).toPrecision(2) + " mmol/l)";
     var bgLog = "BG: " + BG + " mg/dl (" + (BG * 0.0555).toPrecision(2) + " mmol/l)";
     var formula = "";
     var formula = "";
     var weightLog = "";
     var weightLog = "";
@@ -653,36 +655,37 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_
     // New logarithmic formula : var newRatio = profile.sens * adjustmentFactor * tdd * ln(( BG/insulinFactor) + 1 )) / 1800
     // New logarithmic formula : var newRatio = profile.sens * adjustmentFactor * tdd * ln(( BG/insulinFactor) + 1 )) / 1800
     //
     //
 
 
-    const enable_sigmoid = preferences.sigmoid;
     var sigmoidLog = ""
     var sigmoidLog = ""
-
+    
     if (dynISFenabled) {
     if (dynISFenabled) {
-        var newRatio = sensitivity * adjustmentFactor * tdd * Math.log(BG/insulinFactor+1) / 1800;
-        formula = ", Logarithmic formula";
-    }
-
-     // Sigmoid Function
-    if (dynISFenabled && enable_sigmoid) {
-        const as_min = minLimitChris;
-        const autosens_interval = maxLimitChris - as_min;
-        //Blood glucose deviation from set target (the lower BG target) converted to mmol/l to fit current formula.
-        const bg_dev = (BG - profileTarget) * 0.0555;
-        // Account for TDD of insulin. Compare last 2 hours with total data (up to 14 days)
-        var tdd_factor = tdd24h_14d_Ratio; // weighted average TDD / total data average TDD
-        var max_minus_one = maxLimitChris - 1;
-        // Avoid division by 0
-        if (maxLimitChris == 1) {
-            max_minus_one = maxLimitChris + 0.01 - 1;
+        // Logarithmic
+        if (!enable_sigmoid) {
+            var newRatio = sensitivity * adjustmentFactor * tdd * Math.log(BG/insulinFactor+1) / 1800;
+            formula = ", Logarithmic formula";
+        }
+        // Sigmoid
+        else {
+            const as_min = minLimitChris;
+            const autosens_interval = maxLimitChris - as_min;
+            //Blood glucose deviation from set target (the lower BG target) converted to mmol/l to fit current formula.
+            const bg_dev = (BG - profileTarget) * 0.0555;
+            // Account for TDD of insulin. Compare last 2 hours with total data (up to 14 days)
+            var tdd_factor = tdd24h_14d_Ratio; // weighted average TDD / total data average TDD
+            var max_minus_one = maxLimitChris - 1;
+            // Avoid division by 0
+            if (maxLimitChris == 1) {
+                max_minus_one = maxLimitChris + 0.01 - 1;
+            }
+            //Makes sigmoid factor(y) = 1 when BG deviation(x) = 0.
+            const fix_offset = (Math.log10(1/max_minus_one-as_min/max_minus_one) / Math.log10(Math.E));
+            //Exponent used in sigmoid formula
+            const exponent = bg_dev * adjustmentFactorSigmoid * tdd_factor + fix_offset;
+            // The sigmoid function
+            const sigmoid_factor = autosens_interval / (1 + Math.exp(-exponent)) + as_min;
+            newRatio = sigmoid_factor;
+            formula = ", Sigmoid function";
+            // Dynamic CR will be processed further down
         }
         }
-        //Makes sigmoid factor(y) = 1 when BG deviation(x) = 0.
-        const fix_offset = (Math.log10(1/max_minus_one-as_min/max_minus_one) / Math.log10(Math.E));
-        //Exponent used in sigmoid formula
-        const exponent = bg_dev * adjustmentFactor * tdd_factor + fix_offset;
-        // The sigmoid function
-        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;
     var cr = carbRatio;

+ 4 - 2
open-iaps-oref/lib/profile/index.js

@@ -68,12 +68,13 @@ function defaults ( ) {
     , target_bg: false // set to an integer value in mg/dL to override pump min_bg
     , target_bg: false // set to an integer value in mg/dL to override pump min_bg
     // autoISF variables
     // autoISF variables
     , smb_delivery_ratio: 0.5 //Default value: 0.5 Used if flexible delivery ratio is not used. This is another key OpenAPS safety cap, and specifies what share of the total insulin required can be delivered as SMB. This is to prevent people from getting into dangerous territory by setting SMB requests from the caregivers phone at the same time. Increase this experimental value slowly and with caution.
     , smb_delivery_ratio: 0.5 //Default value: 0.5 Used if flexible delivery ratio is not used. This is another key OpenAPS safety cap, and specifies what share of the total insulin required can be delivered as SMB. This is to prevent people from getting into dangerous territory by setting SMB requests from the caregivers phone at the same time. Increase this experimental value slowly and with caution.
-    , adjustmentFactor: 1
+    , adjustmentFactor: 0.8
+    , adjustmentFactorSigmoid: 0.5
     , useNewFormula: false
     , useNewFormula: false
     , enableDynamicCR: false
     , enableDynamicCR: false
     , sigmoid: false
     , sigmoid: false
     , weightPercentage: 0.65 
     , weightPercentage: 0.65 
-    , tddAdjBasal: false // Enable adjustment of basal based on the ratio of 24 h : 7 day average TDD
+    , tddAdjBasal: false // Enable adjustment of basal based on the ratio of 24 h : 10 day average TDD
     , enableSMB_high_bg: false // enable SMBs when a high BG is detected, based on the high BG target (adjusted or profile)
     , enableSMB_high_bg: false // enable SMBs when a high BG is detected, based on the high BG target (adjusted or profile)
     , enableSMB_high_bg_target: 110 // set the value enableSMB_high_bg will compare against to enable SMB. If BG > than this value, SMBs should enable.
     , enableSMB_high_bg_target: 110 // set the value enableSMB_high_bg will compare against to enable SMB. If BG > than this value, SMBs should enable.
     , threshold_setting: 0.60 // Use a configurable threshold setting
     , threshold_setting: 0.60 // Use a configurable threshold setting
@@ -102,6 +103,7 @@ function displayedDefaults () {
     profile.smb_delivery_ratio = allDefaults.smb_delivery_ratio;
     profile.smb_delivery_ratio = allDefaults.smb_delivery_ratio;
     profile.maxDelta_bg_threshold = allDefaults.maxDelta_bg_threshold;
     profile.maxDelta_bg_threshold = allDefaults.maxDelta_bg_threshold;
     profile.adjustmentFactor = allDefaults.adjustmentFactor;
     profile.adjustmentFactor = allDefaults.adjustmentFactor;
+    profile.adjustmentFactorSigmoid = allDefaults.adjustmentFactorSigmoid;
     profile.useNewFormula = allDefaults.useNewFormula;
     profile.useNewFormula = allDefaults.useNewFormula;
     profile.enableDynamicCR = allDefaults.enableDynamicCR;
     profile.enableDynamicCR = allDefaults.enableDynamicCR;
     profile.sigmoid = allDefaults.sigmoid;
     profile.sigmoid = allDefaults.sigmoid;

+ 5 - 1
oref0_source_version.txt

@@ -1,9 +1,13 @@
-oref0 branch: dev - git version: 5774155
+oref0 branch: dev - git version: fa373c9
 
 
 Last commits:
 Last commits:
+fa373c9 Merge pull request #22 from nightscout/tmhastings-tddAdjBasal
+fc0ae69 tddAdjBasal pop-up correction
+487bcbb Merge pull request #21 from MikePlante1/separate_adjustment_factors
 5774155 Merge pull request #20 from MikePlante1/disable_smb_schedule
 5774155 Merge pull request #20 from MikePlante1/disable_smb_schedule
 e3a8d73 Merge pull request #17 from MikePlante1/console_error_refactor
 e3a8d73 Merge pull request #17 from MikePlante1/console_error_refactor
 a29d9ce rename smbIsAlwaysOff to smbIsScheduledOff
 a29d9ce rename smbIsAlwaysOff to smbIsScheduledOff
+b777c77 Separate Adjustment Factors for Logarithmic and Sigmoid
 d898eb1 fix threshold console.error
 d898eb1 fix threshold console.error
 b89a39b Merge pull request #16 from bjornoleh/webpack-update
 b89a39b Merge pull request #16 from bjornoleh/webpack-update
 b8aaf93 Merge pull request #15 from avouspierre/dev
 b8aaf93 Merge pull request #15 from avouspierre/dev