Remove CommandResult.lastBolus in favour of CR.history.bolusHistory.

This commit is contained in:
Johannes Mockenhaupt 2018-01-29 14:48:30 +01:00
parent 3adda9bf6e
commit 739e52dc47
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1
4 changed files with 17 additions and 15 deletions

View file

@ -402,9 +402,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
if (result.reservoirLevel != PumpState.UNKNOWN) {
pump.reservoirLevel = result.reservoirLevel;
}
if (result.lastBolus != null) {
pump.lastBolus = result.lastBolus;
} else if (result.history != null && !result.history.bolusHistory.isEmpty()) {
if (result.history != null && !result.history.bolusHistory.isEmpty()) {
pump.lastBolus = result.history.bolusHistory.get(0);
}
if (result.state.menu != null) {
@ -487,7 +485,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
if (lastRequestedBolus != null
&& Math.abs(lastRequestedBolus.amount - detailedBolusInfo.insulin) < 0.01
&& lastRequestedBolus.timestamp + 120 * 1000 > System.currentTimeMillis()) {
log.error("Bolus delivery failure at stage 0", new Exception());
log.error("Bolus request rejected, same bolus requested recently: " + lastRequestedBolus);
return new PumpEnactResult().success(false).enacted(false)
.comment(MainApp.gs(R.string.bolus_frequency_exceeded));
}
@ -509,7 +507,9 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
.comment(MainApp.gs(R.string.combo_bolus_rejected_due_to_pump_history_change));
}
Bolus previousBolus = stateResult.lastBolus != null ? stateResult.lastBolus : new Bolus(0, 0, false);
Bolus previousBolus = stateResult.history != null && !stateResult.history.bolusHistory.isEmpty()
? stateResult.history.bolusHistory.get(0)
: new Bolus(0, 0, false);
try {
pump.activity = MainApp.gs(R.string.combo_pump_action_bolusing, detailedBolusInfo.insulin);
@ -536,7 +536,9 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
return new PumpEnactResult().success(false).enacted(false)
.comment(MainApp.gs(R.string.combo_error_bolus_verification_failed));
}
Bolus lastPumpBolus = postBolusStateResult.lastBolus;
Bolus lastPumpBolus = postBolusStateResult.history != null && !postBolusStateResult.history.bolusHistory.isEmpty()
? postBolusStateResult.history.bolusHistory.get(0)
: null;
if (lastPumpBolus == null || lastPumpBolus.equals(previousBolus)) {
return new PumpEnactResult().success(false).enacted(false)
.comment(MainApp.gs(R.string.combo_error_no_bolus_delivered));
@ -892,8 +894,6 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
long lastViolation = 0;
if (commandResult.state.unsafeUsageDetected == PumpState.UNSUPPORTED_BOLUS_TYPE) {
lastViolation = System.currentTimeMillis();
} else if (commandResult.lastBolus != null && !commandResult.lastBolus.isValid) {
lastViolation = commandResult.lastBolus.timestamp;
} else if (commandResult.history != null) {
for (Bolus bolus : commandResult.history.bolusHistory) {
if (!bolus.isValid && bolus.timestamp > lastViolation) {

View file

@ -27,10 +27,6 @@ public class CommandResult {
public int reservoirLevel = -1;
/** Only set when by ReadReservoirLevelCommand. */
@Nullable
public Bolus lastBolus;
public CommandResult success(boolean success) {
this.success = success;
return this;
@ -59,7 +55,6 @@ public class CommandResult {
", history=" + history +
", basalProfile=" + basalProfile +
", forwardedWarnings='" + forwardedWarnings + '\'' +
", lastBolus=" + lastBolus +
'}';
}
}

View file

@ -188,7 +188,9 @@ public class BolusCommand extends BaseCommand {
ReadReservoirLevelAndLastBolus readReservoirLevelAndLastBolus = new ReadReservoirLevelAndLastBolus();
readReservoirLevelAndLastBolus.setScripter(scripter);
readReservoirLevelAndLastBolus.execute();
Bolus lastBolus = readReservoirLevelAndLastBolus.result.lastBolus;
Bolus lastBolus = readReservoirLevelAndLastBolus.result.history != null && !readReservoirLevelAndLastBolus.result.history.bolusHistory.isEmpty()
? readReservoirLevelAndLastBolus.result.history.bolusHistory.get(0)
: null;
if (lastBolus == null || Math.abs(System.currentTimeMillis() - lastBolus.timestamp) >= 10 * 60 * 1000) {
throw new CommandException("Unable to determine last bolus");
}

View file

@ -8,9 +8,12 @@ import org.monkey.d.ruffy.ruffy.driver.display.menu.BolusType;
import org.monkey.d.ruffy.ruffy.driver.display.menu.MenuDate;
import org.monkey.d.ruffy.ruffy.driver.display.menu.MenuTime;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.Bolus;
import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.PumpHistory;
public class ReadReservoirLevelAndLastBolus extends BaseCommand {
@Override
@ -22,7 +25,9 @@ public class ReadReservoirLevelAndLastBolus extends BaseCommand {
scripter.verifyMenuIsDisplayed(MenuType.QUICK_INFO);
result.reservoirLevel = ((Double) scripter.getCurrentMenu().getAttribute(MenuAttribute.REMAINING_INSULIN)).intValue();
scripter.pressCheckKey();
result.lastBolus = readBolusRecord();
List<Bolus> bolusHistory = new ArrayList<>(1);
bolusHistory.add(readBolusRecord());
result.history = new PumpHistory().bolusHistory(bolusHistory);
scripter.returnToRootMenu();
result.success = true;
}