diff --git a/app/build.gradle b/app/build.gradle index 327b4df78d..55955d0895 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -105,7 +105,7 @@ android { multiDexEnabled true versionCode 1500 // dev_version: 2.3.1-dev - version "medtronic-0.11.11-SNAPSHOT" + version "medtronic-0.11.12-SNAPSHOT" buildConfigField "String", "VERSION", '"' + version + '"' buildConfigField "String", "BUILDVERSION", '"' + generateGitBuild() + '-' + generateDate() + '"' buildConfigField "String", "HEAD", '"' + generateGitBuild() + '"' diff --git a/app/src/main/java/info/nightscout/androidaps/interfaces/TreatmentsInterface.java b/app/src/main/java/info/nightscout/androidaps/interfaces/TreatmentsInterface.java index d344d66de7..eb0fc7f50a 100644 --- a/app/src/main/java/info/nightscout/androidaps/interfaces/TreatmentsInterface.java +++ b/app/src/main/java/info/nightscout/androidaps/interfaces/TreatmentsInterface.java @@ -31,7 +31,7 @@ public interface TreatmentsInterface { List getTreatmentsFromHistory(); List getTreatments5MinBackFromHistory(long time); - List getTreatmentsFromHistoryXMinutesAgo(int minutesAgo); + List getTreatmentsFromHistoryAfterTimestamp(long timestamp); long getLastBolusTime(); // real basals (not faked by extended bolus) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/pump/MedtronicPumpHistoryDecoder.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/pump/MedtronicPumpHistoryDecoder.java index c523b7cfb6..32ca320de2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/pump/MedtronicPumpHistoryDecoder.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/pump/MedtronicPumpHistoryDecoder.java @@ -147,7 +147,7 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder entryList) { - int dateDifference = getOldestDateDifference(entryList); + long oldestTimestamp = getOldestTimestamp(entryList); - List entriesFromHistory = getDatabaseEntries(dateDifference, ProcessHistoryRecord.Bolus); + List entriesFromHistory = getDatabaseEntriesByLastTimestamp(oldestTimestamp, ProcessHistoryRecord.Bolus); // LOG.debug(processHistoryRecord.getDescription() + " List (before filter): {}, FromDb={}", gsonPretty.toJson(entryList), // gsonPretty.toJson(entriesFromHistory)); @@ -568,9 +568,9 @@ public class MedtronicHistoryData { } } - int dateDifference = getOldestDateDifference(entryList); + long oldestTimestamp = getOldestTimestamp(entryList); - List entriesFromHistory = getDatabaseEntries(dateDifference, ProcessHistoryRecord.TBR); + List entriesFromHistory = getDatabaseEntriesByLastTimestamp(oldestTimestamp, ProcessHistoryRecord.TBR); if (isLogEnabled()) LOG.debug(ProcessHistoryRecord.TBR.getDescription() + " List (before filter): {}, FromDb={}", gson.toJson(entryList), @@ -693,7 +693,7 @@ public class MedtronicHistoryData { long proposedTime = DateTimeUtil.toMillisFromATD(treatment.atechDateTime); - proposedTime += (this.pumpTime.timeDifference * 1000); + //proposedTime += (this.pumpTime.timeDifference * 1000); if (entriesFromHistory.size() == 0) { return null; @@ -701,14 +701,11 @@ public class MedtronicHistoryData { return entriesFromHistory.get(0); } - for (int min = 0; min <= 2; min++) { - for (int sec = 0; sec < 60; sec += 10) { + for (int min = 0; min <= 2; min += 1) { - if (min==1 && sec==50) { - sec = 59; - } + for (int sec = 0; sec <= 40; sec += 10) { - int diff = (min * 60 * 1000) + (sec * 1000); + int diff = (sec * 1000); List outList = new ArrayList<>(); @@ -738,16 +735,11 @@ public class MedtronicHistoryData { } - private List getDatabaseEntries(int dateDifference, ProcessHistoryRecord processHistoryRecord) { + private List getDatabaseEntriesByLastTimestamp(long startTimestamp, ProcessHistoryRecord processHistoryRecord) { if (processHistoryRecord == ProcessHistoryRecord.Bolus) { - return TreatmentsPlugin.getPlugin().getTreatmentsFromHistoryXMinutesAgo( - dateDifference); + return TreatmentsPlugin.getPlugin().getTreatmentsFromHistoryAfterTimestamp(startTimestamp); } else { - - GregorianCalendar gc = new GregorianCalendar(); - gc.add(Calendar.MINUTE, (-1) * dateDifference); - - return databaseHelper.getTemporaryBasalsDataFromTime(gc.getTimeInMillis(), true); + return databaseHelper.getTemporaryBasalsDataFromTime(startTimestamp, true); } } @@ -1162,7 +1154,7 @@ public class MedtronicHistoryData { PumpHistoryEntry currentTreatment = null; if (isCollectionEmpty(treatments)) { - return 6; // default return of 6 (5 for diif on history reading + 1 for max allowed difference) minutes + return 8; // default return of 6 (5 for diif on history reading + 2 for max allowed difference) minutes } for (PumpHistoryEntry treatment : treatments) { @@ -1178,14 +1170,14 @@ public class MedtronicHistoryData { try { oldestEntryTime = DateTimeUtil.toLocalDateTime(dt); - oldestEntryTime = oldestEntryTime.minusMinutes(1); + oldestEntryTime = oldestEntryTime.minusMinutes(3); // if (this.pumpTime.timeDifference < 0) { // oldestEntryTime = oldestEntryTime.plusSeconds(this.pumpTime.timeDifference); // } } catch (Exception ex) { LOG.error("Problem decoding date from last record: {}" + currentTreatment); - return 6; // default return of 6 minutes + return 8; // default return of 6 minutes } LocalDateTime now = new LocalDateTime(); @@ -1201,6 +1193,40 @@ public class MedtronicHistoryData { } + private long getOldestTimestamp(List treatments) { + + long dt = Long.MAX_VALUE; + PumpHistoryEntry currentTreatment = null; + + for (PumpHistoryEntry treatment : treatments) { + + if (treatment.atechDateTime < dt) { + dt = treatment.atechDateTime; + currentTreatment = treatment; + } + } + + //LocalDateTime oldestEntryTime = null; + + try { + + GregorianCalendar oldestEntryTime = DateTimeUtil.toGregorianCalendar(dt); + oldestEntryTime.add(Calendar.MINUTE, -2); + + 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); + return 8; // default return of 6 minutes + } + + + } + + private PumpHistoryEntryType getTDDType() { if (MedtronicUtil.getMedtronicPumpModel() == null) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentsPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentsPlugin.java index 930d888505..7d58d57a99 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentsPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentsPlugin.java @@ -310,14 +310,14 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface @Override - public List getTreatmentsFromHistoryXMinutesAgo(int minutesAgo) { + public List getTreatmentsFromHistoryAfterTimestamp(long fromTimestamp) { List in5minback = new ArrayList<>(); long time = System.currentTimeMillis(); synchronized (treatments) { for (Treatment t : treatments) { if (!t.isValid) continue; - if (t.date <= time && t.date > (time - minutesAgo * 60 * 1000)) + if (t.date <= time && t.date >= fromTimestamp) in5minback.add(t); } return in5minback;