From 75baa473f1ce72e354cfc392bc2338ea399b1422 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Thu, 25 Jul 2019 21:45:54 +0200 Subject: [PATCH 1/2] fix carbtime in BolusWizard --- .../plugins/general/overview/dialogs/WizardDialog.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/WizardDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/WizardDialog.java index 7400729a38..fb903f3bae 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/WizardDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/WizardDialog.java @@ -242,7 +242,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com editCarbs.setParams(0d, 0d, (double) maxCarbs, 1d, new DecimalFormat("0"), false, view.findViewById(R.id.ok), textWatcher); double bolusstep = ConfigBuilderPlugin.getPlugin().getActivePump().getPumpDescription().bolusStep; editCorr.setParams(0d, -maxCorrection, maxCorrection, bolusstep, DecimalFormatter.pumpSupportedBolusFormat(), false, view.findViewById(R.id.ok), textWatcher); - editCarbTime.setParams(0d, -60d, 60d, 5d, new DecimalFormat("0"), false, view.findViewById(R.id.ok)); + editCarbTime.setParams(0d, -60d, 60d, 5d, new DecimalFormat("0"), false, view.findViewById(R.id.ok), textWatcher); initDialog(); setCancelable(true); @@ -392,7 +392,9 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com c_cob = cobInfo.displayCob; } - wizard = new BolusWizard(specificProfile, profileName, tempTarget, carbsAfterConstraint, c_cob, c_bg, corrAfterConstraint, 100d, bgCheckbox.isChecked(), cobCheckbox.isChecked(), bolusIobCheckbox.isChecked(), basalIobCheckbox.isChecked(), superbolusCheckbox.isChecked(), ttCheckbox.isChecked(), bgtrendCheckbox.isChecked(), notesEdit.getText().toString(), SafeParse.stringToInt(editCarbTime.getText())); + int carbTime = SafeParse.stringToInt(editCarbTime.getText()); + + wizard = new BolusWizard(specificProfile, profileName, tempTarget, carbsAfterConstraint, c_cob, c_bg, corrAfterConstraint, 100d, bgCheckbox.isChecked(), cobCheckbox.isChecked(), bolusIobCheckbox.isChecked(), basalIobCheckbox.isChecked(), superbolusCheckbox.isChecked(), ttCheckbox.isChecked(), bgtrendCheckbox.isChecked(), notesEdit.getText().toString(), carbTime); bg.setText(c_bg + " ISF: " + DecimalFormatter.to1Decimal(wizard.getSens())); bgInsulin.setText(StringUtils.formatInsulin(wizard.getInsulinFromBG())); From 76439777b0fa80ac3c75a64eee3035d92fa9aa12 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Thu, 25 Jul 2019 23:32:00 +0200 Subject: [PATCH 2/2] Better bolus wizard warning --- .../general/actions/dialogs/FillDialog.java | 2 +- .../overview/dialogs/NewInsulinDialog.java | 2 +- .../overview/dialogs/NewTreatmentDialog.java | 2 +- .../IobCobCalculatorPlugin.java | 14 +++++++++++++ .../androidaps/utils/BolusWizard.kt | 21 +++++++++++++++---- app/src/main/res/values/colors.xml | 1 + app/src/main/res/values/strings.xml | 3 +++ 7 files changed, 38 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/dialogs/FillDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/dialogs/FillDialog.java index be5a557fa4..77e4f85ea0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/dialogs/FillDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/dialogs/FillDialog.java @@ -184,7 +184,7 @@ public class FillDialog extends DialogFragment implements OnClickListener { confirmMessage.add(""); confirmMessage.add(MainApp.gs(R.string.bolus) + ": " + "" + DecimalFormatter.toPumpSupportedBolus(insulinAfterConstraints) + "U" + ""); if (Math.abs(insulinAfterConstraints - insulin) > 0.01d) - confirmMessage.add("" + MainApp.gs(R.string.bolusconstraintapplied) + ""); + confirmMessage.add(MainApp.gs(R.string.bolusconstraintappliedwarning, MainApp.gc(R.color.warning), insulin, insulinAfterConstraints)); } if (pumpSiteChangeCheckbox.isChecked()) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/NewInsulinDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/NewInsulinDialog.java index bb2174772f..a03bb6e882 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/NewInsulinDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/NewInsulinDialog.java @@ -226,7 +226,7 @@ public class NewInsulinDialog extends DialogFragment implements OnClickListener } if (Math.abs(insulinAfterConstraints - insulin) > pump.getPumpDescription().pumpType.determineCorrectBolusStepSize(insulinAfterConstraints)) - actions.add("" + MainApp.gs(R.string.bolusconstraintapplied) + ""); + actions.add(MainApp.gs(R.string.bolusconstraintappliedwarning, MainApp.gc(R.color.warning), insulin, insulinAfterConstraints)); int eatingSoonTTDuration = SP.getInt(R.string.key_eatingsoon_duration, Constants.defaultEatingSoonTTDuration); eatingSoonTTDuration = eatingSoonTTDuration > 0 ? eatingSoonTTDuration : Constants.defaultEatingSoonTTDuration; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/NewTreatmentDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/NewTreatmentDialog.java index 5c7ad412d6..9f2f42b2d9 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/NewTreatmentDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/NewTreatmentDialog.java @@ -142,7 +142,7 @@ public class NewTreatmentDialog extends DialogFragment implements OnClickListene confirmMessage += "
" + MainApp.gs(R.string.bolusrecordedonly) + ""; } if (Math.abs(insulinAfterConstraints - insulin) > pump.getPumpDescription().pumpType.determineCorrectBolusStepSize(insulinAfterConstraints) || !Objects.equals(carbsAfterConstraints, carbs)) - confirmMessage += "
" + MainApp.gs(R.string.bolusconstraintapplied) + ""; + confirmMessage += "
" + MainApp.gs(R.string.bolusconstraintappliedwarning, MainApp.gc(R.color.warning), insulin, insulinAfterConstraints); } if (carbsAfterConstraints > 0) confirmMessage += "
" + MainApp.gs(R.string.carbs) + ": " + "" + carbsAfterConstraints + "g" + ""; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobCalculatorPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobCalculatorPlugin.java index 687a28a128..5b6b9d0f28 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobCalculatorPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobCalculatorPlugin.java @@ -485,6 +485,20 @@ public class IobCobCalculatorPlugin extends PluginBase { return new CobInfo(displayCob, futureCarbs); } + public double slowAbsorptionPercentage(int timeInMinutes) { + double sum = 0; + int count = 0; + int valuesToProcess = timeInMinutes / 5; + synchronized (dataLock) { + for (int i = autosensDataTable.size() - 1; i >= 0 && count < valuesToProcess; i--) { + if (autosensDataTable.valueAt(i).failoverToMinAbsorbtionRate) + sum++; + count++; + } + } + return sum /count; + } + @Nullable public AutosensData getLastAutosensData(String reason) { if (autosensDataTable.size() < 1) { 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 e9a1b180c2..61b54fed0d 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/BolusWizard.kt +++ b/app/src/main/java/info/nightscout/androidaps/utils/BolusWizard.kt @@ -22,6 +22,7 @@ import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions import info.nightscout.androidaps.plugins.general.overview.dialogs.ErrorHelperActivity import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin import info.nightscout.androidaps.queue.Callback import org.json.JSONException @@ -241,11 +242,23 @@ class BolusWizard @JvmOverloads constructor(val profile: Profile, var confirmMessage = MainApp.gs(R.string.entertreatmentquestion) if (insulinAfterConstraints > 0) confirmMessage += "
" + MainApp.gs(R.string.bolus) + ": " + "" + DecimalFormatter.toPumpSupportedBolus(insulinAfterConstraints) + "U" + "" - if (carbs > 0) - confirmMessage += "
" + MainApp.gs(R.string.carbs) + ": " + "" + carbs + "g" + "" - + if (carbs > 0) { + var timeShift = "" + if (carbTime > 0) { + timeShift += " ( +" + MainApp.gs(R.string.mins, carbTime) + " )" + } else if (carbTime < 0) { + timeShift += " ( -" + MainApp.gs(R.string.mins, carbTime) + " )" + } + confirmMessage += "
" + MainApp.gs(R.string.carbs) + ": " + "" + carbs + "g" + timeShift + "" + } + if (insulinFromCOB > 0) { + confirmMessage += "
" + MainApp.gs(R.string.insulinFromCob, MainApp.gc(R.color.cobAlert), cob, insulinFromCOB) + val absorptionRate = IobCobCalculatorPlugin.getPlugin().slowAbsorptionPercentage(60) + 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)) { - confirmMessage += "
" + MainApp.gs(R.string.bolusconstraintapplied) + "" + confirmMessage += "
" + MainApp.gs(R.string.bolusconstraintappliedwarning, MainApp.gc(R.color.warning), calculatedTotalInsulin, insulinAfterConstraints) } return confirmMessage diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 67499f3a2c..f67a6a3ead 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -20,6 +20,7 @@ #f0003f59 #FF33B5E5 #FF0000 + #7484E2 #2800FF00 #C83F51B5 #C803A9F4 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e480f9d2bd..d2e8ca176a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1648,6 +1648,9 @@ No connection for %1$d hour(s) %2$d min No connection for %1$d day(s) %2$d hours + %2$.1fg %3$.2fU]]> + Bolus constraint applied: %2$.2fU to %3$.2fU]]> + !!!!! Slow carbs absorption detected: %2$d%% of time. Double check your calculation. COB can be really off !!!!!]]> %1$d day