Robert 1 год назад
Родитель
Сommit
6da0b1621a

Разница между файлами не показана из-за своего большого размера
+ 1 - 1
FreeAPS/Resources/javascript/bundle/determine-basal.js


Разница между файлами не показана из-за своего большого размера
+ 1 - 1
FreeAPS/Resources/javascript/bundle/meal.js


Разница между файлами не показана из-за своего большого размера
+ 1 - 1
FreeAPS/Resources/javascript/bundle/profile.js


+ 4 - 1
oref0_source_version.txt

@@ -1,6 +1,9 @@
-oref0 branch: tdd-pumpdataCheck - git version: 46deecb
+oref0 branch: maxAbsorptionTime - git version: f306168
 
 Last commits:
+f306168 reduce dynISF logging
+fb5f9bc introduce maxAbsorptionTime to orefmaxAbsorptionTime
+ade267d Merge pull request #37 from mountrcg/tdd-pumpdataCheck
 46deecb remove dynisf check on pumpdata calc
 2f258b2 Merge pull request #36 from mountrcg/fixTDDcheck
 4998a09 fix condition  to use weightedAverage as TDD

+ 3 - 2
trio-oref/lib/determine-basal/cob.js

@@ -12,7 +12,8 @@ function detectCarbAbsorption(inputs) {
     });
     var iob_inputs = inputs.iob_inputs;
     var basalprofile = inputs.basalprofile;
-    /* TODO why does declaring profile break tests-command-behavior.tests.sh? */ profile = inputs.iob_inputs.profile;
+    /* TODO why does declaring profile break tests-command-behavior.tests.sh? */
+    profile = inputs.iob_inputs.profile;
     var mealTime = new Date(inputs.mealTime);
     var ciTime = new Date(inputs.ciTime);
 
@@ -50,7 +51,7 @@ function detectCarbAbsorption(inputs) {
         }
         // only consider BGs for 6h after a meal for calculating COB
         var hoursAfterMeal = (bgTime-mealTime)/(60*60*1000);
-        if (hoursAfterMeal > 6 || foundPreMealBG) {
+        if (hoursAfterMeal > profile.maxAbsorptionTime || foundPreMealBG) {
             continue;
         } else if (hoursAfterMeal < 0) {
 //console.error("Found pre-meal BG:",glucose_data[i].glucose, bgTime, Math.round(hoursAfterMeal*100)/100);

+ 5 - 5
trio-oref/lib/determine-basal/determine-basal.js

@@ -314,7 +314,7 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_
                         basalScheduledRate_ = basalprofile[m].rate;
                         totalInsulin += accountForIncrements(basalScheduledRate_ * basDuration);
                         totalDuration -= basDuration;
-                        console.log("Dynamic ratios log: scheduled insulin added: " + accountForIncrements(basalScheduledRate_ * basDuration) + " U. Bas duration: " + basDuration.toPrecision(3) + " h. Base Rate: " + basalScheduledRate_ + " U/h" + ". Time :" + baseTime_);
+                        //console.log("Dynamic ratios log: scheduled insulin added: " + accountForIncrements(basalScheduledRate_ * basDuration) + " U. Bas duration: " + basDuration.toPrecision(3) + " h. Base Rate: " + basalScheduledRate_ + " U/h" + ". Time :" + baseTime_);
                         // Move clock to new date
                         old = addTimeToDate(old, basDuration);
                     }
@@ -338,7 +338,7 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_
                                 basalScheduledRate_ = basalprofile[m].rate;
                                 totalInsulin += accountForIncrements(basalScheduledRate_ * basDuration);
                                 totalDuration -= basDuration;
-                                console.log("Dynamic ratios log: scheduled insulin added: " + accountForIncrements(basalScheduledRate_ * basDuration) + " U. Bas duration: " + basDuration.toPrecision(3) + " h. Base Rate: " + basalScheduledRate_ + " U/h" + ". Time :" + baseTime_);
+                                //console.log("Dynamic ratios log: scheduled insulin added: " + accountForIncrements(basalScheduledRate_ * basDuration) + " U. Bas duration: " + basDuration.toPrecision(3) + " h. Base Rate: " + basalScheduledRate_ + " U/h" + ". Time :" + baseTime_);
                                 // Move clock to new date
                                 old = addTimeToDate(old, basDuration);
                             }
@@ -359,7 +359,7 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_
                             basalScheduledRate_ = basalprofile[m].rate;
                             totalInsulin += accountForIncrements(basalScheduledRate_ * basDuration);
                             totalDuration -= basDuration;
-                            console.log("Dynamic ratios log: scheduled insulin added: " + accountForIncrements(basalScheduledRate_ * basDuration) + " U. Bas duration: " + basDuration.toPrecision(3) + " h. Base Rate: " + basalScheduledRate_ + " U/h" + ". Time :" + baseTime_);
+                            //console.log("Dynamic ratios log: scheduled insulin added: " + accountForIncrements(basalScheduledRate_ * basDuration) + " U. Bas duration: " + basDuration.toPrecision(3) + " h. Base Rate: " + basalScheduledRate_ + " U/h" + ". Time :" + baseTime_);
                             // Move clock to new date
                             old = addTimeToDate(old, basDuration);
                         }
@@ -1307,7 +1307,7 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_
                     IOBpredBG = IOBpredBGs[IOBpredBGs.length-1] + (round(( -iobTick.activity * (1800 / ( tdd * adjustmentFactor * (Math.log((Math.max( IOBpredBGs[IOBpredBGs.length-1],39) / insulinFactor ) + 1 ) ) )) * 5 ),2)) + predDev;
                     //var ZTpredBG = ZTpredBGs[ZTpredBGs.length-1] + predZTBGI; // Adding dynamic ISF in predictions for UAM, ZT and IOB:
                     ZTpredBG = ZTpredBGs[ZTpredBGs.length-1] + (round(( -iobTick.iobWithZeroTemp.activity * (1800 / ( tdd * adjustmentFactor * (Math.log(( Math.max(ZTpredBGs[ZTpredBGs.length-1],39) / insulinFactor ) + 1 ) ) )) * 5 ), 2));
-                    console.log("Dynamic ISF (Logarithmic Formula) )adjusted predictions for IOB and ZT: IOBpredBG: " + round(IOBpredBG,2) + " , ZTpredBG: " + round(ZTpredBG,2));
+                    //console.log("Dynamic ISF (Logarithmic Formula) )adjusted predictions for IOB and ZT: IOBpredBG: " + round(IOBpredBG,2) + " , ZTpredBG: " + round(ZTpredBG,2));
                     break;
                 default:
                     IOBpredBG = IOBpredBGs[IOBpredBGs.length-1] + predBGI + predDev;
@@ -1347,7 +1347,7 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_
                 case dynISFenabled && !enable_sigmoid:
                     //UAMpredBG = UAMpredBGs[UAMpredBGs.length-1] + predBGI + Math.min(0, predDev) + predUCI; // Adding dynamic ISF in predictions for UAM:
                     UAMpredBG = UAMpredBGs[UAMpredBGs.length-1] + (round(( -iobTick.activity * (1800 / ( tdd * adjustmentFactor * (Math.log(( Math.max(UAMpredBGs[UAMpredBGs.length-1],39) / insulinFactor ) + 1 ) ) )) * 5 ),2)) + Math.min(0, predDev) + predUCI;
-                    console.log("Dynamic ISF (Logarithmic Formula) adjusted prediction for UAM: UAMpredBG: " + round(UAMpredBG,2));
+                    //console.log("Dynamic ISF (Logarithmic Formula) adjusted prediction for UAM: UAMpredBG: " + round(UAMpredBG,2));
                     break;
                 default:
                     UAMpredBG = UAMpredBGs[UAMpredBGs.length-1] + predBGI + Math.min(0, predDev) + predUCI;

+ 21 - 6
trio-oref/lib/meal/total.js

@@ -1,6 +1,12 @@
 var tz = require('moment-timezone');
 var calcMealCOB = require('../determine-basal/cob');
 
+function round(value, digits) {
+    if (! digits) { digits = 0; }
+    var scale = Math.pow(10, digits);
+    return Math.round(value * scale) / scale;
+}
+
 function recentCarbs(opts, time) {
     var treatments = opts.treatments;
     var profile_data = opts.profile;
@@ -41,10 +47,18 @@ function recentCarbs(opts, time) {
     var nsCarbsToRemove = 0;
     var bwCarbsToRemove = 0;
     var journalCarbsToRemove = 0;
+    var maxAbsorptionTime = 6;
+
+    if (typeof(profile_data.maxAbsorptionTime) === 'number' && ! isNaN(profile_data.maxAbsorptionTime)) {
+        maxAbsorptionTime = profile_data.maxAbsorptionTime;
+    } else {
+        console.error("Bad profile.maxAbsorptionTime:",profile_data.maxAbsorptionTime);
+    }
+
     treatments.forEach(function(treatment) {
         var now = time.getTime();
-        // consider carbs from up to 6 hours ago in calculating COB
-        var carbWindow = now - 6 * 60*60*1000;
+        // consider carbs from up to the meal preference maxAbsorptionTime hours ago in calculating COB
+        var carbWindow = now - maxAbsorptionTime * 60*60*1000;
         var treatmentDate = new Date(tz(treatment.timestamp));
         var treatmentTime = treatmentDate.getTime();
         if (treatmentTime > carbWindow && treatmentTime <= now) {
@@ -98,15 +112,16 @@ function recentCarbs(opts, time) {
     // calculate the current deviation and steepest deviation downslope over the last hour
     COB_inputs.ciTime = time.getTime();
     // set mealTime to 6h ago for Deviation calculations
-    COB_inputs.mealTime = time.getTime() - 6 * 60 * 60 * 1000;
+    COB_inputs.mealTime = time.getTime() - profile_data.maxAbsorptionTime * 60 * 60 * 1000;
     var c = calcMealCOB(COB_inputs);
     //console.error(c.currentDeviation, c.slopeFromMaxDeviation);
 
     // set a hard upper limit on COB to mitigate impact of erroneous or malicious carb entry
-    if (typeof(profile.maxCOB) === 'number' && ! isNaN(profile.maxCOB)) {
-        mealCOB = Math.min( profile.maxCOB, mealCOB );
+    if (typeof(profile_data.maxCOB) === 'number' && ! isNaN(profile_data.maxCOB)) {
+        mealCOB = Math.min( profile_data.maxCOB, mealCOB );
+        console.error("mealCOB: " + round(mealCOB,1) + " with maxCOB " + profile_data.maxCOB + " and maxAbsorptionTime " + maxAbsorptionTime);
     } else {
-        console.error("Bad profile.maxCOB:",profile.maxCOB);
+        console.error("Bad profile.maxCOB:",profile_data.maxCOB);
     }
 
     // if currentDeviation is null or maxDeviation is 0, set mealCOB to 0 for zombie-carb safety

+ 4 - 1
trio-oref/lib/profile/index.js

@@ -25,6 +25,7 @@ function defaults ( ) {
     // (If someone enters more carbs or stacks more; OpenAPS will just truncate dosing based on 120.
     // Essentially, this just limits AMA/SMB as a safety cap against excessive COB entry)
     , maxCOB: 120
+    , maxAbsorptionTime: 6 // Handling of long lasting effects of "heavy meals" containing large cqantities of fat and protein might be improved by letting the system consider meal effects for longer than the default six hours.
     , skip_neutral_temps: false // if true, don't set neutral temps
     , unsuspend_if_no_temp: false // if true, pump will un-suspend after a zero temp finishes
     , min_5m_carbimpact: 8 // mg/dL per 5m (8 mg/dL/5m corresponds to 24g/hr at a CSF of 4 mg/dL/g (x/5*60/4))
@@ -74,7 +75,7 @@ function defaults ( ) {
     , useNewFormula: false
     , enableDynamicCR: false
     , sigmoid: false
-    , weightPercentage: 0.65 
+    , weightPercentage: 0.65
     , tddAdjBasal: false // Enable adjustment of basal based on the ratio of 24 h : 10 day average TDD
     , threshold_setting: 60 // Use a configurable threshold setting
   }
@@ -111,6 +112,8 @@ function displayedDefaults () {
     profile.threshold_setting = allDefaults.threshold_setting;
     profile.enableSMB_high_bg = allDefaults.enableSMB_high_bg;
     profile.enableSMB_high_bg_target = allDefaults.enableSMB_high_bg_target;
+    profile.maxCOB = allDefaults.maxCOB;
+    profile.maxAbsorptionTime = allDefaults.maxAbsorptionTime;
 
     console.error(profile);
     return profile