Fix issues during history read.
This commit is contained in:
parent
066d138e59
commit
b27ee06ebe
|
@ -1,7 +1,8 @@
|
||||||
- [ ] Bugs
|
- [ ] Bugs
|
||||||
- [ ] Taking over benign warnings on connect doesn't work properly
|
- [ ] Taking over benign warnings on connect doesn't work properly
|
||||||
(Notification raised but not confirmed?)
|
(Notification raised but not confirmed?)
|
||||||
- [ ] Reading full history multiple times duplicates entries shown in Stats/TDD dialog
|
- [x] Optimization reading full history doesn't seem to work
|
||||||
|
- [x] Reading full history multiple times duplicates entries shown in Stats/TDD dialog
|
||||||
- [x] ruffy: Accessing the quick info menu yields noMenu when cartridge is low
|
- [x] ruffy: Accessing the quick info menu yields noMenu when cartridge is low
|
||||||
- [x] ruffy: Multi-digit error codes in error history aren't supported
|
- [x] ruffy: Multi-digit error codes in error history aren't supported
|
||||||
- [-] No connection can be established anymore; ruffy issue i can't solve
|
- [-] No connection can be established anymore; ruffy issue i can't solve
|
||||||
|
|
|
@ -21,7 +21,7 @@ public class ComboErrorHistoryDialog extends DialogFragment {
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
View layout = inflater.inflate(R.layout.combo_error_history_fragment, container, false);
|
View layout = inflater.inflate(R.layout.combo_error_history_fragment, container, false);
|
||||||
TextView text = (TextView) layout.findViewById(R.id.combo_error_history_text);
|
TextView text = (TextView) layout.findViewById(R.id.combo_error_history_text);
|
||||||
List<PumpError> errors = ComboPlugin.getPlugin().getPump().history.pumpErrorHistory;
|
List<PumpError> errors = ComboPlugin.getPlugin().getPump().errorHistory;
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
// TODO i18n
|
// TODO i18n
|
||||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd.MM. HH:mm");
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd.MM. HH:mm");
|
||||||
|
|
|
@ -868,9 +868,25 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
updateDbFromPumpHistory(historyResult.history);
|
// update local cache
|
||||||
CommandResult reservoirBolusResult = runCommand(null, 3, ruffyScripter::readReservoirLevelAndLastBolus);
|
PumpHistory history = historyResult.history;
|
||||||
return historyResult.success && reservoirBolusResult.success;
|
if (!history.bolusHistory.isEmpty()) {
|
||||||
|
pump.lastHistoryBolusTime = history.bolusHistory.get(0).timestamp;
|
||||||
|
}
|
||||||
|
if (!history.tbrHistory.isEmpty()) {
|
||||||
|
pump.lastHistoryTbrTime = history.tbrHistory.get(0).timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!history.pumpErrorHistory.isEmpty()) {
|
||||||
|
pump.errorHistory = history.pumpErrorHistory;
|
||||||
|
}
|
||||||
|
if (!history.tddHistory.isEmpty()) {
|
||||||
|
pump.tddHistory = history.tddHistory;
|
||||||
|
}
|
||||||
|
|
||||||
|
updateDbFromPumpHistory(history);
|
||||||
|
|
||||||
|
return historyResult.success;
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void updateDbFromPumpHistory(@NonNull PumpHistory history) {
|
private synchronized void updateDbFromPumpHistory(@NonNull PumpHistory history) {
|
||||||
|
@ -905,34 +921,27 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
||||||
MainApp.getConfigBuilder().addToHistoryTempBasal(temporaryBasal);
|
MainApp.getConfigBuilder().addToHistoryTempBasal(temporaryBasal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// errors (not persisted in DB, read from pump on start up and cached in plugin)
|
|
||||||
for (PumpError pumpError : history.pumpErrorHistory) {
|
|
||||||
if (!pump.history.pumpErrorHistory.contains(pumpError)) {
|
|
||||||
pump.history.pumpErrorHistory.add(pumpError);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TDDs (not persisted in DB, read from pump on start up and cached in plugin)
|
|
||||||
for (Tdd tdd : history.tddHistory) {
|
|
||||||
if (!pump.history.tddHistory.contains(tdd)) {
|
|
||||||
pump.history.tddHistory.add(tdd);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO, opt doesn't seem to work
|
|
||||||
void readAllPumpData() {
|
void readAllPumpData() {
|
||||||
readHistory(new PumpHistoryRequest()
|
readHistory(new PumpHistoryRequest()
|
||||||
.bolusHistory(pump.history.bolusHistory.isEmpty() ? PumpHistoryRequest.FULL : pump.history.bolusHistory.get(0).timestamp)
|
.bolusHistory(pump.lastHistoryBolusTime)
|
||||||
.tbrHistory(pump.history.tbrHistory.isEmpty() ? PumpHistoryRequest.FULL : pump.history.tbrHistory.get(0).timestamp)
|
.tbrHistory(pump.lastHistoryTbrTime)
|
||||||
.pumpErrorHistory(pump.history.pumpErrorHistory.isEmpty() ? PumpHistoryRequest.FULL : pump.history.pumpErrorHistory.get(0).timestamp)
|
.pumpErrorHistory(PumpHistoryRequest.FULL)
|
||||||
.tddHistory(pump.history.tddHistory.isEmpty() ? PumpHistoryRequest.FULL : pump.history.tddHistory.get(0).timestamp));
|
.tddHistory(PumpHistoryRequest.FULL));
|
||||||
CommandResult commandResult = runCommand("Reading basal profile", 2,
|
|
||||||
ruffyScripter::readBasalProfile);
|
CommandResult reservoirResult = runCommand("Checking reservoir level", 2,
|
||||||
if (commandResult.success) {
|
ruffyScripter::readReservoirLevelAndLastBolus);
|
||||||
pump.basalProfile = commandResult.basalProfile;
|
if (!reservoirResult.success) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CommandResult basalResult = runCommand("Reading basal profile", 2, ruffyScripter::readBasalProfile);
|
||||||
|
if (!basalResult.success) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
pump.basalProfile = basalResult.basalProfile;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -3,11 +3,17 @@ package info.nightscout.androidaps.plugins.PumpCombo;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import de.jotomo.ruffy.spi.BasalProfile;
|
import de.jotomo.ruffy.spi.BasalProfile;
|
||||||
import de.jotomo.ruffy.spi.CommandResult;
|
import de.jotomo.ruffy.spi.CommandResult;
|
||||||
import de.jotomo.ruffy.spi.PumpState;
|
import de.jotomo.ruffy.spi.PumpState;
|
||||||
import de.jotomo.ruffy.spi.history.Bolus;
|
import de.jotomo.ruffy.spi.history.Bolus;
|
||||||
|
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.Tdd;
|
||||||
|
|
||||||
class ComboPump {
|
class ComboPump {
|
||||||
boolean initialized = false;
|
boolean initialized = false;
|
||||||
|
@ -22,8 +28,15 @@ class ComboPump {
|
||||||
volatile Bolus lastBolus = null;
|
volatile Bolus lastBolus = null;
|
||||||
@NonNull
|
@NonNull
|
||||||
volatile BasalProfile basalProfile = new BasalProfile();
|
volatile BasalProfile basalProfile = new BasalProfile();
|
||||||
@NonNull
|
|
||||||
volatile PumpHistory history = new PumpHistory();
|
|
||||||
/** Time the active TBR was set (if any). Needed to calculate remaining time in fragment */
|
/** Time the active TBR was set (if any). Needed to calculate remaining time in fragment */
|
||||||
long tbrSetTime;
|
long tbrSetTime;
|
||||||
|
|
||||||
|
// Last known history record times to skip over old ones when reading history
|
||||||
|
long lastHistoryBolusTime = PumpHistoryRequest.FULL;
|
||||||
|
long lastHistoryTbrTime = PumpHistoryRequest.FULL;
|
||||||
|
|
||||||
|
// Alert and TDD histories are not stored in DB, but are read on demand and just cached here
|
||||||
|
List<PumpError> errorHistory = new ArrayList<>(0);
|
||||||
|
List<Tdd> tddHistory = new ArrayList<>(0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ public class ComboTddHistoryDialog extends DialogFragment {
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
View layout = inflater.inflate(R.layout.combo_tdd_history_fragment, container, false);
|
View layout = inflater.inflate(R.layout.combo_tdd_history_fragment, container, false);
|
||||||
TextView text = (TextView) layout.findViewById(R.id.combo_tdd_history_text);
|
TextView text = (TextView) layout.findViewById(R.id.combo_tdd_history_text);
|
||||||
List<Tdd> tdds = ComboPlugin.getPlugin().getPump().history.tddHistory;
|
List<Tdd> tdds = ComboPlugin.getPlugin().getPump().tddHistory;
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
// TODO i18n
|
// TODO i18n
|
||||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd.MM.");
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd.MM.");
|
||||||
|
|
|
@ -138,11 +138,11 @@ public class ReadHistoryCommand extends BaseCommand {
|
||||||
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);
|
||||||
while (true) {
|
while (true) {
|
||||||
log.debug("Reading TDD record #" + record + "/" + totalRecords);
|
|
||||||
Tdd tdd = readTddRecord();
|
Tdd tdd = readTddRecord();
|
||||||
if (requestedTime != PumpHistoryRequest.FULL && tdd.timestamp <= requestedTime) {
|
if (requestedTime != PumpHistoryRequest.FULL && tdd.timestamp <= requestedTime) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
log.debug("Read TDD record #" + record + "/" + totalRecords);
|
||||||
history.tddHistory.add(tdd);
|
history.tddHistory.add(tdd);
|
||||||
log.debug("Parsed " + scripter.getCurrentMenu().toString() + " => " + tdd);
|
log.debug("Parsed " + scripter.getCurrentMenu().toString() + " => " + tdd);
|
||||||
if (record == totalRecords) {
|
if (record == totalRecords) {
|
||||||
|
@ -174,11 +174,11 @@ public class ReadHistoryCommand extends BaseCommand {
|
||||||
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);
|
||||||
while (true) {
|
while (true) {
|
||||||
log.debug("Reading TBR record #" + record + "/" + totalRecords);
|
|
||||||
Tbr tbr = readTbrRecord();
|
Tbr tbr = readTbrRecord();
|
||||||
if (requestedTime != PumpHistoryRequest.FULL && tbr.timestamp <= requestedTime) {
|
if (requestedTime != PumpHistoryRequest.FULL && tbr.timestamp <= requestedTime) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
log.debug("Read TBR record #" + record + "/" + totalRecords);
|
||||||
history.tbrHistory.add(tbr);
|
history.tbrHistory.add(tbr);
|
||||||
log.debug("Parsed " + scripter.getCurrentMenu().toString() + " => " + tbr);
|
log.debug("Parsed " + scripter.getCurrentMenu().toString() + " => " + tbr);
|
||||||
if (record == totalRecords) {
|
if (record == totalRecords) {
|
||||||
|
@ -204,11 +204,11 @@ public class ReadHistoryCommand extends BaseCommand {
|
||||||
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);
|
||||||
while (true) {
|
while (true) {
|
||||||
log.debug("Reading bolus record #" + record + "/" + totalRecords);
|
|
||||||
Bolus bolus = readBolusRecord();
|
Bolus bolus = readBolusRecord();
|
||||||
if (requestedTime != PumpHistoryRequest.FULL && bolus.timestamp <= requestedTime) {
|
if (requestedTime != PumpHistoryRequest.FULL && bolus.timestamp <= requestedTime) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
log.debug("Read bolus record #" + record + "/" + totalRecords);
|
||||||
history.bolusHistory.add(bolus);
|
history.bolusHistory.add(bolus);
|
||||||
log.debug("Parsed " + scripter.getCurrentMenu().toString() + " => " + bolus);
|
log.debug("Parsed " + scripter.getCurrentMenu().toString() + " => " + bolus);
|
||||||
if (record == totalRecords) {
|
if (record == totalRecords) {
|
||||||
|
@ -234,11 +234,11 @@ public class ReadHistoryCommand extends BaseCommand {
|
||||||
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);
|
||||||
while (true) {
|
while (true) {
|
||||||
log.debug("Reading error record #" + record + "/" + totalRecords);
|
|
||||||
PumpError error = readErrorRecord();
|
PumpError error = readErrorRecord();
|
||||||
if (requestedTime != PumpHistoryRequest.FULL && error.timestamp <= requestedTime) {
|
if (requestedTime != PumpHistoryRequest.FULL && error.timestamp <= requestedTime) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
log.debug("Read error record #" + record + "/" + totalRecords);
|
||||||
history.pumpErrorHistory.add(error);
|
history.pumpErrorHistory.add(error);
|
||||||
log.debug("Parsed " + scripter.getCurrentMenu().toString() + " => " + error);
|
log.debug("Parsed " + scripter.getCurrentMenu().toString() + " => " + error);
|
||||||
if (record == totalRecords) {
|
if (record == totalRecords) {
|
||||||
|
|
Loading…
Reference in a new issue