2017-02-22 20:29:41 +01:00
|
|
|
package info.nightscout.utils;
|
|
|
|
|
2018-02-11 22:41:10 +01:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
2017-02-22 20:29:41 +01:00
|
|
|
import info.nightscout.androidaps.MainApp;
|
|
|
|
import info.nightscout.androidaps.R;
|
2018-07-28 23:57:25 +02:00
|
|
|
import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload;
|
2017-02-22 20:29:41 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by mike on 22.02.2017.
|
|
|
|
*/
|
|
|
|
|
|
|
|
public class HardLimits {
|
2018-02-11 22:41:10 +01:00
|
|
|
private static Logger log = LoggerFactory.getLogger(HardLimits.class);
|
|
|
|
|
|
|
|
final static int CHILD = 0;
|
|
|
|
final static int TEENAGE = 1;
|
|
|
|
final static int ADULT = 2;
|
|
|
|
final static int RESISTANTADULT = 3;
|
|
|
|
|
2018-03-20 10:07:52 +01:00
|
|
|
final static double[] MAXBOLUS = {5d, 10d, 17d, 25d};
|
2018-02-11 22:41:10 +01:00
|
|
|
|
|
|
|
// 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;
|
2018-02-16 06:43:47 +01:00
|
|
|
public static final double MAXIC = 100;
|
2018-02-11 22:41:10 +01:00
|
|
|
|
|
|
|
public static final double MINISF = 2; // mgdl
|
|
|
|
public static final double MAXISF = 720; // mgdl
|
|
|
|
|
2018-03-12 17:59:42 +01:00
|
|
|
public static final double[] MAXIOB_AMA = {3, 5, 7, 12};
|
2018-03-20 10:07:52 +01:00
|
|
|
public static final double[] MAXIOB_SMB = {3, 7, 12, 25};
|
2018-02-11 22:41:10 +01:00
|
|
|
|
|
|
|
public static final double[] MAXBASAL = {2, 5, 10, 12};
|
|
|
|
|
|
|
|
|
|
|
|
private static int loadAge() {
|
|
|
|
String sp_age = SP.getString(R.string.key_age, "");
|
|
|
|
int age;
|
|
|
|
|
2018-03-21 23:01:30 +01:00
|
|
|
if (sp_age.equals(MainApp.gs(R.string.key_child)))
|
2018-02-11 22:41:10 +01:00
|
|
|
age = CHILD;
|
2018-03-21 23:01:30 +01:00
|
|
|
else if (sp_age.equals(MainApp.gs(R.string.key_teenage)))
|
2018-02-11 22:41:10 +01:00
|
|
|
age = TEENAGE;
|
2018-03-21 23:01:30 +01:00
|
|
|
else if (sp_age.equals(MainApp.gs(R.string.key_adult)))
|
2018-02-11 22:41:10 +01:00
|
|
|
age = ADULT;
|
2018-03-21 23:01:30 +01:00
|
|
|
else if (sp_age.equals(MainApp.gs(R.string.key_resistantadult)))
|
2018-02-11 22:41:10 +01:00
|
|
|
age = RESISTANTADULT;
|
|
|
|
else age = ADULT;
|
|
|
|
|
|
|
|
return age;
|
|
|
|
}
|
2017-02-22 20:29:41 +01:00
|
|
|
|
|
|
|
public static double maxBolus() {
|
2018-02-11 22:41:10 +01:00
|
|
|
return MAXBOLUS[loadAge()];
|
|
|
|
}
|
|
|
|
|
|
|
|
public static double maxIobAMA() {
|
|
|
|
return MAXIOB_AMA[loadAge()];
|
|
|
|
}
|
2017-02-22 20:29:41 +01:00
|
|
|
|
2018-02-11 22:41:10 +01:00
|
|
|
public static double maxIobSMB() {
|
|
|
|
return MAXIOB_SMB[loadAge()];
|
2017-02-22 20:29:41 +01:00
|
|
|
}
|
|
|
|
|
2018-02-11 22:41:10 +01:00
|
|
|
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);
|
2018-03-21 23:01:30 +01:00
|
|
|
String msg = String.format(MainApp.gs(R.string.valueoutofrange), valueName);
|
2018-02-11 22:41:10 +01:00
|
|
|
msg += ".\n";
|
2018-03-21 23:01:30 +01:00
|
|
|
msg += String.format(MainApp.gs(R.string.valuelimitedto), value, newvalue);
|
2018-02-11 22:41:10 +01:00
|
|
|
log.error(msg);
|
|
|
|
NSUpload.uploadError(msg);
|
|
|
|
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), msg, R.raw.error);
|
|
|
|
}
|
|
|
|
return newvalue;
|
|
|
|
}
|
2017-02-22 20:29:41 +01:00
|
|
|
}
|