- added two special cases when processing list - createTBRProcessList:

- if changed duration is 0 or less, we remove the entry
    - if previously added item makes duration longer than original one, then we use the original duration
This commit is contained in:
Andy Rozman 2022-01-10 22:46:15 +00:00
parent 7243f8fb66
commit 47d0663cf7
4 changed files with 1156 additions and 1 deletions

View file

@ -759,6 +759,7 @@ class MedtronicHistoryData @Inject constructor(
} }
var previousItem: TempBasalProcessDTO? = null var previousItem: TempBasalProcessDTO? = null
val removalList : MutableList<TempBasalProcessDTO> = arrayListOf()
// fix for Zero TBRs // fix for Zero TBRs
for (tempBasalProcessDTO in processList) { for (tempBasalProcessDTO in processList) {
@ -768,8 +769,18 @@ class MedtronicHistoryData @Inject constructor(
pheEnd.atechDateTime = DateTimeUtil.getATDWithAddedSeconds(tempBasalProcessDTO.itemOne.atechDateTime, -2) pheEnd.atechDateTime = DateTimeUtil.getATDWithAddedSeconds(tempBasalProcessDTO.itemOne.atechDateTime, -2)
pheEnd.addDecodedData("Object", TempBasalPair(0.0, false, 0)) pheEnd.addDecodedData("Object", TempBasalPair(0.0, false, 0))
var initialDuration = previousItem.durationAsSeconds
previousItem.itemTwo = pheEnd previousItem.itemTwo = pheEnd
if (previousItem.durationAsSeconds <=0) {
// if we have duration of 0 or less, then we have invalid entry which needs to be removed
removalList.add(previousItem)
} else if (previousItem.durationAsSeconds > initialDuration) {
// if duration with last item is longer than planned TBR duration we remove previous item and leave original duration
previousItem.itemTwo = null
}
previousItem = null previousItem = null
} }
if (tempBasalProcessDTO.itemOneTbr!!.isZeroTBR) { if (tempBasalProcessDTO.itemOneTbr!!.isZeroTBR) {
@ -777,6 +788,13 @@ class MedtronicHistoryData @Inject constructor(
} }
} }
// removing previously tagged item
if (removalList.isNotEmpty()) {
for (tempBasalProcessDTO in removalList) {
processList.remove(tempBasalProcessDTO)
}
}
return processList return processList
} }

View file

@ -12,7 +12,11 @@ class TempBasalProcessDTO constructor(var itemOne: PumpHistoryEntry,
set(value) { set(value) {
field = value field = value
if (objectType == ObjectType.TemporaryBasal) { if (objectType == ObjectType.TemporaryBasal) {
itemTwoTbr = value!!.getDecodedDataEntry("Object") as TempBasalPair if (value!=null) {
itemTwoTbr = value.getDecodedDataEntry("Object") as TempBasalPair
} else {
itemTwoTbr = null
}
} }
} }

View file

@ -86,4 +86,47 @@ class MedtronicHistoryDataUTest : TestBase() {
} }
@Test
fun createTBRProcessList_SpecialCase() {
var unitToTest = MedtronicHistoryData(packetInjector, aapsLogger, sp, rh, rxBus, activePlugin,
medtronicUtil, medtronicPumpHistoryDecoder,
medtronicPumpStatus,
pumpSync,
pumpSyncStorage)
val gson = Gson()
val fileText = ClassLoader.getSystemResource("tbr_data_special.json").readText()
val listType: Type = object : TypeToken<MutableList<PumpHistoryEntry?>?>() {}.getType()
val yourClassList: MutableList<PumpHistoryEntry> = gson.fromJson(fileText, listType)
for (pumpHistoryEntry in yourClassList) {
val stringObject = pumpHistoryEntry.decodedData["Object"] as LinkedTreeMap<String,Object>
val rate : Double = stringObject.get("insulinRate") as Double
val durationMinutes: Double = stringObject.get("durationMinutes") as Double
val durationMinutesInt : Int = durationMinutes.toInt()
var tmbPair = TempBasalPair(rate, false, durationMinutesInt)
pumpHistoryEntry.decodedData.remove("Object")
pumpHistoryEntry.addDecodedData("Object", tmbPair)
}
System.out.println("TBR Pre-Process List (Special): " + gson.toJson(yourClassList))
val createTBRProcessList = unitToTest.createTBRProcessList(yourClassList)
System.out.println("TBR Process List (Special): " + createTBRProcessList.size)
for (tempBasalProcessDTO in createTBRProcessList) {
System.out.println(tempBasalProcessDTO.toTreatmentString())
}
}
} }

File diff suppressed because it is too large Load diff