use last DetailedBolusInfo as failover

This commit is contained in:
Milos Kozak 2020-03-10 20:38:34 +01:00
parent 625d4f58b6
commit c220b49ee7

View file

@ -2,7 +2,6 @@ package info.nightscout.androidaps.plugins.pump.common.bolusInfo
import info.nightscout.androidaps.data.DetailedBolusInfo
import info.nightscout.androidaps.logging.L
import info.nightscout.androidaps.plugins.pump.medtronic.data.MedtronicHistoryData
import info.nightscout.androidaps.utils.T
import org.slf4j.LoggerFactory
import java.util.*
@ -20,10 +19,6 @@ object DetailedBolusInfoStorage {
@Synchronized
fun findDetailedBolusInfo(bolusTime: Long, bolus: Double): DetailedBolusInfo? {
if (MedtronicHistoryData.doubleBolusDebug)
log.debug("DoubleBolusDebug: findDetailedBolusInfo::bolusTime={}, bolus={}", bolusTime, bolus)
// Look for info with bolus
for (i in store.indices) {
val d = store[i]
@ -31,11 +26,8 @@ object DetailedBolusInfoStorage {
log.debug("Existing bolus info: " + store[i])
if (bolusTime > d.date - T.mins(1).msecs() && bolusTime < d.date + T.mins(1).msecs() && abs(store[i].insulin - bolus) < 0.01) {
if (L.isEnabled(L.PUMP))
log.debug("Using & removing bolus info: " + store[i])
log.debug("Using & removing bolus info: ${store[i]}")
store.removeAt(i)
if (MedtronicHistoryData.doubleBolusDebug)
log.debug("DoubleBolusDebug: findDetailedBolusInfo::selectedBolus[DetailedBolusInfo={}]", d)
return d
}
}
@ -44,13 +36,23 @@ object DetailedBolusInfoStorage {
val d = store[i]
if (bolusTime > d.date - T.mins(1).msecs() && bolusTime < d.date + T.mins(1).msecs() && bolus <= store[i].insulin + 0.01) {
if (L.isEnabled(L.PUMP))
log.debug("Using & removing bolus info: " + store[i])
log.debug("Using TIME-ONLY & removing bolus info: ${store[i]}")
store.removeAt(i)
if (MedtronicHistoryData.doubleBolusDebug)
log.debug("DoubleBolusDebug: findDetailedBolusInfo::selectedBolus[DetailedBolusInfo={}]", d)
return d
}
}
// If not found, use last record if amount is the same
if (store.size > 0) {
val d = store[store.size - 1]
if (abs(d.insulin - bolus) < 0.01)
if (L.isEnabled(L.PUMP))
log.debug("Using LAST & removing bolus info: $d")
store.removeAt(store.size - 1)
return d
}
//Not found
if (L.isEnabled(L.PUMP))
log.debug("Bolus info not found")
return null
}
}