From 943205c7829c3db2e8f2f6a96546675f59ae0de4 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sun, 11 Feb 2018 22:41:10 +0100 Subject: [PATCH] HardLimits refactor --- .../info/nightscout/androidaps/Constants.java | 11 --- .../plugins/OpenAPSAMA/OpenAPSAMAPlugin.java | 54 ++++------- .../plugins/OpenAPSMA/OpenAPSMAPlugin.java | 37 ++++---- .../plugins/OpenAPSSMB/OpenAPSSMBPlugin.java | 32 +++---- .../CircadianPercentageProfilePlugin.java | 6 +- .../plugins/Wear/ActionStringHandler.java | 9 +- .../info/nightscout/utils/HardLimits.java | 94 +++++++++++++++++-- app/src/main/res/values-bg/strings.xml | 4 +- app/src/main/res/values-cs/strings.xml | 4 +- app/src/main/res/values-de/strings.xml | 4 +- app/src/main/res/values-el/strings.xml | 4 +- app/src/main/res/values-es/strings.xml | 4 +- app/src/main/res/values-fr/strings.xml | 4 +- app/src/main/res/values-ko/strings.xml | 4 +- app/src/main/res/values-nl/strings.xml | 4 +- app/src/main/res/values-ru/strings.xml | 4 +- app/src/main/res/values-sv/strings.xml | 4 +- app/src/main/res/values/arrays.xml | 2 + app/src/main/res/values/strings.xml | 6 +- 19 files changed, 174 insertions(+), 117 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/Constants.java b/app/src/main/java/info/nightscout/androidaps/Constants.java index 2d6ee910c8..e0549ab9bb 100644 --- a/app/src/main/java/info/nightscout/androidaps/Constants.java +++ b/app/src/main/java/info/nightscout/androidaps/Constants.java @@ -35,17 +35,6 @@ public class Constants { public static final int CPP_MIN_TIMESHIFT = -6; public static final int CPP_MAX_TIMESHIFT = 23; - // Very Hard Limits Ranges - // First value is the Lowest and second value is the Highest a Limit can define - public static final int[] VERY_HARD_LIMIT_MIN_BG = {72,180}; - public static final int[] VERY_HARD_LIMIT_MAX_BG = {90,270}; - public static final int[] VERY_HARD_LIMIT_TARGET_BG = {80,200}; - - // Very Hard Limits Ranges for Temp Targets - public static final int[] VERY_HARD_LIMIT_TEMP_MIN_BG = {72,180}; - public static final int[] VERY_HARD_LIMIT_TEMP_MAX_BG = {72,270}; - public static final int[] VERY_HARD_LIMIT_TEMP_TARGET_BG = {72,200}; - //DanaR public static final double dailyLimitWarning = 0.95d; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAPlugin.java index 14d5396817..19cbecd469 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAPlugin.java @@ -8,7 +8,6 @@ import java.io.IOException; import java.util.Date; import info.nightscout.androidaps.Config; -import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.GlucoseStatus; @@ -18,6 +17,7 @@ import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.db.TempTarget; import info.nightscout.androidaps.interfaces.APSInterface; import info.nightscout.androidaps.interfaces.PluginBase; +import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensResult; import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; @@ -26,11 +26,10 @@ import info.nightscout.androidaps.plugins.Loop.ScriptReader; import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateGui; import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateResultGui; import info.nightscout.utils.DateUtil; -import info.nightscout.utils.NSUpload; +import info.nightscout.utils.HardLimits; import info.nightscout.utils.Profiler; import info.nightscout.utils.Round; import info.nightscout.utils.SP; -import info.nightscout.utils.ToastUtils; /** * Created by mike on 05.08.2016. @@ -148,6 +147,7 @@ public class OpenAPSAMAPlugin implements PluginBase, APSInterface { GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData(); Profile profile = MainApp.getConfigBuilder().getProfile(); + PumpInterface pump = ConfigBuilderPlugin.getActivePump(); if (profile == null) { MainApp.bus().post(new EventOpenAPSUpdateResultGui(MainApp.instance().getString(R.string.noprofileselected))); @@ -192,30 +192,32 @@ public class OpenAPSAMAPlugin implements PluginBase, APSInterface { maxIob = MainApp.getConfigBuilder().applyMaxIOBConstraints(maxIob); - minBg = verifyHardLimits(minBg, "minBg", Constants.VERY_HARD_LIMIT_MIN_BG[0], Constants.VERY_HARD_LIMIT_MIN_BG[1]); - maxBg = verifyHardLimits(maxBg, "maxBg", Constants.VERY_HARD_LIMIT_MAX_BG[0], Constants.VERY_HARD_LIMIT_MAX_BG[1]); - targetBg = verifyHardLimits(targetBg, "targetBg", Constants.VERY_HARD_LIMIT_TARGET_BG[0], Constants.VERY_HARD_LIMIT_TARGET_BG[1]); + minBg = HardLimits.verifyHardLimits(minBg, "minBg", HardLimits.VERY_HARD_LIMIT_MIN_BG[0], HardLimits.VERY_HARD_LIMIT_MIN_BG[1]); + maxBg = HardLimits.verifyHardLimits(maxBg, "maxBg", HardLimits.VERY_HARD_LIMIT_MAX_BG[0], HardLimits.VERY_HARD_LIMIT_MAX_BG[1]); + targetBg = HardLimits.verifyHardLimits(targetBg, "targetBg", HardLimits.VERY_HARD_LIMIT_TARGET_BG[0], HardLimits.VERY_HARD_LIMIT_TARGET_BG[1]); boolean isTempTarget = false; TempTarget tempTarget = MainApp.getConfigBuilder().getTempTargetFromHistory(System.currentTimeMillis()); if (tempTarget != null) { isTempTarget = true; - minBg = verifyHardLimits(tempTarget.low, "minBg", Constants.VERY_HARD_LIMIT_TEMP_MIN_BG[0], Constants.VERY_HARD_LIMIT_TEMP_MIN_BG[1]); - maxBg = verifyHardLimits(tempTarget.high, "maxBg", Constants.VERY_HARD_LIMIT_TEMP_MAX_BG[0], Constants.VERY_HARD_LIMIT_TEMP_MAX_BG[1]); - targetBg = verifyHardLimits((tempTarget.low + tempTarget.high) / 2, "targetBg", Constants.VERY_HARD_LIMIT_TEMP_TARGET_BG[0], Constants.VERY_HARD_LIMIT_TEMP_TARGET_BG[1]); + minBg = HardLimits.verifyHardLimits(tempTarget.low, "minBg", HardLimits.VERY_HARD_LIMIT_TEMP_MIN_BG[0], HardLimits.VERY_HARD_LIMIT_TEMP_MIN_BG[1]); + maxBg = HardLimits.verifyHardLimits(tempTarget.high, "maxBg", HardLimits.VERY_HARD_LIMIT_TEMP_MAX_BG[0], HardLimits.VERY_HARD_LIMIT_TEMP_MAX_BG[1]); + targetBg = HardLimits.verifyHardLimits((tempTarget.low + tempTarget.high) / 2, "targetBg", HardLimits.VERY_HARD_LIMIT_TEMP_TARGET_BG[0], HardLimits.VERY_HARD_LIMIT_TEMP_TARGET_BG[1]); } - maxIob = verifyHardLimits(maxIob, "maxIob", 0, 7); - maxBasal = verifyHardLimits(maxBasal, "max_basal", 0.1, 10); + maxIob = HardLimits.verifyHardLimits(maxIob, "maxIob", 0, HardLimits.maxIobAMA()); + maxBasal = HardLimits.verifyHardLimits(maxBasal, "max_basal", 0.1, HardLimits.maxBasal()); - if (!checkOnlyHardLimits(profile.getDia(), "dia", 2, 7)) return; - if (!checkOnlyHardLimits(profile.getIc(Profile.secondsFromMidnight()), "carbratio", 2, 100)) + if (!HardLimits.checkOnlyHardLimits(profile.getDia(), "dia", HardLimits.MINDIA, HardLimits.MAXDIA)) return; - if (!checkOnlyHardLimits(Profile.toMgdl(profile.getIsf(), units), "sens", 2, 900)) + if (!HardLimits.checkOnlyHardLimits(profile.getIc(profile.secondsFromMidnight()), "carbratio", HardLimits.MINIC, HardLimits.MAXIC)) return; - if (!checkOnlyHardLimits(profile.getMaxDailyBasal(), "max_daily_basal", 0.1, 10)) return; - if (!checkOnlyHardLimits(ConfigBuilderPlugin.getActivePump().getBaseBasalRate(), "current_basal", 0.01, 5)) + if (!HardLimits.checkOnlyHardLimits(Profile.toMgdl(profile.getIsf().doubleValue(), units), "sens", HardLimits.MINISF, HardLimits.MAXISF)) + return; + if (!HardLimits.checkOnlyHardLimits(profile.getMaxDailyBasal(), "max_daily_basal", 0.1, HardLimits.maxBasal())) + return; + if (!HardLimits.checkOnlyHardLimits(pump.getBaseBasalRate(), "current_basal", 0.01, HardLimits.maxBasal())) return; startPart = new Date(); @@ -272,24 +274,4 @@ public class OpenAPSAMAPlugin implements PluginBase, APSInterface { //deviceStatus.suggested = determineBasalResultAMA.json; } - // safety checks - public static boolean checkOnlyHardLimits(Double value, String valueName, double lowLimit, double highLimit) { - return value.equals(verifyHardLimits(value, valueName, lowLimit, highLimit)); - } - - public static Double verifyHardLimits(Double value, String valueName, double lowLimit, double highLimit) { - Double newvalue = value; - if (newvalue < lowLimit || newvalue > highLimit) { - newvalue = Math.max(newvalue, lowLimit); - newvalue = Math.min(newvalue, highLimit); - String msg = String.format(MainApp.sResources.getString(R.string.openapsma_valueoutofrange), valueName); - msg += ".\n"; - msg += String.format(MainApp.sResources.getString(R.string.openapsma_valuelimitedto), value, newvalue); - log.error(msg); - NSUpload.uploadError(msg); - ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), msg, R.raw.error); - } - return newvalue; - } - } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAPlugin.java index 3119a17a96..adb18491a4 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAPlugin.java @@ -8,7 +8,6 @@ import java.io.IOException; import java.util.Date; import info.nightscout.androidaps.Config; -import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.GlucoseStatus; @@ -18,19 +17,21 @@ import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.db.TempTarget; import info.nightscout.androidaps.interfaces.APSInterface; import info.nightscout.androidaps.interfaces.PluginBase; +import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.Loop.APSResult; import info.nightscout.androidaps.plugins.Loop.ScriptReader; import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateGui; import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateResultGui; import info.nightscout.utils.DateUtil; +import info.nightscout.utils.HardLimits; import info.nightscout.utils.Profiler; import info.nightscout.utils.Round; import info.nightscout.utils.SP; import info.nightscout.utils.SafeParse; -import static info.nightscout.androidaps.plugins.OpenAPSAMA.OpenAPSAMAPlugin.checkOnlyHardLimits; -import static info.nightscout.androidaps.plugins.OpenAPSAMA.OpenAPSAMAPlugin.verifyHardLimits; +import static info.nightscout.utils.HardLimits.checkOnlyHardLimits; +import static info.nightscout.utils.HardLimits.verifyHardLimits; /** * Created by mike on 05.08.2016. @@ -147,6 +148,7 @@ public class OpenAPSMAPlugin implements PluginBase, APSInterface { GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData(); Profile profile = MainApp.getConfigBuilder().getProfile(); + PumpInterface pump = ConfigBuilderPlugin.getActivePump(); if (profile == null) { MainApp.bus().post(new EventOpenAPSUpdateResultGui(MainApp.instance().getString(R.string.noprofileselected))); @@ -195,26 +197,29 @@ public class OpenAPSMAPlugin implements PluginBase, APSInterface { maxIob = MainApp.getConfigBuilder().applyMaxIOBConstraints(maxIob); Profiler.log(log, "MA data gathering", start); - minBg = verifyHardLimits(minBg, "minBg", Constants.VERY_HARD_LIMIT_MIN_BG[0], Constants.VERY_HARD_LIMIT_MIN_BG[1]); - maxBg = verifyHardLimits(maxBg, "maxBg", Constants.VERY_HARD_LIMIT_MAX_BG[0], Constants.VERY_HARD_LIMIT_MAX_BG[1]); - targetBg = verifyHardLimits(targetBg, "targetBg", Constants.VERY_HARD_LIMIT_TARGET_BG[0], Constants.VERY_HARD_LIMIT_TARGET_BG[1]); + minBg = verifyHardLimits(minBg, "minBg", HardLimits.VERY_HARD_LIMIT_MIN_BG[0], HardLimits.VERY_HARD_LIMIT_MIN_BG[1]); + maxBg = verifyHardLimits(maxBg, "maxBg", HardLimits.VERY_HARD_LIMIT_MAX_BG[0], HardLimits.VERY_HARD_LIMIT_MAX_BG[1]); + targetBg = verifyHardLimits(targetBg, "targetBg", HardLimits.VERY_HARD_LIMIT_TARGET_BG[0], HardLimits.VERY_HARD_LIMIT_TARGET_BG[1]); TempTarget tempTarget = MainApp.getConfigBuilder().getTempTargetFromHistory(System.currentTimeMillis()); if (tempTarget != null) { - minBg = verifyHardLimits(tempTarget.low, "minBg", Constants.VERY_HARD_LIMIT_TEMP_MIN_BG[0], Constants.VERY_HARD_LIMIT_TEMP_MIN_BG[1]); - maxBg = verifyHardLimits(tempTarget.high, "maxBg", Constants.VERY_HARD_LIMIT_TEMP_MAX_BG[0], Constants.VERY_HARD_LIMIT_TEMP_MAX_BG[1]); - targetBg = verifyHardLimits((tempTarget.low + tempTarget.high) / 2, "targetBg", Constants.VERY_HARD_LIMIT_TEMP_TARGET_BG[0], Constants.VERY_HARD_LIMIT_TEMP_TARGET_BG[1]); + minBg = verifyHardLimits(tempTarget.low, "minBg", HardLimits.VERY_HARD_LIMIT_TEMP_MIN_BG[0], HardLimits.VERY_HARD_LIMIT_TEMP_MIN_BG[1]); + maxBg = verifyHardLimits(tempTarget.high, "maxBg", HardLimits.VERY_HARD_LIMIT_TEMP_MAX_BG[0], HardLimits.VERY_HARD_LIMIT_TEMP_MAX_BG[1]); + targetBg = verifyHardLimits((tempTarget.low + tempTarget.high) / 2, "targetBg", HardLimits.VERY_HARD_LIMIT_TEMP_TARGET_BG[0], HardLimits.VERY_HARD_LIMIT_TEMP_TARGET_BG[1]); } - maxIob = verifyHardLimits(maxIob, "maxIob", 0, 7); - maxBasal = verifyHardLimits(maxBasal, "max_basal", 0.1, 10); + maxIob = verifyHardLimits(maxIob, "maxIob", 0, HardLimits.maxIobAMA()); + maxBasal = verifyHardLimits(maxBasal, "max_basal", 0.1, HardLimits.maxBasal()); - if (!checkOnlyHardLimits(profile.getDia(), "dia", 2, 7)) return; - if (!checkOnlyHardLimits(profile.getIc(), "carbratio", 2, 100)) return; - if (!checkOnlyHardLimits(Profile.toMgdl(profile.getIsf(), units), "sens", 2, 900)) + if (!checkOnlyHardLimits(profile.getDia(), "dia", HardLimits.MINDIA, HardLimits.MAXDIA)) return; - if (!checkOnlyHardLimits(profile.getMaxDailyBasal(), "max_daily_basal", 0.1, 10)) return; - if (!checkOnlyHardLimits(ConfigBuilderPlugin.getActivePump().getBaseBasalRate(), "current_basal", 0.01, 5)) + if (!checkOnlyHardLimits(profile.getIc(profile.secondsFromMidnight()), "carbratio", HardLimits.MINIC, HardLimits.MAXIC)) + return; + if (!checkOnlyHardLimits(Profile.toMgdl(profile.getIsf().doubleValue(), units), "sens", HardLimits.MINISF, HardLimits.MAXISF)) + return; + if (!checkOnlyHardLimits(profile.getMaxDailyBasal(), "max_daily_basal", 0.1, HardLimits.maxBasal())) + return; + if (!checkOnlyHardLimits(pump.getBaseBasalRate(), "current_basal", 0.01, HardLimits.maxBasal())) return; start = new Date(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/OpenAPSSMBPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/OpenAPSSMBPlugin.java index f056a9c607..2bed09d744 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/OpenAPSSMBPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/OpenAPSSMBPlugin.java @@ -8,7 +8,6 @@ import java.io.IOException; import java.util.Date; import info.nightscout.androidaps.Config; -import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.GlucoseStatus; @@ -27,6 +26,7 @@ import info.nightscout.androidaps.plugins.Loop.ScriptReader; import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateGui; import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateResultGui; import info.nightscout.utils.DateUtil; +import info.nightscout.utils.HardLimits; import info.nightscout.utils.NSUpload; import info.nightscout.utils.Profiler; import info.nightscout.utils.Round; @@ -197,30 +197,30 @@ public class OpenAPSSMBPlugin implements PluginBase, APSInterface { maxIob = MainApp.getConfigBuilder().applyMaxIOBConstraints(maxIob); - minBg = verifyHardLimits(minBg, "minBg", Constants.VERY_HARD_LIMIT_MIN_BG[0], Constants.VERY_HARD_LIMIT_MIN_BG[1]); - maxBg = verifyHardLimits(maxBg, "maxBg", Constants.VERY_HARD_LIMIT_MAX_BG[0], Constants.VERY_HARD_LIMIT_MAX_BG[1]); - targetBg = verifyHardLimits(targetBg, "targetBg", Constants.VERY_HARD_LIMIT_TARGET_BG[0], Constants.VERY_HARD_LIMIT_TARGET_BG[1]); + minBg = verifyHardLimits(minBg, "minBg", HardLimits.VERY_HARD_LIMIT_MIN_BG[0], HardLimits.VERY_HARD_LIMIT_MIN_BG[1]); + maxBg = verifyHardLimits(maxBg, "maxBg", HardLimits.VERY_HARD_LIMIT_MAX_BG[0], HardLimits.VERY_HARD_LIMIT_MAX_BG[1]); + targetBg = verifyHardLimits(targetBg, "targetBg", HardLimits.VERY_HARD_LIMIT_TARGET_BG[0], HardLimits.VERY_HARD_LIMIT_TARGET_BG[1]); boolean isTempTarget = false; TempTarget tempTarget = MainApp.getConfigBuilder().getTempTargetFromHistory(System.currentTimeMillis()); if (tempTarget != null) { isTempTarget = true; - minBg = verifyHardLimits(tempTarget.low, "minBg", Constants.VERY_HARD_LIMIT_TEMP_MIN_BG[0], Constants.VERY_HARD_LIMIT_TEMP_MIN_BG[1]); - maxBg = verifyHardLimits(tempTarget.high, "maxBg", Constants.VERY_HARD_LIMIT_TEMP_MAX_BG[0], Constants.VERY_HARD_LIMIT_TEMP_MAX_BG[1]); - targetBg = verifyHardLimits((tempTarget.low + tempTarget.high) / 2, "targetBg", Constants.VERY_HARD_LIMIT_TEMP_TARGET_BG[0], Constants.VERY_HARD_LIMIT_TEMP_TARGET_BG[1]); + minBg = verifyHardLimits(tempTarget.low, "minBg", HardLimits.VERY_HARD_LIMIT_TEMP_MIN_BG[0], HardLimits.VERY_HARD_LIMIT_TEMP_MIN_BG[1]); + maxBg = verifyHardLimits(tempTarget.high, "maxBg", HardLimits.VERY_HARD_LIMIT_TEMP_MAX_BG[0], HardLimits.VERY_HARD_LIMIT_TEMP_MAX_BG[1]); + targetBg = verifyHardLimits((tempTarget.low + tempTarget.high) / 2, "targetBg", HardLimits.VERY_HARD_LIMIT_TEMP_TARGET_BG[0], HardLimits.VERY_HARD_LIMIT_TEMP_TARGET_BG[1]); } - maxIob = verifyHardLimits(maxIob, "maxIob", 0, 7); - maxBasal = verifyHardLimits(maxBasal, "max_basal", 0.1, 10); + maxIob = verifyHardLimits(maxIob, "maxIob", 0, HardLimits.maxIobSMB()); + maxBasal = verifyHardLimits(maxBasal, "max_basal", 0.1, HardLimits.maxBasal()); - if (!checkOnlyHardLimits(profile.getDia(), "dia", 2, 7)) return; - if (!checkOnlyHardLimits(profile.getIc(profile.secondsFromMidnight()), "carbratio", 2, 100)) + if (!checkOnlyHardLimits(profile.getDia(), "dia", HardLimits.MINDIA, HardLimits.MAXDIA)) return; + if (!checkOnlyHardLimits(profile.getIc(profile.secondsFromMidnight()), "carbratio", HardLimits.MINIC, HardLimits.MAXIC)) return; - if (!checkOnlyHardLimits(Profile.toMgdl(profile.getIsf().doubleValue(), units), "sens", 2, 900)) + if (!checkOnlyHardLimits(Profile.toMgdl(profile.getIsf().doubleValue(), units), "sens", HardLimits.MINISF, HardLimits.MAXISF)) return; - if (!checkOnlyHardLimits(profile.getMaxDailyBasal(), "max_daily_basal", 0.1, 10)) return; - if (!checkOnlyHardLimits(pump.getBaseBasalRate(), "current_basal", 0.01, 5)) return; + if (!checkOnlyHardLimits(profile.getMaxDailyBasal(), "max_daily_basal", 0.1, HardLimits.maxBasal())) return; + if (!checkOnlyHardLimits(pump.getBaseBasalRate(), "current_basal", 0.01, HardLimits.maxBasal())) return; startPart = new Date(); if (MainApp.getConfigBuilder().isAMAModeEnabled()) { @@ -288,9 +288,9 @@ public class OpenAPSSMBPlugin implements PluginBase, APSInterface { if (newvalue < lowLimit || newvalue > highLimit) { newvalue = Math.max(newvalue, lowLimit); newvalue = Math.min(newvalue, highLimit); - String msg = String.format(MainApp.sResources.getString(R.string.openapsma_valueoutofrange), valueName); + String msg = String.format(MainApp.sResources.getString(R.string.valueoutofrange), valueName); msg += ".\n"; - msg += String.format(MainApp.sResources.getString(R.string.openapsma_valuelimitedto), value, newvalue); + msg += String.format(MainApp.sResources.getString(R.string.valuelimitedto), value, newvalue); log.error(msg); NSUpload.uploadError(msg); ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), msg, R.raw.error); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileCircadianPercentage/CircadianPercentageProfilePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileCircadianPercentage/CircadianPercentageProfilePlugin.java index ec9c6d1e40..f9d9976f8c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileCircadianPercentage/CircadianPercentageProfilePlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileCircadianPercentage/CircadianPercentageProfilePlugin.java @@ -174,10 +174,10 @@ public class CircadianPercentageProfilePlugin implements PluginBase, ProfileInte //check for validity if (percentage < Constants.CPP_MIN_PERCENTAGE || percentage > Constants.CPP_MAX_PERCENTAGE) { - msg += String.format(MainApp.sResources.getString(R.string.openapsma_valueoutofrange), "Profile-Percentage") + "\n"; + msg += String.format(MainApp.sResources.getString(R.string.valueoutofrange), "Profile-Percentage") + "\n"; } if (timeshift < 0 || timeshift > 23) { - msg += String.format(MainApp.sResources.getString(R.string.openapsma_valueoutofrange), "Profile-Timeshift") + "\n"; + msg += String.format(MainApp.sResources.getString(R.string.valueoutofrange), "Profile-Timeshift") + "\n"; } final Profile profile = MainApp.getConfigBuilder().getProfile(); @@ -367,7 +367,7 @@ public class CircadianPercentageProfilePlugin implements PluginBase, ProfileInte private void performLimitCheck() { if (percentage < Constants.CPP_MIN_PERCENTAGE || percentage > Constants.CPP_MAX_PERCENTAGE) { - String msg = String.format(MainApp.sResources.getString(R.string.openapsma_valueoutofrange), "Profile-Percentage"); + String msg = String.format(MainApp.sResources.getString(R.string.valueoutofrange), "Profile-Percentage"); log.error(msg); NSUpload.uploadError(msg); ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), msg, R.raw.error); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java index fbec0a2308..9e0942f8a2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java @@ -44,6 +44,7 @@ import info.nightscout.androidaps.queue.Callback; import info.nightscout.utils.BolusWizard; import info.nightscout.utils.DateUtil; import info.nightscout.utils.DecimalFormatter; +import info.nightscout.utils.HardLimits; import info.nightscout.utils.SP; import info.nightscout.utils.SafeParse; import info.nightscout.utils.ToastUtils; @@ -149,11 +150,11 @@ public class ActionStringHandler { low *= Constants.MMOLL_TO_MGDL; high *= Constants.MMOLL_TO_MGDL; } - if (low < Constants.VERY_HARD_LIMIT_TEMP_MIN_BG[0] || low > Constants.VERY_HARD_LIMIT_TEMP_MIN_BG[1]) { + if (low < HardLimits.VERY_HARD_LIMIT_TEMP_MIN_BG[0] || low > HardLimits.VERY_HARD_LIMIT_TEMP_MIN_BG[1]) { sendError("Min-BG out of range!"); return; } - if (high < Constants.VERY_HARD_LIMIT_TEMP_MAX_BG[0] || high > Constants.VERY_HARD_LIMIT_TEMP_MAX_BG[1]) { + if (high < HardLimits.VERY_HARD_LIMIT_TEMP_MAX_BG[0] || high > HardLimits.VERY_HARD_LIMIT_TEMP_MAX_BG[1]) { sendError("Max-BG out of range!"); return; } @@ -577,10 +578,10 @@ public class ActionStringHandler { //check for validity if (percentage < Constants.CPP_MIN_PERCENTAGE || percentage > Constants.CPP_MAX_PERCENTAGE) { - msg += String.format(MainApp.sResources.getString(R.string.openapsma_valueoutofrange), "Profile-Percentage") + "\n"; + msg += String.format(MainApp.sResources.getString(R.string.valueoutofrange), "Profile-Percentage") + "\n"; } if (timeshift < 0 || timeshift > 23) { - msg += String.format(MainApp.sResources.getString(R.string.openapsma_valueoutofrange), "Profile-Timeshift") + "\n"; + msg += String.format(MainApp.sResources.getString(R.string.valueoutofrange), "Profile-Timeshift") + "\n"; } final Profile profile = MainApp.getConfigBuilder().getProfile(); diff --git a/app/src/main/java/info/nightscout/utils/HardLimits.java b/app/src/main/java/info/nightscout/utils/HardLimits.java index ff92cf2e87..aadabba382 100644 --- a/app/src/main/java/info/nightscout/utils/HardLimits.java +++ b/app/src/main/java/info/nightscout/utils/HardLimits.java @@ -1,5 +1,8 @@ package info.nightscout.utils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; @@ -8,17 +11,90 @@ import info.nightscout.androidaps.R; */ public class HardLimits { - final static double MAXBOLUS_ADULT = 17d; - final static double MAXBOLUS_TEENAGE = 10d; - final static double MAXBOLUS_CHILD = 5d; + private static Logger log = LoggerFactory.getLogger(HardLimits.class); - public static double maxBolus() { - String age = SP.getString(R.string.key_age, ""); + final static int CHILD = 0; + final static int TEENAGE = 1; + final static int ADULT = 2; + final static int RESISTANTADULT = 3; - if (age.equals(MainApp.sResources.getString(R.string.key_adult))) return MAXBOLUS_ADULT; - if (age.equals(MainApp.sResources.getString(R.string.key_teenage))) return MAXBOLUS_TEENAGE; - if (age.equals(MainApp.sResources.getString(R.string.key_child))) return MAXBOLUS_CHILD; - return MAXBOLUS_ADULT; + final static double[] MAXBOLUS = {5d, 10d, 17d, 21d}; + + // Very Hard Limits Ranges + // First value is the Lowest and second value is the Highest a Limit can define + public static final int[] VERY_HARD_LIMIT_MIN_BG = {72, 180}; + public static final int[] VERY_HARD_LIMIT_MAX_BG = {90, 270}; + public static final int[] VERY_HARD_LIMIT_TARGET_BG = {80, 200}; + // Very Hard Limits Ranges for Temp Targets + public static final int[] VERY_HARD_LIMIT_TEMP_MIN_BG = {72, 180}; + public static final int[] VERY_HARD_LIMIT_TEMP_MAX_BG = {72, 270}; + public static final int[] VERY_HARD_LIMIT_TEMP_TARGET_BG = {72, 200}; + + public static final double MINDIA = 2; + public static final double MAXDIA = 7; + + public static final double MINIC = 2; + public static final double MAXIC = 40; + + public static final double MINISF = 2; // mgdl + public static final double MAXISF = 720; // mgdl + + public static final double[] MAXIOB_AMA = {3, 5, 7, 7}; + public static final double[] MAXIOB_SMB = {3, 6, 10, 12}; + + public static final double[] MAXBASAL = {2, 5, 10, 12}; + + + private static int loadAge() { + String sp_age = SP.getString(R.string.key_age, ""); + int age; + + if (sp_age.equals(MainApp.sResources.getString(R.string.key_child))) + age = CHILD; + else if (sp_age.equals(MainApp.sResources.getString(R.string.key_teenage))) + age = TEENAGE; + else if (sp_age.equals(MainApp.sResources.getString(R.string.key_adult))) + age = ADULT; + else if (sp_age.equals(MainApp.sResources.getString(R.string.key_resistantadult))) + age = RESISTANTADULT; + else age = ADULT; + + return age; } + public static double maxBolus() { + return MAXBOLUS[loadAge()]; + } + + public static double maxIobAMA() { + return MAXIOB_AMA[loadAge()]; + } + + public static double maxIobSMB() { + return MAXIOB_SMB[loadAge()]; + } + + public static double maxBasal() { + return MAXBASAL[loadAge()]; + } + + // safety checks + public static boolean checkOnlyHardLimits(Double value, String valueName, double lowLimit, double highLimit) { + return value.equals(verifyHardLimits(value, valueName, lowLimit, highLimit)); + } + + public static Double verifyHardLimits(Double value, String valueName, double lowLimit, double highLimit) { + Double newvalue = value; + if (newvalue < lowLimit || newvalue > highLimit) { + newvalue = Math.max(newvalue, lowLimit); + newvalue = Math.min(newvalue, highLimit); + String msg = String.format(MainApp.sResources.getString(R.string.valueoutofrange), valueName); + msg += ".\n"; + msg += String.format(MainApp.sResources.getString(R.string.valuelimitedto), value, newvalue); + log.error(msg); + NSUpload.uploadError(msg); + ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), msg, R.raw.error); + } + return newvalue; + } } diff --git a/app/src/main/res/values-bg/strings.xml b/app/src/main/res/values-bg/strings.xml index 5839ae79ce..9e7dc48376 100644 --- a/app/src/main/res/values-bg/strings.xml +++ b/app/src/main/res/values-bg/strings.xml @@ -310,8 +310,8 @@ Loop has been enabled Loop is disabled Loop is enabled - %.2f ограничен до %.2f - Стойността %s е извън границите + %.2f ограничен до %.2f + Стойността %s е извън границите Remote basal setting is not allowed Remote command is not allowed To start basal %.2fU/h reply with code %s diff --git a/app/src/main/res/values-cs/strings.xml b/app/src/main/res/values-cs/strings.xml index 8e8d09f692..c76af23781 100644 --- a/app/src/main/res/values-cs/strings.xml +++ b/app/src/main/res/values-cs/strings.xml @@ -285,7 +285,7 @@ Smyčka je povolena Spanish Není vybrán žádný profil - Hodnota %s je mimo přednastavený rozsah + Hodnota %s je mimo přednastavený rozsah Vzdálené posílání příkazů není povoleno Na spuštění bazálu %.2fU/h odpověz SMS s kódem %s Na ukončení bazálu odpověz SMS s kódem %s @@ -375,7 +375,7 @@ Používat autodetekci senzitivity Data detekce senzitivity Ladící informace - %.2f omezeno na %.2f + %.2f omezeno na %.2f Odstranit záznam: Krátkodobý průměr Obnovit události z NS diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 265c6c63ac..c5ddb77dc9 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -481,7 +481,7 @@ OAPS OpenAPS AMA Skript Debug - Wert %s ist außerhalb des festen Limits + Wert %s ist außerhalb des festen Limits Kalibrierung Kalibrierung Button-Text: @@ -579,7 +579,7 @@ Unbekannter Befehl oder falsche Antwort Falsche Dauer Einstellungen freischalten - %.2f limitiert auf %.2f + %.2f limitiert auf %.2f S-Bolus Model: %02X Protokoll: %02X Code: %02X Empfindlichkeitserkennung diff --git a/app/src/main/res/values-el/strings.xml b/app/src/main/res/values-el/strings.xml index b9fd9bff78..dc91ee09b8 100644 --- a/app/src/main/res/values-el/strings.xml +++ b/app/src/main/res/values-el/strings.xml @@ -307,8 +307,8 @@ Το κύκλωμα ενεργοποιήθηκε Κύκλωμα απενεργοποιημένο Κύκλωμα ενεργοποιημένο - %.2f limited to %.2f - Τιμή %s είναι έξω από τα όρια + %.2f limited to %.2f + Τιμή %s είναι έξω από τα όρια "Δεν επιτρέπεται η απομακρυσμένη ρύθμιση βασικού ρυθμού " Δεν επιτρέπεται απομακρυσμένη εντολή Για έναρξη βασικού %.2fU/h SMS με κωσικό %s diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 1b4f3aa944..95ebe1bc77 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -287,7 +287,7 @@ Corr Lazo Inactivo Bolo Comida - Valor %s fuera de limites + Valor %s fuera de limites Botón Texto: Carbohidratos: Validar: @@ -392,7 +392,7 @@ Duración de acitividad de insulina Errores habilitar funciones adicionales para uso durante el día como SMB - %.2f limitado a %.\"f + %.2f limitado a %.2f no permitido el mando remoto Para cancelar loop por %d minutos responde con código %s Rellenar/Llenar diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 8ca3415ac4..67eae6e7f9 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -306,8 +306,8 @@ Loop a été désactivé "Loop est désactivé " Loop est activé - %.2f limité à %.2f - La valeur %s est hors limites strictes + %.2f limité à %.2f + La valeur %s est hors limites strictes Le réglage du basal à distance n\'est pas autorisé La commande à distance n\'est pas autorisée Lancer le basal %.2fU/h retour avec un code %s diff --git a/app/src/main/res/values-ko/strings.xml b/app/src/main/res/values-ko/strings.xml index 98471c491f..96bf789524 100644 --- a/app/src/main/res/values-ko/strings.xml +++ b/app/src/main/res/values-ko/strings.xml @@ -312,8 +312,8 @@ Loop가 실행되었습니다. Loop가 중지중입니다. Loop가 실행중입니다. - %.2f, %.2f으로 제한됨 - %s값이 하드리밋(Hard Limit)를 벗어났습니다 + %.2f, %.2f으로 제한됨 + %s값이 하드리밋(Hard Limit)를 벗어났습니다 원격 기초주입설정이 허가되지 않았습니다 원격 명령이 허가되지 않았습니다 기초주입 %.2fU/h 을 실행하려면 %s 를 입력하고 답장하세요 diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml index 8a822898df..9dd9dfd33d 100644 --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -451,7 +451,7 @@ Geen profiel beschikbaar Maximaal basaal IOB OpenAPS kan toedienen [E] Profiel - Waarde %s is buiten de toegestane limieten + Waarde %s is buiten de toegestane limieten Basis basale dosis Laatse berekening Laatste uitvoering @@ -627,7 +627,7 @@ Model: %02X Protokoll: %02X Code: %02X Verbonden gedurende %d s Totaal %d gegevens geupload - %.2f gelimitteerd tot %.2f + %.2f gelimitteerd tot %.2f Om de loop te onderbreken voor %d minuten antwoord met de code %s Tijdelijk basaal %.2fE/u voor %d minuten succesvol gestart Gemiddelde gevoeligheid diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index 1535d82c26..92373e4f1d 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -362,8 +362,8 @@ результат выполнить сейчас отладка скрипта - %.2f ограничено до %.2f - величина %s недопустима + %.2f ограничено до %.2f + величина %s недопустима открытый цикл есть новое предложение другое diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml index b27b70da43..2293360635 100644 --- a/app/src/main/res/values-sv/strings.xml +++ b/app/src/main/res/values-sv/strings.xml @@ -477,8 +477,8 @@ Andra Ny behandlingsrekommendation tillgänglig Open Loop - Värde %s är utanför gränserna - %.2f begränsad till %.2f + Värde %s är utanför gränserna + %.2f begränsad till %.2f Kör nu Fråga Profil diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index 1fad149686..e96bb29caa 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -45,11 +45,13 @@ @string/child @string/teenage @string/adult + @string/resistantadult @string/key_child @string/key_teenage @string/key_adult + @string/key_resistantadult diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 81ebebc2ba..3de6fba4f6 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -323,8 +323,8 @@ Loop has been enabled Loop is disabled Loop is enabled - %.2f limited to %.2f - Value %s is out of hard limits + %.2f limited to %.2f + Value %s is out of hard limits Remote basal setting is not allowed Remote command is not allowed To start basal %.2fU/h reply with code %s @@ -542,10 +542,12 @@ Child Teenage Adult + Insulin resistant adult age child teenage adult + resistantadult Please select patient age to setup safety limits I_understand Glimp