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-25 23:56:52 +02:00
|
|
|
import info.nightscout.androidaps.interfaces.BgSourceInterface;
|
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-25 23:56:52 +02:00
|
|
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
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() {
|
|
|
|
return isLoopInvokationAllowed(new Constraint<>(true));
|
|
|
|
}
|
|
|
|
|
|
|
|
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-25 23:56:52 +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-03-19 18:45:23 +01:00
|
|
|
public Constraint<Boolean> isLoopInvokationAllowed(Constraint<Boolean> value) {
|
2018-03-19 18:21:02 +01: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.isLoopInvokationAllowed(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
|
|
|
|
|
|
|
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);
|
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-03-25 23:56:52 +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;
|
2018-03-31 00:36:03 +02:00
|
|
|
if (!p.isEnabled(PluginType.CONSTRAINTS)) continue;
|
2018-03-25 23:56:52 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|