2018-03-19 18:21:02 +01:00
|
|
|
package info.nightscout.androidaps.data;
|
|
|
|
|
|
|
|
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:21:02 +01:00
|
|
|
private MainApp mainApp;
|
2018-03-22 23:20:10 +01:00
|
|
|
|
2018-03-19 18:21:02 +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-06-29 22:43:54 +02:00
|
|
|
public Constraint<Boolean> isAdvancedFilteringEnabled() {
|
|
|
|
return isAdvancedFilteringEnabled(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));
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2018-06-09 22:07:41 +02:00
|
|
|
public Constraint<Boolean> isLoopInvocationAllowed(Constraint<Boolean> value) {
|
2018-03-19 18:21:02 +01:00
|
|
|
|
2018-06-29 22:43:54 +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
|
2018-03-19 18:45:23 +01:00
|
|
|
public Constraint<Boolean> isClosedLoopAllowed(Constraint<Boolean> value) {
|
2018-03-19 18:21:02 +01:00
|
|
|
|
2018-06-29 22:43:54 +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
|
2018-03-19 22:36:08 +01:00
|
|
|
public Constraint<Boolean> isAutosensModeEnabled(Constraint<Boolean> value) {
|
2018-03-19 18:21:02 +01: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 18:21:02 +01:00
|
|
|
}
|
2018-03-19 22:36:08 +01:00
|
|
|
return value;
|
2018-03-19 18:21:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-03-19 22:59:25 +01:00
|
|
|
public Constraint<Boolean> isAMAModeEnabled(Constraint<Boolean> value) {
|
2018-03-19 18:21:02 +01: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 18:21:02 +01:00
|
|
|
}
|
2018-03-19 22:59:25 +01:00
|
|
|
return value;
|
2018-03-19 18:21:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-03-19 23:14:04 +01:00
|
|
|
public Constraint<Boolean> isSMBModeEnabled(Constraint<Boolean> value) {
|
2018-03-19 18:21:02 +01: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 18:21:02 +01:00
|
|
|
}
|
2018-03-19 23:14:04 +01:00
|
|
|
return value;
|
2018-03-19 18:21:02 +01:00
|
|
|
}
|
|
|
|
|
2018-06-29 22:43:54 +02:00
|
|
|
@Override
|
|
|
|
public Constraint<Boolean> isAdvancedFilteringEnabled(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;
|
|
|
|
}
|
|
|
|
|
2018-03-19 18:21:02 +01:00
|
|
|
@Override
|
2018-03-20 22:09:22 +01:00
|
|
|
public Constraint<Double> applyBasalConstraints(Constraint<Double> absoluteRate, Profile profile) {
|
2018-03-19 18:21:02 +01:00
|
|
|
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-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
|
2018-03-21 20:24:02 +01:00
|
|
|
public Constraint<Integer> applyBasalPercentConstraints(Constraint<Integer> percentRate, Profile profile) {
|
2018-03-19 18:21:02 +01: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-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
|
2018-03-21 23:01:30 +01:00
|
|
|
public Constraint<Double> applyBolusConstraints(Constraint<Double> insulin) {
|
2018-03-19 18:21:02 +01: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-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-03-19 18:21:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-03-22 10:31:07 +01:00
|
|
|
public Constraint<Integer> applyCarbsConstraints(Constraint<Integer> carbs) {
|
2018-03-19 18:21:02 +01: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-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
|
2018-03-22 21:13:26 +01:00
|
|
|
public Constraint<Double> applyMaxIOBConstraints(Constraint<Double> maxIob) {
|
2018-03-19 18:21:02 +01: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-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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|