medtronic-0.11.12-SNAPSHOT
- another look at duplicate bolus problem. This should have fixed the problem, if we still get duplicated, we will have to investigate NS angle
This commit is contained in:
parent
38f13cd6db
commit
7713270524
|
@ -105,7 +105,7 @@ android {
|
||||||
multiDexEnabled true
|
multiDexEnabled true
|
||||||
versionCode 1500
|
versionCode 1500
|
||||||
// dev_version: 2.3.1-dev
|
// dev_version: 2.3.1-dev
|
||||||
version "medtronic-0.11.11-SNAPSHOT"
|
version "medtronic-0.11.12-SNAPSHOT"
|
||||||
buildConfigField "String", "VERSION", '"' + version + '"'
|
buildConfigField "String", "VERSION", '"' + version + '"'
|
||||||
buildConfigField "String", "BUILDVERSION", '"' + generateGitBuild() + '-' + generateDate() + '"'
|
buildConfigField "String", "BUILDVERSION", '"' + generateGitBuild() + '-' + generateDate() + '"'
|
||||||
buildConfigField "String", "HEAD", '"' + generateGitBuild() + '"'
|
buildConfigField "String", "HEAD", '"' + generateGitBuild() + '"'
|
||||||
|
|
|
@ -31,7 +31,7 @@ public interface TreatmentsInterface {
|
||||||
|
|
||||||
List<Treatment> getTreatmentsFromHistory();
|
List<Treatment> getTreatmentsFromHistory();
|
||||||
List<Treatment> getTreatments5MinBackFromHistory(long time);
|
List<Treatment> getTreatments5MinBackFromHistory(long time);
|
||||||
List<Treatment> getTreatmentsFromHistoryXMinutesAgo(int minutesAgo);
|
List<Treatment> getTreatmentsFromHistoryAfterTimestamp(long timestamp);
|
||||||
long getLastBolusTime();
|
long getLastBolusTime();
|
||||||
|
|
||||||
// real basals (not faked by extended bolus)
|
// real basals (not faked by extended bolus)
|
||||||
|
|
|
@ -147,7 +147,7 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder<PumpHis
|
||||||
RecordDecodeStatus decoded = decodeRecord(pe);
|
RecordDecodeStatus decoded = decodeRecord(pe);
|
||||||
|
|
||||||
if ((decoded == RecordDecodeStatus.OK) || (decoded == RecordDecodeStatus.Ignored)) {
|
if ((decoded == RecordDecodeStatus.OK) || (decoded == RecordDecodeStatus.Ignored)) {
|
||||||
Log.i(TAG, "#" + record + " " + decoded.getDescription() + " " + pe);
|
//Log.i(TAG, "#" + record + " " + decoded.getDescription() + " " + pe);
|
||||||
} else {
|
} else {
|
||||||
Log.w(TAG, "#" + record + " " + decoded.getDescription() + " " + pe);
|
Log.w(TAG, "#" + record + " " + decoded.getDescription() + " " + pe);
|
||||||
}
|
}
|
||||||
|
|
|
@ -515,9 +515,9 @@ public class MedtronicHistoryData {
|
||||||
|
|
||||||
private void processBolusEntries(List<PumpHistoryEntry> entryList) {
|
private void processBolusEntries(List<PumpHistoryEntry> entryList) {
|
||||||
|
|
||||||
int dateDifference = getOldestDateDifference(entryList);
|
long oldestTimestamp = getOldestTimestamp(entryList);
|
||||||
|
|
||||||
List<? extends DbObjectBase> entriesFromHistory = getDatabaseEntries(dateDifference, ProcessHistoryRecord.Bolus);
|
List<? extends DbObjectBase> entriesFromHistory = getDatabaseEntriesByLastTimestamp(oldestTimestamp, ProcessHistoryRecord.Bolus);
|
||||||
|
|
||||||
// LOG.debug(processHistoryRecord.getDescription() + " List (before filter): {}, FromDb={}", gsonPretty.toJson(entryList),
|
// LOG.debug(processHistoryRecord.getDescription() + " List (before filter): {}, FromDb={}", gsonPretty.toJson(entryList),
|
||||||
// gsonPretty.toJson(entriesFromHistory));
|
// gsonPretty.toJson(entriesFromHistory));
|
||||||
|
@ -568,9 +568,9 @@ public class MedtronicHistoryData {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int dateDifference = getOldestDateDifference(entryList);
|
long oldestTimestamp = getOldestTimestamp(entryList);
|
||||||
|
|
||||||
List<? extends DbObjectBase> entriesFromHistory = getDatabaseEntries(dateDifference, ProcessHistoryRecord.TBR);
|
List<? extends DbObjectBase> entriesFromHistory = getDatabaseEntriesByLastTimestamp(oldestTimestamp, ProcessHistoryRecord.TBR);
|
||||||
|
|
||||||
if (isLogEnabled())
|
if (isLogEnabled())
|
||||||
LOG.debug(ProcessHistoryRecord.TBR.getDescription() + " List (before filter): {}, FromDb={}", gson.toJson(entryList),
|
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);
|
long proposedTime = DateTimeUtil.toMillisFromATD(treatment.atechDateTime);
|
||||||
|
|
||||||
proposedTime += (this.pumpTime.timeDifference * 1000);
|
//proposedTime += (this.pumpTime.timeDifference * 1000);
|
||||||
|
|
||||||
if (entriesFromHistory.size() == 0) {
|
if (entriesFromHistory.size() == 0) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -701,14 +701,11 @@ public class MedtronicHistoryData {
|
||||||
return entriesFromHistory.get(0);
|
return entriesFromHistory.get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int min = 0; min <= 2; min++) {
|
for (int min = 0; min <= 2; min += 1) {
|
||||||
for (int sec = 0; sec < 60; sec += 10) {
|
|
||||||
|
|
||||||
if (min==1 && sec==50) {
|
for (int sec = 0; sec <= 40; sec += 10) {
|
||||||
sec = 59;
|
|
||||||
}
|
|
||||||
|
|
||||||
int diff = (min * 60 * 1000) + (sec * 1000);
|
int diff = (sec * 1000);
|
||||||
|
|
||||||
List<DbObjectBase> outList = new ArrayList<>();
|
List<DbObjectBase> outList = new ArrayList<>();
|
||||||
|
|
||||||
|
@ -738,16 +735,11 @@ public class MedtronicHistoryData {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private List<? extends DbObjectBase> getDatabaseEntries(int dateDifference, ProcessHistoryRecord processHistoryRecord) {
|
private List<? extends DbObjectBase> getDatabaseEntriesByLastTimestamp(long startTimestamp, ProcessHistoryRecord processHistoryRecord) {
|
||||||
if (processHistoryRecord == ProcessHistoryRecord.Bolus) {
|
if (processHistoryRecord == ProcessHistoryRecord.Bolus) {
|
||||||
return TreatmentsPlugin.getPlugin().getTreatmentsFromHistoryXMinutesAgo(
|
return TreatmentsPlugin.getPlugin().getTreatmentsFromHistoryAfterTimestamp(startTimestamp);
|
||||||
dateDifference);
|
|
||||||
} else {
|
} else {
|
||||||
|
return databaseHelper.getTemporaryBasalsDataFromTime(startTimestamp, true);
|
||||||
GregorianCalendar gc = new GregorianCalendar();
|
|
||||||
gc.add(Calendar.MINUTE, (-1) * dateDifference);
|
|
||||||
|
|
||||||
return databaseHelper.getTemporaryBasalsDataFromTime(gc.getTimeInMillis(), true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1162,7 +1154,7 @@ public class MedtronicHistoryData {
|
||||||
PumpHistoryEntry currentTreatment = null;
|
PumpHistoryEntry currentTreatment = null;
|
||||||
|
|
||||||
if (isCollectionEmpty(treatments)) {
|
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) {
|
for (PumpHistoryEntry treatment : treatments) {
|
||||||
|
@ -1178,14 +1170,14 @@ public class MedtronicHistoryData {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
oldestEntryTime = DateTimeUtil.toLocalDateTime(dt);
|
oldestEntryTime = DateTimeUtil.toLocalDateTime(dt);
|
||||||
oldestEntryTime = oldestEntryTime.minusMinutes(1);
|
oldestEntryTime = oldestEntryTime.minusMinutes(3);
|
||||||
|
|
||||||
// if (this.pumpTime.timeDifference < 0) {
|
// if (this.pumpTime.timeDifference < 0) {
|
||||||
// oldestEntryTime = oldestEntryTime.plusSeconds(this.pumpTime.timeDifference);
|
// oldestEntryTime = oldestEntryTime.plusSeconds(this.pumpTime.timeDifference);
|
||||||
// }
|
// }
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
LOG.error("Problem decoding date from last record: {}" + currentTreatment);
|
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();
|
LocalDateTime now = new LocalDateTime();
|
||||||
|
@ -1201,6 +1193,40 @@ public class MedtronicHistoryData {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private long getOldestTimestamp(List<PumpHistoryEntry> 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() {
|
private PumpHistoryEntryType getTDDType() {
|
||||||
|
|
||||||
if (MedtronicUtil.getMedtronicPumpModel() == null) {
|
if (MedtronicUtil.getMedtronicPumpModel() == null) {
|
||||||
|
|
|
@ -310,14 +310,14 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Treatment> getTreatmentsFromHistoryXMinutesAgo(int minutesAgo) {
|
public List<Treatment> getTreatmentsFromHistoryAfterTimestamp(long fromTimestamp) {
|
||||||
List<Treatment> in5minback = new ArrayList<>();
|
List<Treatment> in5minback = new ArrayList<>();
|
||||||
long time = System.currentTimeMillis();
|
long time = System.currentTimeMillis();
|
||||||
synchronized (treatments) {
|
synchronized (treatments) {
|
||||||
for (Treatment t : treatments) {
|
for (Treatment t : treatments) {
|
||||||
if (!t.isValid)
|
if (!t.isValid)
|
||||||
continue;
|
continue;
|
||||||
if (t.date <= time && t.date > (time - minutesAgo * 60 * 1000))
|
if (t.date <= time && t.date >= fromTimestamp)
|
||||||
in5minback.add(t);
|
in5minback.add(t);
|
||||||
}
|
}
|
||||||
return in5minback;
|
return in5minback;
|
||||||
|
|
Loading…
Reference in a new issue