use constants in objectives

This commit is contained in:
Milos Kozak 2019-09-01 09:59:34 +02:00
parent 764e4cfb7c
commit 0de7413427
4 changed files with 31 additions and 24 deletions

View file

@ -42,6 +42,13 @@ public class ObjectivesPlugin extends PluginBase implements ConstraintsInterface
public boolean pumpStatusIsAvailableInNS = false;
public Integer manualEnacts = 0;
public static final int FIRST_OBJECTIVE = 0;
public static final int CLOSED_LOOP_OBJECTIVE = 3;
public static final int MAXIOB_ZERO_OBJECTIVE = 3;
public static final int AUTOSENS_OBJECTIVE = 5;
public static final int AMA_OBJECTIVE = 6;
public static final int SMB_OBJECTIVE = 7;
public static ObjectivesPlugin getPlugin() {
if (objectivesPlugin == null) {
objectivesPlugin = new ObjectivesPlugin();
@ -121,43 +128,43 @@ public class ObjectivesPlugin extends PluginBase implements ConstraintsInterface
**/
@Override
public Constraint<Boolean> isLoopInvocationAllowed(Constraint<Boolean> value) {
if (!objectives.get(0).isStarted())
value.set(false, String.format(MainApp.gs(R.string.objectivenotstarted), 1), this);
if (!objectives.get(FIRST_OBJECTIVE).isStarted())
value.set(false, String.format(MainApp.gs(R.string.objectivenotstarted), FIRST_OBJECTIVE + 1), this);
return value;
}
@Override
public Constraint<Boolean> isClosedLoopAllowed(Constraint<Boolean> value) {
if (!objectives.get(3).isStarted())
value.set(false, String.format(MainApp.gs(R.string.objectivenotstarted), 4), this);
if (!objectives.get(CLOSED_LOOP_OBJECTIVE).isStarted())
value.set(false, String.format(MainApp.gs(R.string.objectivenotstarted), CLOSED_LOOP_OBJECTIVE + 1), this);
return value;
}
@Override
public Constraint<Boolean> isAutosensModeEnabled(Constraint<Boolean> value) {
if (!objectives.get(5).isStarted())
value.set(false, String.format(MainApp.gs(R.string.objectivenotstarted), 6), this);
if (!objectives.get(AUTOSENS_OBJECTIVE).isStarted())
value.set(false, String.format(MainApp.gs(R.string.objectivenotstarted), AUTOSENS_OBJECTIVE + 1), this);
return value;
}
@Override
public Constraint<Boolean> isAMAModeEnabled(Constraint<Boolean> value) {
if (!objectives.get(6).isStarted())
value.set(false, String.format(MainApp.gs(R.string.objectivenotstarted), 7), this);
if (!objectives.get(AMA_OBJECTIVE).isStarted())
value.set(false, String.format(MainApp.gs(R.string.objectivenotstarted), AMA_OBJECTIVE + 1), this);
return value;
}
@Override
public Constraint<Boolean> isSMBModeEnabled(Constraint<Boolean> value) {
if (!objectives.get(7).isStarted())
value.set(false, String.format(MainApp.gs(R.string.objectivenotstarted), 8), this);
if (!objectives.get(SMB_OBJECTIVE).isStarted())
value.set(false, String.format(MainApp.gs(R.string.objectivenotstarted), SMB_OBJECTIVE + 1), this);
return value;
}
@Override
public Constraint<Double> applyMaxIOBConstraints(Constraint<Double> maxIob) {
if (objectives.get(3).isStarted() && !objectives.get(3).isAccomplished())
maxIob.set(0d, String.format(MainApp.gs(R.string.objectivenotfinished), 4), this);
if (objectives.get(MAXIOB_ZERO_OBJECTIVE).isStarted() && !objectives.get(MAXIOB_ZERO_OBJECTIVE).isAccomplished())
maxIob.set(0d, String.format(MainApp.gs(R.string.objectivenotfinished), MAXIOB_ZERO_OBJECTIVE + 1), this);
return maxIob;
}

View file

@ -425,8 +425,8 @@ public class SWDefinition {
.add(new SWBreak())
.add(new SWFragment(this)
.add(new ObjectivesFragment()))
.validator(() -> ObjectivesPlugin.getPlugin().objectives.get(0).isStarted())
.visibility(() -> !ObjectivesPlugin.getPlugin().objectives.get(0).isStarted() && Config.APS);
.validator(() -> ObjectivesPlugin.getPlugin().objectives.get(ObjectivesPlugin.FIRST_OBJECTIVE).isStarted())
.visibility(() -> !ObjectivesPlugin.getPlugin().objectives.get(ObjectivesPlugin.FIRST_OBJECTIVE).isStarted() && Config.APS);
private void SWDefinitionFull() {
// List all the screens here

View file

@ -75,7 +75,7 @@ public class ConstraintsCheckerTest {
@Test
public void isClosedLoopAllowedTest() throws Exception {
when(SP.getString(R.string.key_aps_mode, "open")).thenReturn("closed");
objectivesPlugin.objectives.get(3).setStartedOn(null);
objectivesPlugin.objectives.get(ObjectivesPlugin.CLOSED_LOOP_OBJECTIVE).setStartedOn(null);
Constraint<Boolean> c = constraintChecker.isClosedLoopAllowed();
Assert.assertEquals(true, c.getReasonList().size() == 2); // Safety & Objectives
@ -91,7 +91,7 @@ public class ConstraintsCheckerTest {
@Test
public void isAutosensModeEnabledTest() throws Exception {
objectivesPlugin.objectives.get(5).setStartedOn(null);
objectivesPlugin.objectives.get(ObjectivesPlugin.AUTOSENS_OBJECTIVE).setStartedOn(null);
when(SP.getBoolean(R.string.key_openapsama_useautosens, false)).thenReturn(false);
Constraint<Boolean> c = constraintChecker.isAutosensModeEnabled();
@ -102,7 +102,7 @@ public class ConstraintsCheckerTest {
@Test
public void isAMAModeEnabledTest() throws Exception {
objectivesPlugin.objectives.get(6).setStartedOn(null);
objectivesPlugin.objectives.get(ObjectivesPlugin.AMA_OBJECTIVE).setStartedOn(null);
Constraint<Boolean> c = constraintChecker.isAMAModeEnabled();
Assert.assertEquals(true, c.getReasonList().size() == 1); // Objectives
@ -130,7 +130,7 @@ public class ConstraintsCheckerTest {
@Test
public void isSMBModeEnabledTest() throws Exception {
objectivesPlugin.objectives.get(7).setStartedOn(null);
objectivesPlugin.objectives.get(ObjectivesPlugin.SMB_OBJECTIVE).setStartedOn(null);
when(SP.getBoolean(R.string.key_use_smb, false)).thenReturn(false);
when(MainApp.getConstraintChecker().isClosedLoopAllowed()).thenReturn(new Constraint<>(true));

View file

@ -28,18 +28,18 @@ public class ObjectivesPluginTest {
@Test
public void notStartedObjectivesShouldLimitLoopInvocation() throws Exception {
objectivesPlugin.objectives.get(0).setStartedOn(null);
objectivesPlugin.objectives.get(ObjectivesPlugin.FIRST_OBJECTIVE).setStartedOn(null);
Constraint<Boolean> c = new Constraint<>(true);
c = objectivesPlugin.isLoopInvocationAllowed(c);
Assert.assertEquals("Objectives: Objective 1 not started", c.getReasons());
Assert.assertEquals(Boolean.FALSE, c.value());
objectivesPlugin.objectives.get(0).setStartedOn(new Date());
objectivesPlugin.objectives.get(ObjectivesPlugin.FIRST_OBJECTIVE).setStartedOn(new Date());
}
@Test
public void notStartedObjective4ShouldLimitClosedLoop() throws Exception {
objectivesPlugin.objectives.get(3).setStartedOn(null);
objectivesPlugin.objectives.get(ObjectivesPlugin.CLOSED_LOOP_OBJECTIVE).setStartedOn(null);
Constraint<Boolean> c = new Constraint<>(true);
c = objectivesPlugin.isClosedLoopAllowed(c);
@ -49,7 +49,7 @@ public class ObjectivesPluginTest {
@Test
public void notStartedObjective6ShouldLimitAutosensMode() throws Exception {
objectivesPlugin.objectives.get(5).setStartedOn(null);
objectivesPlugin.objectives.get(ObjectivesPlugin.AUTOSENS_OBJECTIVE).setStartedOn(null);
Constraint<Boolean> c = new Constraint<>(true);
c = objectivesPlugin.isAutosensModeEnabled(c);
@ -59,7 +59,7 @@ public class ObjectivesPluginTest {
@Test
public void notStartedObjective7ShouldLimitAMAMode() throws Exception {
objectivesPlugin.objectives.get(6).setStartedOn(null);
objectivesPlugin.objectives.get(ObjectivesPlugin.AMA_OBJECTIVE).setStartedOn(null);
Constraint<Boolean> c = new Constraint<>(true);
c = objectivesPlugin.isAMAModeEnabled(c);
@ -69,7 +69,7 @@ public class ObjectivesPluginTest {
@Test
public void notStartedObjective8ShouldLimitSMBMode() throws Exception {
objectivesPlugin.objectives.get(7).setStartedOn(null);
objectivesPlugin.objectives.get(ObjectivesPlugin.SMB_OBJECTIVE).setStartedOn(null);
Constraint<Boolean> c = new Constraint<>(true);
c = objectivesPlugin.isSMBModeEnabled(c);