Merge pull request #553 from andyrozman/mdt_new_fix_2

MDT problem fixing
This commit is contained in:
Milos Kozak 2021-06-08 09:13:26 +02:00 committed by GitHub
commit a03c916172
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 5 deletions

View file

@ -9,6 +9,7 @@ import info.nightscout.androidaps.interfaces.PumpSync
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType
import info.nightscout.androidaps.plugins.pump.common.sync.PumpDbEntry
import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil
import info.nightscout.androidaps.plugins.pump.common.utils.StringUtil
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.MedtronicPumpHistoryDecoder
@ -490,9 +491,11 @@ class MedtronicHistoryData @Inject constructor(
if (!multiwave) {
val entryWithTempId = findDbEntry(bolus, boluses)
aapsLogger.debug(LTag.PUMP, String.format("DD: entryWithTempId=%s", gson.toJson(entryWithTempId)))
aapsLogger.debug(LTag.PUMP, "DD: entryWithTempId=$entryWithTempId")
if (entryWithTempId != null) {
aapsLogger.debug(LTag.PUMP, String.format("DD: entryWithTempId.bolusData=%s", if (entryWithTempId.bolusData == null) "null" else entryWithTempId.bolusData))
temporaryId = entryWithTempId.temporaryId
pumpSyncStorage.removeBolusWithTemporaryId(temporaryId)
boluses.remove(entryWithTempId)
@ -578,7 +581,7 @@ class MedtronicHistoryData @Inject constructor(
val tbrRecords = pumpSyncStorage.getTBRs()
aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, ProcessHistoryRecord.TBR.description + " List (before filter): %s, FromDb=%s", gson.toJson(entryList),
gson.toJson(tbrRecords)))
tbrRecords))
var processDTO: TempBasalProcessDTO? = null
val processList: MutableList<TempBasalProcessDTO> = mutableListOf()
for (treatment in entryList) {
@ -611,6 +614,8 @@ class MedtronicHistoryData @Inject constructor(
if (processList.isNotEmpty()) {
for (tempBasalProcessDTO in processList) {
aapsLogger.debug(LTag.PUMP, "DD: tempBasalProcessDTO.itemOne: " + gson.toJson(tempBasalProcessDTO.itemOne))
val entryWithTempId = findDbEntry(tempBasalProcessDTO.itemOne, tbrRecords)
aapsLogger.debug(LTag.PUMP, "DD: entryWithTempId: " + (if (entryWithTempId == null) "null" else entryWithTempId.toString()))
@ -624,6 +629,13 @@ class MedtronicHistoryData @Inject constructor(
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 " +
"[date=${tempBasalProcessDTO.atechDateTime}, dateProcess=${tryToGetByLocalTime(tempBasalProcessDTO.atechDateTime)}, " +
"tbrEntry.insulinRate=${tbrEntry.insulinRate}, duration=${tempBasalProcessDTO.duration * 60L * 1000L}, " +
"isAbsolute=${!tbrEntry.isPercent}, temporaryId=${entryWithTempId.temporaryId}, " +
"pumpId=${tempBasalProcessDTO.pumpId}, pumpType=${medtronicPumpStatus.pumpType}, " +
"pumpSerial=${medtronicPumpStatus.serialNumber}]")
val result = pumpSync.syncTemporaryBasalWithTempId(
tryToGetByLocalTime(tempBasalProcessDTO.atechDateTime),
tbrEntry.insulinRate,
@ -711,7 +723,7 @@ class MedtronicHistoryData @Inject constructor(
/**
* Looks at all boluses that have temporaryId and find one that is correct for us (if such entry exists)
*/
private fun findDbEntry(treatment: PumpHistoryEntry, temporaryEntries: MutableList<info.nightscout.androidaps.plugins.pump.common.sync.PumpDbEntry>): info.nightscout.androidaps.plugins.pump.common.sync.PumpDbEntry? {
private fun findDbEntry(treatment: PumpHistoryEntry, temporaryEntries: MutableList<PumpDbEntry>): PumpDbEntry? {
if (temporaryEntries.isEmpty()) {
return null

View file

@ -46,7 +46,9 @@ class PumpSyncStorage @Inject constructor(
if (!jsonData.isBlank()) {
pumpSyncStorage = xstream.fromXML(jsonData, MutableMap::class.java) as MutableMap<String, MutableList<PumpDbEntry>>
aapsLogger.debug(String.format("Loading Pump Sync Storage: boluses=%d, tbrs=%d.", pumpSyncStorage[BOLUS]!!.size, pumpSyncStorage[TBR]!!.size))
aapsLogger.debug(LTag.PUMP, String.format("Loading Pump Sync Storage: boluses=%d, tbrs=%d.", pumpSyncStorage[BOLUS]!!.size, pumpSyncStorage[TBR]!!.size))
aapsLogger.debug(LTag.PUMP, "DD: PumpSyncStorage=$pumpSyncStorage")
loaded = true
}
}
@ -97,7 +99,11 @@ class PumpSyncStorage @Inject constructor(
if (result && writeToInternalHistory) {
val innerList: MutableList<PumpDbEntry> = pumpSyncStorage[BOLUS]!!
innerList.add(PumpDbEntry(temporaryId, detailedBolusInfo.timestamp, creator.model(), creator.serialNumber(), detailedBolusInfo))
val dbEntry = PumpDbEntry(temporaryId, detailedBolusInfo.timestamp, creator.model(), creator.serialNumber(), detailedBolusInfo)
aapsLogger.debug("PumpDbEntry: $dbEntry")
innerList.add(dbEntry)
pumpSyncStorage[BOLUS] = innerList
saveStorage()
}