Skip to content

Commit

Permalink
Updated oref2 files based on findings in minimised files in iAPS v3.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy-storring committed Feb 28, 2024
1 parent a9bdbb1 commit 05a1a2e
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 67 deletions.
3 changes: 1 addition & 2 deletions lib/autotune-prep/categorize.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ function categorizeBGDatums(opts) {
var type="";
// main for loop
var fullHistory = IOBInputs.history;
var lastIsfResult = null;
for (i=bucketedData.length-5; i > 0; --i) {
glucoseDatum = bucketedData[i];
//console.error(glucoseDatum);
Expand Down Expand Up @@ -169,7 +168,7 @@ function categorizeBGDatums(opts) {

//sens = ISF
var sens;
[sens, lastIsfResult] = ISF.isfLookup(IOBInputs.profile.isfProfile, BGDate, lastIsfResult);
sens = ISF.isfLookup(IOBInputs.profile.isfProfile, BGDate);
IOBInputs.clock=BGDate.toISOString();
// trim down IOBInputs.history to just the data for 6h prior to BGDate
//console.error(IOBInputs.history[0].created_at);
Expand Down
2 changes: 1 addition & 1 deletion lib/autotune/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ function tuneAllTheThings (inputs) {
var maxCR = pumpCarbRatio * autotuneMax;
if (maxCR > 150) { maxCR = 150 }
var minCR = pumpCarbRatio * autotuneMin;
if (minCR < 3) { minCR = 3 }
if (minCR < 1) { minCR = 3 }
// safety cap fullNewCR
if (typeof(pumpCarbRatio) !== 'undefined') {
if (fullNewCR > maxCR) {
Expand Down
3 changes: 1 addition & 2 deletions lib/determine-basal/autosens.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,11 @@ function detectSensitivity(inputs) {
var mealCarbs = 0;
var mealStartCounter = 999;
var type="";
var lastIsfResult = null;
//console.error(bucketed_data);
for (i=3; i < bucketed_data.length; ++i) {
bgTime = new Date(bucketed_data[i].date);
var sens;
[sens, lastIsfResult] = isf.isfLookup(profile.isfProfile, bgTime, lastIsfResult);
sens = isf.isfLookup(profile.isfProfile, bgTime);

//console.error(bgTime , bucketed_data[i].glucose);
var bg;
Expand Down
3 changes: 1 addition & 2 deletions lib/determine-basal/cob.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,11 @@ function detectCarbAbsorption(inputs) {
var minDeviation = 999;
var allDeviations = [];
//console.error(bucketed_data);
var lastIsfResult = null;
for (i=0; i < bucketed_data.length-3; ++i) {
bgTime = new Date(bucketed_data[i].date);

var sens;
[sens, lastIsfResult] = isf.isfLookup(profile.isfProfile, bgTime, lastIsfResult);
sens = isf.isfLookup(profile.isfProfile, bgTime);

//console.error(bgTime , bucketed_data[i].glucose, bucketed_data[i].date);
var bg;
Expand Down
11 changes: 10 additions & 1 deletion lib/determine-basal/determine-basal.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ function enable_smb(
}


var determine_basal = function determine_basal(glucose_status, currenttemp, iob_data, profile, autosens_data, meal_data, tempBasalFunctions, microBolusAllowed, reservoir_data, currentTime, pumphistory, preferences, basalprofile, oref2_variables) {
var determine_basal = function determine_basal(glucose_status, currenttemp, iob_data, profile, autosens_data, meal_data, tempBasalFunctions, microBolusAllowed, reservoir_data, currentTime, pumphistory, preferences, basalprofile, oref2_variables, middleWare) {

var profileTarget = profile.min_bg;
var overrideTarget = oref2_variables.overrideTarget;
Expand Down Expand Up @@ -732,6 +732,15 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_
}
else if (dynISFenabled && !profile.tddAdjBasal) { tddReason += log_isfCR + formula + limitLog + afLog; }

if (0.5 !== profile.smb_delivery_ratio) {
tddReason += ", SMB Ratio: " + Math.min(profile.smb_delivery_ratio, 1);
}

// Not confident but something like this in iAPS v3.0.3
if (tddReason !== "" && tddReason !== "Nothing changed"){
tddReason += ", Middleware: " + middleWare;
}

// --------------- END OF DYNAMIC RATIOS CALCULATION ------ A FEW LINES ADDED ALSO AT LINE NR 1136 and 1178 ------------------------------------------------


Expand Down
17 changes: 11 additions & 6 deletions lib/meal/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,18 @@ function findMealInputs (inputs) {

for (var i=0; i < carbHistory.length; i++) {
var current = carbHistory[i];
if (current.carbs && current.created_at) {
if (current.carbs && current.actualDate) {
var temp = {};
temp.timestamp = current.actualDate;
temp.carbs = current.carbs;
temp.nsCarbs = current.carbs;
} else if (current.carbs && current.created_at) {
var temp = {};
temp.timestamp = current.created_at;
temp.carbs = current.carbs;
temp.nsCarbs = current.carbs;
if (!arrayHasElementWithSameTimestampAndProperty(mealInputs,current.created_at,"carbs")) {
if (!arrayHasElementWithSameTimestampAndProperty(mealInputs,current.created_at,"carbs") ||
!arrayHasElementWithSameTimestampAndProperty(mealInputs, current.actualDate,"carbs")) {
mealInputs.push(temp);
} else {
duplicates += 1;
Expand All @@ -57,8 +63,7 @@ function findMealInputs (inputs) {
// More specifically, we need to make sure we process the corresponding bolus entry first.
bolusWizardInputs.push(current);

} else if ((current._type === "Meal Bolus" || current._type === "Correction Bolus" || current._type === "Snack Bolus" || current._type === "Bolus Wizard" || current._type === "Carb Correction") && current.created_at) {
//imports carbs entered through Nightscout Care Portal
} else if ((current._type === "Meal Bolus" || current._type === "Correction Bolus" || current._type === "Snack Bolus" || current._type === "Bolus Wizard" || current._type === "Carb Correction") && current.created_at || current.actualDate) { //imports carbs entered through Nightscout Care Portal
//"Bolus Wizard" refers to the Nightscout Bolus Wizard, not the Medtronic Bolus Wizard
temp = {};
temp.timestamp = current.created_at;
Expand Down Expand Up @@ -86,7 +91,7 @@ function findMealInputs (inputs) {
temp = {};
temp.carbs = current.carbs;
temp.nsCarbs = current.carbs;
temp.timestamp = current.created_at;
temp.timestamp = current.actualDate || current.created_at;
temp.bolus = current.insulin;
if (!arrayHasElementWithSameTimestampAndProperty(mealInputs,current.timestamp,"carbs")) {
mealInputs.push(temp);
Expand All @@ -95,7 +100,7 @@ function findMealInputs (inputs) {
}
} else if (current._type === "JournalEntryMealMarker" && current.carb_input > 0 && current.timestamp) {
temp = {};
temp.timestamp = current.timestamp;
temp.timestamp = current.actualDate || current.created_at;
temp.carbs = current.carb_input;
temp.journalCarbs = current.carb_input;
if (!arrayHasElementWithSameTimestampAndProperty(mealInputs,current.timestamp,"carbs")) {
Expand Down
46 changes: 3 additions & 43 deletions lib/profile/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,14 @@ function defaults ( ) {
, sensitivity_raises_target: false // raise BG target when autosens detects sensitivity
, resistance_lowers_target: false // lower BG target when autosens detects resistance
, exercise_mode: false // when true, > 100 mg/dL high temp target adjusts sensitivityRatio for exercise_mode. This majorly changes the behavior of high temp targets from before. synonmym for high_temptarget_raises_sensitivity
, half_basal_exercise_target: 150 // when temptarget is 160 mg/dL *and* exercise_mode=true, run 50% basal at this level (120 = 75%; 140 = 60%)
, half_basal_exercise_target: 150 // when temptarget is 150 mg/dL *and* exercise_mode=true, run 50% basal at this level (120 = 75%; 140 = 60%)
// create maxCOB and default it to 120 because that's the most a typical body can absorb over 4 hours.
// (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
, 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
, bolussnooze_dia_divisor: 2 // bolus snooze decays after 1/2 of DIA
, 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))
, floating_carbs: false // if true, use all entered carbs for predBGs: don't decay them as COB
, autotune_isf_adjustmentFraction: 1.0 // keep autotune ISF closer to pump ISF via a weighted average of fullNewISF and pumpISF. 1.0 allows full adjustment, 0 is no adjustment from pump ISF.
, remainingCarbsFraction: 1.0 // fraction of carbs we'll assume will absorb over 4h if we don't yet see carb absorption
, remainingCarbsCap: 90 // max carbs we'll assume will absorb over 4h if we don't yet see carb absorption
Expand Down Expand Up @@ -72,32 +70,13 @@ function defaults ( ) {
//, maxRaw: 200 // highest raw/noisy CGM value considered safe to use for looping
, calc_glucose_noise: false
, target_bg: false // set to an integer value in mg/dL to override pump min_bg
, edison_battery_shutdown_voltage: 3050
, pi_battery_shutdown_percent: 2
// autoISF variables
, use_autoisf: false // Defaults to false. Enable to use autoISF & SMB Range extension.
, autoisf_hourlychange: 0.2 // rate at which autoISF grows per hour assuming bg is twice target. When value = 1.0, ISF is reduced to 50% after 1 hour of BG at 2x target
, autoisf_max: 1.5 // Multiplier cap on how high the autoISF ratio can be and therefore how low it can adjust ISF
, autoisf_min: 1 // This is a multiplier cap for autoISF to set a limit on how low the autoISF ratio can be, which in turn determines how high it can adjust ISF.
, smb_max_range_extension: 1 //Default value: 1 This is another key OpenAPS safety cap, and specifies by what factor you can exceed the regular 120 maxSMB/maxUAM minutes. Increase this experimental value slowly and with caution.
, enableautoisf_with_COB: false // Enables autoISF not just for UAM, but also with COB
, higher_ISFrange_weight: 0 // Default value: 0.0 This is the weight applied to the polygon which adapts ISF if glucose is above target. With 0.0 the effect is effectively disabled.
, lower_ISFrange_weight: 0 // Default value: 0.0 This is the weight applied to the polygon which adapts ISF if glucose is below target. With 0.0 the effect is effectively disabled.
, delta_ISFrange_weight: 0 // Default value: 0.0 This is the weight applied to the polygon which adapts ISF higher deltas. With 0.0 the effect is effectively disabled.
, smb_delivery_ratio_bg_range: 0 // Default value: 0, Sensible is 40. The linearly increasing SMB delivery ratio is mapped to the glucose range [target_bg, target_bg+bg_range]. At target_bg the SMB ratio is smb_delivery_ratio_min, at target_bg+bg_range it is smb_delivery_ratio_max. With 0 the linearly increasing SMB ratio is disabled and the fix smb_delivery_ratio is used.
, smb_delivery_ratio_min: 0.5 // Default value: 0.5 This is the lower end of a linearly increasing ratio rather than the fix value above.
, smb_delivery_ratio_max: 0.9 // Default value: 0.9 This is the upper end of a linearly increasing ratio rather than the fix value above.
, 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.
, postmeal_ISF_weight: 0 // Default value: 0.0 This is the weight applied to the linear slope while glucose rises and which adapts ISF. With 0.0 this contribution is effectively disabled.
, postmeal_ISF_duration: 3 // Default value: 3 This is the duration in hours how long after a meal the effect will be active. Oref will delete carb timing after 10 hours latest no matter what you enter.
, enableppisf_always: false // Enable the postprandial ISF adaptation all the time regardless of when the last meal was taken.
, enable_BG_acceleration: false //Enable the additional use of autoISF 2.2 BG acceleration adaption
, bgAccel_ISF_weight: 0 // Default value: 0 This is the weight applied while glucose accelerates and which strengthens ISF. With 0 this contribution is effectively disabled.
, bgBrake_ISF_weight: 0 // Default value: 0 This is the weight applied while glucose decelerates and which weakens ISF. With 0 this contribution is effectively disabled.
, adjustmentFactor: 1
, useNewFormula: false
, enableDynamicCR: false
, enableChris: false
, sigmoid: false
, weightPercentage: 0.65
, tddAdjBasal: false // Enable adjustment of basal based on the ratio of 24 h : 7 day average TDD
, enableSMB_high_bg: false // enable SMBs when a high BG is detected, based on the high BG target (adjusted or profile)
Expand All @@ -124,33 +103,14 @@ function displayedDefaults (final_result) {
profile.enableUAM = allDefaults.enableUAM;
profile.curve = allDefaults.curve;
profile.offline_hotspot = allDefaults.offline_hotspot;
profile.edison_battery_shutdown_voltage = allDefaults.edison_battery_shutdown_voltage;
profile.pi_battery_shutdown_percent = allDefaults.pi_battery_shutdown_percent;
profile.bolus_increment = allDefaults.bolus_increment;
profile.use_autoisf = allDefaults.use_autoisf;
profile.autoisf_hourlychange = allDefaults.autoisf_hourlychange;
profile.autoisf_max = allDefaults.autoisf_max;
profile.autoisf_min = allDefaults.autoisf_min;
profile.smb_delivery_ratio = allDefaults.smb_delivery_ratio;
profile.smb_max_range_extension = allDefaults.smb_max_range_extension;
profile.enableautoisf_with_COB = allDefaults.enableautoisf_with_COB;
profile.higher_ISFrange_weight = allDefaults.higher_ISFrange_weight;
profile.lower_ISFrange_weight = allDefaults.lower_ISFrange_weight;
profile.delta_ISFrange_weight = allDefaults.delta_ISFrange_weight;
profile.smb_delivery_ratio_bg_range = allDefaults.smb_delivery_ratio_bg_range;
profile.smb_delivery_ratio_min = allDefaults.smb_delivery_ratio_min;
profile.smb_delivery_ratio_max = allDefaults.smb_delivery_ratio_max;
profile.postmeal_ISF_weight = allDefaults.postmeal_ISF_weight;
profile.postmeal_ISF_duration = allDefaults.postmeal_ISF_duration;
profile.enableppisf_always = allDefaults.enableppisf_always;
profile.enable_BG_acceleration = allDefaults.enable_BG_acceleration;
profile.bgAccel_ISF_weight = allDefaults.bgAccel_ISF_weight;
profile.bgBrake_ISF_weight = allDefaults.bgBrake_ISF_weight;
profile.maxDelta_bg_threshold = allDefaults.maxDelta_bg_threshold;
profile.adjustmentFactor = allDefaults.adjustmentFactor;
profile.useNewFormula = allDefaults.useNewFormula;
profile.enableDynamicCR = allDefaults.enableDynamicCR;
profile.enableChris = allDefaults.enableChris;
profile.sigmoid = allDefaults.sigmoid;
profile.weightPercentage = allDefaults.weightPercentage;
profile.tddAdjBasal = allDefaults.tddAdjBasal;
profile.threshold_setting = allDefaults.threshold_setting;
Expand Down
13 changes: 3 additions & 10 deletions lib/profile/isf.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

var _ = require('lodash');

function isfLookup(isf_data, timestamp, lastResult) {
function isfLookup(isf_data, timestamp) {

var nowDate = timestamp;

Expand All @@ -12,16 +12,12 @@ function isfLookup(isf_data, timestamp, lastResult) {

var nowMinutes = nowDate.getHours() * 60 + nowDate.getMinutes();

if (lastResult && nowMinutes >= lastResult.offset && nowMinutes < lastResult.endOffset) {
return [lastResult.sensitivity, lastResult];
}

isf_data = _.sortBy(isf_data.sensitivities, function(o) { return o.offset; });

var isfSchedule = isf_data[isf_data.length - 1];

if (isf_data[0].offset !== 0) {
return [-1, lastResult];
return -1;
}

var endMinutes = 1440;
Expand All @@ -36,10 +32,7 @@ function isfLookup(isf_data, timestamp, lastResult) {
}
}

lastResult = isfSchedule;
lastResult.endOffset = endMinutes;

return [isfSchedule.sensitivity, lastResult];
return isfSchedule.sensitivity;
}

isfLookup.isfLookup = isfLookup;
Expand Down

0 comments on commit 05a1a2e

Please sign in to comment.