Merge pull request #2204 from andyrozman/double_bolus_debug_master

Fix for some Double bolus problems
This commit is contained in:
Milos Kozak 2019-11-19 17:35:15 +01:00 committed by GitHub
commit 117f56e247
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 61 additions and 66 deletions

View file

@ -48,6 +48,7 @@ import info.nightscout.androidaps.plugins.general.overview.dialogs.ErrorHelperAc
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
import info.nightscout.androidaps.plugins.pump.common.PumpPluginAbstract; import info.nightscout.androidaps.plugins.pump.common.PumpPluginAbstract;
import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpDriverState; import info.nightscout.androidaps.plugins.pump.common.defs.PumpDriverState;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType; import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst;
@ -372,7 +373,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
refreshAnyStatusThatNeedsToBeRefreshed(); refreshAnyStatusThatNeedsToBeRefreshed();
} }
RxBus.INSTANCE.send(new EventMedtronicPumpValuesChanged()); RxBus.INSTANCE.send(new EventMedtronicPumpValuesChanged());
} }
@ -386,7 +387,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
RileyLinkServiceState rileyLinkServiceState = MedtronicUtil.getServiceState(); RileyLinkServiceState rileyLinkServiceState = MedtronicUtil.getServiceState();
if (rileyLinkServiceState==null) { if (rileyLinkServiceState == null) {
LOG.error("RileyLink unreachable. RileyLinkServiceState is null."); LOG.error("RileyLink unreachable. RileyLinkServiceState is null.");
return false; return false;
} }
@ -744,13 +745,13 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
ClockDTO clock = MedtronicUtil.getPumpTime(); ClockDTO clock = MedtronicUtil.getPumpTime();
if (clock==null) { // retry if (clock == null) { // retry
medtronicUIComm.executeCommand(MedtronicCommandType.GetRealTimeClock); medtronicUIComm.executeCommand(MedtronicCommandType.GetRealTimeClock);
clock = MedtronicUtil.getPumpTime(); clock = MedtronicUtil.getPumpTime();
} }
if (clock==null) if (clock == null)
return; return;
int timeDiff = Math.abs(clock.timeDifference); int timeDiff = Math.abs(clock.timeDifference);
@ -866,6 +867,11 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
}).start(); }).start();
} }
long now = System.currentTimeMillis();
detailedBolusInfo.date = now;
detailedBolusInfo.deliverAt = now; // not sure about that one
TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, true); TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, true);
// we subtract insulin, exact amount will be visible with next remainingInsulin update. // we subtract insulin, exact amount will be visible with next remainingInsulin update.
@ -877,7 +883,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
// calculate time for bolus and set driver to busy for that time // calculate time for bolus and set driver to busy for that time
int bolusTime = (int) (detailedBolusInfo.insulin * 42.0d); int bolusTime = (int) (detailedBolusInfo.insulin * 42.0d);
long time = System.currentTimeMillis() + (bolusTime * 1000); long time = now + (bolusTime * 1000);
this.busyTimestamps.add(time); this.busyTimestamps.add(time);
setEnableCustomAction(MedtronicCustomActionType.ClearBolusBlock, true); setEnableCustomAction(MedtronicCustomActionType.ClearBolusBlock, true);
@ -1065,10 +1071,10 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
@Override @Override
public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, Profile profile, public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, Profile profile,
boolean enforceNew) { boolean enforceNew) {
if (percent==0) { if (percent == 0) {
return setTempBasalAbsolute(0.0d, durationInMinutes, profile, enforceNew); return setTempBasalAbsolute(0.0d, durationInMinutes, profile, enforceNew);
} else { } else {
double absoluteValue = profile.getBasal() * (percent /100.0d); double absoluteValue = profile.getBasal() * (percent / 100.0d);
getMDTPumpStatus(); getMDTPumpStatus();
absoluteValue = pumpStatusLocal.pumpType.determineCorrectBasalSize(absoluteValue); absoluteValue = pumpStatusLocal.pumpType.determineCorrectBasalSize(absoluteValue);
LOG.warn("setTempBasalPercent [MedtronicPumpPlugin] - You are trying to use setTempBasalPercent with percent other then 0% (%d). This will start setTempBasalAbsolute, with calculated value (%.3f). Result might not be 100% correct.", percent, absoluteValue); LOG.warn("setTempBasalPercent [MedtronicPumpPlugin] - You are trying to use setTempBasalPercent with percent other then 0% (%d). This will start setTempBasalAbsolute, with calculated value (%.3f). Result might not be 100% correct.", percent, absoluteValue);

View file

@ -412,25 +412,18 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder<PumpHis
rate = body[1] * 0.025f; rate = body[1] * 0.025f;
} }
LOG.info("Basal Profile Start: offset={}, rate={}, index={}, body_raw={}", offset, rate, index, //LOG.info("Basal Profile Start: offset={}, rate={}, index={}, body_raw={}", offset, rate, index, body);
body);
if (rate == null) { if (rate == null) {
LOG.warn("Basal Profile Start (ERROR): offset={}, rate={}, index={}, body_raw={}", offset, rate, index, LOG.warn("Basal Profile Start (ERROR): offset={}, rate={}, index={}, body_raw={}", offset, rate, index,
body); body);
return RecordDecodeStatus.Error; return RecordDecodeStatus.Error;
} else { } else {
// writeData(PumpBaseType.Basal, PumpBasalType.ValueChange, getFormattedFloat(rate, 3),
// entry.getATechDate());
entry.addDecodedData("Value", getFormattedFloat(rate, 3)); entry.addDecodedData("Value", getFormattedFloat(rate, 3));
entry.setDisplayableValue(getFormattedFloat(rate, 3)); entry.setDisplayableValue(getFormattedFloat(rate, 3));
return RecordDecodeStatus.OK; return RecordDecodeStatus.OK;
} }
// profileIndex = asUINT8(data[1]);
// offset = asUINT8(data[7]) * 30 * 1000 * 60;
// rate = (double)(asUINT8(data[8])) / 40.0;
} }

View file

@ -10,12 +10,10 @@ import java.util.List;
import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil; import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil;
/**
* Created by andy on 9/23/18.
*/
/** /**
* History page contains data, sorted from newest to oldest (0=newest..n=oldest) * History page contains data, sorted from newest to oldest (0=newest..n=oldest)
*
* Created by andy on 9/23/18.
*/ */
public class PumpHistoryResult { public class PumpHistoryResult {
@ -29,8 +27,6 @@ public class PumpHistoryResult {
public List<PumpHistoryEntry> validEntries; public List<PumpHistoryEntry> validEntries;
// private Object validValues;
public PumpHistoryResult(PumpHistoryEntry searchEntry, Long targetDate) { public PumpHistoryResult(PumpHistoryEntry searchEntry, Long targetDate) {
if (searchEntry != null) { if (searchEntry != null) {
/* /*
@ -109,9 +105,8 @@ public class PumpHistoryResult {
if (unprocessedEntry.isAfter(this.searchDate)) { if (unprocessedEntry.isAfter(this.searchDate)) {
this.validEntries.add(unprocessedEntry); this.validEntries.add(unprocessedEntry);
} else { } else {
LOG.debug("PE. PumpHistoryResult. Not after.. Unprocessed Entry [year={},entry={}]", // LOG.debug("PE. PumpHistoryResult. Not after.. Unprocessed Entry [year={},entry={}]",
DateTimeUtil.getYear(unprocessedEntry.atechDateTime), unprocessedEntry); // DateTimeUtil.getYear(unprocessedEntry.atechDateTime), unprocessedEntry);
if (DateTimeUtil.getYear(unprocessedEntry.atechDateTime) > 2015) if (DateTimeUtil.getYear(unprocessedEntry.atechDateTime) > 2015)
olderEntries++; olderEntries++;
} }
@ -131,14 +126,6 @@ public class PumpHistoryResult {
} }
private void clearOrPrepareList() {
if (this.validEntries == null)
this.validEntries = new ArrayList<>();
else
this.validEntries.clear();
}
public String toString() { public String toString() {
return "PumpHistoryResult [unprocessed=" + (unprocessedEntries != null ? "" + unprocessedEntries.size() : "0") + // return "PumpHistoryResult [unprocessed=" + (unprocessedEntries != null ? "" + unprocessedEntries.size() : "0") + //
", valid=" + (validEntries != null ? "" + validEntries.size() : "0") + // ", valid=" + (validEntries != null ? "" + validEntries.size() : "0") + //

View file

@ -49,6 +49,7 @@ import info.nightscout.androidaps.plugins.pump.medtronic.driver.MedtronicPumpSta
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicConst; import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicConst;
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil; import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
import info.nightscout.androidaps.plugins.treatments.Treatment; import info.nightscout.androidaps.plugins.treatments.Treatment;
import info.nightscout.androidaps.plugins.treatments.TreatmentService;
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.utils.DateUtil; import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.SP; import info.nightscout.androidaps.utils.SP;
@ -76,6 +77,7 @@ public class MedtronicHistoryData {
private boolean isInit = false; private boolean isInit = false;
private Gson gson; private Gson gson;
private Gson gsonCore;
private DatabaseHelper databaseHelper = MainApp.getDbHelper(); private DatabaseHelper databaseHelper = MainApp.getDbHelper();
private ClockDTO pumpTime; private ClockDTO pumpTime;
@ -93,10 +95,15 @@ public class MedtronicHistoryData {
public MedtronicHistoryData() { public MedtronicHistoryData() {
this.allHistory = new ArrayList<>(); this.allHistory = new ArrayList<>();
this.gson = MedtronicUtil.gsonInstance; this.gson = MedtronicUtil.gsonInstance;
this.gsonCore = MedtronicUtil.getGsonInstanceCore();
if (this.gson == null) { if (this.gson == null) {
this.gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create(); this.gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
} }
if (this.gsonCore == null) {
this.gsonCore = new GsonBuilder().create();
}
} }
@ -596,7 +603,7 @@ public class MedtronicHistoryData {
if (doubleBolusDebug) if (doubleBolusDebug)
LOG.debug("DoubleBolusDebug: List (before filter): {}, FromDb={}", gson.toJson(entryList), LOG.debug("DoubleBolusDebug: List (before filter): {}, FromDb={}", gson.toJson(entryList),
gson.toJson(entriesFromHistory)); gsonCore.toJson(entriesFromHistory));
filterOutAlreadyAddedEntries(entryList, entriesFromHistory); filterOutAlreadyAddedEntries(entryList, entriesFromHistory);
@ -608,7 +615,7 @@ public class MedtronicHistoryData {
if (doubleBolusDebug) if (doubleBolusDebug)
LOG.debug("DoubleBolusDebug: List (after filter): {}, FromDb={}", gson.toJson(entryList), LOG.debug("DoubleBolusDebug: List (after filter): {}, FromDb={}", gson.toJson(entryList),
gson.toJson(entriesFromHistory)); gsonCore.toJson(entriesFromHistory));
if (isCollectionEmpty(entriesFromHistory)) { if (isCollectionEmpty(entriesFromHistory)) {
for (PumpHistoryEntry treatment : entryList) { for (PumpHistoryEntry treatment : entryList) {
@ -861,6 +868,7 @@ public class MedtronicHistoryData {
return; return;
List<DbObjectBase> removeTreatmentsFromHistory = new ArrayList<>(); List<DbObjectBase> removeTreatmentsFromHistory = new ArrayList<>();
List<PumpHistoryEntry> removeTreatmentsFromPH = new ArrayList<>();
for (DbObjectBase treatment : treatmentsFromHistory) { for (DbObjectBase treatment : treatmentsFromHistory) {
@ -878,11 +886,17 @@ public class MedtronicHistoryData {
if (selectedBolus != null) { if (selectedBolus != null) {
entryList.remove(selectedBolus); entryList.remove(selectedBolus);
removeTreatmentsFromPH.add(selectedBolus);
removeTreatmentsFromHistory.add(treatment); removeTreatmentsFromHistory.add(treatment);
} }
} }
} }
if (doubleBolusDebug)
LOG.debug("DoubleBolusDebug: filterOutAlreadyAddedEntries: PumpHistory={}, Treatments={}",
gson.toJson(removeTreatmentsFromPH),
gsonCore.toJson(removeTreatmentsFromHistory));
treatmentsFromHistory.removeAll(removeTreatmentsFromHistory); treatmentsFromHistory.removeAll(removeTreatmentsFromHistory);
} }
@ -946,36 +960,23 @@ public class MedtronicHistoryData {
} else { } else {
DetailedBolusInfo detailedBolusInfo = DetailedBolusInfoStorage.INSTANCE.findDetailedBolusInfo(treatment.date, bolusDTO.getDeliveredAmount()); if (doubleBolusDebug)
LOG.debug("DoubleBolusDebug: addBolus(OldTreatment={}): Bolus={}", treatment, bolusDTO);
treatment.source = Source.PUMP;
treatment.pumpId = bolus.getPumpId();
treatment.insulin = bolusDTO.getDeliveredAmount();
TreatmentService.UpdateReturn updateReturn = TreatmentsPlugin.getPlugin().getService().createOrUpdateMedtronic(treatment, false);
if (doubleBolusDebug) if (doubleBolusDebug)
LOG.debug("DoubleBolusDebug: addBolus(tretament={}): Bolus={}, DetailedBolusInfo={}", treatment, bolusDTO, detailedBolusInfo); LOG.debug("DoubleBolusDebug: addBolus(tretament!=null): NewTreatment={}, UpdateReturn={}", treatment, updateReturn);
if (detailedBolusInfo == null) {
detailedBolusInfo = new DetailedBolusInfo();
if (doubleBolusDebug)
LOG.debug("DoubleBolusDebug: detailedBolusInfoCouldNotBeRetrived !");
}
detailedBolusInfo.date = treatment.date;
detailedBolusInfo.source = Source.PUMP;
detailedBolusInfo.pumpId = bolus.getPumpId();
detailedBolusInfo.insulin = bolusDTO.getDeliveredAmount();
detailedBolusInfo.carbs = treatment.carbs;
addCarbsFromEstimate(detailedBolusInfo, bolus);
if (doubleBolusDebug)
LOG.debug("DoubleBolusDebug: addBolus(tretament!=null): DetailedBolusInfo(New)={}", detailedBolusInfo);
boolean newRecord = TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, false);
bolus.setLinkedObject(detailedBolusInfo);
if (isLogEnabled()) if (isLogEnabled())
LOG.debug("editBolus - [date={},pumpId={}, insulin={}, newRecord={}]", detailedBolusInfo.date, LOG.debug("editBolus - [date={},pumpId={}, insulin={}, newRecord={}]", treatment.date,
detailedBolusInfo.pumpId, detailedBolusInfo.insulin, newRecord); treatment.pumpId, treatment.insulin, updateReturn.toString());
bolus.setLinkedObject(treatment);
} }
} }

View file

@ -61,8 +61,7 @@ public class MedtronicUtil extends RileyLinkUtil {
private static int doneBit = 1 << 7; private static int doneBit = 1 << 7;
private static ClockDTO pumpTime; private static ClockDTO pumpTime;
public static Gson gsonInstance = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create(); public static Gson gsonInstance = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
public static Gson gsonInstancePretty = new GsonBuilder().excludeFieldsWithoutExposeAnnotation() public static Gson gsonInstanceCore = new GsonBuilder().create();
.setPrettyPrinting().create();
private static BatteryType batteryType = BatteryType.None; private static BatteryType batteryType = BatteryType.None;
@ -70,8 +69,9 @@ public class MedtronicUtil extends RileyLinkUtil {
return gsonInstance; return gsonInstance;
} }
public static Gson getGsonInstancePretty() {
return gsonInstancePretty; public static Gson getGsonInstanceCore() {
return gsonInstanceCore;
} }

View file

@ -736,6 +736,14 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
boolean newRecord; boolean newRecord;
boolean success; boolean success;
@Override
public String toString() {
return "UpdateReturn [" +
"newRecord=" + newRecord +
", success=" + success +
']';
}
} }
} }

View file

@ -349,7 +349,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
synchronized (treatments) { synchronized (treatments) {
if (MedtronicHistoryData.doubleBolusDebug) if (MedtronicHistoryData.doubleBolusDebug)
log.debug("DoubleBolusDebug: AllTreatmentsInDb: {}", MedtronicUtil.getGsonInstance().toJson(treatments)); log.debug("DoubleBolusDebug: AllTreatmentsInDb: {}", MedtronicUtil.getGsonInstanceCore().toJson(treatments));
for (Treatment t : treatments) { for (Treatment t : treatments) {
if (t.date <= time && t.date >= fromTimestamp) if (t.date <= time && t.date >= fromTimestamp)
@ -357,7 +357,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
} }
if (MedtronicHistoryData.doubleBolusDebug) if (MedtronicHistoryData.doubleBolusDebug)
log.debug("DoubleBolusDebug: FilteredTreatments: AfterTime={}, Items={}", fromTimestamp, MedtronicUtil.getGsonInstance().toJson(in5minback)); log.debug("DoubleBolusDebug: FilteredTreatments: AfterTime={}, Items={}", fromTimestamp, MedtronicUtil.getGsonInstanceCore().toJson(in5minback));
return in5minback; return in5minback;
} }