refactor a bit

This commit is contained in:
AdrianLxM 2018-03-19 18:45:23 +01:00
parent ce63655097
commit 01a9e76827
16 changed files with 37 additions and 32 deletions

View file

@ -201,7 +201,7 @@ public class MainApp extends Application {
FabricPrivacy.getInstance().logCustom(new CustomEvent("AppStart-G5Uploader"));
else if (Config.PUMPCONTROL)
FabricPrivacy.getInstance().logCustom(new CustomEvent("AppStart-PumpControl"));
else if (MainApp.getConstraintChecker().limitClosedLoop(new Constraint<>(true)).get())
else if (MainApp.getConstraintChecker().isClosedLoopAllowed().get())
FabricPrivacy.getInstance().logCustom(new CustomEvent("AppStart-ClosedLoop"));
else
FabricPrivacy.getInstance().logCustom(new CustomEvent("AppStart-OpenLoop"));

View file

@ -20,26 +20,35 @@ public class ConstraintChecker implements ConstraintsInterface {
this.mainApp = mainApp;
}
public Constraint<Boolean> isLoopInvokationAllowed() {
return isLoopInvokationAllowed(new Constraint<>(true));
}
public Constraint<Boolean> isClosedLoopAllowed() {
return isClosedLoopAllowed(new Constraint<>(true));
}
@Override
public Constraint<Boolean> limitRunningLoop(Constraint<Boolean> value) {
public Constraint<Boolean> isLoopInvokationAllowed(Constraint<Boolean> value) {
ArrayList<PluginBase> constraintsPlugins = mainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
for (PluginBase p : constraintsPlugins) {
ConstraintsInterface constraint = (ConstraintsInterface) p;
if (!p.isEnabled(PluginBase.CONSTRAINTS)) continue;
constraint.limitRunningLoop(value);
constraint.isLoopInvokationAllowed(value);
}
return value;
}
@Override
public Constraint<Boolean> limitClosedLoop(Constraint<Boolean> value) {
public Constraint<Boolean> isClosedLoopAllowed(Constraint<Boolean> value) {
ArrayList<PluginBase> constraintsPlugins = mainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
for (PluginBase p : constraintsPlugins) {
ConstraintsInterface constraint = (ConstraintsInterface) p;
if (!p.isEnabled(PluginBase.CONSTRAINTS)) continue;
constraint.limitClosedLoop(value);
constraint.isClosedLoopAllowed(value);
}
return value;
}

View file

@ -5,9 +5,9 @@ package info.nightscout.androidaps.interfaces;
*/
public interface ConstraintsInterface {
Constraint<Boolean> limitRunningLoop(Constraint<Boolean> value);
Constraint<Boolean> isLoopInvokationAllowed(Constraint<Boolean> value);
Constraint<Boolean> limitClosedLoop(Constraint<Boolean> value);
Constraint<Boolean> isClosedLoopAllowed(Constraint<Boolean> value);
boolean isAutosensModeEnabled();

View file

@ -184,7 +184,7 @@ public class ObjectivesPlugin implements PluginBase, ConstraintsInterface {
return new RequirementResult(true, "");
case 3:
Constraint<Boolean> closedLoopEnabled = new Constraint<>(true);
SafetyPlugin.getPlugin().limitClosedLoop(closedLoopEnabled);
SafetyPlugin.getPlugin().isClosedLoopAllowed(closedLoopEnabled);
return new RequirementResult(closedLoopEnabled.get(), MainApp.sResources.getString(R.string.closedmodeenabled) + ": " + yesOrNo(closedLoopEnabled.get()));
case 4:
double maxIOB = MainApp.getConstraintChecker().applyMaxIOBConstraints(1000d);
@ -295,14 +295,14 @@ public class ObjectivesPlugin implements PluginBase, ConstraintsInterface {
* Constraints interface
**/
@Override
public Constraint<Boolean> limitRunningLoop(Constraint<Boolean> value) {
public Constraint<Boolean> isLoopInvokationAllowed(Constraint<Boolean> value) {
if (objectives.get(0).started.getTime() == 0)
value.set(false, String.format(MainApp.gs(R.string.objectivenotstarted), 1));
return value;
}
@Override
public Constraint<Boolean> limitClosedLoop(Constraint<Boolean> value) {
public Constraint<Boolean> isClosedLoopAllowed(Constraint<Boolean> value) {
if (objectives.get(3).started.getTime() == 0)
value.set(false, String.format(MainApp.gs(R.string.objectivenotstarted), 4));
return value;

View file

@ -96,14 +96,14 @@ public class SafetyPlugin implements PluginBase, ConstraintsInterface {
* Constraints interface
**/
@Override
public Constraint<Boolean> limitRunningLoop(Constraint<Boolean> value) {
public Constraint<Boolean> isLoopInvokationAllowed(Constraint<Boolean> value) {
if (!ConfigBuilderPlugin.getActivePump().getPumpDescription().isTempBasalCapable)
value.set(false, MainApp.gs(R.string.pumpisnottempbasalcapable));
return value;
}
@Override
public Constraint<Boolean> limitClosedLoop(Constraint<Boolean> value) {
public Constraint<Boolean> isClosedLoopAllowed(Constraint<Boolean> value) {
if (!MainApp.isEngineeringModeOrRelease())
value.set(false, MainApp.gs(R.string.closed_loop_disabled_on_dev_branch));

View file

@ -259,8 +259,7 @@ public class LoopPlugin implements PluginBase {
try {
if (Config.logFunctionCalls)
log.debug("invoke from " + initiator);
Constraint<Boolean> loopEnabled = new Constraint<>(true);
MainApp.getConstraintChecker().limitRunningLoop(loopEnabled);
Constraint<Boolean> loopEnabled = MainApp.getConstraintChecker().isLoopInvokationAllowed();
if (!loopEnabled.get()) {
String message = MainApp.sResources.getString(R.string.loopdisabled) + "\n" + loopEnabled.getReasons();
@ -331,8 +330,7 @@ public class LoopPlugin implements PluginBase {
return;
}
Constraint<Boolean> closedLoopEnabled = new Constraint<>(true);
MainApp.getConstraintChecker().limitClosedLoop(closedLoopEnabled);
Constraint<Boolean> closedLoopEnabled = MainApp.getConstraintChecker().isClosedLoopAllowed();
if (closedLoopEnabled.get()) {
if (result.isChangeRequested()) {

View file

@ -249,7 +249,7 @@ public class OpenAPSAMAPlugin implements PluginBase, APSInterface {
if (determineBasalResultAMA.rate == 0d && determineBasalResultAMA.duration == 0 && !MainApp.getConfigBuilder().isTempBasalInProgress())
determineBasalResultAMA.tempBasalReqested = false;
// limit requests on openloop mode
if (!MainApp.getConstraintChecker().limitClosedLoop(new Constraint<>(true)).get()) {
if (!MainApp.getConstraintChecker().isClosedLoopAllowed().get()) {
long now = System.currentTimeMillis();
TemporaryBasal activeTemp = MainApp.getConfigBuilder().getTempBasalFromHistory(now);
if (activeTemp != null && determineBasalResultAMA.rate == 0 && determineBasalResultAMA.duration == 0) {

View file

@ -238,7 +238,7 @@ public class OpenAPSMAPlugin implements PluginBase, APSInterface {
if (determineBasalResultMA.rate == 0d && determineBasalResultMA.duration == 0 && !MainApp.getConfigBuilder().isTempBasalInProgress())
determineBasalResultMA.tempBasalReqested = false;
// limit requests on openloop mode
if (!MainApp.getConstraintChecker().limitClosedLoop(new Constraint<>(true)).get()) {
if (!MainApp.getConstraintChecker().isClosedLoopAllowed().get()) {
TemporaryBasal activeTemp = MainApp.getConfigBuilder().getTempBasalFromHistory(now);
if (activeTemp != null && determineBasalResultMA.rate == 0 && determineBasalResultMA.duration == 0) {
// going to cancel

View file

@ -216,8 +216,7 @@ public class DetermineBasalAdapterSMBJS {
String units = profile.getUnits();
Constraint<Boolean> closedLoopEnabled = new Constraint<>(true);
MainApp.getConstraintChecker().limitClosedLoop(closedLoopEnabled);
Constraint<Boolean> closedLoopEnabled = MainApp.getConstraintChecker().isClosedLoopAllowed();
mProfile = new JSONObject();

View file

@ -254,7 +254,7 @@ public class OpenAPSSMBPlugin implements PluginBase, APSInterface {
if (determineBasalResultSMB.rate == 0d && determineBasalResultSMB.duration == 0 && !MainApp.getConfigBuilder().isTempBasalInProgress())
determineBasalResultSMB.tempBasalReqested = false;
// limit requests on openloop mode
if (!MainApp.getConstraintChecker().limitClosedLoop(new Constraint<>(true)).get()) {
if (!MainApp.getConstraintChecker().isClosedLoopAllowed().get()) {
TemporaryBasal activeTemp = MainApp.getConfigBuilder().getTempBasalFromHistory(now);
if (activeTemp != null && determineBasalResultSMB.rate == 0 && determineBasalResultSMB.duration == 0) {
// going to cancel

View file

@ -1017,8 +1017,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
}
}
Constraint<Boolean> closedLoopEnabled = new Constraint<>(true);
MainApp.getConstraintChecker().limitClosedLoop(closedLoopEnabled);
Constraint<Boolean> closedLoopEnabled = MainApp.getConstraintChecker().isClosedLoopAllowed();
// open loop mode
final LoopPlugin.LastRun finalLastRun = LoopPlugin.lastRun;

View file

@ -1422,14 +1422,14 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
private boolean validBasalRateProfileSelectedOnPump = true;
@Override
public Constraint<Boolean> limitRunningLoop(Constraint<Boolean> value) {
public Constraint<Boolean> isLoopInvokationAllowed(Constraint<Boolean> value) {
if (!validBasalRateProfileSelectedOnPump)
value.set(false, MainApp.gs(R.string.novalidbasalrate));
return value;
}
@Override
public Constraint<Boolean> limitClosedLoop(Constraint<Boolean> value) {
public Constraint<Boolean> isClosedLoopAllowed(Constraint<Boolean> value) {
return value;
}

View file

@ -434,12 +434,12 @@ public abstract class AbstractDanaRPlugin implements PluginBase, PumpInterface,
*/
@Override
public Constraint<Boolean> limitRunningLoop(Constraint<Boolean> value) {
public Constraint<Boolean> isLoopInvokationAllowed(Constraint<Boolean> value) {
return value;
}
@Override
public Constraint<Boolean> limitClosedLoop(Constraint<Boolean> value) {
public Constraint<Boolean> isClosedLoopAllowed(Constraint<Boolean> value) {
return value;
}

View file

@ -274,12 +274,12 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
// Constraints interface
@Override
public Constraint<Boolean> limitRunningLoop(Constraint<Boolean> value) {
public Constraint<Boolean> isLoopInvokationAllowed(Constraint<Boolean> value) {
return value;
}
@Override
public Constraint<Boolean> limitClosedLoop(Constraint<Boolean> value) {
public Constraint<Boolean> isClosedLoopAllowed(Constraint<Boolean> value) {
return value;
}

View file

@ -1080,12 +1080,12 @@ public class InsightPumpPlugin implements PluginBase, PumpInterface, Constraints
// Constraints
@Override
public Constraint<Boolean> limitRunningLoop(Constraint<Boolean> value) {
public Constraint<Boolean> isLoopInvokationAllowed(Constraint<Boolean> value) {
return value;
}
@Override
public Constraint<Boolean> limitClosedLoop(Constraint<Boolean> value) {
public Constraint<Boolean> isClosedLoopAllowed(Constraint<Boolean> value) {
return value;
}

View file

@ -435,7 +435,7 @@ public class ActionStringHandler {
// decide if enabled/disabled closed/open; what Plugin as APS?
final LoopPlugin activeloop = MainApp.getConfigBuilder().getActiveLoop();
if (activeloop != null && activeloop.isEnabled(activeloop.getType())) {
if (MainApp.getConstraintChecker().limitClosedLoop(new Constraint<>(true)).get()) {
if (MainApp.getConstraintChecker().isClosedLoopAllowed().get()) {
ret += "CLOSED LOOP\n";
} else {
ret += "OPEN LOOP\n";