Merge branch 'uam-smb-basal' into update-oref

This commit is contained in:
Tim Gunn 2019-08-10 16:00:31 +12:00
commit 2b4f27421a
5 changed files with 55 additions and 8 deletions

View file

@ -995,8 +995,7 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_
// eventual BG is at/above target // eventual BG is at/above target
// if iob is over max, just cancel any temps // if iob is over max, just cancel any temps
// if we're not here because of SMB, eventual BG is at/above target if ( eventualBG >= max_bg ) {
if (! (microBolusAllowed && rT.COB)) {
rT.reason += "Eventual BG " + convert_bg(eventualBG, profile) + " >= " + convert_bg(max_bg, profile) + ", "; rT.reason += "Eventual BG " + convert_bg(eventualBG, profile) + " >= " + convert_bg(max_bg, profile) + ", ";
} }
if (iob_data.iob > max_iob) { if (iob_data.iob > max_iob) {
@ -1047,20 +1046,27 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_
// if IOB covers more than COB, limit maxBolus to 30m of basal // if IOB covers more than COB, limit maxBolus to 30m of basal
} else if ( iob_data.iob > mealInsulinReq && iob_data.iob > 0 ) { } else if ( iob_data.iob > mealInsulinReq && iob_data.iob > 0 ) {
console.error("IOB",iob_data.iob,"> COB",meal_data.mealCOB+"; mealInsulinReq =",mealInsulinReq); console.error("IOB",iob_data.iob,"> COB",meal_data.mealCOB+"; mealInsulinReq =",mealInsulinReq);
maxBolus = round( profile.current_basal * 30 / 60 ,1); if (profile.maxUAMSMBBasalMinutes) {
console.error("profile.maxUAMSMBBasalMinutes:",profile.maxUAMSMBBasalMinutes,"profile.current_basal:",profile.current_basal);
maxBolus = round( profile.current_basal * profile.maxUAMSMBBasalMinutes / 60 ,1);
} else {
console.error("profile.maxUAMSMBBasalMinutes undefined: defaulting to 30m");
maxBolus = round( profile.current_basal * 30 / 60 ,1);
}
} else { } else {
console.error("profile.maxSMBBasalMinutes:",profile.maxSMBBasalMinutes,"profile.current_basal:",profile.current_basal); console.error("profile.maxSMBBasalMinutes:",profile.maxSMBBasalMinutes,"profile.current_basal:",profile.current_basal);
maxBolus = round( profile.current_basal * profile.maxSMBBasalMinutes / 60 ,1); maxBolus = round( profile.current_basal * profile.maxSMBBasalMinutes / 60 ,1);
} }
// bolus 1/2 the insulinReq, up to maxBolus, rounding down to nearest 0.1U // bolus 1/2 the insulinReq, up to maxBolus, rounding down to nearest bolus increment
microBolus = Math.floor(Math.min(insulinReq/2,maxBolus)*10)/10; var roundSMBTo = 1 / profile.bolus_increment;
microBolus = Math.floor(Math.min(insulinReq/2,maxBolus)*roundSMBTo)/roundSMBTo;
// calculate a long enough zero temp to eventually correct back up to target // calculate a long enough zero temp to eventually correct back up to target
var smbTarget = target_bg; var smbTarget = target_bg;
var worstCaseInsulinReq = (smbTarget - (naive_eventualBG + minIOBPredBG)/2 ) / sens; var worstCaseInsulinReq = (smbTarget - (naive_eventualBG + minIOBPredBG)/2 ) / sens;
var durationReq = round(60*worstCaseInsulinReq / profile.current_basal); var durationReq = round(60*worstCaseInsulinReq / profile.current_basal);
// if insulinReq > 0 but not enough for a microBolus, don't set an SMB zero temp // if insulinReq > 0 but not enough for a microBolus, don't set an SMB zero temp
if (insulinReq > 0 && microBolus < 0.1) { if (insulinReq > 0 && microBolus < profile.bolus_increment) {
durationReq = 0; durationReq = 0;
} }

View file

@ -33,6 +33,7 @@ import info.nightscout.androidaps.plugins.aps.openAPSMA.LoggerCallback;
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.utils.SP; import info.nightscout.androidaps.utils.SP;
import info.nightscout.androidaps.utils.SafeParse; import info.nightscout.androidaps.utils.SafeParse;
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
public class DetermineBasalAdapterSMBJS { public class DetermineBasalAdapterSMBJS {
private static Logger log = LoggerFactory.getLogger(L.APS); private static Logger log = LoggerFactory.getLogger(L.APS);
@ -217,7 +218,8 @@ public class DetermineBasalAdapterSMBJS {
) throws JSONException { ) throws JSONException {
String units = profile.getUnits(); String units = profile.getUnits();
Double bolusincrement = SP.getDouble("key_bolus_increment", SMBDefaults.bolus_increment);
Double pumpbolusstep = ConfigBuilderPlugin.getPlugin().getActivePump().getPumpDescription().bolusStep;
mProfile = new JSONObject(); mProfile = new JSONObject();
mProfile.put("max_iob", maxIob); mProfile.put("max_iob", maxIob);
@ -264,6 +266,12 @@ public class DetermineBasalAdapterSMBJS {
mProfile.put("enableSMB_always", smbEnabled && SP.getBoolean(R.string.key_enableSMB_always, false) && advancedFiltering); mProfile.put("enableSMB_always", smbEnabled && SP.getBoolean(R.string.key_enableSMB_always, false) && advancedFiltering);
mProfile.put("enableSMB_after_carbs", smbEnabled && SP.getBoolean(R.string.key_enableSMB_after_carbs, false) && advancedFiltering); mProfile.put("enableSMB_after_carbs", smbEnabled && SP.getBoolean(R.string.key_enableSMB_after_carbs, false) && advancedFiltering);
mProfile.put("maxSMBBasalMinutes", SP.getInt(R.string.key_smbmaxminutes, SMBDefaults.maxSMBBasalMinutes)); mProfile.put("maxSMBBasalMinutes", SP.getInt(R.string.key_smbmaxminutes, SMBDefaults.maxSMBBasalMinutes));
mProfile.put("maxUAMSMBBasalMinutes", SP.getInt("key_uamsmbmaxminutes", SMBDefaults.maxUAMSMBBasalMinutes));
if (bolusincrement < pumpbolusstep){
//the bolus incrument is less than what the pump can support (by pump settings or pump restriction), set to value supported by the pump
bolusincrement = pumpbolusstep;
}
mProfile.put("bolus_increment", bolusincrement);
mProfile.put("carbsReqThreshold", SMBDefaults.carbsReqThreshold); mProfile.put("carbsReqThreshold", SMBDefaults.carbsReqThreshold);
mProfile.put("current_basal", basalrate); mProfile.put("current_basal", basalrate);

View file

@ -56,9 +56,11 @@ public class SMBDefaults {
//public final static boolean enableSMB_after_carbs = false; // enable supermicrobolus for 6h after carbs, even with 0 COB //public final static boolean enableSMB_after_carbs = false; // enable supermicrobolus for 6h after carbs, even with 0 COB
//public final static boolean allowSMB_with_high_temptarget = false; // allow supermicrobolus (if otherwise enabled) even with high temp targets //public final static boolean allowSMB_with_high_temptarget = false; // allow supermicrobolus (if otherwise enabled) even with high temp targets
public final static int maxSMBBasalMinutes = 30; // maximum minutes of basal that can be delivered as a single SMB with uncovered COB public final static int maxSMBBasalMinutes = 30; // maximum minutes of basal that can be delivered as a single SMB with uncovered COB
public final static int maxUAMSMBBasalMinutes = 30; // maximum minutes of basal that can be delivered as a single SMB when IOB exceeds COB
// curve:"rapid-acting" // Supported curves: "bilinear", "rapid-acting" (Novolog, Novorapid, Humalog, Apidra) and "ultra-rapid" (Fiasp) // curve:"rapid-acting" // Supported curves: "bilinear", "rapid-acting" (Novolog, Novorapid, Humalog, Apidra) and "ultra-rapid" (Fiasp)
// useCustomPeakTime:false // allows changing insulinPeakTime // useCustomPeakTime:false // allows changing insulinPeakTime
// insulinPeakTime:75 // number of minutes after a bolus activity peaks. defaults to 55m for Fiasp if useCustomPeakTime: false // insulinPeakTime:75 // number of minutes after a bolus activity peaks. defaults to 55m for Fiasp if useCustomPeakTime: false
public final static int carbsReqThreshold = 1; // grams of carbsReq to trigger a pushover public final static int carbsReqThreshold = 1; // grams of carbsReq to trigger a pushover
// offline_hotspot:false // enabled an offline-only local wifi hotspot if no Internet available // offline_hotspot:false // enabled an offline-only local wifi hotspot if no Internet available
public final static double bolus_increment = 0.1; // minimum bolus that can be delivered as an SMB
} }

View file

@ -840,6 +840,10 @@
<string name="wear_detailed_delta_summary">Show delta with one more decimal place</string> <string name="wear_detailed_delta_summary">Show delta with one more decimal place</string>
<string name="smbmaxminutes" translatable="false">45 60 75 90 105 120</string> <string name="smbmaxminutes" translatable="false">45 60 75 90 105 120</string>
<string name="smbmaxminutes_summary">Max minutes of basal to limit SMB to</string> <string name="smbmaxminutes_summary">Max minutes of basal to limit SMB to</string>
<string name="uamsmbmaxminutes" translatable="false">45 60 75 90 105 120</string>
<string name="uamsmbmaxminutes_summary">Max minutes of basal to limit SMB to for UAM</string>
<string name="key_bolus_increment" translatable="false">bolus_increment</string>
<string name="bolus_increment_summary">Minimum bolus that can be delivered as an SMB</string>
<string name="unsupportedfirmware">Unsupported pump firmware</string> <string name="unsupportedfirmware">Unsupported pump firmware</string>
<string name="dexcomg5_xdripupload_title">Send BG data to xDrip+</string> <string name="dexcomg5_xdripupload_title">Send BG data to xDrip+</string>
<string name="key_dexcomg5_xdripupload" translatable="false">dexcomg5_xdripupload</string> <string name="key_dexcomg5_xdripupload" translatable="false">dexcomg5_xdripupload</string>

View file

@ -79,6 +79,33 @@
validate:minNumber="15" validate:minNumber="15"
validate:testType="numericRange" /> validate:testType="numericRange" />
<com.andreabaccega.widget.ValidatingEditTextPreference
android:defaultValue="30"
android:dialogMessage="@string/uamsmbmaxminutes"
android:digits="0123456789"
android:inputType="number"
android:key="key_uamsmbmaxminutes"
android:maxLines="20"
android:selectAllOnFocus="true"
android:singleLine="true"
android:title="@string/uamsmbmaxminutes_summary"
validate:maxNumber="120"
validate:minNumber="15"
validate:testType="numericRange" />
<com.andreabaccega.widget.ValidatingEditTextPreference
android:defaultValue="0.1"
android:inputType="numberDecimal"
android:key="key_bolus_increment"
android:maxLines="20"
android:selectAllOnFocus="true"
android:singleLine="true"
android:title="@string/bolus_increment_summary"
validate:floatmaxNumber="1.0"
validate:floatminNumber="0.05"
validate:testType="floatNumericRange" />
<SwitchPreference <SwitchPreference
android:defaultValue="false" android:defaultValue="false"
android:key="@string/key_use_uam" android:key="@string/key_use_uam"
@ -149,4 +176,4 @@
</PreferenceCategory> </PreferenceCategory>
</PreferenceScreen> </PreferenceScreen>