HardLimits refactor

This commit is contained in:
Milos Kozak 2018-02-11 22:41:10 +01:00
parent 5dd0f70686
commit 943205c782
19 changed files with 174 additions and 117 deletions

View file

@ -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;

View file

@ -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;
}
}

View file

@ -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();

View file

@ -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);

View file

@ -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);

View file

@ -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();

View file

@ -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;
}
}

View file

@ -310,8 +310,8 @@
<string name="smscommunicator_loophasbeenenabled">Loop has been enabled</string>
<string name="smscommunicator_loopisdisabled">Loop is disabled</string>
<string name="smscommunicator_loopisenabled">Loop is enabled</string>
<string name="openapsma_valuelimitedto" formatted="false">%.2f ограничен до %.2f</string>
<string name="openapsma_valueoutofrange" formatted="false">Стойността %s е извън границите</string>
<string name="valuelimitedto" formatted="false">%.2f ограничен до %.2f</string>
<string name="valueoutofrange" formatted="false">Стойността %s е извън границите</string>
<string name="smscommunicator_remotebasalnotallowed">Remote basal setting is not allowed</string>
<string name="smscommunicator_remotecommandnotallowed">Remote command is not allowed</string>
<string name="smscommunicator_basalreplywithcode" formatted="false">To start basal %.2fU/h reply with code %s</string>

View file

@ -285,7 +285,7 @@
<string name="smscommunicator_loopisenabled">Smyčka je povolena</string>
<string name="es_lang">Spanish</string>
<string name="noprofileselected">Není vybrán žádný profil</string>
<string name="openapsma_valueoutofrange" formatted="false">Hodnota %s je mimo přednastavený rozsah</string>
<string name="valueoutofrange" formatted="false">Hodnota %s je mimo přednastavený rozsah</string>
<string name="smscommunicator_remotebasalnotallowed">Vzdálené posílání příkazů není povoleno</string>
<string name="smscommunicator_basalreplywithcode" formatted="false">Na spuštění bazálu %.2fU/h odpověz SMS s kódem %s</string>
<string name="smscommunicator_basalstopreplywithcode" formatted="false">Na ukončení bazálu odpověz SMS s kódem %s</string>
@ -375,7 +375,7 @@
<string name="openapsama_useautosens">Používat autodetekci senzitivity</string>
<string name="openapsma_autosensdata_label">Data detekce senzitivity</string>
<string name="openapsma_scriptdebugdata_label">Ladící informace</string>
<string name="openapsma_valuelimitedto" formatted="false">%.2f omezeno na %.2f</string>
<string name="valuelimitedto" formatted="false">%.2f omezeno na %.2f</string>
<string name="removerecord">Odstranit záznam:</string>
<string name="short_avgdelta">Krátkodobý průměr</string>
<string name="refresheventsfromnightscout">Obnovit události z NS</string>

View file

@ -481,7 +481,7 @@
<string name="openaps_short">OAPS</string>
<string name="openapsama">OpenAPS AMA</string>
<string name="openapsma_scriptdebugdata_label">Skript Debug</string>
<string name="openapsma_valueoutofrange">Wert %s ist außerhalb des festen Limits</string>
<string name="valueoutofrange">Wert %s ist außerhalb des festen Limits</string>
<string name="overview_calibration">Kalibrierung</string>
<string name="overview_calibration_bg_label">Kalibrierung</string>
<string name="overview_editquickwizard_buttontext">Button-Text:</string>
@ -579,7 +579,7 @@
<string name="smscommunicator_unknowncommand">Unbekannter Befehl oder falsche Antwort</string>
<string name="smscommunicator_wrongduration">Falsche Dauer</string>
<string name="unlock_settings">Einstellungen freischalten</string>
<string formatted="false" name="openapsma_valuelimitedto">%.2f limitiert auf %.2f</string>
<string formatted="false" name="valuelimitedto">%.2f limitiert auf %.2f</string>
<string name="danar_sbolus">S-Bolus</string>
<string formatted="false" name="danar_model">Model: %02X Protokoll: %02X Code: %02X</string>
<string name="configbuilder_sensitivity">Empfindlichkeitserkennung</string>

View file

@ -307,8 +307,8 @@
<string name="smscommunicator_loophasbeenenabled">Το κύκλωμα ενεργοποιήθηκε</string>
<string name="smscommunicator_loopisdisabled">Κύκλωμα απενεργοποιημένο</string>
<string name="smscommunicator_loopisenabled">Κύκλωμα ενεργοποιημένο</string>
<string name="openapsma_valuelimitedto" formatted="false">%.2f limited to %.2f</string>
<string name="openapsma_valueoutofrange" formatted="false">Τιμή %s είναι έξω από τα όρια</string>
<string name="valuelimitedto" formatted="false">%.2f limited to %.2f</string>
<string name="valueoutofrange" formatted="false">Τιμή %s είναι έξω από τα όρια</string>
<string name="smscommunicator_remotebasalnotallowed">"Δεν επιτρέπεται η απομακρυσμένη ρύθμιση βασικού ρυθμού "</string>
<string name="smscommunicator_remotecommandnotallowed">Δεν επιτρέπεται απομακρυσμένη εντολή</string>
<string name="smscommunicator_basalreplywithcode" formatted="false">Για έναρξη βασικού %.2fU/h SMS με κωσικό %s</string>

View file

@ -287,7 +287,7 @@
<string name="correctionbous">Corr</string>
<string name="disabledloop">Lazo Inactivo</string>
<string name="mealbolus">Bolo Comida</string>
<string name="openapsma_valueoutofrange" formatted="false">Valor %s fuera de limites</string>
<string name="valueoutofrange" formatted="false">Valor %s fuera de limites</string>
<string name="overview_editquickwizard_buttontext">Botón Texto:</string>
<string name="overview_editquickwizard_carbs">Carbohidratos:</string>
<string name="overview_editquickwizard_valid">Validar:</string>
@ -392,7 +392,7 @@
<string name="danarprofile_dia_summary">Duración de acitividad de insulina</string>
<string name="pump_errors_history">Errores</string>
<string name="objectives_7_objective">habilitar funciones adicionales para uso durante el día como SMB</string>
<string name="openapsma_valuelimitedto" formatted="false">%.2f limitado a %.\"f</string>
<string name="valuelimitedto" formatted="false">%.2f limitado a %.2f</string>
<string name="smscommunicator_remotecommandnotallowed">no permitido el mando remoto</string>
<string name="smscommunicator_suspendreplywithcode" formatted="false">Para cancelar loop por %d minutos responde con código %s</string>
<string name="primefill">Rellenar/Llenar</string>

View file

@ -306,8 +306,8 @@
<string name="smscommunicator_loophasbeenenabled">Loop a été désactivé</string>
<string name="smscommunicator_loopisdisabled">"Loop est désactivé "</string>
<string name="smscommunicator_loopisenabled">Loop est activé</string>
<string name="openapsma_valuelimitedto" formatted="false">%.2f limité à %.2f</string>
<string name="openapsma_valueoutofrange" formatted="false">La valeur %s est hors limites strictes</string>
<string name="valuelimitedto" formatted="false">%.2f limité à %.2f</string>
<string name="valueoutofrange" formatted="false">La valeur %s est hors limites strictes</string>
<string name="smscommunicator_remotebasalnotallowed">Le réglage du basal à distance n\'est pas autorisé</string>
<string name="smscommunicator_remotecommandnotallowed">La commande à distance n\'est pas autorisée</string>
<string name="smscommunicator_basalreplywithcode" formatted="false">Lancer le basal %.2fU/h retour avec un code %s</string>

View file

@ -312,8 +312,8 @@
<string name="smscommunicator_loophasbeenenabled">Loop가 실행되었습니다.</string>
<string name="smscommunicator_loopisdisabled">Loop가 중지중입니다.</string>
<string name="smscommunicator_loopisenabled">Loop가 실행중입니다.</string>
<string name="openapsma_valuelimitedto" formatted="false">%.2f, %.2f으로 제한됨</string>
<string name="openapsma_valueoutofrange" formatted="false">%s값이 하드리밋(Hard Limit)를 벗어났습니다</string>
<string name="valuelimitedto" formatted="false">%.2f, %.2f으로 제한됨</string>
<string name="valueoutofrange" formatted="false">%s값이 하드리밋(Hard Limit)를 벗어났습니다</string>
<string name="smscommunicator_remotebasalnotallowed">원격 기초주입설정이 허가되지 않았습니다</string>
<string name="smscommunicator_remotecommandnotallowed">원격 명령이 허가되지 않았습니다</string>
<string name="smscommunicator_basalreplywithcode" formatted="false">기초주입 %.2fU/h 을 실행하려면 %s 를 입력하고 답장하세요</string>

View file

@ -451,7 +451,7 @@
<string name="openapsma_noprofile">Geen profiel beschikbaar</string>
<string name="openapsma_maxiob_title">Maximaal basaal IOB OpenAPS kan toedienen [E]</string>
<string name="openapsma_profile_label">Profiel</string>
<string name="openapsma_valueoutofrange">Waarde %s is buiten de toegestane limieten</string>
<string name="valueoutofrange">Waarde %s is buiten de toegestane limieten</string>
<string name="pump_basebasalrate_label">Basis basale dosis</string>
<string name="openapsma_lastrun_label">Laatse berekening</string>
<string name="openapsma_lastenact_label">Laatste uitvoering</string>
@ -627,7 +627,7 @@
<string name="danar_model" formatted="false">Model: %02X Protokoll: %02X Code: %02X</string>
<string name="danar_history_connectingfor">Verbonden gedurende %d s</string>
<string name="danar_totaluploaded">Totaal %d gegevens geupload</string>
<string name="openapsma_valuelimitedto" formatted="false">%.2f gelimitteerd tot %.2f</string>
<string name="valuelimitedto" formatted="false">%.2f gelimitteerd tot %.2f</string>
<string name="smscommunicator_suspendreplywithcode" formatted="false">Om de loop te onderbreken voor %d minuten antwoord met de code %s</string>
<string name="smscommunicator_tempbasalset" formatted="false">Tijdelijk basaal %.2fE/u voor %d minuten succesvol gestart</string>
<string name="sensitivityweightedaverage">Gemiddelde gevoeligheid</string>

View file

@ -362,8 +362,8 @@
<string name="result">результат</string>
<string name="openapsma_run">выполнить сейчас</string>
<string name="openapsma_scriptdebugdata_label">отладка скрипта</string>
<string name="openapsma_valuelimitedto" formatted="false">%.2f ограничено до %.2f</string>
<string name="openapsma_valueoutofrange" formatted="false">величина %s недопустима</string>
<string name="valuelimitedto" formatted="false">%.2f ограничено до %.2f</string>
<string name="valueoutofrange" formatted="false">величина %s недопустима</string>
<string name="openloop">открытый цикл</string>
<string name="openloop_newsuggestion">есть новое предложение</string>
<string name="othersettings_title">другое</string>

View file

@ -477,8 +477,8 @@
<string name="othersettings_title">Andra</string>
<string name="openloop_newsuggestion">Ny behandlingsrekommendation tillgänglig</string>
<string name="openloop">Open Loop</string>
<string name="openapsma_valueoutofrange" formatted="false">Värde %s är utanför gränserna</string>
<string name="openapsma_valuelimitedto" formatted="false">%.2f begränsad till %.2f</string>
<string name="valueoutofrange" formatted="false">Värde %s är utanför gränserna</string>
<string name="valuelimitedto" formatted="false">%.2f begränsad till %.2f</string>
<string name="openapsma_run">Kör nu</string>
<string name="openapsma_request_label">Fråga</string>
<string name="openapsma_profile_label">Profil</string>

View file

@ -45,11 +45,13 @@
<item>@string/child</item>
<item>@string/teenage</item>
<item>@string/adult</item>
<item>@string/resistantadult</item>
</string-array>
<string-array name="ageValues" translatable="false">
<item>@string/key_child</item>
<item>@string/key_teenage</item>
<item>@string/key_adult</item>
<item>@string/key_resistantadult</item>
</string-array>
<string-array name="danaSpeedArray">

View file

@ -323,8 +323,8 @@
<string name="smscommunicator_loophasbeenenabled">Loop has been enabled</string>
<string name="smscommunicator_loopisdisabled">Loop is disabled</string>
<string name="smscommunicator_loopisenabled">Loop is enabled</string>
<string name="openapsma_valuelimitedto" formatted="false">%.2f limited to %.2f</string>
<string name="openapsma_valueoutofrange" formatted="false">Value %s is out of hard limits</string>
<string name="valuelimitedto" formatted="false">%.2f limited to %.2f</string>
<string name="valueoutofrange" formatted="false">Value %s is out of hard limits</string>
<string name="smscommunicator_remotebasalnotallowed">Remote basal setting is not allowed</string>
<string name="smscommunicator_remotecommandnotallowed">Remote command is not allowed</string>
<string name="smscommunicator_basalreplywithcode" formatted="false">To start basal %.2fU/h reply with code %s</string>
@ -542,10 +542,12 @@
<string name="child">Child</string>
<string name="teenage">Teenage</string>
<string name="adult">Adult</string>
<string name="resistantadult">Insulin resistant adult</string>
<string name="key_age" translatable="false">age</string>
<string name="key_child" translatable="false">child</string>
<string name="key_teenage" translatable="false">teenage</string>
<string name="key_adult" translatable="false">adult</string>
<string name="key_resistantadult" translatable="false">resistantadult</string>
<string name="patientage_summary">Please select patient age to setup safety limits</string>
<string name="key_i_understand" translatable="false">I_understand</string>
<string name="Glimp">Glimp</string>