isAMAModeEnabled reactor & tests
This commit is contained in:
parent
f8a3b7aee7
commit
26ecc3dd60
14 changed files with 50 additions and 21 deletions
|
@ -33,6 +33,10 @@ public class ConstraintChecker implements ConstraintsInterface {
|
||||||
return isAutosensModeEnabled(new Constraint<>(true));
|
return isAutosensModeEnabled(new Constraint<>(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Constraint<Boolean> isAMAModeEnabled() {
|
||||||
|
return isAMAModeEnabled(new Constraint<>(true));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Constraint<Boolean> isLoopInvokationAllowed(Constraint<Boolean> value) {
|
public Constraint<Boolean> isLoopInvokationAllowed(Constraint<Boolean> value) {
|
||||||
|
|
||||||
|
@ -70,16 +74,15 @@ public class ConstraintChecker implements ConstraintsInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAMAModeEnabled() {
|
public Constraint<Boolean> isAMAModeEnabled(Constraint<Boolean> value) {
|
||||||
boolean result = SP.getBoolean("openapsama_useautosens", false);
|
|
||||||
|
|
||||||
ArrayList<PluginBase> constraintsPlugins = mainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
|
ArrayList<PluginBase> constraintsPlugins = mainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
|
||||||
for (PluginBase p : constraintsPlugins) {
|
for (PluginBase p : constraintsPlugins) {
|
||||||
ConstraintsInterface constrain = (ConstraintsInterface) p;
|
ConstraintsInterface constrain = (ConstraintsInterface) p;
|
||||||
if (!p.isEnabled(PluginBase.CONSTRAINTS)) continue;
|
if (!p.isEnabled(PluginBase.CONSTRAINTS)) continue;
|
||||||
result = result && constrain.isAMAModeEnabled();
|
constrain.isAMAModeEnabled(value);
|
||||||
}
|
}
|
||||||
return result;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -11,7 +11,7 @@ public interface ConstraintsInterface {
|
||||||
|
|
||||||
Constraint<Boolean> isAutosensModeEnabled(Constraint<Boolean> value);
|
Constraint<Boolean> isAutosensModeEnabled(Constraint<Boolean> value);
|
||||||
|
|
||||||
boolean isAMAModeEnabled();
|
Constraint<Boolean> isAMAModeEnabled(Constraint<Boolean> value);
|
||||||
|
|
||||||
boolean isSMBModeEnabled();
|
boolean isSMBModeEnabled();
|
||||||
|
|
||||||
|
|
|
@ -320,8 +320,10 @@ public class ObjectivesPlugin implements PluginBase, ConstraintsInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAMAModeEnabled() {
|
public Constraint<Boolean> isAMAModeEnabled(Constraint<Boolean> value) {
|
||||||
return objectives.get(6).started.getTime() > 0;
|
if (objectives.get(6).started.getTime() == 0)
|
||||||
|
value.set(false, String.format(MainApp.gs(R.string.objectivenotstarted), 7));
|
||||||
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -119,8 +119,11 @@ public class SafetyPlugin implements PluginBase, ConstraintsInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAMAModeEnabled() {
|
public Constraint<Boolean> isAMAModeEnabled(Constraint<Boolean> value) {
|
||||||
return true;
|
boolean enabled = SP.getBoolean("openapsama_useautosens", false);
|
||||||
|
if (!enabled)
|
||||||
|
value.set(false, MainApp.gs(R.string.amadisabledinpreferences));
|
||||||
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -250,7 +250,7 @@ public class DetermineBasalAdapterAMAJS {
|
||||||
mMealData.put("boluses", mealData.boluses);
|
mMealData.put("boluses", mealData.boluses);
|
||||||
mMealData.put("mealCOB", mealData.mealCOB);
|
mMealData.put("mealCOB", mealData.mealCOB);
|
||||||
|
|
||||||
if (MainApp.getConstraintChecker().isAMAModeEnabled()) {
|
if (MainApp.getConstraintChecker().isAMAModeEnabled().get()) {
|
||||||
mAutosensData = new JSONObject();
|
mAutosensData = new JSONObject();
|
||||||
mAutosensData.put("ratio", autosensDataRatio);
|
mAutosensData.put("ratio", autosensDataRatio);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -223,7 +223,7 @@ public class OpenAPSAMAPlugin implements PluginBase, APSInterface {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
startPart = new Date();
|
startPart = new Date();
|
||||||
if (MainApp.getConstraintChecker().isAMAModeEnabled()) {
|
if (MainApp.getConstraintChecker().isAMAModeEnabled().get()) {
|
||||||
lastAutosensResult = IobCobCalculatorPlugin.getPlugin().detectSensitivityWithLock(IobCobCalculatorPlugin.oldestDataAvailable(), System.currentTimeMillis());
|
lastAutosensResult = IobCobCalculatorPlugin.getPlugin().detectSensitivityWithLock(IobCobCalculatorPlugin.oldestDataAvailable(), System.currentTimeMillis());
|
||||||
} else {
|
} else {
|
||||||
lastAutosensResult = new AutosensResult();
|
lastAutosensResult = new AutosensResult();
|
||||||
|
|
|
@ -303,7 +303,7 @@ public class DetermineBasalAdapterSMBJS {
|
||||||
mMealData.put("lastCarbTime", mealData.lastCarbTime);
|
mMealData.put("lastCarbTime", mealData.lastCarbTime);
|
||||||
|
|
||||||
|
|
||||||
if (MainApp.getConstraintChecker().isAMAModeEnabled()) {
|
if (MainApp.getConstraintChecker().isAMAModeEnabled().get()) {
|
||||||
mAutosensData = new JSONObject();
|
mAutosensData = new JSONObject();
|
||||||
mAutosensData.put("ratio", autosensDataRatio);
|
mAutosensData.put("ratio", autosensDataRatio);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -225,7 +225,7 @@ public class OpenAPSSMBPlugin implements PluginBase, APSInterface {
|
||||||
if (!checkOnlyHardLimits(pump.getBaseBasalRate(), "current_basal", 0.01, HardLimits.maxBasal())) return;
|
if (!checkOnlyHardLimits(pump.getBaseBasalRate(), "current_basal", 0.01, HardLimits.maxBasal())) return;
|
||||||
|
|
||||||
startPart = new Date();
|
startPart = new Date();
|
||||||
if (MainApp.getConstraintChecker().isAMAModeEnabled()) {
|
if (MainApp.getConstraintChecker().isAMAModeEnabled().get()) {
|
||||||
lastAutosensResult = IobCobCalculatorPlugin.getPlugin().detectSensitivityWithLock(IobCobCalculatorPlugin.oldestDataAvailable(), System.currentTimeMillis());
|
lastAutosensResult = IobCobCalculatorPlugin.getPlugin().detectSensitivityWithLock(IobCobCalculatorPlugin.oldestDataAvailable(), System.currentTimeMillis());
|
||||||
} else {
|
} else {
|
||||||
lastAutosensResult = new AutosensResult();
|
lastAutosensResult = new AutosensResult();
|
||||||
|
|
|
@ -1443,8 +1443,8 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAMAModeEnabled() {
|
public Constraint<Boolean> isAMAModeEnabled(Constraint<Boolean> value) {
|
||||||
return true;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -449,8 +449,8 @@ public abstract class AbstractDanaRPlugin implements PluginBase, PumpInterface,
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAMAModeEnabled() {
|
public Constraint<Boolean> isAMAModeEnabled(Constraint<Boolean> value) {
|
||||||
return true;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -289,8 +289,8 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAMAModeEnabled() {
|
public Constraint<Boolean> isAMAModeEnabled(Constraint<Boolean> value) {
|
||||||
return true;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1095,8 +1095,8 @@ public class InsightPumpPlugin implements PluginBase, PumpInterface, Constraints
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAMAModeEnabled() {
|
public Constraint<Boolean> isAMAModeEnabled(Constraint<Boolean> value) {
|
||||||
return true;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -966,5 +966,6 @@
|
||||||
<string name="pumpisnottempbasalcapable">Pump is not temp basal capable</string>
|
<string name="pumpisnottempbasalcapable">Pump is not temp basal capable</string>
|
||||||
<string name="novalidbasalrate">No valid basal rate read from pump</string>
|
<string name="novalidbasalrate">No valid basal rate read from pump</string>
|
||||||
<string name="closedmodedisabledinpreferences">Closed loop mode disabled in preferences</string>
|
<string name="closedmodedisabledinpreferences">Closed loop mode disabled in preferences</string>
|
||||||
|
<string name="amadisabledinpreferences">AMA disabled in preferences</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
||||||
|
|
|
@ -117,6 +117,25 @@ public class ConstraintsCheckerTest {
|
||||||
Assert.assertEquals(Boolean.FALSE, c.get());
|
Assert.assertEquals(Boolean.FALSE, c.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// isAMAModeEnabled tests
|
||||||
|
@Test
|
||||||
|
public void notEnabledAMAInPreferencesDisablesAMA() throws Exception {
|
||||||
|
when(SP.getBoolean("openapsama_useautosens", false)).thenReturn(false);
|
||||||
|
|
||||||
|
Constraint<Boolean> c = constraintChecker.isAMAModeEnabled();
|
||||||
|
Assert.assertEquals(true, c.getReasons().contains("AMA disabled in preferences"));
|
||||||
|
Assert.assertEquals(Boolean.FALSE, c.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void notStartedObjective7ShouldLimitAMAMode() throws Exception {
|
||||||
|
objectivesPlugin.objectives.get(6).setStarted(new Date(0));
|
||||||
|
|
||||||
|
Constraint<Boolean> c = constraintChecker.isAMAModeEnabled();
|
||||||
|
Assert.assertEquals(true, c.getReasons().contains("Objective 7 not started"));
|
||||||
|
Assert.assertEquals(Boolean.FALSE, c.get());
|
||||||
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void prepareMock() throws Exception {
|
public void prepareMock() throws Exception {
|
||||||
PowerMockito.mockStatic(ConfigBuilderPlugin.class);
|
PowerMockito.mockStatic(ConfigBuilderPlugin.class);
|
||||||
|
@ -137,6 +156,7 @@ public class ConstraintsCheckerTest {
|
||||||
when(MainApp.gs(R.string.closedmodedisabledinpreferences)).thenReturn("Closed loop mode disabled in preferences");
|
when(MainApp.gs(R.string.closedmodedisabledinpreferences)).thenReturn("Closed loop mode disabled in preferences");
|
||||||
when(MainApp.gs(R.string.objectivenotstarted)).thenReturn("Objective %d not started");
|
when(MainApp.gs(R.string.objectivenotstarted)).thenReturn("Objective %d not started");
|
||||||
when(MainApp.gs(R.string.novalidbasalrate)).thenReturn("No valid basal rate read from pump");
|
when(MainApp.gs(R.string.novalidbasalrate)).thenReturn("No valid basal rate read from pump");
|
||||||
|
when(MainApp.gs(R.string.amadisabledinpreferences)).thenReturn("AMA disabled in preferences");
|
||||||
|
|
||||||
safetyPlugin = SafetyPlugin.getPlugin();
|
safetyPlugin = SafetyPlugin.getPlugin();
|
||||||
objectivesPlugin = ObjectivesPlugin.getPlugin();
|
objectivesPlugin = ObjectivesPlugin.getPlugin();
|
||||||
|
|
Loading…
Reference in a new issue