Remove CommandResult.lastBolus in favour of CR.history.bolusHistory.
This commit is contained in:
parent
3adda9bf6e
commit
739e52dc47
|
@ -402,9 +402,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
||||||
if (result.reservoirLevel != PumpState.UNKNOWN) {
|
if (result.reservoirLevel != PumpState.UNKNOWN) {
|
||||||
pump.reservoirLevel = result.reservoirLevel;
|
pump.reservoirLevel = result.reservoirLevel;
|
||||||
}
|
}
|
||||||
if (result.lastBolus != null) {
|
if (result.history != null && !result.history.bolusHistory.isEmpty()) {
|
||||||
pump.lastBolus = result.lastBolus;
|
|
||||||
} else if (result.history != null && !result.history.bolusHistory.isEmpty()) {
|
|
||||||
pump.lastBolus = result.history.bolusHistory.get(0);
|
pump.lastBolus = result.history.bolusHistory.get(0);
|
||||||
}
|
}
|
||||||
if (result.state.menu != null) {
|
if (result.state.menu != null) {
|
||||||
|
@ -487,7 +485,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
||||||
if (lastRequestedBolus != null
|
if (lastRequestedBolus != null
|
||||||
&& Math.abs(lastRequestedBolus.amount - detailedBolusInfo.insulin) < 0.01
|
&& Math.abs(lastRequestedBolus.amount - detailedBolusInfo.insulin) < 0.01
|
||||||
&& lastRequestedBolus.timestamp + 120 * 1000 > System.currentTimeMillis()) {
|
&& 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)
|
return new PumpEnactResult().success(false).enacted(false)
|
||||||
.comment(MainApp.gs(R.string.bolus_frequency_exceeded));
|
.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));
|
.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 {
|
try {
|
||||||
pump.activity = MainApp.gs(R.string.combo_pump_action_bolusing, detailedBolusInfo.insulin);
|
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)
|
return new PumpEnactResult().success(false).enacted(false)
|
||||||
.comment(MainApp.gs(R.string.combo_error_bolus_verification_failed));
|
.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)) {
|
if (lastPumpBolus == null || lastPumpBolus.equals(previousBolus)) {
|
||||||
return new PumpEnactResult().success(false).enacted(false)
|
return new PumpEnactResult().success(false).enacted(false)
|
||||||
.comment(MainApp.gs(R.string.combo_error_no_bolus_delivered));
|
.comment(MainApp.gs(R.string.combo_error_no_bolus_delivered));
|
||||||
|
@ -892,8 +894,6 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
||||||
long lastViolation = 0;
|
long lastViolation = 0;
|
||||||
if (commandResult.state.unsafeUsageDetected == PumpState.UNSUPPORTED_BOLUS_TYPE) {
|
if (commandResult.state.unsafeUsageDetected == PumpState.UNSUPPORTED_BOLUS_TYPE) {
|
||||||
lastViolation = System.currentTimeMillis();
|
lastViolation = System.currentTimeMillis();
|
||||||
} else if (commandResult.lastBolus != null && !commandResult.lastBolus.isValid) {
|
|
||||||
lastViolation = commandResult.lastBolus.timestamp;
|
|
||||||
} else if (commandResult.history != null) {
|
} else if (commandResult.history != null) {
|
||||||
for (Bolus bolus : commandResult.history.bolusHistory) {
|
for (Bolus bolus : commandResult.history.bolusHistory) {
|
||||||
if (!bolus.isValid && bolus.timestamp > lastViolation) {
|
if (!bolus.isValid && bolus.timestamp > lastViolation) {
|
||||||
|
|
|
@ -27,10 +27,6 @@ public class CommandResult {
|
||||||
|
|
||||||
public int reservoirLevel = -1;
|
public int reservoirLevel = -1;
|
||||||
|
|
||||||
/** Only set when by ReadReservoirLevelCommand. */
|
|
||||||
@Nullable
|
|
||||||
public Bolus lastBolus;
|
|
||||||
|
|
||||||
public CommandResult success(boolean success) {
|
public CommandResult success(boolean success) {
|
||||||
this.success = success;
|
this.success = success;
|
||||||
return this;
|
return this;
|
||||||
|
@ -59,7 +55,6 @@ public class CommandResult {
|
||||||
", history=" + history +
|
", history=" + history +
|
||||||
", basalProfile=" + basalProfile +
|
", basalProfile=" + basalProfile +
|
||||||
", forwardedWarnings='" + forwardedWarnings + '\'' +
|
", forwardedWarnings='" + forwardedWarnings + '\'' +
|
||||||
", lastBolus=" + lastBolus +
|
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -188,7 +188,9 @@ public class BolusCommand extends BaseCommand {
|
||||||
ReadReservoirLevelAndLastBolus readReservoirLevelAndLastBolus = new ReadReservoirLevelAndLastBolus();
|
ReadReservoirLevelAndLastBolus readReservoirLevelAndLastBolus = new ReadReservoirLevelAndLastBolus();
|
||||||
readReservoirLevelAndLastBolus.setScripter(scripter);
|
readReservoirLevelAndLastBolus.setScripter(scripter);
|
||||||
readReservoirLevelAndLastBolus.execute();
|
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) {
|
if (lastBolus == null || Math.abs(System.currentTimeMillis() - lastBolus.timestamp) >= 10 * 60 * 1000) {
|
||||||
throw new CommandException("Unable to determine last bolus");
|
throw new CommandException("Unable to determine last bolus");
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.MenuDate;
|
||||||
import org.monkey.d.ruffy.ruffy.driver.display.menu.MenuTime;
|
import org.monkey.d.ruffy.ruffy.driver.display.menu.MenuTime;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
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.Bolus;
|
||||||
|
import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.PumpHistory;
|
||||||
|
|
||||||
public class ReadReservoirLevelAndLastBolus extends BaseCommand {
|
public class ReadReservoirLevelAndLastBolus extends BaseCommand {
|
||||||
@Override
|
@Override
|
||||||
|
@ -22,7 +25,9 @@ public class ReadReservoirLevelAndLastBolus extends BaseCommand {
|
||||||
scripter.verifyMenuIsDisplayed(MenuType.QUICK_INFO);
|
scripter.verifyMenuIsDisplayed(MenuType.QUICK_INFO);
|
||||||
result.reservoirLevel = ((Double) scripter.getCurrentMenu().getAttribute(MenuAttribute.REMAINING_INSULIN)).intValue();
|
result.reservoirLevel = ((Double) scripter.getCurrentMenu().getAttribute(MenuAttribute.REMAINING_INSULIN)).intValue();
|
||||||
scripter.pressCheckKey();
|
scripter.pressCheckKey();
|
||||||
result.lastBolus = readBolusRecord();
|
List<Bolus> bolusHistory = new ArrayList<>(1);
|
||||||
|
bolusHistory.add(readBolusRecord());
|
||||||
|
result.history = new PumpHistory().bolusHistory(bolusHistory);
|
||||||
scripter.returnToRootMenu();
|
scripter.returnToRootMenu();
|
||||||
result.success = true;
|
result.success = true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue