- 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( processDTO = TempBasalProcessDTO(
itemOne = treatment, itemOne = treatment,
processOperation = TempBasalProcessDTO.Operation.Add, processOperation = TempBasalProcessDTO.Operation.Add,
aapsLogger = aapsLogger aapsLogger = aapsLogger,
objectType = TempBasalProcessDTO.ObjectType.TemporaryBasal
) )
} }
} }
@ -875,7 +876,8 @@ class MedtronicHistoryData @Inject constructor(
val tbrProcess = TempBasalProcessDTO( val tbrProcess = TempBasalProcessDTO(
itemOne = filtered2Items[i], itemOne = filtered2Items[i],
processOperation = TempBasalProcessDTO.Operation.Add, processOperation = TempBasalProcessDTO.Operation.Add,
aapsLogger = aapsLogger) aapsLogger = aapsLogger,
objectType = TempBasalProcessDTO.ObjectType.Suspend)
tbrProcess.itemTwo = filtered2Items[i + 1] tbrProcess.itemTwo = filtered2Items[i + 1]
@ -944,7 +946,8 @@ class MedtronicHistoryData @Inject constructor(
val tbrProcess = TempBasalProcessDTO( val tbrProcess = TempBasalProcessDTO(
itemOne = items[items.size - 1], itemOne = items[items.size - 1],
processOperation = TempBasalProcessDTO.Operation.Add, processOperation = TempBasalProcessDTO.Operation.Add,
aapsLogger = aapsLogger) aapsLogger = aapsLogger,
objectType = TempBasalProcessDTO.ObjectType.Suspend)
tbrProcess.itemTwo = itemTwo tbrProcess.itemTwo = itemTwo
@ -957,7 +960,8 @@ class MedtronicHistoryData @Inject constructor(
outList.add(TempBasalProcessDTO( outList.add(TempBasalProcessDTO(
itemOne = items[0], itemOne = items[0],
processOperation = TempBasalProcessDTO.Operation.Add, processOperation = TempBasalProcessDTO.Operation.Add,
aapsLogger = aapsLogger)) aapsLogger = aapsLogger,
objectType = TempBasalProcessDTO.ObjectType.Suspend))
return outList return outList
} }
return outList return outList

View file

@ -7,13 +7,16 @@ import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.PumpH
class TempBasalProcessDTO constructor(var itemOne: PumpHistoryEntry, class TempBasalProcessDTO constructor(var itemOne: PumpHistoryEntry,
var processOperation: Operation = Operation.None, var processOperation: Operation = Operation.None,
var aapsLogger: AAPSLogger) { var aapsLogger: AAPSLogger,
var objectType: ObjectType = ObjectType.TemporaryBasal) {
var itemTwo: PumpHistoryEntry? = null var itemTwo: PumpHistoryEntry? = null
set(value) { set(value) {
field = value field = value
if (objectType == ObjectType.TemporaryBasal) {
itemTwoTbr = value!!.getDecodedDataEntry("Object") as TempBasalPair itemTwoTbr = value!!.getDecodedDataEntry("Object") as TempBasalPair
} }
}
var itemOneTbr: TempBasalPair? = null var itemOneTbr: TempBasalPair? = null
var itemTwoTbr: TempBasalPair? = null var itemTwoTbr: TempBasalPair? = null
@ -27,27 +30,38 @@ class TempBasalProcessDTO constructor(var itemOne: PumpHistoryEntry,
get() = itemOne.pumpId get() = itemOne.pumpId
val durationAsSeconds: Int val durationAsSeconds: Int
get() = if (itemTwo == null) { get() {
if (objectType == ObjectType.TemporaryBasal) {
if (itemTwo == null) {
if (itemOneTbr != null) { if (itemOneTbr != null) {
aapsLogger.debug("TemporaryBasalPair - itemOneSingle: $itemOneTbr") aapsLogger.debug("TemporaryBasalPair - itemOneSingle: $itemOneTbr")
itemOneTbr!!.durationMinutes * 60 return itemOneTbr!!.durationMinutes * 60
} else { } else {
aapsLogger.error("Couldn't find TempBasalPair in entry: $itemOne") aapsLogger.error("Couldn't find TempBasalPair in entry: $itemOne")
0 return 0
} }
} else { } else {
aapsLogger.debug(LTag.PUMP, "Found 2 items for duration: itemOne=$itemOne, itemTwo=$itemTwo") aapsLogger.debug(LTag.PUMP, "Found 2 items for duration: itemOne=$itemOne, itemTwo=$itemTwo")
val secondsDiff = DateTimeUtil.getATechDateDiferenceAsSeconds(itemOne.atechDateTime, itemTwo!!.atechDateTime) val secondsDiff = DateTimeUtil.getATechDateDiferenceAsSeconds(itemOne.atechDateTime, itemTwo!!.atechDateTime)
aapsLogger.debug(LTag.PUMP, "Difference in seconds: $secondsDiff") aapsLogger.debug(LTag.PUMP, "Difference in seconds: $secondsDiff")
secondsDiff return secondsDiff
}
} else {
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
}
} }
init { init {
if (objectType == ObjectType.TemporaryBasal) {
itemOneTbr = itemOne.getDecodedDataEntry("Object") as TempBasalPair itemOneTbr = itemOne.getDecodedDataEntry("Object") as TempBasalPair
} }
}
override fun toString(): String { 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 { enum class Operation {
@ -55,4 +69,9 @@ class TempBasalProcessDTO constructor(var itemOne: PumpHistoryEntry,
Add, Add,
Edit Edit
} }
enum class ObjectType {
TemporaryBasal,
Suspend,
}
} }