WIP scripter: reading history

This commit is contained in:
Johannes Mockenhaupt 2017-10-19 01:12:46 +02:00
parent 0a67bb73a4
commit eb87dfb3f1
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1
3 changed files with 73 additions and 7 deletions

View file

@ -14,6 +14,7 @@ public class PumpHistoryRequest {
public long bolusHistory = SKIP;
public long tbrHistory = SKIP;
public long errorHistory = SKIP;
public long tddHistory = SKIP;
public PumpHistoryRequest reservoirLevel(boolean reservoirLevel) {
this.reservoirLevel = reservoirLevel;
@ -35,6 +36,11 @@ public class PumpHistoryRequest {
return this;
}
public PumpHistoryRequest tddHistory(long tddHistory) {
this.tddHistory = tddHistory;
return this;
}
@Override
public String toString() {
return "PumpHistoryRequest{" +
@ -42,6 +48,7 @@ public class PumpHistoryRequest {
", bolusHistory=" + bolusHistory +
", tbrHistory=" + tbrHistory +
", errorHistory=" + errorHistory +
", tddHistory=" + tddHistory +
'}';
}
}

View file

@ -675,7 +675,7 @@ public class RuffyScripter implements RuffyCommands {
boolean movedOnce = false;
while (getCurrentMenu().getType() != desiredMenu) {
MenuType currentMenuType = getCurrentMenu().getType();
log.debug("Navigating to menu " + desiredMenu + ", currenty menu: " + currentMenuType);
log.debug("Navigating to menu " + desiredMenu + ", current menu: " + currentMenuType);
if (movedOnce && currentMenuType == startedFrom) {
throw new CommandException().message("Menu not found searching for " + desiredMenu
+ ". Check menu settings on your pump to ensure it's not hidden.");

View file

@ -2,13 +2,17 @@ package de.jotomo.ruffyscripter.commands;
import org.monkey.d.ruffy.ruffy.driver.display.MenuAttribute;
import org.monkey.d.ruffy.ruffy.driver.display.MenuType;
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.Collections;
import java.util.List;
import de.jotomo.ruffy.spi.CommandResult;
import de.jotomo.ruffy.spi.history.Bolus;
import de.jotomo.ruffy.spi.history.PumpHistory;
import de.jotomo.ruffy.spi.history.PumpHistoryRequest;
import de.jotomo.ruffy.spi.CommandResult;
public class ReadHistoryCommand extends BaseCommand {
private final PumpHistoryRequest request;
@ -20,12 +24,67 @@ public class ReadHistoryCommand extends BaseCommand {
@Override
public CommandResult execute() {
PumpHistory history = new PumpHistory();
if (request.reservoirLevel) readReservoirLevel(history);
if (request.bolusHistory != PumpHistoryRequest.SKIP) readBolusHistory(history, request.bolusHistory);
return new CommandResult().success(true).enacted(false).history(history);
}
if (request.reservoirLevel)
readReservoirLevel(history);
if (request.bolusHistory != PumpHistoryRequest.SKIP
|| request.bolusHistory != PumpHistoryRequest.SKIP
|| request.tbrHistory != PumpHistoryRequest.SKIP
|| request.errorHistory != PumpHistoryRequest.SKIP
|| request.tddHistory != PumpHistoryRequest.SKIP) {
scripter.navigateToMenu(MenuType.MY_DATA_MENU);
scripter.verifyMenuIsDisplayed(MenuType.MY_DATA_MENU);
scripter.pressCheckKey();
scripter.verifyMenuIsDisplayed(MenuType.BOLUS_DATA);
if (request.bolusHistory != PumpHistoryRequest.SKIP) {
// Could also be extended, multiwave:
BolusType bolusType = (BolusType) scripter.getCurrentMenu().getAttribute(MenuAttribute.BOLUS_TYPE);
if (!bolusType.equals(BolusType.NORMAL)) {
throw new CommandException().success(false).enacted(false).message("Unsupported bolus type encountered: " + bolusType);
}
Double bolus = (Double) scripter.getCurrentMenu().getAttribute(MenuAttribute.BOLUS);
MenuDate date = (MenuDate) scripter.getCurrentMenu().getAttribute(MenuAttribute.DATE);
MenuTime time = (MenuTime) scripter.getCurrentMenu().getAttribute(MenuAttribute.TIME);
private void readBolusHistory(PumpHistory history, long bolusHistory) {
history.bolusHistory.add(new Bolus(0, bolus));
int record = (int) scripter.getCurrentMenu().getAttribute(MenuAttribute.CURRENT_RECORD);
int totalRecords = (int) scripter.getCurrentMenu().getAttribute(MenuAttribute.TOTAL_RECORD);
/*
read displayed date, bolus, add to history
while data > last known, press up to go through history
*/
}
scripter.pressMenuKey();
scripter.verifyMenuIsDisplayed(MenuType.ERROR_DATA);
if (request.errorHistory != PumpHistoryRequest.SKIP) {
int code = (int) scripter.getCurrentMenu().getAttribute(MenuAttribute.WARNING);
String message = (String) scripter.getCurrentMenu().getAttribute(MenuAttribute.MESSAGE);
MenuDate date = (MenuDate) scripter.getCurrentMenu().getAttribute(MenuAttribute.DATE);
MenuTime time = (MenuTime) scripter.getCurrentMenu().getAttribute(MenuAttribute.TIME);
}
scripter.pressMenuKey();
scripter.verifyMenuIsDisplayed(MenuType.DAILY_DATA);
if (request.tddHistory != PumpHistoryRequest.SKIP) {
Double total = (Double) scripter.getCurrentMenu().getAttribute(MenuAttribute.DAILY_TOTAL);
MenuDate date = (MenuDate) scripter.getCurrentMenu().getAttribute(MenuAttribute.DATE);
MenuTime time = (MenuTime) scripter.getCurrentMenu().getAttribute(MenuAttribute.TIME);
}
scripter.pressMenuKey();
scripter.verifyMenuIsDisplayed(MenuType.TBR_DATA);
if (request.tbrHistory != PumpHistoryRequest.SKIP) {
Double percentage = (Double) scripter.getCurrentMenu().getAttribute(MenuAttribute.TBR);
MenuTime duration = (MenuTime) scripter.getCurrentMenu().getAttribute(MenuAttribute.RUNTIME);
MenuDate date = (MenuDate) scripter.getCurrentMenu().getAttribute(MenuAttribute.DATE);
// TODO start or end time?
MenuTime time = (MenuTime) scripter.getCurrentMenu().getAttribute(MenuAttribute.TIME);
}
scripter.returnToMainMenu();
}
scripter.verifyMenuIsDisplayed(MenuType.MAIN_MENU);
return new CommandResult().success(true).enacted(false).history(history);
}
private void readReservoirLevel(PumpHistory history) {