- Added a lot of logging for Double Bolus problem...
- Found one small problem when calling update treatment (if called from NS)...
This commit is contained in:
parent
43f0fe1df9
commit
66e7d0d29a
4 changed files with 76 additions and 15 deletions
|
@ -34,6 +34,7 @@ import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewB
|
|||
import info.nightscout.androidaps.plugins.pump.common.data.PumpStatus;
|
||||
import info.nightscout.androidaps.plugins.pump.common.defs.PumpDriverState;
|
||||
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
|
||||
import info.nightscout.androidaps.plugins.pump.medtronic.data.MedtronicHistoryData;
|
||||
import info.nightscout.androidaps.plugins.treatments.Treatment;
|
||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
||||
import info.nightscout.androidaps.utils.DateUtil;
|
||||
|
@ -415,6 +416,9 @@ public abstract class PumpPluginAbstract extends PluginBase implements PumpInter
|
|||
// bolus needed, ask pump to deliver it
|
||||
return deliverBolus(detailedBolusInfo);
|
||||
} else {
|
||||
if (MedtronicHistoryData.doubleBolusDebug)
|
||||
LOG.debug("DoubleBolusDebug: deliverTreatment::(carb only entry)");
|
||||
|
||||
// no bolus required, carb only treatment
|
||||
TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, true);
|
||||
|
||||
|
|
|
@ -77,6 +77,8 @@ public class MedtronicHistoryData {
|
|||
|
||||
private long lastIdUsed = 0;
|
||||
|
||||
public static boolean doubleBolusDebug = true;
|
||||
|
||||
|
||||
public MedtronicHistoryData() {
|
||||
this.allHistory = new ArrayList<>();
|
||||
|
@ -517,18 +519,23 @@ public class MedtronicHistoryData {
|
|||
|
||||
long oldestTimestamp = getOldestTimestamp(entryList);
|
||||
|
||||
Gson gson = MedtronicUtil.getGsonInstance();
|
||||
|
||||
List<? extends DbObjectBase> entriesFromHistory = getDatabaseEntriesByLastTimestamp(oldestTimestamp, ProcessHistoryRecord.Bolus);
|
||||
|
||||
// LOG.debug(processHistoryRecord.getDescription() + " List (before filter): {}, FromDb={}", gsonPretty.toJson(entryList),
|
||||
// gsonPretty.toJson(entriesFromHistory));
|
||||
if (doubleBolusDebug)
|
||||
LOG.debug("DoubleBolusDebug: List (before filter): {}, FromDb={}", gson.toJson(entryList),
|
||||
gson.toJson(entriesFromHistory));
|
||||
|
||||
filterOutAlreadyAddedEntries(entryList, entriesFromHistory);
|
||||
|
||||
if (entryList.isEmpty())
|
||||
if (entryList.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// LOG.debug(processHistoryRecord.getDescription() + " List (after filter): {}, FromDb={}", gsonPretty.toJson(entryList),
|
||||
// gsonPretty.toJson(entriesFromHistory));
|
||||
if (doubleBolusDebug)
|
||||
LOG.debug("DoubleBolusDebug: List (after filter): {}, FromDb={}", gson.toJson(entryList),
|
||||
gson.toJson(entriesFromHistory));
|
||||
|
||||
if (isCollectionEmpty(entriesFromHistory)) {
|
||||
for (PumpHistoryEntry treatment : entryList) {
|
||||
|
@ -681,12 +688,11 @@ public class MedtronicHistoryData {
|
|||
|
||||
/**
|
||||
* findDbEntry - finds Db entries in database, while theoretically this should have same dateTime they
|
||||
* don't. Entry on pump is few seconds before treatment in AAPS, and on manual boluses on pump there
|
||||
* is no treatment at all. For now we look fro tratment that was from 0s - 1m59s within pump entry.
|
||||
* don't. Entry on pump is few seconds before treatment in AAPS, and on manual boluses on pump there
|
||||
* is no treatment at all. For now we look fro tratment that was from 0s - 1m59s within pump entry.
|
||||
*
|
||||
* @param treatment Pump Entry
|
||||
* @param treatment Pump Entry
|
||||
* @param entriesFromHistory entries from history
|
||||
*
|
||||
* @return DbObject from AAPS (if found)
|
||||
*/
|
||||
private DbObjectBase findDbEntry(PumpHistoryEntry treatment, List<? extends DbObjectBase> entriesFromHistory) {
|
||||
|
@ -784,7 +790,10 @@ public class MedtronicHistoryData {
|
|||
|
||||
BolusDTO bolusDTO = (BolusDTO) bolus.getDecodedData().get("Object");
|
||||
|
||||
|
||||
if (treatment == null) {
|
||||
if (doubleBolusDebug)
|
||||
LOG.debug("DoubleBolusDebug: addBolus(tretament==null): Bolus={}", bolusDTO);
|
||||
|
||||
switch (bolusDTO.getBolusType()) {
|
||||
case Normal: {
|
||||
|
@ -797,6 +806,9 @@ public class MedtronicHistoryData {
|
|||
|
||||
addCarbsFromEstimate(detailedBolusInfo, bolus);
|
||||
|
||||
if (doubleBolusDebug)
|
||||
LOG.debug("DoubleBolusDebug: addBolus(tretament==null): DetailedBolusInfo={}", detailedBolusInfo);
|
||||
|
||||
boolean newRecord = TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, false);
|
||||
|
||||
bolus.setLinkedObject(detailedBolusInfo);
|
||||
|
@ -862,6 +874,9 @@ public class MedtronicHistoryData {
|
|||
|
||||
BolusWizardDTO bolusWizard = (BolusWizardDTO) bolus.getDecodedData().get("Estimate");
|
||||
|
||||
if (doubleBolusDebug)
|
||||
LOG.debug("DoubleBolusDebug: addCarbsFromEstimate: Bolus={}, BolusWizardDTO={}", bolus, bolusWizard);
|
||||
|
||||
detailedBolusInfo.carbs = bolusWizard.carbs;
|
||||
}
|
||||
}
|
||||
|
@ -1212,22 +1227,26 @@ public class MedtronicHistoryData {
|
|||
|
||||
//LocalDateTime oldestEntryTime = null;
|
||||
|
||||
if (doubleBolusDebug)
|
||||
LOG.debug("DoubleBolusDebug: getOldestTimestamp. Oldest entry found: time={}, object={}", dt, currentTreatment);
|
||||
|
||||
try {
|
||||
|
||||
GregorianCalendar oldestEntryTime = DateTimeUtil.toGregorianCalendar(dt);
|
||||
if (doubleBolusDebug)
|
||||
LOG.debug("DoubleBolusDebug: getOldestTimestamp. oldestEntryTime: {}", DateTimeUtil.toString(oldestEntryTime));
|
||||
oldestEntryTime.add(Calendar.MINUTE, -2);
|
||||
|
||||
if (doubleBolusDebug)
|
||||
LOG.debug("DoubleBolusDebug: getOldestTimestamp. oldestEntryTime (-2m): {}, timeInMillis={}", DateTimeUtil.toString(oldestEntryTime), oldestEntryTime.getTimeInMillis());
|
||||
|
||||
return oldestEntryTime.getTimeInMillis();
|
||||
|
||||
// if (this.pumpTime.timeDifference < 0) {
|
||||
// oldestEntryTime = oldestEntryTime.plusSeconds(this.pumpTime.timeDifference);
|
||||
// }
|
||||
} catch (Exception ex) {
|
||||
LOG.error("Problem decoding date from last record: {}" + currentTreatment);
|
||||
LOG.error("Problem decoding date from last record: {}", currentTreatment);
|
||||
return 8; // default return of 6 minutes
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -39,6 +39,7 @@ import info.nightscout.androidaps.events.EventTreatmentChange;
|
|||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventNewHistoryData;
|
||||
import info.nightscout.androidaps.plugins.pump.medtronic.data.MedtronicHistoryData;
|
||||
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy;
|
||||
import info.nightscout.androidaps.utils.JsonHelper;
|
||||
|
@ -249,10 +250,14 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
|
|||
try {
|
||||
Treatment treatment = Treatment.createFromJson(json);
|
||||
if (treatment != null) {
|
||||
|
||||
if (MedtronicHistoryData.doubleBolusDebug)
|
||||
log.debug("DoubleBolusDebug: createTreatmentFromJsonIfNotExists:: medtronicPump={}", MedtronicUtil.isMedtronicPump());
|
||||
|
||||
if (!MedtronicUtil.isMedtronicPump())
|
||||
createOrUpdate(treatment);
|
||||
else
|
||||
createOrUpdateMedtronic(treatment, false);
|
||||
createOrUpdateMedtronic(treatment, true);
|
||||
} else
|
||||
log.error("Date is null: " + treatment.toString());
|
||||
} catch (JSONException e) {
|
||||
|
@ -392,11 +397,18 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
|
|||
|
||||
|
||||
public UpdateReturn createOrUpdateMedtronic(Treatment treatment, boolean fromNightScout) {
|
||||
|
||||
if (MedtronicHistoryData.doubleBolusDebug)
|
||||
log.debug("DoubleBolusDebug: createOrUpdateMedtronic:: originalTreatment={}, fromNightScout={}", treatment, fromNightScout);
|
||||
|
||||
try {
|
||||
treatment.date = DatabaseHelper.roundDateToSec(treatment.date);
|
||||
|
||||
Treatment existingTreatment = getRecord(treatment.pumpId, treatment.date);
|
||||
|
||||
if (MedtronicHistoryData.doubleBolusDebug)
|
||||
log.debug("DoubleBolusDebug: createOrUpdateMedtronic:: existingTreatment={}", treatment);
|
||||
|
||||
if (existingTreatment == null) {
|
||||
getDao().create(treatment);
|
||||
if (L.isEnabled(L.DATATREATMENTS))
|
||||
|
@ -407,6 +419,9 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
|
|||
} else {
|
||||
|
||||
if (existingTreatment.date == treatment.date) {
|
||||
if (MedtronicHistoryData.doubleBolusDebug)
|
||||
log.debug("DoubleBolusDebug: createOrUpdateMedtronic::(existingTreatment.date==treatment.date)");
|
||||
|
||||
// we will do update only, if entry changed
|
||||
if (!optionalTreatmentCopy(existingTreatment, treatment, fromNightScout)) {
|
||||
return new UpdateReturn(true, false);
|
||||
|
@ -416,6 +431,9 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
|
|||
scheduleTreatmentChange(treatment);
|
||||
return new UpdateReturn(true, false);
|
||||
} else {
|
||||
if (MedtronicHistoryData.doubleBolusDebug)
|
||||
log.debug("DoubleBolusDebug: createOrUpdateMedtronic::(existingTreatment.date != treatment.date)");
|
||||
|
||||
// date is different, we need to remove entry
|
||||
getDao().delete(existingTreatment);
|
||||
optionalTreatmentCopy(existingTreatment, treatment, fromNightScout);
|
||||
|
|
|
@ -51,6 +51,7 @@ import info.nightscout.androidaps.plugins.general.overview.notifications.Notific
|
|||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensData;
|
||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensResult;
|
||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin;
|
||||
import info.nightscout.androidaps.plugins.pump.medtronic.data.MedtronicHistoryData;
|
||||
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
|
||||
import info.nightscout.androidaps.plugins.sensitivity.SensitivityAAPSPlugin;
|
||||
import info.nightscout.androidaps.plugins.sensitivity.SensitivityWeightedAveragePlugin;
|
||||
|
@ -344,12 +345,20 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
|||
@Override
|
||||
public List<Treatment> getTreatmentsFromHistoryAfterTimestamp(long fromTimestamp) {
|
||||
List<Treatment> in5minback = new ArrayList<>();
|
||||
|
||||
long time = System.currentTimeMillis();
|
||||
synchronized (treatments) {
|
||||
if (MedtronicHistoryData.doubleBolusDebug)
|
||||
log.debug("DoubleBolusDebug: AllTreatmentsInDb: {}", MedtronicUtil.getGsonInstance().toJson(treatments));
|
||||
|
||||
for (Treatment t : treatments) {
|
||||
if (t.date <= time && t.date >= fromTimestamp)
|
||||
in5minback.add(t);
|
||||
}
|
||||
|
||||
if (MedtronicHistoryData.doubleBolusDebug)
|
||||
log.debug("DoubleBolusDebug: FilteredTreatments: After={}, Items={}", fromTimestamp, MedtronicUtil.getGsonInstance().toJson(in5minback));
|
||||
|
||||
return in5minback;
|
||||
}
|
||||
}
|
||||
|
@ -623,6 +632,9 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
|||
public boolean addToHistoryTreatment(DetailedBolusInfo detailedBolusInfo, boolean allowUpdate) {
|
||||
boolean medtronicPump = MedtronicUtil.isMedtronicPump();
|
||||
|
||||
if (MedtronicHistoryData.doubleBolusDebug)
|
||||
log.debug("DoubleBolusDebug: addToHistoryTreatment::isMedtronicPump={}", medtronicPump);
|
||||
|
||||
Treatment treatment = new Treatment();
|
||||
treatment.date = detailedBolusInfo.date;
|
||||
treatment.source = detailedBolusInfo.source;
|
||||
|
@ -637,6 +649,9 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
|||
treatment.boluscalc = detailedBolusInfo.boluscalc != null ? detailedBolusInfo.boluscalc.toString() : null;
|
||||
TreatmentService.UpdateReturn creatOrUpdateResult;
|
||||
|
||||
if (medtronicPump && MedtronicHistoryData.doubleBolusDebug)
|
||||
log.debug("DoubleBolusDebug: addToHistoryTreatment::treatment={}", treatment);
|
||||
|
||||
if (!medtronicPump)
|
||||
creatOrUpdateResult = getService().createOrUpdate(treatment);
|
||||
else
|
||||
|
@ -645,12 +660,17 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
|||
boolean newRecordCreated = creatOrUpdateResult.newRecord;
|
||||
//log.debug("Adding new Treatment record" + treatment.toString());
|
||||
if (detailedBolusInfo.carbTime != 0) {
|
||||
|
||||
Treatment carbsTreatment = new Treatment();
|
||||
carbsTreatment.source = detailedBolusInfo.source;
|
||||
carbsTreatment.pumpId = detailedBolusInfo.pumpId; // but this should never happen
|
||||
carbsTreatment.date = detailedBolusInfo.date + detailedBolusInfo.carbTime * 60 * 1000L + 1000L; // add 1 sec to make them different records
|
||||
carbsTreatment.carbs = detailedBolusInfo.carbs;
|
||||
carbsTreatment.source = detailedBolusInfo.source;
|
||||
|
||||
if (medtronicPump && MedtronicHistoryData.doubleBolusDebug)
|
||||
log.debug("DoubleBolusDebug: carbTime!=0, creating second treatment. CarbsTreatment={}", carbsTreatment);
|
||||
|
||||
if (!medtronicPump)
|
||||
getService().createOrUpdate(carbsTreatment);
|
||||
else
|
||||
|
|
Loading…
Reference in a new issue