- refactoring TempBasalProcess

- changed some logging
This commit is contained in:
Andy Rozman 2021-06-08 22:31:15 +01:00
parent 6c81770c4d
commit ee5413ed06
2 changed files with 105 additions and 67 deletions

View file

@ -615,17 +615,19 @@ 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) {
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))
@ -661,8 +663,14 @@ class MedtronicHistoryData @Inject constructor(
if (isTBRActive(entryWithTempId)) {
medtronicPumpStatus.runningTBR = entryWithTempId
}
} else {
aapsLogger.warn(LTag.PUMP, "tbrEntry (itemOne) is null, shouldn't be.")
}
} else {
if (tbrEntry != null) {
val result = pumpSync.syncTemporaryBasalWithPumpId(
tryToGetByLocalTime(tempBasalProcessDTO.atechDateTime),
tbrEntry.insulinRate,
@ -695,6 +703,9 @@ class MedtronicHistoryData @Inject constructor(
tempBasalProcessDTO.pumpId)
}
}
} else {
aapsLogger.warn(LTag.PUMP, "tbrEntry (itemOne) is null, shouldn't be.")
}
}
} // for
} // collection
@ -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)

View file

@ -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,15 +28,26 @@ 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 {