From 14dd29befd79aeaca88196d9534c708ccf6583db Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sun, 13 Oct 2019 00:01:15 +0200 Subject: [PATCH] boluswizard: do not check for correction constraints --- .../general/overview/dialogs/WizardDialog.kt | 12 ++----- .../androidaps/utils/BolusWizard.kt | 35 ++++++++----------- 2 files changed, 17 insertions(+), 30 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/WizardDialog.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/WizardDialog.kt index 4e34d3312c..34bbcf6fc3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/WizardDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/WizardDialog.kt @@ -271,15 +271,7 @@ class WizardDialog : DialogFragment() { // Entered values var c_bg = SafeParse.stringToDouble(treatments_wizard_bginput.text) val c_carbs = SafeParse.stringToInt(treatments_wizard_carbsinput.text) - var c_correction = SafeParse.stringToDouble(treatments_wizard_correctioninput.text) - val corrAfterConstraint = c_correction - if (c_correction > 0) - c_correction = MainApp.getConstraintChecker().applyBolusConstraints(Constraint(c_correction)).value() - if (Math.abs(c_correction - corrAfterConstraint) > 0.01) { // c_correction != corrAfterConstraint doesn't work - treatments_wizard_correctioninput.value = 0.0 - ToastUtils.showToastInUiThread(MainApp.instance().applicationContext, MainApp.gs(R.string.bolusconstraintapplied)) - return - } + val c_correction = SafeParse.stringToDouble(treatments_wizard_correctioninput.text) val carbsAfterConstraint = MainApp.getConstraintChecker().applyCarbsConstraints(Constraint(c_carbs)).value() if (Math.abs(c_carbs - carbsAfterConstraint) > 0.01) { treatments_wizard_carbsinput.value = 0.0 @@ -299,7 +291,7 @@ class WizardDialog : DialogFragment() { val carbTime = SafeParse.stringToInt(treatments_wizard_carbtimeinput.text) - wizard = BolusWizard(specificProfile, profileName, tempTarget, carbsAfterConstraint, c_cob, c_bg, corrAfterConstraint, + wizard = BolusWizard(specificProfile, profileName, tempTarget, carbsAfterConstraint, c_cob, c_bg, c_correction, SP.getInt(R.string.key_boluswizard_percentage, 100).toDouble(), treatments_wizard_bgcheckbox.isChecked, treatments_wizard_cobcheckbox.isChecked, diff --git a/app/src/main/java/info/nightscout/androidaps/utils/BolusWizard.kt b/app/src/main/java/info/nightscout/androidaps/utils/BolusWizard.kt index 11e8f7a5a9..f4bdd186ec 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/BolusWizard.kt +++ b/app/src/main/java/info/nightscout/androidaps/utils/BolusWizard.kt @@ -28,6 +28,7 @@ import org.json.JSONException import org.json.JSONObject import org.slf4j.LoggerFactory import java.util.* +import kotlin.math.abs class BolusWizard @JvmOverloads constructor(val profile: Profile, val profileName: String, @@ -60,14 +61,11 @@ class BolusWizard @JvmOverloads constructor(val profile: Profile, var glucoseStatus: GlucoseStatus? = null private set - var targetBGLow = 0.0 - private set + private var targetBGLow = 0.0 - var targetBGHigh = 0.0 - private set + private var targetBGHigh = 0.0 - var bgDiff = 0.0 - private set + private var bgDiff = 0.0 var insulinFromBG = 0.0 private set @@ -96,8 +94,7 @@ class BolusWizard @JvmOverloads constructor(val profile: Profile, var trend = 0.0 private set - var accepted = false - private set + private var accepted = false // Result var calculatedTotalInsulin: Double = 0.0 @@ -127,12 +124,10 @@ class BolusWizard @JvmOverloads constructor(val profile: Profile, targetBGHigh = Profile.fromMgdlToUnits(tempTarget.high, profile.units) } if (useBg && bg > 0) { - if (bg >= targetBGLow && bg <= targetBGHigh) { - bgDiff = 0.0 - } else if (bg <= targetBGLow) { - bgDiff = bg - targetBGLow - } else { - bgDiff = bg - targetBGHigh + bgDiff = when { + bg in targetBGLow..targetBGHigh -> 0.0 + bg <= targetBGLow -> bg - targetBGLow + else -> bg - targetBGHigh } insulinFromBG = bgDiff / sens } @@ -147,7 +142,7 @@ class BolusWizard @JvmOverloads constructor(val profile: Profile, } - // Insuling from carbs + // Insulin from carbs ic = profile.ic insulinFromCarbs = carbs / ic insulinFromCOB = if (useCob) (cob / ic) else 0.0 @@ -197,7 +192,7 @@ class BolusWizard @JvmOverloads constructor(val profile: Profile, log.debug(this.toString()) } - fun nsJSON(): JSONObject { + private fun nsJSON(): JSONObject { val boluscalcJSON = JSONObject() try { boluscalcJSON.put("profile", profileName) @@ -260,7 +255,7 @@ class BolusWizard @JvmOverloads constructor(val profile: Profile, if (absorptionRate > .25) confirmMessage += "
" + MainApp.gs(R.string.slowabsorptiondetected, MainApp.gc(R.color.cobAlert), (absorptionRate * 100).toInt()) } - if (Math.abs(insulinAfterConstraints - calculatedTotalInsulin) > pump.getPumpDescription().pumpType.determineCorrectBolusStepSize(insulinAfterConstraints)) { + if (abs(insulinAfterConstraints - calculatedTotalInsulin) > pump.pumpDescription.pumpType.determineCorrectBolusStepSize(insulinAfterConstraints)) { confirmMessage += "
" + MainApp.gs(R.string.bolusconstraintappliedwarning, MainApp.gc(R.color.warning), calculatedTotalInsulin, insulinAfterConstraints) } @@ -268,10 +263,10 @@ class BolusWizard @JvmOverloads constructor(val profile: Profile, } fun confirmAndExecute(context: Context) { - val profile = ProfileFunctions.getInstance().profile - val pump = ConfigBuilderPlugin.getPlugin().activePump + val profile = ProfileFunctions.getInstance().profile ?: return + val pump = ConfigBuilderPlugin.getPlugin().activePump ?: return - if (pump != null && profile != null && (calculatedTotalInsulin > 0.0 || carbs > 0.0)) { + if (calculatedTotalInsulin > 0.0 || carbs > 0.0) { val confirmMessage = confirmMessageAfterConstraints(pump) val builder = AlertDialog.Builder(context)