Finish ReadHistoryCommand for TBR, TDD.

This commit is contained in:
Johannes Mockenhaupt 2017-11-11 21:40:50 +01:00
parent 89d5593a52
commit a1b0240088
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1

View file

@ -16,8 +16,11 @@ import de.jotomo.ruffy.spi.history.Bolus;
import de.jotomo.ruffy.spi.history.PumpError; import de.jotomo.ruffy.spi.history.PumpError;
import de.jotomo.ruffy.spi.history.PumpHistory; import de.jotomo.ruffy.spi.history.PumpHistory;
import de.jotomo.ruffy.spi.history.PumpHistoryRequest; import de.jotomo.ruffy.spi.history.PumpHistoryRequest;
import de.jotomo.ruffy.spi.history.Tbr;
import de.jotomo.ruffy.spi.history.Tdd;
// Note: TBRs are added to history only after they've completed running // Note: TBRs are added to history only after they've completed running
// TODO remove duplication
public class ReadHistoryCommand extends BaseCommand { public class ReadHistoryCommand extends BaseCommand {
private static Logger log = LoggerFactory.getLogger(ReadHistoryCommand.class); private static Logger log = LoggerFactory.getLogger(ReadHistoryCommand.class);
@ -37,8 +40,6 @@ public class ReadHistoryCommand extends BaseCommand {
scripter.verifyMenuIsDisplayed(MenuType.MY_DATA_MENU); scripter.verifyMenuIsDisplayed(MenuType.MY_DATA_MENU);
scripter.pressCheckKey(); scripter.pressCheckKey();
// TODO see how dana does time mangling for timezones
// bolus history // bolus history
scripter.verifyMenuIsDisplayed(MenuType.BOLUS_DATA); scripter.verifyMenuIsDisplayed(MenuType.BOLUS_DATA);
if (request.bolusHistory != PumpHistoryRequest.SKIP) { if (request.bolusHistory != PumpHistoryRequest.SKIP) {
@ -71,18 +72,32 @@ public class ReadHistoryCommand extends BaseCommand {
// tdd history // tdd history
scripter.pressMenuKey(); scripter.pressMenuKey();
scripter.verifyMenuIsDisplayed(MenuType.DAILY_DATA); scripter.verifyMenuIsDisplayed(MenuType.DAILY_DATA);
/* if (request.tddHistory != PumpHistoryRequest.SKIP) {
int totalRecords = (int) scripter.getCurrentMenu().getAttribute(MenuAttribute.TOTAL_RECORD);
if (totalRecords > 0) {
if (request.tddHistory == PumpHistoryRequest.LAST) {
Tdd tdd = readTddRecord();
history.tddHistory.add(tdd);
} else {
readTddRecords(request.tbrHistory);
}
}
}
// tbr history // tbr history
scripter.pressMenuKey(); scripter.pressMenuKey();
scripter.verifyMenuIsDisplayed(MenuType.TBR_DATA); scripter.verifyMenuIsDisplayed(MenuType.TBR_DATA);
if (request.tbrHistory != PumpHistoryRequest.SKIP) { if (request.tbrHistory != PumpHistoryRequest.SKIP) {
Double percentage = (Double) scripter.getCurrentMenu().getAttribute(MenuAttribute.TBR); int totalRecords = (int) scripter.getCurrentMenu().getAttribute(MenuAttribute.TOTAL_RECORD);
MenuTime duration = (MenuTime) scripter.getCurrentMenu().getAttribute(MenuAttribute.RUNTIME); if (totalRecords > 0) {
MenuDate date = (MenuDate) scripter.getCurrentMenu().getAttribute(MenuAttribute.DATE); if (request.tbrHistory == PumpHistoryRequest.LAST) {
// TODO start or end time? Tbr tbr = readTbrRecord();
MenuTime time = (MenuTime) scripter.getCurrentMenu().getAttribute(MenuAttribute.TIME); history.tbrHistory.add(tbr);
} else {
readTbrRecords(request.tbrHistory);
}
}
} }
*/
scripter.pressBackKey(); scripter.pressBackKey();
scripter.returnToRootMenu(); scripter.returnToRootMenu();
@ -102,10 +117,78 @@ public class ReadHistoryCommand extends BaseCommand {
log.debug(new Date(pumpError.timestamp) + ": " + pumpError.toString()); log.debug(new Date(pumpError.timestamp) + ": " + pumpError.toString());
} }
} }
if (!history.tddHistory.isEmpty()) {
log.debug("Read TDD history:");
for (Tdd tdd : history.tddHistory) {
log.debug(new Date(tdd.timestamp) + ": " + tdd.toString());
}
}
if (!history.tbrHistory.isEmpty()) {
log.debug("Read TBR history:");
for (Tbr tbr : history.tbrHistory) {
log.debug(new Date(tbr.timestamp) + ": " + tbr.toString());
}
}
} }
result.success(true).history(history); result.success(true).history(history);
} }
private void readTddRecords(long requestedTime) {
int record = (int) scripter.getCurrentMenu().getAttribute(MenuAttribute.CURRENT_RECORD);
int totalRecords = (int) scripter.getCurrentMenu().getAttribute(MenuAttribute.TOTAL_RECORD);
while (true) {
log.debug("Reading TDD record #" + record + "/" + totalRecords);
Tdd tdd = readTddRecord();
if (requestedTime != PumpHistoryRequest.FULL && tdd.timestamp <= requestedTime) {
break;
}
history.tddHistory.add(tdd);
scripter.pressDownKey();
scripter.waitForMenuUpdate();
record = (int) scripter.getCurrentMenu().getAttribute(MenuAttribute.CURRENT_RECORD);
if (record == totalRecords) {
break;
}
}
}
@NonNull
private Tdd readTddRecord() {
scripter.verifyMenuIsDisplayed(MenuType.DAILY_DATA);
Double dailyTotal = (Double) scripter.getCurrentMenu().getAttribute(MenuAttribute.DAILY_TOTAL);
long recordDate = readRecordDate();
return new Tdd(recordDate, dailyTotal);
}
private void readTbrRecords(long requestedTime) {
int record = (int) scripter.getCurrentMenu().getAttribute(MenuAttribute.CURRENT_RECORD);
int totalRecords = (int) scripter.getCurrentMenu().getAttribute(MenuAttribute.TOTAL_RECORD);
while (true) {
log.debug("Reading TBR record #" + record + "/" + totalRecords);
Tbr tbr = readTbrRecord();
if (requestedTime != PumpHistoryRequest.FULL && tbr.timestamp <= requestedTime) {
break;
}
history.tbrHistory.add(tbr);
scripter.pressDownKey();
scripter.waitForMenuUpdate();
record = (int) scripter.getCurrentMenu().getAttribute(MenuAttribute.CURRENT_RECORD);
if (record == totalRecords) {
break;
}
}
}
@NonNull
private Tbr readTbrRecord() {
scripter.verifyMenuIsDisplayed(MenuType.TBR_DATA);
Double percentage = (Double) scripter.getCurrentMenu().getAttribute(MenuAttribute.TBR);
MenuTime durationTime = (MenuTime) scripter.getCurrentMenu().getAttribute(MenuAttribute.RUNTIME);
int duration = durationTime.getHour() * 60 + durationTime.getMinute();
long recordDate = readRecordDate();
return new Tbr(recordDate, duration, percentage.intValue());
}
private void readBolusRecords(long requestedTime) { private void readBolusRecords(long requestedTime) {
int record = (int) scripter.getCurrentMenu().getAttribute(MenuAttribute.CURRENT_RECORD); int record = (int) scripter.getCurrentMenu().getAttribute(MenuAttribute.CURRENT_RECORD);
int totalRecords = (int) scripter.getCurrentMenu().getAttribute(MenuAttribute.TOTAL_RECORD); int totalRecords = (int) scripter.getCurrentMenu().getAttribute(MenuAttribute.TOTAL_RECORD);