- refactoring TempBasalProcess
- changed some logging
This commit is contained in:
parent
6c81770c4d
commit
ee5413ed06
2 changed files with 105 additions and 67 deletions
|
@ -615,85 +615,96 @@ class MedtronicHistoryData @Inject constructor(
|
||||||
for (tempBasalProcessDTO in processList) {
|
for (tempBasalProcessDTO in processList) {
|
||||||
|
|
||||||
aapsLogger.debug(LTag.PUMP, "DD: tempBasalProcessDTO.itemOne: " + gson.toJson(tempBasalProcessDTO.itemOne))
|
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)
|
val entryWithTempId = findDbEntry(tempBasalProcessDTO.itemOne, tbrRecords)
|
||||||
|
|
||||||
aapsLogger.debug(LTag.PUMP, "DD: entryWithTempId: " + (if (entryWithTempId == null) "null" else entryWithTempId.toString()))
|
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)))
|
aapsLogger.debug(LTag.PUMP, String.format("DD: tbrEntry=%s, tempBasalProcessDTO=%s", gson.toJson(tbrEntry), gson.toJson(tempBasalProcessDTO)))
|
||||||
|
|
||||||
if (entryWithTempId != null) {
|
if (entryWithTempId != null) {
|
||||||
|
|
||||||
aapsLogger.debug(LTag.PUMP, String.format("DD: tempIdEntry=%s, tbrEntry=%s, tempBasalProcessDTO=%s, pumpType=%s, serial=%s",
|
if (tbrEntry != null) {
|
||||||
gson.toJson(entryWithTempId), gson.toJson(tbrEntry), gson.toJson(tempBasalProcessDTO), medtronicPumpStatus.pumpType, medtronicPumpStatus.serialNumber))
|
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 " +
|
aapsLogger.debug(LTag.PUMP, "BEFORE syncTemporaryBasalWithTempId " +
|
||||||
"[date=${tempBasalProcessDTO.atechDateTime}, dateProcess=${tryToGetByLocalTime(tempBasalProcessDTO.atechDateTime)}, " +
|
"[date=${tempBasalProcessDTO.atechDateTime}, dateProcess=${tryToGetByLocalTime(tempBasalProcessDTO.atechDateTime)}, " +
|
||||||
"tbrEntry.insulinRate=${tbrEntry.insulinRate}, duration=${tempBasalProcessDTO.duration * 60L * 1000L}, " +
|
"tbrEntry.insulinRate=${tbrEntry.insulinRate}, duration=${tempBasalProcessDTO.duration * 60L * 1000L}, " +
|
||||||
"isAbsolute=${!tbrEntry.isPercent}, temporaryId=${entryWithTempId.temporaryId}, " +
|
"isAbsolute=${!tbrEntry.isPercent}, temporaryId=${entryWithTempId.temporaryId}, " +
|
||||||
"pumpId=${tempBasalProcessDTO.pumpId}, pumpType=${medtronicPumpStatus.pumpType}, " +
|
"pumpId=${tempBasalProcessDTO.pumpId}, pumpType=${medtronicPumpStatus.pumpType}, " +
|
||||||
"pumpSerial=${medtronicPumpStatus.serialNumber}]")
|
"pumpSerial=${medtronicPumpStatus.serialNumber}]")
|
||||||
|
|
||||||
val result = pumpSync.syncTemporaryBasalWithTempId(
|
val result = pumpSync.syncTemporaryBasalWithTempId(
|
||||||
tryToGetByLocalTime(tempBasalProcessDTO.atechDateTime),
|
tryToGetByLocalTime(tempBasalProcessDTO.atechDateTime),
|
||||||
tbrEntry.insulinRate,
|
tbrEntry.insulinRate,
|
||||||
tempBasalProcessDTO.duration * 60L * 1000L,
|
tempBasalProcessDTO.duration * 60L * 1000L,
|
||||||
!tbrEntry.isPercent,
|
!tbrEntry.isPercent,
|
||||||
entryWithTempId.temporaryId,
|
entryWithTempId.temporaryId,
|
||||||
PumpSync.TemporaryBasalType.NORMAL,
|
PumpSync.TemporaryBasalType.NORMAL,
|
||||||
tempBasalProcessDTO.pumpId,
|
tempBasalProcessDTO.pumpId,
|
||||||
medtronicPumpStatus.pumpType,
|
medtronicPumpStatus.pumpType,
|
||||||
medtronicPumpStatus.serialNumber)
|
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",
|
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,
|
tempBasalProcessDTO.atechDateTime, entryWithTempId.temporaryId, tempBasalProcessDTO.pumpId,
|
||||||
tbrEntry.insulinRate, (if (tbrEntry.isPercent) "%" else "U"), tempBasalProcessDTO.duration,
|
tbrEntry.insulinRate, (if (tbrEntry.isPercent) "%" else "U"), tempBasalProcessDTO.duration,
|
||||||
medtronicPumpStatus.serialNumber, result))
|
medtronicPumpStatus.serialNumber, result))
|
||||||
|
|
||||||
pumpSyncStorage.removeTemporaryBasalWithTemporaryId(entryWithTempId.temporaryId)
|
pumpSyncStorage.removeTemporaryBasalWithTemporaryId(entryWithTempId.temporaryId)
|
||||||
tbrRecords.remove(entryWithTempId)
|
tbrRecords.remove(entryWithTempId)
|
||||||
|
|
||||||
entryWithTempId.pumpId = tempBasalProcessDTO.pumpId
|
entryWithTempId.pumpId = tempBasalProcessDTO.pumpId
|
||||||
entryWithTempId.date = tryToGetByLocalTime(tempBasalProcessDTO.atechDateTime)
|
entryWithTempId.date = tryToGetByLocalTime(tempBasalProcessDTO.atechDateTime)
|
||||||
|
|
||||||
if (isTBRActive(entryWithTempId)) {
|
if (isTBRActive(entryWithTempId)) {
|
||||||
medtronicPumpStatus.runningTBR = entryWithTempId
|
medtronicPumpStatus.runningTBR = entryWithTempId
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
aapsLogger.warn(LTag.PUMP, "tbrEntry (itemOne) is null, shouldn't be.")
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} 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",
|
if (tbrEntry != null) {
|
||||||
tempBasalProcessDTO.atechDateTime, tempBasalProcessDTO.pumpId,
|
|
||||||
tbrEntry.insulinRate, (if (tbrEntry.isPercent) "%" else "U"), tempBasalProcessDTO.duration,
|
|
||||||
medtronicPumpStatus.serialNumber, result))
|
|
||||||
|
|
||||||
if (medtronicPumpStatus.runningTBR != null) {
|
val result = pumpSync.syncTemporaryBasalWithPumpId(
|
||||||
if (!isTBRActive(medtronicPumpStatus.runningTBR!!)) {
|
tryToGetByLocalTime(tempBasalProcessDTO.atechDateTime),
|
||||||
medtronicPumpStatus.runningTBR = null
|
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 (isTBRActive(tryToGetByLocalTime(tempBasalProcessDTO.atechDateTime), tempBasalProcessDTO.duration)) {
|
||||||
if (medtronicPumpStatus.runningTBR == null) {
|
if (medtronicPumpStatus.runningTBR == null) {
|
||||||
medtronicPumpStatus.runningTBR = info.nightscout.androidaps.plugins.pump.common.sync.PumpDbEntry(0L,
|
medtronicPumpStatus.runningTBR = info.nightscout.androidaps.plugins.pump.common.sync.PumpDbEntry(0L,
|
||||||
tryToGetByLocalTime(tempBasalProcessDTO.atechDateTime),
|
tryToGetByLocalTime(tempBasalProcessDTO.atechDateTime),
|
||||||
medtronicPumpStatus.pumpType,
|
medtronicPumpStatus.pumpType,
|
||||||
medtronicPumpStatus.serialNumber,
|
medtronicPumpStatus.serialNumber,
|
||||||
null,
|
null,
|
||||||
info.nightscout.androidaps.plugins.pump.common.sync.PumpDbEntryTBR(tbrEntry.insulinRate, !tbrEntry.isPercent, tempBasalProcessDTO.duration, PumpSync.TemporaryBasalType.NORMAL),
|
info.nightscout.androidaps.plugins.pump.common.sync.PumpDbEntryTBR(tbrEntry.insulinRate, !tbrEntry.isPercent, tempBasalProcessDTO.duration, PumpSync.TemporaryBasalType.NORMAL),
|
||||||
tempBasalProcessDTO.pumpId)
|
tempBasalProcessDTO.pumpId)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
aapsLogger.warn(LTag.PUMP, "tbrEntry (itemOne) is null, shouldn't be.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // for
|
} // for
|
||||||
|
@ -852,11 +863,14 @@ class MedtronicHistoryData @Inject constructor(
|
||||||
Collections.reverse(filtered2Items)
|
Collections.reverse(filtered2Items)
|
||||||
var i = 0
|
var i = 0
|
||||||
while (i < filtered2Items.size) {
|
while (i < filtered2Items.size) {
|
||||||
outList.add(TempBasalProcessDTO(
|
val tbrProcess = TempBasalProcessDTO(
|
||||||
itemOne = filtered2Items[i],
|
itemOne = filtered2Items[i],
|
||||||
itemTwo = filtered2Items[i + 1],
|
|
||||||
processOperation = TempBasalProcessDTO.Operation.Add,
|
processOperation = TempBasalProcessDTO.Operation.Add,
|
||||||
aapsLogger = aapsLogger))
|
aapsLogger = aapsLogger)
|
||||||
|
|
||||||
|
tbrProcess.itemTwo = filtered2Items[i + 1]
|
||||||
|
|
||||||
|
outList.add(tbrProcess)
|
||||||
|
|
||||||
i += 2
|
i += 2
|
||||||
}
|
}
|
||||||
|
@ -918,11 +932,15 @@ class MedtronicHistoryData @Inject constructor(
|
||||||
var itemTwo = items[0]
|
var itemTwo = items[0]
|
||||||
items = getFilteredItems(tempData, PumpHistoryEntryType.NoDeliveryAlarm)
|
items = getFilteredItems(tempData, PumpHistoryEntryType.NoDeliveryAlarm)
|
||||||
if (items.size > 0) {
|
if (items.size > 0) {
|
||||||
outList.add(TempBasalProcessDTO(
|
val tbrProcess = TempBasalProcessDTO(
|
||||||
itemOne = items[items.size - 1],
|
itemOne = items[items.size - 1],
|
||||||
itemTwo = itemTwo,
|
|
||||||
processOperation = TempBasalProcessDTO.Operation.Add,
|
processOperation = TempBasalProcessDTO.Operation.Add,
|
||||||
aapsLogger = aapsLogger))
|
aapsLogger = aapsLogger)
|
||||||
|
|
||||||
|
tbrProcess.itemTwo = itemTwo
|
||||||
|
|
||||||
|
outList.add(tbrProcess)
|
||||||
|
|
||||||
return outList
|
return outList
|
||||||
}
|
}
|
||||||
items = getFilteredItems(tempData, PumpHistoryEntryType.Rewind)
|
items = getFilteredItems(tempData, PumpHistoryEntryType.Rewind)
|
||||||
|
|
|
@ -1,14 +1,23 @@
|
||||||
package info.nightscout.androidaps.plugins.pump.medtronic.data.dto
|
package info.nightscout.androidaps.plugins.pump.medtronic.data.dto
|
||||||
|
|
||||||
import info.nightscout.androidaps.logging.AAPSLogger
|
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.common.utils.DateTimeUtil
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.PumpHistoryEntry
|
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.PumpHistoryEntry
|
||||||
|
|
||||||
class TempBasalProcessDTO constructor(var itemOne: PumpHistoryEntry,
|
class TempBasalProcessDTO constructor(var itemOne: PumpHistoryEntry,
|
||||||
var itemTwo: PumpHistoryEntry? = null,
|
|
||||||
var processOperation: Operation = Operation.None,
|
var processOperation: Operation = Operation.None,
|
||||||
var aapsLogger: AAPSLogger) {
|
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
|
var cancelPresent: Boolean = false
|
||||||
|
|
||||||
val atechDateTime: Long
|
val atechDateTime: Long
|
||||||
|
@ -19,17 +28,28 @@ class TempBasalProcessDTO constructor(var itemOne: PumpHistoryEntry,
|
||||||
|
|
||||||
val duration: Int
|
val duration: Int
|
||||||
get() = if (itemTwo == null) {
|
get() = if (itemTwo == null) {
|
||||||
val tbr = itemOne.getDecodedDataEntry("Object") as? TempBasalPair
|
if (itemOneTbr != null) {
|
||||||
if (tbr != null)
|
aapsLogger.debug("TemporaryBasalPair: $itemOneTbr")
|
||||||
tbr.durationMinutes
|
itemOneTbr!!.durationMinutes
|
||||||
else {
|
} else {
|
||||||
aapsLogger.error("Couldn't find TempBasalPair in entry: $itemOne")
|
aapsLogger.error("Couldn't find TempBasalPair in entry: $itemOne")
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
} else {
|
} 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 {
|
enum class Operation {
|
||||||
None, Add, Edit
|
None, Add, Edit
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue