From 2b610e16e4dfb55be4421ca5b14d732f4e636ab8 Mon Sep 17 00:00:00 2001 From: Andy Rozman Date: Fri, 24 Jun 2022 21:47:54 +0100 Subject: [PATCH 1/3] - started changes for rewind/stop --- .../plugins/pump/medtronic/data/MedtronicHistoryData.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/MedtronicHistoryData.kt b/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/MedtronicHistoryData.kt index 752d7e187b..941aee3bb4 100644 --- a/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/MedtronicHistoryData.kt +++ b/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/MedtronicHistoryData.kt @@ -796,6 +796,9 @@ class MedtronicHistoryData @Inject constructor( } } + val suspendList = getFilteredItems(newHistory, // + setOf(PumpHistoryEntryType.SuspendPump)) + // see if rewind items, need to fix any of current tempBasalProcessDTO items (bug 1724) if (rewindList.isNotEmpty()) { for (rewindEntry in rewindList) { From 700a5685cf70a149dfe0685c96d8b876d38af990 Mon Sep 17 00:00:00 2001 From: Andy Rozman Date: Sat, 25 Jun 2022 19:32:06 +0100 Subject: [PATCH 2/3] - extending solution --- .../medtronic/data/MedtronicHistoryData.kt | 42 ++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/MedtronicHistoryData.kt b/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/MedtronicHistoryData.kt index 941aee3bb4..142a321375 100644 --- a/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/MedtronicHistoryData.kt +++ b/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/MedtronicHistoryData.kt @@ -799,7 +799,11 @@ class MedtronicHistoryData @Inject constructor( val suspendList = getFilteredItems(newHistory, // setOf(PumpHistoryEntryType.SuspendPump)) - // see if rewind items, need to fix any of current tempBasalProcessDTO items (bug 1724) + val stopList : MutableList = mutableListOf() + stopList.addAll(suspendList); + stopList.addAll(rewindList); + + // TODO remove see if rewind items, need to fix any of current tempBasalProcessDTO items (bug 1724) if (rewindList.isNotEmpty()) { for (rewindEntry in rewindList) { for (tempBasalProcessDTO in processList) { @@ -816,9 +820,45 @@ class MedtronicHistoryData @Inject constructor( } } + // see if have rewind/stop items that need to fix any of current tempBasalProcessDTO items (bug 1724) + if (stopList.isNotEmpty()) { + for (tempBasalProcessDTO in processList) { + if (tempBasalProcessDTO.itemTwo==null) { + val endTime: Long = DateTimeUtil.getATDWithAddedMinutes(tempBasalProcessDTO.itemOne.atechDateTime, tempBasalProcessDTO.itemOneTbr!!.durationMinutes) + + val findNearestEntry = findNearestEntry(tempBasalProcessDTO.itemOne.atechDateTime, endTime, stopList); + + if (findNearestEntry!=null) { + tempBasalProcessDTO.itemTwo = findNearestEntry + stopList.remove(findNearestEntry) + } + } + } + } + return processList } + fun findNearestEntry(startTime: Long, endTime: Long, list: MutableList) : PumpHistoryEntry? { + val outList: MutableList = mutableListOf() + + for (pumpHistoryEntry in list) { + if ((pumpHistoryEntry.atechDateTime > startTime) && + (pumpHistoryEntry.atechDateTime < endTime)) { + outList.add(pumpHistoryEntry) + } + } + + if (outList.size == 0) { + return null + } else if (outList.size==1) { + return outList[0] + } else { + // TODO + return null + } + } + fun isTBRActive(dbEntry: PumpDbEntryTBR): Boolean { return isTBRActive( startTimestamp = dbEntry.date, From 2e40b17973f8202cb307ada3d355ee6bf1f28515 Mon Sep 17 00:00:00 2001 From: Andy Rozman Date: Sun, 24 Jul 2022 12:42:33 +0100 Subject: [PATCH 3/3] - reverting change done for 1724 (code is still there just commented). I need to rework this, and reuse the code, just on different position) --- .../medtronic/data/MedtronicHistoryData.kt | 79 ++++++++++--------- 1 file changed, 40 insertions(+), 39 deletions(-) diff --git a/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/MedtronicHistoryData.kt b/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/MedtronicHistoryData.kt index d54a3ca2e5..6f17edbe0c 100644 --- a/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/MedtronicHistoryData.kt +++ b/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/MedtronicHistoryData.kt @@ -797,45 +797,46 @@ class MedtronicHistoryData @Inject constructor( } } - val suspendList = getFilteredItems(newHistory, // - setOf(PumpHistoryEntryType.SuspendPump)) - - val stopList : MutableList = mutableListOf() - stopList.addAll(suspendList); - stopList.addAll(rewindList); - - // TODO remove see if rewind items, need to fix any of current tempBasalProcessDTO items (bug 1724) - if (rewindList.isNotEmpty()) { - for (rewindEntry in rewindList) { - for (tempBasalProcessDTO in processList) { - if (tempBasalProcessDTO.itemTwo==null) { - val endTime: Long = DateTimeUtil.getATDWithAddedMinutes(tempBasalProcessDTO.itemOne.atechDateTime, tempBasalProcessDTO.itemOneTbr!!.durationMinutes) - - if ((rewindEntry.atechDateTime > tempBasalProcessDTO.itemOne.atechDateTime) && - (rewindEntry.atechDateTime < endTime)) { - tempBasalProcessDTO.itemTwo = rewindEntry - continue - } - } - } - } - } - - // see if have rewind/stop items that need to fix any of current tempBasalProcessDTO items (bug 1724) - if (stopList.isNotEmpty()) { - for (tempBasalProcessDTO in processList) { - if (tempBasalProcessDTO.itemTwo==null) { - val endTime: Long = DateTimeUtil.getATDWithAddedMinutes(tempBasalProcessDTO.itemOne.atechDateTime, tempBasalProcessDTO.itemOneTbr!!.durationMinutes) - - val findNearestEntry = findNearestEntry(tempBasalProcessDTO.itemOne.atechDateTime, endTime, stopList); - - if (findNearestEntry!=null) { - tempBasalProcessDTO.itemTwo = findNearestEntry - stopList.remove(findNearestEntry) - } - } - } - } + // TODO this solution needs to be overworked, commenting out for now + // val suspendList = getFilteredItems(newHistory, // + // setOf(PumpHistoryEntryType.SuspendPump)) + // + // val stopList : MutableList = mutableListOf() + // stopList.addAll(suspendList); + // stopList.addAll(rewindList); + // + // // TODO remove see if rewind items, need to fix any of current tempBasalProcessDTO items (bug 1724) + // if (rewindList.isNotEmpty()) { + // for (rewindEntry in rewindList) { + // for (tempBasalProcessDTO in processList) { + // if (tempBasalProcessDTO.itemTwo==null) { + // val endTime: Long = DateTimeUtil.getATDWithAddedMinutes(tempBasalProcessDTO.itemOne.atechDateTime, tempBasalProcessDTO.itemOneTbr!!.durationMinutes) + // + // if ((rewindEntry.atechDateTime > tempBasalProcessDTO.itemOne.atechDateTime) && + // (rewindEntry.atechDateTime < endTime)) { + // tempBasalProcessDTO.itemTwo = rewindEntry + // continue + // } + // } + // } + // } + // } + // + // // see if have rewind/stop items that need to fix any of current tempBasalProcessDTO items (bug 1724) + // if (stopList.isNotEmpty()) { + // for (tempBasalProcessDTO in processList) { + // if (tempBasalProcessDTO.itemTwo==null) { + // val endTime: Long = DateTimeUtil.getATDWithAddedMinutes(tempBasalProcessDTO.itemOne.atechDateTime, tempBasalProcessDTO.itemOneTbr!!.durationMinutes) + // + // val findNearestEntry = findNearestEntry(tempBasalProcessDTO.itemOne.atechDateTime, endTime, stopList); + // + // if (findNearestEntry!=null) { + // tempBasalProcessDTO.itemTwo = findNearestEntry + // stopList.remove(findNearestEntry) + // } + // } + // } + // } return processList }