AndroidAPS/app/src/main/java/info/nightscout/androidaps/data/ConstraintChecker.java

238 lines
9.4 KiB
Java
Raw Normal View History

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
import java.util.ArrayList;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.interfaces.Constraint;
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;
/**
* 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));
}
public Constraint<Boolean> isUAMEnabled() {
return isUAMEnabled(new Constraint<>(true));
}
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) {
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));
}
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));
}
@Override
2019-04-17 21:29:16 +02:00
public Constraint<Boolean> isLoopInvocationAllowed(@NonNull Constraint<Boolean> value) {
2019-04-17 21:29:16 +02:00
ArrayList<PluginBase> constraintsPlugins = MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
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);
}
return value;
}
@Override
2019-04-17 21:29:16 +02:00
public Constraint<Boolean> isClosedLoopAllowed(@NonNull Constraint<Boolean> value) {
2019-04-17 21:29:16 +02:00
ArrayList<PluginBase> constraintsPlugins = MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
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);
}
return value;
}
@Override
2019-04-17 21:29:16 +02:00
public Constraint<Boolean> isAutosensModeEnabled(@NonNull Constraint<Boolean> value) {
2019-04-17 21:29:16 +02:00
ArrayList<PluginBase> constraintsPlugins = MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
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 22:36:08 +01:00
return value;
}
@Override
2019-04-17 21:29:16 +02:00
public Constraint<Boolean> isAMAModeEnabled(@NonNull Constraint<Boolean> value) {
2019-04-17 21:29:16 +02:00
ArrayList<PluginBase> constraintsPlugins = MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
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 22:59:25 +01:00
return value;
}
@Override
2019-04-17 21:29:16 +02:00
public Constraint<Boolean> isSMBModeEnabled(@NonNull Constraint<Boolean> value) {
2019-04-17 21:29:16 +02:00
ArrayList<PluginBase> constraintsPlugins = MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
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 23:14:04 +01:00
return value;
}
@Override
2019-04-17 21:29:16 +02:00
public Constraint<Boolean> isUAMEnabled(@NonNull Constraint<Boolean> value) {
2019-04-17 21:29:16 +02:00
ArrayList<PluginBase> constraintsPlugins = MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
for (PluginBase p : constraintsPlugins) {
ConstraintsInterface constraint = (ConstraintsInterface) p;
if (!p.isEnabled(PluginType.CONSTRAINTS)) continue;
constraint.isUAMEnabled(value);
}
return value;
}
@Override
2019-04-17 21:29:16 +02:00
public Constraint<Boolean> isAdvancedFilteringEnabled(@NonNull Constraint<Boolean> value) {
ArrayList<PluginBase> constraintsPlugins = MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
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;
}
@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);
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-20 22:09:22 +01:00
return absoluteRate;
}
@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);
for (PluginBase p : constraintsPlugins) {
ConstraintsInterface constrain = (ConstraintsInterface) p;
2018-03-31 00:36:03 +02:00
if (!p.isEnabled(PluginType.CONSTRAINTS)) continue;
constrain.applyBasalPercentConstraints(percentRate, profile);
}
return percentRate;
}
@Override
2019-04-17 21:29:16 +02:00
public Constraint<Double> applyBolusConstraints(@NonNull Constraint<Double> insulin) {
ArrayList<PluginBase> constraintsPlugins = MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
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-21 23:01:30 +01:00
return insulin;
}
@Override
2019-04-17 21:29:16 +02:00
public Constraint<Double> applyExtendedBolusConstraints(@NonNull Constraint<Double> insulin) {
ArrayList<PluginBase> constraintsPlugins = MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
for (PluginBase p : constraintsPlugins) {
ConstraintsInterface constrain = (ConstraintsInterface) p;
if (!p.isEnabled(PluginType.CONSTRAINTS)) continue;
constrain.applyExtendedBolusConstraints(insulin);
}
return insulin;
}
@Override
2019-04-17 21:29:16 +02:00
public Constraint<Integer> applyCarbsConstraints(@NonNull Constraint<Integer> carbs) {
ArrayList<PluginBase> constraintsPlugins = MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
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-22 10:31:07 +01:00
return carbs;
}
@Override
2019-04-17 21:29:16 +02:00
public Constraint<Double> applyMaxIOBConstraints(@NonNull Constraint<Double> maxIob) {
ArrayList<PluginBase> constraintsPlugins = MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
for (PluginBase p : constraintsPlugins) {
ConstraintsInterface constrain = (ConstraintsInterface) p;
2018-03-31 00:36:03 +02:00
if (!p.isEnabled(PluginType.CONSTRAINTS)) continue;
constrain.applyMaxIOBConstraints(maxIob);
}
return maxIob;
}
}