use constants in objectives
This commit is contained in:
parent
764e4cfb7c
commit
0de7413427
|
@ -42,6 +42,13 @@ public class ObjectivesPlugin extends PluginBase implements ConstraintsInterface
|
||||||
public boolean pumpStatusIsAvailableInNS = false;
|
public boolean pumpStatusIsAvailableInNS = false;
|
||||||
public Integer manualEnacts = 0;
|
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() {
|
public static ObjectivesPlugin getPlugin() {
|
||||||
if (objectivesPlugin == null) {
|
if (objectivesPlugin == null) {
|
||||||
objectivesPlugin = new ObjectivesPlugin();
|
objectivesPlugin = new ObjectivesPlugin();
|
||||||
|
@ -121,43 +128,43 @@ public class ObjectivesPlugin extends PluginBase implements ConstraintsInterface
|
||||||
**/
|
**/
|
||||||
@Override
|
@Override
|
||||||
public Constraint<Boolean> isLoopInvocationAllowed(Constraint<Boolean> value) {
|
public Constraint<Boolean> isLoopInvocationAllowed(Constraint<Boolean> value) {
|
||||||
if (!objectives.get(0).isStarted())
|
if (!objectives.get(FIRST_OBJECTIVE).isStarted())
|
||||||
value.set(false, String.format(MainApp.gs(R.string.objectivenotstarted), 1), this);
|
value.set(false, String.format(MainApp.gs(R.string.objectivenotstarted), FIRST_OBJECTIVE + 1), this);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Constraint<Boolean> isClosedLoopAllowed(Constraint<Boolean> value) {
|
public Constraint<Boolean> isClosedLoopAllowed(Constraint<Boolean> value) {
|
||||||
if (!objectives.get(3).isStarted())
|
if (!objectives.get(CLOSED_LOOP_OBJECTIVE).isStarted())
|
||||||
value.set(false, String.format(MainApp.gs(R.string.objectivenotstarted), 4), this);
|
value.set(false, String.format(MainApp.gs(R.string.objectivenotstarted), CLOSED_LOOP_OBJECTIVE + 1), this);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Constraint<Boolean> isAutosensModeEnabled(Constraint<Boolean> value) {
|
public Constraint<Boolean> isAutosensModeEnabled(Constraint<Boolean> value) {
|
||||||
if (!objectives.get(5).isStarted())
|
if (!objectives.get(AUTOSENS_OBJECTIVE).isStarted())
|
||||||
value.set(false, String.format(MainApp.gs(R.string.objectivenotstarted), 6), this);
|
value.set(false, String.format(MainApp.gs(R.string.objectivenotstarted), AUTOSENS_OBJECTIVE + 1), this);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Constraint<Boolean> isAMAModeEnabled(Constraint<Boolean> value) {
|
public Constraint<Boolean> isAMAModeEnabled(Constraint<Boolean> value) {
|
||||||
if (!objectives.get(6).isStarted())
|
if (!objectives.get(AMA_OBJECTIVE).isStarted())
|
||||||
value.set(false, String.format(MainApp.gs(R.string.objectivenotstarted), 7), this);
|
value.set(false, String.format(MainApp.gs(R.string.objectivenotstarted), AMA_OBJECTIVE + 1), this);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Constraint<Boolean> isSMBModeEnabled(Constraint<Boolean> value) {
|
public Constraint<Boolean> isSMBModeEnabled(Constraint<Boolean> value) {
|
||||||
if (!objectives.get(7).isStarted())
|
if (!objectives.get(SMB_OBJECTIVE).isStarted())
|
||||||
value.set(false, String.format(MainApp.gs(R.string.objectivenotstarted), 8), this);
|
value.set(false, String.format(MainApp.gs(R.string.objectivenotstarted), SMB_OBJECTIVE + 1), this);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Constraint<Double> applyMaxIOBConstraints(Constraint<Double> maxIob) {
|
public Constraint<Double> applyMaxIOBConstraints(Constraint<Double> maxIob) {
|
||||||
if (objectives.get(3).isStarted() && !objectives.get(3).isAccomplished())
|
if (objectives.get(MAXIOB_ZERO_OBJECTIVE).isStarted() && !objectives.get(MAXIOB_ZERO_OBJECTIVE).isAccomplished())
|
||||||
maxIob.set(0d, String.format(MainApp.gs(R.string.objectivenotfinished), 4), this);
|
maxIob.set(0d, String.format(MainApp.gs(R.string.objectivenotfinished), MAXIOB_ZERO_OBJECTIVE + 1), this);
|
||||||
return maxIob;
|
return maxIob;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -425,8 +425,8 @@ public class SWDefinition {
|
||||||
.add(new SWBreak())
|
.add(new SWBreak())
|
||||||
.add(new SWFragment(this)
|
.add(new SWFragment(this)
|
||||||
.add(new ObjectivesFragment()))
|
.add(new ObjectivesFragment()))
|
||||||
.validator(() -> ObjectivesPlugin.getPlugin().objectives.get(0).isStarted())
|
.validator(() -> ObjectivesPlugin.getPlugin().objectives.get(ObjectivesPlugin.FIRST_OBJECTIVE).isStarted())
|
||||||
.visibility(() -> !ObjectivesPlugin.getPlugin().objectives.get(0).isStarted() && Config.APS);
|
.visibility(() -> !ObjectivesPlugin.getPlugin().objectives.get(ObjectivesPlugin.FIRST_OBJECTIVE).isStarted() && Config.APS);
|
||||||
|
|
||||||
private void SWDefinitionFull() {
|
private void SWDefinitionFull() {
|
||||||
// List all the screens here
|
// List all the screens here
|
||||||
|
|
|
@ -75,7 +75,7 @@ public class ConstraintsCheckerTest {
|
||||||
@Test
|
@Test
|
||||||
public void isClosedLoopAllowedTest() throws Exception {
|
public void isClosedLoopAllowedTest() throws Exception {
|
||||||
when(SP.getString(R.string.key_aps_mode, "open")).thenReturn("closed");
|
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();
|
Constraint<Boolean> c = constraintChecker.isClosedLoopAllowed();
|
||||||
Assert.assertEquals(true, c.getReasonList().size() == 2); // Safety & Objectives
|
Assert.assertEquals(true, c.getReasonList().size() == 2); // Safety & Objectives
|
||||||
|
@ -91,7 +91,7 @@ public class ConstraintsCheckerTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAutosensModeEnabledTest() throws Exception {
|
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);
|
when(SP.getBoolean(R.string.key_openapsama_useautosens, false)).thenReturn(false);
|
||||||
|
|
||||||
Constraint<Boolean> c = constraintChecker.isAutosensModeEnabled();
|
Constraint<Boolean> c = constraintChecker.isAutosensModeEnabled();
|
||||||
|
@ -102,7 +102,7 @@ public class ConstraintsCheckerTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAMAModeEnabledTest() throws Exception {
|
public void isAMAModeEnabledTest() throws Exception {
|
||||||
objectivesPlugin.objectives.get(6).setStartedOn(null);
|
objectivesPlugin.objectives.get(ObjectivesPlugin.AMA_OBJECTIVE).setStartedOn(null);
|
||||||
|
|
||||||
Constraint<Boolean> c = constraintChecker.isAMAModeEnabled();
|
Constraint<Boolean> c = constraintChecker.isAMAModeEnabled();
|
||||||
Assert.assertEquals(true, c.getReasonList().size() == 1); // Objectives
|
Assert.assertEquals(true, c.getReasonList().size() == 1); // Objectives
|
||||||
|
@ -130,7 +130,7 @@ public class ConstraintsCheckerTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isSMBModeEnabledTest() throws Exception {
|
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(SP.getBoolean(R.string.key_use_smb, false)).thenReturn(false);
|
||||||
when(MainApp.getConstraintChecker().isClosedLoopAllowed()).thenReturn(new Constraint<>(true));
|
when(MainApp.getConstraintChecker().isClosedLoopAllowed()).thenReturn(new Constraint<>(true));
|
||||||
|
|
||||||
|
|
|
@ -28,18 +28,18 @@ public class ObjectivesPluginTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void notStartedObjectivesShouldLimitLoopInvocation() throws Exception {
|
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);
|
Constraint<Boolean> c = new Constraint<>(true);
|
||||||
c = objectivesPlugin.isLoopInvocationAllowed(c);
|
c = objectivesPlugin.isLoopInvocationAllowed(c);
|
||||||
Assert.assertEquals("Objectives: Objective 1 not started", c.getReasons());
|
Assert.assertEquals("Objectives: Objective 1 not started", c.getReasons());
|
||||||
Assert.assertEquals(Boolean.FALSE, c.value());
|
Assert.assertEquals(Boolean.FALSE, c.value());
|
||||||
objectivesPlugin.objectives.get(0).setStartedOn(new Date());
|
objectivesPlugin.objectives.get(ObjectivesPlugin.FIRST_OBJECTIVE).setStartedOn(new Date());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void notStartedObjective4ShouldLimitClosedLoop() throws Exception {
|
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);
|
Constraint<Boolean> c = new Constraint<>(true);
|
||||||
c = objectivesPlugin.isClosedLoopAllowed(c);
|
c = objectivesPlugin.isClosedLoopAllowed(c);
|
||||||
|
@ -49,7 +49,7 @@ public class ObjectivesPluginTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void notStartedObjective6ShouldLimitAutosensMode() throws Exception {
|
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);
|
Constraint<Boolean> c = new Constraint<>(true);
|
||||||
c = objectivesPlugin.isAutosensModeEnabled(c);
|
c = objectivesPlugin.isAutosensModeEnabled(c);
|
||||||
|
@ -59,7 +59,7 @@ public class ObjectivesPluginTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void notStartedObjective7ShouldLimitAMAMode() throws Exception {
|
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);
|
Constraint<Boolean> c = new Constraint<>(true);
|
||||||
c = objectivesPlugin.isAMAModeEnabled(c);
|
c = objectivesPlugin.isAMAModeEnabled(c);
|
||||||
|
@ -69,7 +69,7 @@ public class ObjectivesPluginTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void notStartedObjective8ShouldLimitSMBMode() throws Exception {
|
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);
|
Constraint<Boolean> c = new Constraint<>(true);
|
||||||
c = objectivesPlugin.isSMBModeEnabled(c);
|
c = objectivesPlugin.isSMBModeEnabled(c);
|
||||||
|
|
Loading…
Reference in a new issue