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

182 lines
6.9 KiB
Java
Raw Normal View History

package info.nightscout.androidaps.data;
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
private MainApp mainApp;
2018-03-22 23:20:10 +01:00
public ConstraintChecker(MainApp mainApp) {
this.mainApp = mainApp;
}
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-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<Integer> getMaxCarbsAllowed() {
return applyCarbsConstraints(new Constraint<>(Constants.REALLYHIGHCARBS));
}
public Constraint<Double> getMaxIOBAllowed() {
return applyMaxIOBConstraints(new Constraint<>(Constants.REALLYHIGHIOB));
}
@Override
2018-06-09 22:07:41 +02:00
public Constraint<Boolean> isLoopInvocationAllowed(Constraint<Boolean> value) {
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
2018-03-19 18:45:23 +01:00
public Constraint<Boolean> isClosedLoopAllowed(Constraint<Boolean> value) {
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
2018-03-19 22:36:08 +01:00
public Constraint<Boolean> isAutosensModeEnabled(Constraint<Boolean> value) {
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
2018-03-19 22:59:25 +01:00
public Constraint<Boolean> isAMAModeEnabled(Constraint<Boolean> value) {
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
2018-03-19 23:14:04 +01:00
public Constraint<Boolean> isSMBModeEnabled(Constraint<Boolean> value) {
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
2018-03-20 22:09:22 +01:00
public Constraint<Double> applyBasalConstraints(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
public Constraint<Integer> applyBasalPercentConstraints(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
2018-03-21 23:01:30 +01:00
public Constraint<Double> applyBolusConstraints(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
2018-03-22 10:31:07 +01:00
public Constraint<Integer> applyCarbsConstraints(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
public Constraint<Double> applyMaxIOBConstraints(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;
}
}