From ee5413ed067c5382cd8461a96c86bae5f1391794 Mon Sep 17 00:00:00 2001 From: Andy Rozman Date: Tue, 8 Jun 2021 22:31:15 +0100 Subject: [PATCH 1/8] - refactoring TempBasalProcess - changed some logging --- .../medtronic/data/MedtronicHistoryData.kt | 140 ++++++++++-------- .../medtronic/data/dto/TempBasalProcessDTO.kt | 32 +++- 2 files changed, 105 insertions(+), 67 deletions(-) diff --git a/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/MedtronicHistoryData.kt b/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/MedtronicHistoryData.kt index 5c8fa3750f..bcc090302f 100644 --- a/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/MedtronicHistoryData.kt +++ b/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/MedtronicHistoryData.kt @@ -615,85 +615,96 @@ class MedtronicHistoryData @Inject constructor( for (tempBasalProcessDTO in processList) { aapsLogger.debug(LTag.PUMP, "DD: tempBasalProcessDTO.itemOne: " + gson.toJson(tempBasalProcessDTO.itemOne)) + aapsLogger.debug(LTag.PUMP, "DD: tempBasalProcessDTO.itemTwo: " + (if (tempBasalProcessDTO.itemTwo == null) "null" else gson.toJson(tempBasalProcessDTO.itemTwo!!))) val entryWithTempId = findDbEntry(tempBasalProcessDTO.itemOne, tbrRecords) aapsLogger.debug(LTag.PUMP, "DD: entryWithTempId: " + (if (entryWithTempId == null) "null" else entryWithTempId.toString())) - val tbrEntry = tempBasalProcessDTO.itemOne.getDecodedDataEntry("Object") as TempBasalPair + val tbrEntry = tempBasalProcessDTO.itemOneTbr //.getDecodedDataEntry("Object") as TempBasalPair aapsLogger.debug(LTag.PUMP, String.format("DD: tbrEntry=%s, tempBasalProcessDTO=%s", gson.toJson(tbrEntry), gson.toJson(tempBasalProcessDTO))) if (entryWithTempId != null) { - aapsLogger.debug(LTag.PUMP, String.format("DD: tempIdEntry=%s, tbrEntry=%s, tempBasalProcessDTO=%s, pumpType=%s, serial=%s", - gson.toJson(entryWithTempId), gson.toJson(tbrEntry), gson.toJson(tempBasalProcessDTO), medtronicPumpStatus.pumpType, medtronicPumpStatus.serialNumber)) + if (tbrEntry != null) { + aapsLogger.debug(LTag.PUMP, String.format("DD: tempIdEntry=%s, tbrEntry=%s, tempBasalProcessDTO=%s, pumpType=%s, serial=%s", + gson.toJson(entryWithTempId), gson.toJson(tbrEntry), gson.toJson(tempBasalProcessDTO), medtronicPumpStatus.pumpType, medtronicPumpStatus.serialNumber)) - aapsLogger.debug(LTag.PUMP, "BEFORE syncTemporaryBasalWithTempId " + - "[date=${tempBasalProcessDTO.atechDateTime}, dateProcess=${tryToGetByLocalTime(tempBasalProcessDTO.atechDateTime)}, " + - "tbrEntry.insulinRate=${tbrEntry.insulinRate}, duration=${tempBasalProcessDTO.duration * 60L * 1000L}, " + - "isAbsolute=${!tbrEntry.isPercent}, temporaryId=${entryWithTempId.temporaryId}, " + - "pumpId=${tempBasalProcessDTO.pumpId}, pumpType=${medtronicPumpStatus.pumpType}, " + - "pumpSerial=${medtronicPumpStatus.serialNumber}]") + aapsLogger.debug(LTag.PUMP, "BEFORE syncTemporaryBasalWithTempId " + + "[date=${tempBasalProcessDTO.atechDateTime}, dateProcess=${tryToGetByLocalTime(tempBasalProcessDTO.atechDateTime)}, " + + "tbrEntry.insulinRate=${tbrEntry.insulinRate}, duration=${tempBasalProcessDTO.duration * 60L * 1000L}, " + + "isAbsolute=${!tbrEntry.isPercent}, temporaryId=${entryWithTempId.temporaryId}, " + + "pumpId=${tempBasalProcessDTO.pumpId}, pumpType=${medtronicPumpStatus.pumpType}, " + + "pumpSerial=${medtronicPumpStatus.serialNumber}]") - val result = pumpSync.syncTemporaryBasalWithTempId( - tryToGetByLocalTime(tempBasalProcessDTO.atechDateTime), - tbrEntry.insulinRate, - tempBasalProcessDTO.duration * 60L * 1000L, - !tbrEntry.isPercent, - entryWithTempId.temporaryId, - PumpSync.TemporaryBasalType.NORMAL, - tempBasalProcessDTO.pumpId, - medtronicPumpStatus.pumpType, - medtronicPumpStatus.serialNumber) + val result = pumpSync.syncTemporaryBasalWithTempId( + tryToGetByLocalTime(tempBasalProcessDTO.atechDateTime), + tbrEntry.insulinRate, + tempBasalProcessDTO.duration * 60L * 1000L, + !tbrEntry.isPercent, + entryWithTempId.temporaryId, + PumpSync.TemporaryBasalType.NORMAL, + tempBasalProcessDTO.pumpId, + medtronicPumpStatus.pumpType, + medtronicPumpStatus.serialNumber) - aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "syncTemporaryBasalWithTempId [date=%d, temporaryId=%d, pumpId=%d, rate=%.2f %s, duration=%d, pumpSerial=%s] - Result: %b", - tempBasalProcessDTO.atechDateTime, entryWithTempId.temporaryId, tempBasalProcessDTO.pumpId, - tbrEntry.insulinRate, (if (tbrEntry.isPercent) "%" else "U"), tempBasalProcessDTO.duration, - medtronicPumpStatus.serialNumber, result)) + aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "syncTemporaryBasalWithTempId [date=%d, temporaryId=%d, pumpId=%d, rate=%.2f %s, duration=%d, pumpSerial=%s] - Result: %b", + tempBasalProcessDTO.atechDateTime, entryWithTempId.temporaryId, tempBasalProcessDTO.pumpId, + tbrEntry.insulinRate, (if (tbrEntry.isPercent) "%" else "U"), tempBasalProcessDTO.duration, + medtronicPumpStatus.serialNumber, result)) - pumpSyncStorage.removeTemporaryBasalWithTemporaryId(entryWithTempId.temporaryId) - tbrRecords.remove(entryWithTempId) + pumpSyncStorage.removeTemporaryBasalWithTemporaryId(entryWithTempId.temporaryId) + tbrRecords.remove(entryWithTempId) - entryWithTempId.pumpId = tempBasalProcessDTO.pumpId - entryWithTempId.date = tryToGetByLocalTime(tempBasalProcessDTO.atechDateTime) + entryWithTempId.pumpId = tempBasalProcessDTO.pumpId + entryWithTempId.date = tryToGetByLocalTime(tempBasalProcessDTO.atechDateTime) - if (isTBRActive(entryWithTempId)) { - medtronicPumpStatus.runningTBR = entryWithTempId + if (isTBRActive(entryWithTempId)) { + medtronicPumpStatus.runningTBR = entryWithTempId + } + } else { + aapsLogger.warn(LTag.PUMP, "tbrEntry (itemOne) is null, shouldn't be.") } } else { - val result = pumpSync.syncTemporaryBasalWithPumpId( - tryToGetByLocalTime(tempBasalProcessDTO.atechDateTime), - tbrEntry.insulinRate, - tempBasalProcessDTO.duration * 60L * 1000L, - !tbrEntry.isPercent, - PumpSync.TemporaryBasalType.NORMAL, - tempBasalProcessDTO.pumpId, - medtronicPumpStatus.pumpType, - medtronicPumpStatus.serialNumber) - aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "syncTemporaryBasalWithPumpId [date=%d, pumpId=%d, rate=%.2f %s, duration=%d, pumpSerial=%s] - Result: %b", - tempBasalProcessDTO.atechDateTime, tempBasalProcessDTO.pumpId, - tbrEntry.insulinRate, (if (tbrEntry.isPercent) "%" else "U"), tempBasalProcessDTO.duration, - medtronicPumpStatus.serialNumber, result)) + if (tbrEntry != null) { - if (medtronicPumpStatus.runningTBR != null) { - if (!isTBRActive(medtronicPumpStatus.runningTBR!!)) { - medtronicPumpStatus.runningTBR = null + val result = pumpSync.syncTemporaryBasalWithPumpId( + tryToGetByLocalTime(tempBasalProcessDTO.atechDateTime), + tbrEntry.insulinRate, + tempBasalProcessDTO.duration * 60L * 1000L, + !tbrEntry.isPercent, + PumpSync.TemporaryBasalType.NORMAL, + tempBasalProcessDTO.pumpId, + medtronicPumpStatus.pumpType, + medtronicPumpStatus.serialNumber) + + aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "syncTemporaryBasalWithPumpId [date=%d, pumpId=%d, rate=%.2f %s, duration=%d, pumpSerial=%s] - Result: %b", + tempBasalProcessDTO.atechDateTime, tempBasalProcessDTO.pumpId, + tbrEntry.insulinRate, (if (tbrEntry.isPercent) "%" else "U"), tempBasalProcessDTO.duration, + medtronicPumpStatus.serialNumber, result)) + + if (medtronicPumpStatus.runningTBR != null) { + if (!isTBRActive(medtronicPumpStatus.runningTBR!!)) { + medtronicPumpStatus.runningTBR = null + } } - } - if (isTBRActive(tryToGetByLocalTime(tempBasalProcessDTO.atechDateTime), tempBasalProcessDTO.duration)) { - if (medtronicPumpStatus.runningTBR == null) { - medtronicPumpStatus.runningTBR = info.nightscout.androidaps.plugins.pump.common.sync.PumpDbEntry(0L, - tryToGetByLocalTime(tempBasalProcessDTO.atechDateTime), - medtronicPumpStatus.pumpType, - medtronicPumpStatus.serialNumber, - null, - info.nightscout.androidaps.plugins.pump.common.sync.PumpDbEntryTBR(tbrEntry.insulinRate, !tbrEntry.isPercent, tempBasalProcessDTO.duration, PumpSync.TemporaryBasalType.NORMAL), - tempBasalProcessDTO.pumpId) + if (isTBRActive(tryToGetByLocalTime(tempBasalProcessDTO.atechDateTime), tempBasalProcessDTO.duration)) { + if (medtronicPumpStatus.runningTBR == null) { + medtronicPumpStatus.runningTBR = info.nightscout.androidaps.plugins.pump.common.sync.PumpDbEntry(0L, + tryToGetByLocalTime(tempBasalProcessDTO.atechDateTime), + medtronicPumpStatus.pumpType, + medtronicPumpStatus.serialNumber, + null, + info.nightscout.androidaps.plugins.pump.common.sync.PumpDbEntryTBR(tbrEntry.insulinRate, !tbrEntry.isPercent, tempBasalProcessDTO.duration, PumpSync.TemporaryBasalType.NORMAL), + tempBasalProcessDTO.pumpId) + } } + } else { + aapsLogger.warn(LTag.PUMP, "tbrEntry (itemOne) is null, shouldn't be.") } } } // for @@ -852,11 +863,14 @@ class MedtronicHistoryData @Inject constructor( Collections.reverse(filtered2Items) var i = 0 while (i < filtered2Items.size) { - outList.add(TempBasalProcessDTO( + val tbrProcess = TempBasalProcessDTO( itemOne = filtered2Items[i], - itemTwo = filtered2Items[i + 1], processOperation = TempBasalProcessDTO.Operation.Add, - aapsLogger = aapsLogger)) + aapsLogger = aapsLogger) + + tbrProcess.itemTwo = filtered2Items[i + 1] + + outList.add(tbrProcess) i += 2 } @@ -918,11 +932,15 @@ class MedtronicHistoryData @Inject constructor( var itemTwo = items[0] items = getFilteredItems(tempData, PumpHistoryEntryType.NoDeliveryAlarm) if (items.size > 0) { - outList.add(TempBasalProcessDTO( + val tbrProcess = TempBasalProcessDTO( itemOne = items[items.size - 1], - itemTwo = itemTwo, processOperation = TempBasalProcessDTO.Operation.Add, - aapsLogger = aapsLogger)) + aapsLogger = aapsLogger) + + tbrProcess.itemTwo = itemTwo + + outList.add(tbrProcess) + return outList } items = getFilteredItems(tempData, PumpHistoryEntryType.Rewind) diff --git a/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/TempBasalProcessDTO.kt b/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/TempBasalProcessDTO.kt index 9cbb0b6dbc..04a7983e3c 100644 --- a/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/TempBasalProcessDTO.kt +++ b/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/TempBasalProcessDTO.kt @@ -1,14 +1,23 @@ package info.nightscout.androidaps.plugins.pump.medtronic.data.dto import info.nightscout.androidaps.logging.AAPSLogger +import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.PumpHistoryEntry class TempBasalProcessDTO constructor(var itemOne: PumpHistoryEntry, - var itemTwo: PumpHistoryEntry? = null, var processOperation: Operation = Operation.None, var aapsLogger: AAPSLogger) { + var itemTwo: PumpHistoryEntry? = null + set(value) { + field = value + itemTwoTbr = value!!.getDecodedDataEntry("Object") as TempBasalPair + } + + var itemOneTbr: TempBasalPair? = null + var itemTwoTbr: TempBasalPair? = null + var cancelPresent: Boolean = false val atechDateTime: Long @@ -19,17 +28,28 @@ class TempBasalProcessDTO constructor(var itemOne: PumpHistoryEntry, val duration: Int get() = if (itemTwo == null) { - val tbr = itemOne.getDecodedDataEntry("Object") as? TempBasalPair - if (tbr != null) - tbr.durationMinutes - else { + if (itemOneTbr != null) { + aapsLogger.debug("TemporaryBasalPair: $itemOneTbr") + itemOneTbr!!.durationMinutes + } else { aapsLogger.error("Couldn't find TempBasalPair in entry: $itemOne") 0 } } else { - DateTimeUtil.getATechDateDiferenceAsMinutes(itemOne.atechDateTime, itemTwo!!.atechDateTime) + aapsLogger.debug(LTag.PUMP, "Found 2 items for duration: itemOne=$itemOne, itemTwo=$itemTwo") + val minuteDiff = DateTimeUtil.getATechDateDiferenceAsMinutes(itemOne.atechDateTime, itemTwo!!.atechDateTime) + aapsLogger.debug(LTag.PUMP, "Difference in minutes: $minuteDiff") + minuteDiff } + init { + itemOneTbr = itemOne.getDecodedDataEntry("Object") as TempBasalPair + } + + override fun toString(): String { + return "ItemOne: $itemOne, ItemTwo: $itemTwo, Duration: $duration, Operation: $processOperation" + } + enum class Operation { None, Add, Edit } From 6fd1a8bd8d1e9b760dc06e7abdf25267bdc6eae8 Mon Sep 17 00:00:00 2001 From: Andy Rozman Date: Thu, 10 Jun 2021 18:15:52 +0100 Subject: [PATCH 2/8] - fix for reading history TBR readings (with duration less than minute) --- .../pump/common/utils/DateTimeUtil.java | 9 ++- .../medtronic/data/MedtronicHistoryData.kt | 59 +++++++++++-------- .../medtronic/data/dto/TempBasalProcessDTO.kt | 18 +++--- .../plugins/pump/common/sync/PumpDbEntry.kt | 2 +- .../pump/common/sync/PumpSyncStorage.kt | 2 +- 5 files changed, 53 insertions(+), 37 deletions(-) diff --git a/core/src/main/java/info/nightscout/androidaps/plugins/pump/common/utils/DateTimeUtil.java b/core/src/main/java/info/nightscout/androidaps/plugins/pump/common/utils/DateTimeUtil.java index 32c1d36488..2f37f541a6 100644 --- a/core/src/main/java/info/nightscout/androidaps/plugins/pump/common/utils/DateTimeUtil.java +++ b/core/src/main/java/info/nightscout/androidaps/plugins/pump/common/utils/DateTimeUtil.java @@ -6,6 +6,7 @@ package info.nightscout.androidaps.plugins.pump.common.utils; import org.joda.time.LocalDateTime; import org.joda.time.Minutes; +import org.joda.time.Seconds; import java.util.Calendar; import java.util.GregorianCalendar; @@ -245,13 +246,17 @@ public class DateTimeUtil { public static int getATechDateDiferenceAsMinutes(Long date1, Long date2) { - Minutes minutes = Minutes.minutesBetween(toLocalDateTime(date1), toLocalDateTime(date2)); - return minutes.getMinutes(); } + public static int getATechDateDiferenceAsSeconds(Long date1, Long date2) { + Seconds seconds = Seconds.secondsBetween(toLocalDateTime(date1), toLocalDateTime(date2)); + return seconds.getSeconds(); + } + + public static long getMillisFromATDWithAddedMinutes(long atd, int minutesDiff) { GregorianCalendar oldestEntryTime = DateTimeUtil.toGregorianCalendar(atd); oldestEntryTime.add(Calendar.MINUTE, minutesDiff); diff --git a/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/MedtronicHistoryData.kt b/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/MedtronicHistoryData.kt index bcc090302f..a6d59363bc 100644 --- a/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/MedtronicHistoryData.kt +++ b/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/MedtronicHistoryData.kt @@ -10,6 +10,7 @@ import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.pump.common.defs.PumpType import info.nightscout.androidaps.plugins.pump.common.sync.PumpDbEntry +import info.nightscout.androidaps.plugins.pump.common.sync.PumpDbEntryTBR import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil import info.nightscout.androidaps.plugins.pump.common.utils.StringUtil import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.MedtronicPumpHistoryDecoder @@ -628,12 +629,14 @@ class MedtronicHistoryData @Inject constructor( if (entryWithTempId != null) { if (tbrEntry != null) { - aapsLogger.debug(LTag.PUMP, String.format("DD: tempIdEntry=%s, tbrEntry=%s, tempBasalProcessDTO=%s, pumpType=%s, serial=%s", - gson.toJson(entryWithTempId), gson.toJson(tbrEntry), gson.toJson(tempBasalProcessDTO), medtronicPumpStatus.pumpType, medtronicPumpStatus.serialNumber)) + aapsLogger.debug(LTag.PUMP, "DD: tempIdEntry=${entryWithTempId}, tbrEntry=${tbrEntry}, " + + "tempBasalProcessDTO=${tempBasalProcessDTO}, " + + "pumpType=${medtronicPumpStatus.pumpType}, serial=${medtronicPumpStatus.serialNumber}") - aapsLogger.debug(LTag.PUMP, "BEFORE syncTemporaryBasalWithTempId " + + aapsLogger.debug(LTag.PUMP, "syncTemporaryBasalWithTempId " + "[date=${tempBasalProcessDTO.atechDateTime}, dateProcess=${tryToGetByLocalTime(tempBasalProcessDTO.atechDateTime)}, " + - "tbrEntry.insulinRate=${tbrEntry.insulinRate}, duration=${tempBasalProcessDTO.duration * 60L * 1000L}, " + + "tbrEntry.insulinRate=${tbrEntry.insulinRate}, " + + "duration=${tempBasalProcessDTO.durationAsSeconds} s, " + "isAbsolute=${!tbrEntry.isPercent}, temporaryId=${entryWithTempId.temporaryId}, " + "pumpId=${tempBasalProcessDTO.pumpId}, pumpType=${medtronicPumpStatus.pumpType}, " + "pumpSerial=${medtronicPumpStatus.serialNumber}]") @@ -641,7 +644,7 @@ class MedtronicHistoryData @Inject constructor( val result = pumpSync.syncTemporaryBasalWithTempId( tryToGetByLocalTime(tempBasalProcessDTO.atechDateTime), tbrEntry.insulinRate, - tempBasalProcessDTO.duration * 60L * 1000L, + tempBasalProcessDTO.durationAsSeconds * 1000L, !tbrEntry.isPercent, entryWithTempId.temporaryId, PumpSync.TemporaryBasalType.NORMAL, @@ -649,10 +652,7 @@ class MedtronicHistoryData @Inject constructor( medtronicPumpStatus.pumpType, medtronicPumpStatus.serialNumber) - aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "syncTemporaryBasalWithTempId [date=%d, temporaryId=%d, pumpId=%d, rate=%.2f %s, duration=%d, pumpSerial=%s] - Result: %b", - tempBasalProcessDTO.atechDateTime, entryWithTempId.temporaryId, tempBasalProcessDTO.pumpId, - tbrEntry.insulinRate, (if (tbrEntry.isPercent) "%" else "U"), tempBasalProcessDTO.duration, - medtronicPumpStatus.serialNumber, result)) + aapsLogger.debug(LTag.PUMP, "syncTemporaryBasalWithTempId - Result: ${result}") pumpSyncStorage.removeTemporaryBasalWithTemporaryId(entryWithTempId.temporaryId) tbrRecords.remove(entryWithTempId) @@ -671,20 +671,21 @@ class MedtronicHistoryData @Inject constructor( if (tbrEntry != null) { + aapsLogger.debug(LTag.PUMP, "syncTemporaryBasalWithPumpId [date=${tempBasalProcessDTO.atechDateTime}, " + + "pumpId=${tempBasalProcessDTO.pumpId}, rate=${tbrEntry.insulinRate} U, " + + "duration=${tempBasalProcessDTO.durationAsSeconds} s, pumpSerial=${medtronicPumpStatus.serialNumber}]") + val result = pumpSync.syncTemporaryBasalWithPumpId( tryToGetByLocalTime(tempBasalProcessDTO.atechDateTime), tbrEntry.insulinRate, - tempBasalProcessDTO.duration * 60L * 1000L, + tempBasalProcessDTO.durationAsSeconds * 1000L, !tbrEntry.isPercent, PumpSync.TemporaryBasalType.NORMAL, tempBasalProcessDTO.pumpId, medtronicPumpStatus.pumpType, medtronicPumpStatus.serialNumber) - aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "syncTemporaryBasalWithPumpId [date=%d, pumpId=%d, rate=%.2f %s, duration=%d, pumpSerial=%s] - Result: %b", - tempBasalProcessDTO.atechDateTime, tempBasalProcessDTO.pumpId, - tbrEntry.insulinRate, (if (tbrEntry.isPercent) "%" else "U"), tempBasalProcessDTO.duration, - medtronicPumpStatus.serialNumber, result)) + aapsLogger.debug(LTag.PUMP, "syncTemporaryBasalWithPumpId - Result: $result") if (medtronicPumpStatus.runningTBR != null) { if (!isTBRActive(medtronicPumpStatus.runningTBR!!)) { @@ -692,14 +693,18 @@ class MedtronicHistoryData @Inject constructor( } } - if (isTBRActive(tryToGetByLocalTime(tempBasalProcessDTO.atechDateTime), tempBasalProcessDTO.duration)) { + if (isTBRActive(startTimestamp = tryToGetByLocalTime(tempBasalProcessDTO.atechDateTime), + durationSeconds = tempBasalProcessDTO.durationAsSeconds)) { if (medtronicPumpStatus.runningTBR == null) { medtronicPumpStatus.runningTBR = info.nightscout.androidaps.plugins.pump.common.sync.PumpDbEntry(0L, tryToGetByLocalTime(tempBasalProcessDTO.atechDateTime), medtronicPumpStatus.pumpType, medtronicPumpStatus.serialNumber, null, - info.nightscout.androidaps.plugins.pump.common.sync.PumpDbEntryTBR(tbrEntry.insulinRate, !tbrEntry.isPercent, tempBasalProcessDTO.duration, PumpSync.TemporaryBasalType.NORMAL), + PumpDbEntryTBR(rate = tbrEntry.insulinRate, + isAbsolute = !tbrEntry.isPercent, + durationInSeconds = tempBasalProcessDTO.durationAsSeconds, + tbrType = PumpSync.TemporaryBasalType.NORMAL), tempBasalProcessDTO.pumpId) } } @@ -711,12 +716,14 @@ class MedtronicHistoryData @Inject constructor( } // collection } - fun isTBRActive(dbEntry: info.nightscout.androidaps.plugins.pump.common.sync.PumpDbEntry): Boolean { - return isTBRActive(dbEntry.date, dbEntry.tbrData!!.durationInMinutes) + fun isTBRActive(dbEntry: PumpDbEntry): Boolean { + return isTBRActive( + startTimestamp = dbEntry.date, + durationSeconds = dbEntry.tbrData!!.durationInSeconds) } - fun isTBRActive(startTimestamp: Long, durationMin: Int): Boolean { - val endDate = startTimestamp + (durationMin * 60 * 1000) + fun isTBRActive(startTimestamp: Long, durationSeconds: Int): Boolean { + val endDate = startTimestamp + (durationSeconds * 1000) return (endDate > System.currentTimeMillis()) } @@ -794,20 +801,22 @@ class MedtronicHistoryData @Inject constructor( private fun processSuspends(tempBasalProcessList: List) { for (tempBasalProcess in tempBasalProcessList) { + aapsLogger.debug(LTag.PUMP, "processSuspends::syncTemporaryBasalWithPumpId [date=${tempBasalProcess.itemOne.atechDateTime}, " + + "rate=0.0, duration=${tempBasalProcess.durationAsSeconds} s, type=${PumpSync.TemporaryBasalType.PUMP_SUSPEND}, " + + "pumpId=${tempBasalProcess.itemOne.pumpId}, " + + "pumpSerial=${medtronicPumpStatus.serialNumber}]") + val result = pumpSync.syncTemporaryBasalWithPumpId( tryToGetByLocalTime(tempBasalProcess.itemOne.atechDateTime), 0.0, - tempBasalProcess.duration * 60 * 1000L, + tempBasalProcess.durationAsSeconds * 1000L, true, PumpSync.TemporaryBasalType.PUMP_SUSPEND, tempBasalProcess.itemOne.pumpId, medtronicPumpStatus.pumpType, medtronicPumpStatus.serialNumber) - aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "processSuspends::syncTemporaryBasalWithPumpId [date=%d, rate=%.2f, duration=%d, pumpId=%d, pumpSerial=%s] - Result: %b", - tempBasalProcess.itemOne.atechDateTime, 0.0, tempBasalProcess.duration, tempBasalProcess.itemOne.pumpId, - medtronicPumpStatus.serialNumber, result)) - + aapsLogger.debug(LTag.PUMP, "syncTemporaryBasalWithPumpId: Result: $result") } } diff --git a/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/TempBasalProcessDTO.kt b/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/TempBasalProcessDTO.kt index 04a7983e3c..b121049063 100644 --- a/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/TempBasalProcessDTO.kt +++ b/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/TempBasalProcessDTO.kt @@ -26,20 +26,20 @@ class TempBasalProcessDTO constructor(var itemOne: PumpHistoryEntry, val pumpId: Long get() = itemOne.pumpId - val duration: Int + val durationAsSeconds: Int get() = if (itemTwo == null) { if (itemOneTbr != null) { - aapsLogger.debug("TemporaryBasalPair: $itemOneTbr") - itemOneTbr!!.durationMinutes + aapsLogger.debug("TemporaryBasalPair - itemOneSingle: $itemOneTbr") + itemOneTbr!!.durationMinutes * 60 } else { aapsLogger.error("Couldn't find TempBasalPair in entry: $itemOne") 0 } } else { aapsLogger.debug(LTag.PUMP, "Found 2 items for duration: itemOne=$itemOne, itemTwo=$itemTwo") - val minuteDiff = DateTimeUtil.getATechDateDiferenceAsMinutes(itemOne.atechDateTime, itemTwo!!.atechDateTime) - aapsLogger.debug(LTag.PUMP, "Difference in minutes: $minuteDiff") - minuteDiff + val secondsDiff = DateTimeUtil.getATechDateDiferenceAsSeconds(itemOne.atechDateTime, itemTwo!!.atechDateTime) + aapsLogger.debug(LTag.PUMP, "Difference in seconds: $secondsDiff") + secondsDiff } init { @@ -47,10 +47,12 @@ class TempBasalProcessDTO constructor(var itemOne: PumpHistoryEntry, } override fun toString(): String { - return "ItemOne: $itemOne, ItemTwo: $itemTwo, Duration: $duration, Operation: $processOperation" + return "ItemOne: $itemOne, ItemTwo: $itemTwo, Duration: $durationAsSeconds, Operation: $processOperation" } enum class Operation { - None, Add, Edit + None, + Add, + Edit } } \ No newline at end of file diff --git a/pump-common/src/main/java/info/nightscout/androidaps/plugins/pump/common/sync/PumpDbEntry.kt b/pump-common/src/main/java/info/nightscout/androidaps/plugins/pump/common/sync/PumpDbEntry.kt index e1b734b048..918fc9d3ee 100644 --- a/pump-common/src/main/java/info/nightscout/androidaps/plugins/pump/common/sync/PumpDbEntry.kt +++ b/pump-common/src/main/java/info/nightscout/androidaps/plugins/pump/common/sync/PumpDbEntry.kt @@ -59,5 +59,5 @@ data class PumpDbEntryCarbs(var date: Long, data class PumpDbEntryTBR(var rate: Double, var isAbsolute: Boolean, - var durationInMinutes: Int, + var durationInSeconds: Int, var tbrType: PumpSync.TemporaryBasalType) \ No newline at end of file diff --git a/pump-common/src/main/java/info/nightscout/androidaps/plugins/pump/common/sync/PumpSyncStorage.kt b/pump-common/src/main/java/info/nightscout/androidaps/plugins/pump/common/sync/PumpSyncStorage.kt index 874843015b..5ddddb052b 100644 --- a/pump-common/src/main/java/info/nightscout/androidaps/plugins/pump/common/sync/PumpSyncStorage.kt +++ b/pump-common/src/main/java/info/nightscout/androidaps/plugins/pump/common/sync/PumpSyncStorage.kt @@ -129,7 +129,7 @@ class PumpSyncStorage @Inject constructor( val response = pumpSync.addTemporaryBasalWithTempId( timenow, temporaryBasal.rate, - (temporaryBasal.durationInMinutes * 60L * 1000L), + (temporaryBasal.durationInSeconds * 1000L), temporaryBasal.isAbsolute, temporaryId, temporaryBasal.tbrType, From 95326a2894fcf335ec151d1144054642eb18cee5 Mon Sep 17 00:00:00 2001 From: Andy Rozman Date: Fri, 11 Jun 2021 15:57:14 +0100 Subject: [PATCH 3/8] - storage fix (new key) --- .../plugins/general/maintenance/MaintenancePlugin.kt | 6 +++++- .../plugins/pump/common/sync/PumpSyncStorage.kt | 10 ++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/MaintenancePlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/MaintenancePlugin.kt index cf5c9a6621..7a4b5ffe39 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/MaintenancePlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/MaintenancePlugin.kt @@ -8,8 +8,8 @@ import androidx.preference.PreferenceFragmentCompat import androidx.preference.SwitchPreference import dagger.android.HasAndroidInjector import info.nightscout.androidaps.BuildConfig -import info.nightscout.androidaps.interfaces.Config import info.nightscout.androidaps.R +import info.nightscout.androidaps.interfaces.Config import info.nightscout.androidaps.interfaces.PluginBase import info.nightscout.androidaps.interfaces.PluginDescription import info.nightscout.androidaps.interfaces.PluginType @@ -67,6 +67,10 @@ class MaintenancePlugin @Inject constructor( //todo replace this with a call on startup of the application, specifically to remove // unnecessary garbage from the log exports fun deleteLogs(keep: Int) { + + if (true) + return + val logDir = File(loggerUtils.logDirectory) val files = logDir.listFiles { _: File?, name: String -> (name.startsWith("AndroidAPS") && name.endsWith(".zip")) diff --git a/pump-common/src/main/java/info/nightscout/androidaps/plugins/pump/common/sync/PumpSyncStorage.kt b/pump-common/src/main/java/info/nightscout/androidaps/plugins/pump/common/sync/PumpSyncStorage.kt index 5ddddb052b..6891b04aaf 100644 --- a/pump-common/src/main/java/info/nightscout/androidaps/plugins/pump/common/sync/PumpSyncStorage.kt +++ b/pump-common/src/main/java/info/nightscout/androidaps/plugins/pump/common/sync/PumpSyncStorage.kt @@ -32,6 +32,7 @@ class PumpSyncStorage @Inject constructor( init { initStorage() + cleanOldStorage(); } fun initStorage() { @@ -66,6 +67,15 @@ class PumpSyncStorage @Inject constructor( } } + fun cleanOldStorage(): Unit { + val oldSpKeys = setOf("pump_sync_storage", "pump_sync_storage_xstream") + + for (oldSpKey in oldSpKeys) { + if (sp.contains(oldSpKey)) + sp.remove(oldSpKey) + } + } + fun isStorageEmpty(): Boolean { return pumpSyncStorage[BOLUS]!!.isEmpty() && pumpSyncStorage[TBR]!!.isEmpty() } From 71bedba7eece2e51f6316c63ea047c086ce01f59 Mon Sep 17 00:00:00 2001 From: Andy Rozman Date: Fri, 11 Jun 2021 16:52:38 +0100 Subject: [PATCH 4/8] - storage fix --- .../androidaps/plugins/pump/common/sync/PumpSyncStorage.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pump-common/src/main/java/info/nightscout/androidaps/plugins/pump/common/sync/PumpSyncStorage.kt b/pump-common/src/main/java/info/nightscout/androidaps/plugins/pump/common/sync/PumpSyncStorage.kt index 6891b04aaf..dd4a55dced 100644 --- a/pump-common/src/main/java/info/nightscout/androidaps/plugins/pump/common/sync/PumpSyncStorage.kt +++ b/pump-common/src/main/java/info/nightscout/androidaps/plugins/pump/common/sync/PumpSyncStorage.kt @@ -22,7 +22,7 @@ class PumpSyncStorage @Inject constructor( val aapsLogger: AAPSLogger ) { - val pumpSyncStorageKey: String = "pump_sync_storage_xstream" + val pumpSyncStorageKey: String = "pump_sync_storage_xstream_v2" var pumpSyncStorage: MutableMap> = mutableMapOf() var TBR: String = "TBR" var BOLUS: String = "BOLUS" From b90ce3804fff544aecdcca05b08c2f046f0e6c1a Mon Sep 17 00:00:00 2001 From: Andy Rozman Date: Sun, 13 Jun 2021 14:07:59 +0100 Subject: [PATCH 5/8] - fixing handling of Suspend items --- .../medtronic/data/MedtronicHistoryData.kt | 12 +++-- .../medtronic/data/dto/TempBasalProcessDTO.kt | 49 +++++++++++++------ 2 files changed, 42 insertions(+), 19 deletions(-) diff --git a/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/MedtronicHistoryData.kt b/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/MedtronicHistoryData.kt index a6d59363bc..39b20381fb 100644 --- a/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/MedtronicHistoryData.kt +++ b/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/MedtronicHistoryData.kt @@ -605,7 +605,8 @@ class MedtronicHistoryData @Inject constructor( processDTO = TempBasalProcessDTO( itemOne = treatment, processOperation = TempBasalProcessDTO.Operation.Add, - aapsLogger = aapsLogger + aapsLogger = aapsLogger, + objectType = TempBasalProcessDTO.ObjectType.TemporaryBasal ) } } @@ -875,7 +876,8 @@ class MedtronicHistoryData @Inject constructor( val tbrProcess = TempBasalProcessDTO( itemOne = filtered2Items[i], processOperation = TempBasalProcessDTO.Operation.Add, - aapsLogger = aapsLogger) + aapsLogger = aapsLogger, + objectType = TempBasalProcessDTO.ObjectType.Suspend) tbrProcess.itemTwo = filtered2Items[i + 1] @@ -944,7 +946,8 @@ class MedtronicHistoryData @Inject constructor( val tbrProcess = TempBasalProcessDTO( itemOne = items[items.size - 1], processOperation = TempBasalProcessDTO.Operation.Add, - aapsLogger = aapsLogger) + aapsLogger = aapsLogger, + objectType = TempBasalProcessDTO.ObjectType.Suspend) tbrProcess.itemTwo = itemTwo @@ -957,7 +960,8 @@ class MedtronicHistoryData @Inject constructor( outList.add(TempBasalProcessDTO( itemOne = items[0], processOperation = TempBasalProcessDTO.Operation.Add, - aapsLogger = aapsLogger)) + aapsLogger = aapsLogger, + objectType = TempBasalProcessDTO.ObjectType.Suspend)) return outList } return outList diff --git a/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/TempBasalProcessDTO.kt b/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/TempBasalProcessDTO.kt index b121049063..eb4ba2c5de 100644 --- a/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/TempBasalProcessDTO.kt +++ b/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/TempBasalProcessDTO.kt @@ -7,12 +7,15 @@ import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.PumpH class TempBasalProcessDTO constructor(var itemOne: PumpHistoryEntry, var processOperation: Operation = Operation.None, - var aapsLogger: AAPSLogger) { + var aapsLogger: AAPSLogger, + var objectType: ObjectType = ObjectType.TemporaryBasal) { var itemTwo: PumpHistoryEntry? = null set(value) { field = value - itemTwoTbr = value!!.getDecodedDataEntry("Object") as TempBasalPair + if (objectType == ObjectType.TemporaryBasal) { + itemTwoTbr = value!!.getDecodedDataEntry("Object") as TempBasalPair + } } var itemOneTbr: TempBasalPair? = null @@ -27,27 +30,38 @@ class TempBasalProcessDTO constructor(var itemOne: PumpHistoryEntry, get() = itemOne.pumpId val durationAsSeconds: Int - get() = if (itemTwo == null) { - if (itemOneTbr != null) { - aapsLogger.debug("TemporaryBasalPair - itemOneSingle: $itemOneTbr") - itemOneTbr!!.durationMinutes * 60 + get() { + if (objectType == ObjectType.TemporaryBasal) { + if (itemTwo == null) { + if (itemOneTbr != null) { + aapsLogger.debug("TemporaryBasalPair - itemOneSingle: $itemOneTbr") + return itemOneTbr!!.durationMinutes * 60 + } else { + aapsLogger.error("Couldn't find TempBasalPair in entry: $itemOne") + return 0 + } + } else { + aapsLogger.debug(LTag.PUMP, "Found 2 items for duration: itemOne=$itemOne, itemTwo=$itemTwo") + val secondsDiff = DateTimeUtil.getATechDateDiferenceAsSeconds(itemOne.atechDateTime, itemTwo!!.atechDateTime) + aapsLogger.debug(LTag.PUMP, "Difference in seconds: $secondsDiff") + return secondsDiff + } } else { - aapsLogger.error("Couldn't find TempBasalPair in entry: $itemOne") - 0 + aapsLogger.debug(LTag.PUMP, "Found 2 items for duration (in SuspendMode): itemOne=$itemOne, itemTwo=$itemTwo") + val secondsDiff = DateTimeUtil.getATechDateDiferenceAsSeconds(itemOne.atechDateTime, itemTwo!!.atechDateTime) + aapsLogger.debug(LTag.PUMP, "Difference in seconds: $secondsDiff") + return secondsDiff } - } else { - aapsLogger.debug(LTag.PUMP, "Found 2 items for duration: itemOne=$itemOne, itemTwo=$itemTwo") - val secondsDiff = DateTimeUtil.getATechDateDiferenceAsSeconds(itemOne.atechDateTime, itemTwo!!.atechDateTime) - aapsLogger.debug(LTag.PUMP, "Difference in seconds: $secondsDiff") - secondsDiff } init { - itemOneTbr = itemOne.getDecodedDataEntry("Object") as TempBasalPair + if (objectType == ObjectType.TemporaryBasal) { + itemOneTbr = itemOne.getDecodedDataEntry("Object") as TempBasalPair + } } override fun toString(): String { - return "ItemOne: $itemOne, ItemTwo: $itemTwo, Duration: $durationAsSeconds, Operation: $processOperation" + return "ItemOne: $itemOne, ItemTwo: $itemTwo, Duration: $durationAsSeconds, Operation: $processOperation, ObjectType: $objectType" } enum class Operation { @@ -55,4 +69,9 @@ class TempBasalProcessDTO constructor(var itemOne: PumpHistoryEntry, Add, Edit } + + enum class ObjectType { + TemporaryBasal, + Suspend, + } } \ No newline at end of file From cc172e8d0f1e11dc10974c37692d6aabbd6c696b Mon Sep 17 00:00:00 2001 From: Andy Rozman Date: Fri, 18 Jun 2021 10:44:46 +0100 Subject: [PATCH 6/8] - added additional log line --- .../plugins/pump/medtronic/data/dto/TempBasalProcessDTO.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/TempBasalProcessDTO.kt b/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/TempBasalProcessDTO.kt index eb4ba2c5de..a0ce5241de 100644 --- a/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/TempBasalProcessDTO.kt +++ b/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/TempBasalProcessDTO.kt @@ -31,6 +31,7 @@ class TempBasalProcessDTO constructor(var itemOne: PumpHistoryEntry, val durationAsSeconds: Int get() { + aapsLogger.debug(LTag.PUMP, "durationAsSeconds: [objectType=$objectType]") if (objectType == ObjectType.TemporaryBasal) { if (itemTwo == null) { if (itemOneTbr != null) { From c8d11c375a5c5899d83b7a532f9d5b8f597f2b88 Mon Sep 17 00:00:00 2001 From: Andy Rozman Date: Sat, 26 Jun 2021 17:12:03 +0100 Subject: [PATCH 7/8] - problem with evaluating Rewing/NoDelivery records --- .../medtronic/data/MedtronicHistoryData.kt | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/MedtronicHistoryData.kt b/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/MedtronicHistoryData.kt index 39b20381fb..e558a22f88 100644 --- a/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/MedtronicHistoryData.kt +++ b/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/MedtronicHistoryData.kt @@ -349,7 +349,7 @@ class MedtronicHistoryData @Inject constructor( aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "ProcessHistoryData: TBRs Processed [count=%d, items=%s]", tbrs.size, gson.toJson(tbrs))) if (tbrs.isNotEmpty()) { try { - processTBREntries(tbrs) // TODO not implemented yet + processTBREntries(tbrs) } catch (ex: Exception) { aapsLogger.error(LTag.PUMP, "ProcessHistoryData: Error processing TBR entries: " + ex.message, ex) throw ex @@ -836,6 +836,9 @@ class MedtronicHistoryData @Inject constructor( private fun getSuspendResumeRecordsList(): List { val filteredItems = getFilteredItems(newHistory, // setOf(PumpHistoryEntryType.SuspendPump, PumpHistoryEntryType.ResumePump)) + + aapsLogger.debug(LTag.PUMP, "SuspendResume Records: $filteredItems") + val outList: MutableList = mutableListOf() if (filteredItems.size > 0) { val filtered2Items: MutableList = mutableListOf() @@ -881,7 +884,8 @@ class MedtronicHistoryData @Inject constructor( tbrProcess.itemTwo = filtered2Items[i + 1] - outList.add(tbrProcess) + if (tbrProcess.itemTwo != null) + outList.add(tbrProcess) i += 2 } @@ -893,6 +897,9 @@ class MedtronicHistoryData @Inject constructor( private fun getNoDeliveryRewindPrimeRecordsList(): List { val primeItems: MutableList = getFilteredItems(newHistory, // setOf(PumpHistoryEntryType.Prime)) + + aapsLogger.debug(LTag.PUMP, "Prime Records: $primeItems") + val outList: MutableList = ArrayList() if (primeItems.size == 0) return outList val filteredItems: MutableList = getFilteredItems(newHistory, // @@ -902,6 +909,9 @@ class MedtronicHistoryData @Inject constructor( PumpHistoryEntryType.Bolus, PumpHistoryEntryType.TempBasalCombined) ) + + aapsLogger.debug(LTag.PUMP, "Filtered Records: $filteredItems") + val tempData: MutableList = mutableListOf() var startedItems = false var finishedItems = false @@ -940,7 +950,8 @@ class MedtronicHistoryData @Inject constructor( } showLogs("NoDeliveryRewindPrimeRecords: Records to evaluate: ", gson.toJson(tempData)) var items: MutableList = getFilteredItems(tempData, PumpHistoryEntryType.Prime) - var itemTwo = items[0] + val itemTwo = items[0] + items = getFilteredItems(tempData, PumpHistoryEntryType.NoDeliveryAlarm) if (items.size > 0) { val tbrProcess = TempBasalProcessDTO( @@ -951,19 +962,28 @@ class MedtronicHistoryData @Inject constructor( tbrProcess.itemTwo = itemTwo - outList.add(tbrProcess) + if (tbrProcess.itemTwo != null) + outList.add(tbrProcess) return outList } + items = getFilteredItems(tempData, PumpHistoryEntryType.Rewind) if (items.size > 0) { - outList.add(TempBasalProcessDTO( + val tbrProcess = TempBasalProcessDTO( itemOne = items[0], processOperation = TempBasalProcessDTO.Operation.Add, aapsLogger = aapsLogger, - objectType = TempBasalProcessDTO.ObjectType.Suspend)) + objectType = TempBasalProcessDTO.ObjectType.Suspend) + + tbrProcess.itemTwo = itemTwo + + if (tbrProcess.itemTwo != null) + outList.add(tbrProcess) + return outList } + return outList } From d5a8838cabbdcc0ea210e1125dcb56e8db91c231 Mon Sep 17 00:00:00 2001 From: Andy Rozman Date: Sat, 26 Jun 2021 22:00:29 +0100 Subject: [PATCH 8/8] - changed/reverted change --- .../general/maintenance/MaintenancePlugin.kt | 40 ++++++++++--------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/MaintenancePlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/MaintenancePlugin.kt index edb5b68621..deb2d9e7e8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/MaintenancePlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/MaintenancePlugin.kt @@ -37,16 +37,17 @@ class MaintenancePlugin @Inject constructor( private val config: Config, private val fileListProvider: PrefFileListProvider, private val loggerUtils: LoggerUtils -) : PluginBase(PluginDescription() - .mainType(PluginType.GENERAL) - .fragmentClass(MaintenanceFragment::class.java.name) - .alwaysVisible(false) - .alwaysEnabled(true) - .pluginIcon(R.drawable.ic_maintenance) - .pluginName(R.string.maintenance) - .shortName(R.string.maintenance_shortname) - .preferencesId(R.xml.pref_maintenance) - .description(R.string.description_maintenance), +) : PluginBase( + PluginDescription() + .mainType(PluginType.GENERAL) + .fragmentClass(MaintenanceFragment::class.java.name) + .alwaysVisible(false) + .alwaysEnabled(true) + .pluginIcon(R.drawable.ic_maintenance) + .pluginName(R.string.maintenance) + .shortName(R.string.maintenance_shortname) + .preferencesId(R.xml.pref_maintenance) + .description(R.string.description_maintenance), aapsLogger, resourceHelper, injector ) { @@ -58,7 +59,8 @@ class MaintenancePlugin @Inject constructor( val zipFile = File(zipDir, constructName()) aapsLogger.debug("zipFile: ${zipFile.absolutePath}") val zip = zipLogs(zipFile, logs) - val attachmentUri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID + ".fileprovider", zip) + val attachmentUri = + FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID + ".fileprovider", zip) val emailIntent: Intent = this.sendMail(attachmentUri, recipient, "Log Export") aapsLogger.debug("sending emailIntent") context.startActivity(emailIntent) @@ -67,10 +69,6 @@ class MaintenancePlugin @Inject constructor( //todo replace this with a call on startup of the application, specifically to remove // unnecessary garbage from the log exports fun deleteLogs(keep: Int) { - - if (true) - return - val logDir = File(loggerUtils.logDirectory) val files = logDir.listFiles { _: File?, name: String -> (name.startsWith("AndroidAPS") && name.endsWith(".zip")) @@ -197,7 +195,12 @@ class MaintenancePlugin @Inject constructor( * * @return */ - private fun sendMail(attachmentUri: Uri, recipient: String, subject: String, body: String): Intent { + private fun sendMail( + attachmentUri: Uri, + recipient: String, + subject: String, + body: String + ): Intent { aapsLogger.debug("sending email to $recipient with subject $subject") val emailIntent = Intent(Intent.ACTION_SEND) emailIntent.type = "text/plain" @@ -212,8 +215,9 @@ class MaintenancePlugin @Inject constructor( override fun preprocessPreferences(preferenceFragment: PreferenceFragmentCompat) { super.preprocessPreferences(preferenceFragment) - val encryptSwitch = preferenceFragment.findPreference(resourceHelper.gs(R.string.key_maintenance_encrypt_exported_prefs)) as SwitchPreference? - ?: return + val encryptSwitch = + preferenceFragment.findPreference(resourceHelper.gs(R.string.key_maintenance_encrypt_exported_prefs)) as SwitchPreference? + ?: return encryptSwitch.isVisible = buildHelper.isEngineeringMode() encryptSwitch.isEnabled = buildHelper.isEngineeringMode() }