2018-03-19 18:21:02 +01:00
|
|
|
package info.nightscout.androidaps.data;
|
|
|
|
|
2019-05-16 13:57:37 +02:00
|
|
|
import androidx.annotation.NonNull;
|
2019-04-17 21:29:16 +02:00
|
|
|
|
2018-03-19 18:21:02 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
2018-03-22 23:05:00 +01:00
|
|
|
import info.nightscout.androidaps.Constants;
|
2018-03-19 18:21:02 +01:00
|
|
|
import info.nightscout.androidaps.MainApp;
|
2018-03-19 22:20:42 +01:00
|
|
|
import info.nightscout.androidaps.interfaces.Constraint;
|
2018-03-19 18:21:02 +01:00
|
|
|
import info.nightscout.androidaps.interfaces.ConstraintsInterface;
|
|
|
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
2018-03-31 00:36:03 +02:00
|
|
|
import info.nightscout.androidaps.interfaces.PluginType;
|
2018-03-19 18:21:02 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by mike on 19.03.2018.
|
|
|
|
*/
|
|
|
|
|
|
|
|
public class ConstraintChecker implements ConstraintsInterface {
|
2018-03-22 23:20:10 +01:00
|
|
|
|
2018-03-19 18:45:23 +01:00
|
|
|
public Constraint<Boolean> isLoopInvokationAllowed() {
|
2018-06-09 22:07:41 +02:00
|
|
|
return isLoopInvocationAllowed(new Constraint<>(true));
|
2018-03-19 18:45:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public Constraint<Boolean> isClosedLoopAllowed() {
|
|
|
|
return isClosedLoopAllowed(new Constraint<>(true));
|
|
|
|
}
|
|
|
|
|
2018-03-22 23:20:10 +01:00
|
|
|
public Constraint<Boolean> isAutosensModeEnabled() {
|
2018-03-19 22:36:08 +01:00
|
|
|
return isAutosensModeEnabled(new Constraint<>(true));
|
|
|
|
}
|
|
|
|
|
2018-03-22 23:20:10 +01:00
|
|
|
public Constraint<Boolean> isAMAModeEnabled() {
|
2018-03-19 22:59:25 +01:00
|
|
|
return isAMAModeEnabled(new Constraint<>(true));
|
|
|
|
}
|
|
|
|
|
2018-03-22 23:20:10 +01:00
|
|
|
public Constraint<Boolean> isSMBModeEnabled() {
|
2018-03-19 23:14:04 +01:00
|
|
|
return isSMBModeEnabled(new Constraint<>(true));
|
|
|
|
}
|
|
|
|
|
2018-10-13 18:07:01 +02:00
|
|
|
public Constraint<Boolean> isUAMEnabled() {
|
|
|
|
return isUAMEnabled(new Constraint<>(true));
|
|
|
|
}
|
|
|
|
|
2018-06-29 22:43:54 +02:00
|
|
|
public Constraint<Boolean> isAdvancedFilteringEnabled() {
|
|
|
|
return isAdvancedFilteringEnabled(new Constraint<>(true));
|
|
|
|
}
|
|
|
|
|
2019-03-13 14:33:28 +01:00
|
|
|
public Constraint<Boolean> isSuperBolusEnabled() {
|
|
|
|
return isSuperBolusEnabled(new Constraint<>(true));
|
|
|
|
}
|
|
|
|
|
2018-03-22 23:20:10 +01:00
|
|
|
public Constraint<Double> getMaxBasalAllowed(Profile profile) {
|
2018-03-22 23:05:00 +01:00
|
|
|
return applyBasalConstraints(new Constraint<>(Constants.REALLYHIGHBASALRATE), profile);
|
|
|
|
}
|
|
|
|
|
2018-03-22 23:20:10 +01:00
|
|
|
public Constraint<Integer> getMaxBasalPercentAllowed(Profile profile) {
|
|
|
|
return applyBasalPercentConstraints(new Constraint<>(Constants.REALLYHIGHPERCENTBASALRATE), profile);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Constraint<Double> getMaxBolusAllowed() {
|
|
|
|
return applyBolusConstraints(new Constraint<>(Constants.REALLYHIGHBOLUS));
|
|
|
|
}
|
|
|
|
|
2018-09-01 22:45:15 +02:00
|
|
|
public Constraint<Double> getMaxExtendedBolusAllowed() {
|
|
|
|
return applyExtendedBolusConstraints(new Constraint<>(Constants.REALLYHIGHBOLUS));
|
|
|
|
}
|
|
|
|
|
2018-03-22 23:20:10 +01:00
|
|
|
public Constraint<Integer> getMaxCarbsAllowed() {
|
|
|
|
return applyCarbsConstraints(new Constraint<>(Constants.REALLYHIGHCARBS));
|
|
|
|
}
|
|
|
|
|
|
|
|
public Constraint<Double> getMaxIOBAllowed() {
|
|
|
|
return applyMaxIOBConstraints(new Constraint<>(Constants.REALLYHIGHIOB));
|
|
|
|
}
|
|
|
|
|
2018-03-19 18:21:02 +01:00
|
|
|
@Override
|
2019-04-17 21:29:16 +02:00
|
|
|
public Constraint<Boolean> isLoopInvocationAllowed(@NonNull Constraint<Boolean> value) {
|
2018-03-19 18:21:02 +01:00
|
|
|
|
2019-04-17 21:29:16 +02:00
|
|
|
ArrayList<PluginBase> constraintsPlugins = MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
|
2018-03-19 18:21:02 +01:00
|
|
|
for (PluginBase p : constraintsPlugins) {
|
|
|
|
ConstraintsInterface constraint = (ConstraintsInterface) p;
|
2018-03-31 00:36:03 +02:00
|
|
|
if (!p.isEnabled(PluginType.CONSTRAINTS)) continue;
|
2018-06-09 22:07:41 +02:00
|
|
|
constraint.isLoopInvocationAllowed(value);
|
2018-03-19 18:21:02 +01:00
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-04-17 21:29:16 +02:00
|
|
|
public Constraint<Boolean> isClosedLoopAllowed(@NonNull Constraint<Boolean> value) {
|
2018-03-19 18:21:02 +01:00
|
|
|
|
2019-04-17 21:29:16 +02:00
|
|
|
ArrayList<PluginBase> constraintsPlugins = MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
|
2018-03-19 18:21:02 +01:00
|
|
|
for (PluginBase p : constraintsPlugins) {
|
|
|
|
ConstraintsInterface constraint = (ConstraintsInterface) p;
|
2018-03-31 00:36:03 +02:00
|
|
|
if (!p.isEnabled(PluginType.CONSTRAINTS)) continue;
|
2018-03-19 18:45:23 +01:00
|
|
|
constraint.isClosedLoopAllowed(value);
|
2018-03-19 18:21:02 +01:00
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-04-17 21:29:16 +02:00
|
|
|
public Constraint<Boolean> isAutosensModeEnabled(@NonNull Constraint<Boolean> value) {
|
2018-03-19 18:21:02 +01:00
|
|
|
|
2019-04-17 21:29:16 +02:00
|
|
|
ArrayList<PluginBase> constraintsPlugins = MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
|
2018-03-19 18:21:02 +01:00
|
|
|
for (PluginBase p : constraintsPlugins) {
|
2018-03-19 22:36:08 +01:00
|
|
|
ConstraintsInterface constraint = (ConstraintsInterface) p;
|
2018-03-31 00:36:03 +02:00
|
|
|
if (!p.isEnabled(PluginType.CONSTRAINTS)) continue;
|
2018-03-19 22:36:08 +01:00
|
|
|
constraint.isAutosensModeEnabled(value);
|
2018-03-19 18:21:02 +01:00
|
|
|
}
|
2018-03-19 22:36:08 +01:00
|
|
|
return value;
|
2018-03-19 18:21:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-04-17 21:29:16 +02:00
|
|
|
public Constraint<Boolean> isAMAModeEnabled(@NonNull Constraint<Boolean> value) {
|
2018-03-19 18:21:02 +01:00
|
|
|
|
2019-04-17 21:29:16 +02:00
|
|
|
ArrayList<PluginBase> constraintsPlugins = MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
|
2018-03-19 18:21:02 +01:00
|
|
|
for (PluginBase p : constraintsPlugins) {
|
|
|
|
ConstraintsInterface constrain = (ConstraintsInterface) p;
|
2018-03-31 00:36:03 +02:00
|
|
|
if (!p.isEnabled(PluginType.CONSTRAINTS)) continue;
|
2018-03-19 22:59:25 +01:00
|
|
|
constrain.isAMAModeEnabled(value);
|
2018-03-19 18:21:02 +01:00
|
|
|
}
|
2018-03-19 22:59:25 +01:00
|
|
|
return value;
|
2018-03-19 18:21:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-04-17 21:29:16 +02:00
|
|
|
public Constraint<Boolean> isSMBModeEnabled(@NonNull Constraint<Boolean> value) {
|
2018-03-19 18:21:02 +01:00
|
|
|
|
2019-04-17 21:29:16 +02:00
|
|
|
ArrayList<PluginBase> constraintsPlugins = MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
|
2018-03-19 18:21:02 +01:00
|
|
|
for (PluginBase p : constraintsPlugins) {
|
2018-03-19 23:14:04 +01:00
|
|
|
ConstraintsInterface constraint = (ConstraintsInterface) p;
|
2018-03-31 00:36:03 +02:00
|
|
|
if (!p.isEnabled(PluginType.CONSTRAINTS)) continue;
|
2018-03-19 23:14:04 +01:00
|
|
|
constraint.isSMBModeEnabled(value);
|
2018-03-19 18:21:02 +01:00
|
|
|
}
|
2018-03-19 23:14:04 +01:00
|
|
|
return value;
|
2018-03-19 18:21:02 +01:00
|
|
|
}
|
|
|
|
|
2018-10-13 18:07:01 +02:00
|
|
|
@Override
|
2019-04-17 21:29:16 +02:00
|
|
|
public Constraint<Boolean> isUAMEnabled(@NonNull Constraint<Boolean> value) {
|
2018-10-13 18:07:01 +02:00
|
|
|
|
2019-04-17 21:29:16 +02:00
|
|
|
ArrayList<PluginBase> constraintsPlugins = MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
|
2018-10-13 18:07:01 +02:00
|
|
|
for (PluginBase p : constraintsPlugins) {
|
|
|
|
ConstraintsInterface constraint = (ConstraintsInterface) p;
|
|
|
|
if (!p.isEnabled(PluginType.CONSTRAINTS)) continue;
|
|
|
|
constraint.isUAMEnabled(value);
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2018-06-29 22:43:54 +02:00
|
|
|
@Override
|
2019-04-17 21:29:16 +02:00
|
|
|
public Constraint<Boolean> isAdvancedFilteringEnabled(@NonNull Constraint<Boolean> value) {
|
|
|
|
ArrayList<PluginBase> constraintsPlugins = MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
|
2018-06-29 22:43:54 +02:00
|
|
|
for (PluginBase p : constraintsPlugins) {
|
|
|
|
ConstraintsInterface constraint = (ConstraintsInterface) p;
|
|
|
|
if (!p.isEnabled(PluginType.CONSTRAINTS)) continue;
|
|
|
|
constraint.isAdvancedFilteringEnabled(value);
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2019-03-13 14:33:28 +01:00
|
|
|
@Override
|
2019-04-17 21:29:16 +02:00
|
|
|
public Constraint<Boolean> isSuperBolusEnabled(@NonNull Constraint<Boolean> value) {
|
|
|
|
ArrayList<PluginBase> constraintsPlugins = MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
|
2019-03-13 14:33:28 +01:00
|
|
|
for (PluginBase p : constraintsPlugins) {
|
|
|
|
ConstraintsInterface constraint = (ConstraintsInterface) p;
|
|
|
|
if (!p.isEnabled(PluginType.CONSTRAINTS)) continue;
|
|
|
|
constraint.isSuperBolusEnabled(value);
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2018-03-19 18:21:02 +01:00
|
|
|
@Override
|
2019-04-17 21:29:16 +02:00
|
|
|
public Constraint<Double> applyBasalConstraints(@NonNull Constraint<Double> absoluteRate, Profile profile) {
|
|
|
|
ArrayList<PluginBase> constraintsPlugins = MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
|
2018-03-19 18:21:02 +01:00
|
|
|
for (PluginBase p : constraintsPlugins) {
|
2018-03-20 22:09:22 +01:00
|
|
|
ConstraintsInterface constraint = (ConstraintsInterface) p;
|
2018-03-31 00:36:03 +02:00
|
|
|
if (!p.isEnabled(PluginType.CONSTRAINTS)) continue;
|
2018-03-20 22:09:22 +01:00
|
|
|
constraint.applyBasalConstraints(absoluteRate, profile);
|
2018-03-19 18:21:02 +01:00
|
|
|
}
|
2018-03-20 22:09:22 +01:00
|
|
|
return absoluteRate;
|
2018-03-19 18:21:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-04-17 21:29:16 +02:00
|
|
|
public Constraint<Integer> applyBasalPercentConstraints(@NonNull Constraint<Integer> percentRate, Profile profile) {
|
|
|
|
ArrayList<PluginBase> constraintsPlugins = MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
|
2018-03-19 18:21:02 +01:00
|
|
|
for (PluginBase p : constraintsPlugins) {
|
|
|
|
ConstraintsInterface constrain = (ConstraintsInterface) p;
|
2018-03-31 00:36:03 +02:00
|
|
|
if (!p.isEnabled(PluginType.CONSTRAINTS)) continue;
|
2018-03-21 20:24:02 +01:00
|
|
|
constrain.applyBasalPercentConstraints(percentRate, profile);
|
2018-03-19 18:21:02 +01:00
|
|
|
}
|
2018-03-21 20:24:02 +01:00
|
|
|
return percentRate;
|
2018-03-19 18:21:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-04-17 21:29:16 +02:00
|
|
|
public Constraint<Double> applyBolusConstraints(@NonNull Constraint<Double> insulin) {
|
|
|
|
ArrayList<PluginBase> constraintsPlugins = MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
|
2018-03-19 18:21:02 +01:00
|
|
|
for (PluginBase p : constraintsPlugins) {
|
|
|
|
ConstraintsInterface constrain = (ConstraintsInterface) p;
|
2018-03-31 00:36:03 +02:00
|
|
|
if (!p.isEnabled(PluginType.CONSTRAINTS)) continue;
|
2018-03-21 23:01:30 +01:00
|
|
|
constrain.applyBolusConstraints(insulin);
|
2018-03-19 18:21:02 +01:00
|
|
|
}
|
2018-03-21 23:01:30 +01:00
|
|
|
return insulin;
|
2018-09-01 22:45:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-04-17 21:29:16 +02:00
|
|
|
public Constraint<Double> applyExtendedBolusConstraints(@NonNull Constraint<Double> insulin) {
|
|
|
|
ArrayList<PluginBase> constraintsPlugins = MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
|
2018-09-01 22:45:15 +02:00
|
|
|
for (PluginBase p : constraintsPlugins) {
|
|
|
|
ConstraintsInterface constrain = (ConstraintsInterface) p;
|
|
|
|
if (!p.isEnabled(PluginType.CONSTRAINTS)) continue;
|
|
|
|
constrain.applyExtendedBolusConstraints(insulin);
|
|
|
|
}
|
|
|
|
return insulin;
|
2018-03-19 18:21:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-04-17 21:29:16 +02:00
|
|
|
public Constraint<Integer> applyCarbsConstraints(@NonNull Constraint<Integer> carbs) {
|
|
|
|
ArrayList<PluginBase> constraintsPlugins = MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
|
2018-03-19 18:21:02 +01:00
|
|
|
for (PluginBase p : constraintsPlugins) {
|
|
|
|
ConstraintsInterface constrain = (ConstraintsInterface) p;
|
2018-03-31 00:36:03 +02:00
|
|
|
if (!p.isEnabled(PluginType.CONSTRAINTS)) continue;
|
2018-03-22 10:31:07 +01:00
|
|
|
constrain.applyCarbsConstraints(carbs);
|
2018-03-19 18:21:02 +01:00
|
|
|
}
|
2018-03-22 10:31:07 +01:00
|
|
|
return carbs;
|
2018-03-19 18:21:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-04-17 21:29:16 +02:00
|
|
|
public Constraint<Double> applyMaxIOBConstraints(@NonNull Constraint<Double> maxIob) {
|
|
|
|
ArrayList<PluginBase> constraintsPlugins = MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
|
2018-03-19 18:21:02 +01:00
|
|
|
for (PluginBase p : constraintsPlugins) {
|
|
|
|
ConstraintsInterface constrain = (ConstraintsInterface) p;
|
2018-03-31 00:36:03 +02:00
|
|
|
if (!p.isEnabled(PluginType.CONSTRAINTS)) continue;
|
2018-03-22 21:13:26 +01:00
|
|
|
constrain.applyMaxIOBConstraints(maxIob);
|
2018-03-19 18:21:02 +01:00
|
|
|
}
|
2018-03-22 21:13:26 +01:00
|
|
|
return maxIob;
|
2018-03-19 18:21:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|