- fixing handling of Suspend items

This commit is contained in:
Andy Rozman 2021-06-13 14:07:59 +01:00
parent 71bedba7ee
commit b90ce3804f
2 changed files with 42 additions and 19 deletions

View file

@ -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

View file

@ -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,
}
}