fix ending EB

This commit is contained in:
Milos Kozak 2021-11-15 23:00:04 +01:00
parent 6aaedefbed
commit d0e9761e70
2 changed files with 5 additions and 1 deletions

View file

@ -44,6 +44,8 @@ class SyncNsExtendedBolusTransaction(private val extendedBolus: ExtendedBolus) :
result.updatedNsId.add(running) result.updatedNsId.add(running)
} else if (running != null) { } else if (running != null) {
// another running record. end current and insert new // another running record. end current and insert new
val pctRun = (extendedBolus.timestamp - running.timestamp) / running.duration.toDouble()
running.amount *= pctRun
running.end = extendedBolus.timestamp running.end = extendedBolus.timestamp
database.extendedBolusDao.updateExistingEntry(running) database.extendedBolusDao.updateExistingEntry(running)
database.extendedBolusDao.insertNewEntry(extendedBolus) database.extendedBolusDao.insertNewEntry(extendedBolus)
@ -59,6 +61,8 @@ class SyncNsExtendedBolusTransaction(private val extendedBolus: ExtendedBolus) :
// ending event // ending event
val running = database.extendedBolusDao.getExtendedBolusActiveAt(extendedBolus.timestamp).blockingGet() val running = database.extendedBolusDao.getExtendedBolusActiveAt(extendedBolus.timestamp).blockingGet()
if (running != null) { if (running != null) {
val pctRun = (extendedBolus.timestamp - running.timestamp) / running.duration.toDouble()
running.amount *= pctRun
running.end = extendedBolus.timestamp running.end = extendedBolus.timestamp
database.extendedBolusDao.updateExistingEntry(running) database.extendedBolusDao.updateExistingEntry(running)
result.ended.add(running) result.ended.add(running)

View file

@ -30,7 +30,7 @@ class SyncPumpExtendedBolusTransaction(private val extendedBolus: ExtendedBolus)
val running = database.extendedBolusDao.getExtendedBolusActiveAt(extendedBolus.timestamp, extendedBolus.interfaceIDs.pumpType!!, extendedBolus.interfaceIDs.pumpSerial!!).blockingGet() val running = database.extendedBolusDao.getExtendedBolusActiveAt(extendedBolus.timestamp, extendedBolus.interfaceIDs.pumpType!!, extendedBolus.interfaceIDs.pumpSerial!!).blockingGet()
if (running != null) { if (running != null) {
val pctRun = (extendedBolus.timestamp - running.timestamp) / running.duration.toDouble() val pctRun = (extendedBolus.timestamp - running.timestamp) / running.duration.toDouble()
running.amount /= pctRun running.amount *= pctRun
running.end = extendedBolus.timestamp running.end = extendedBolus.timestamp
running.interfaceIDs.endId = extendedBolus.interfaceIDs.pumpId running.interfaceIDs.endId = extendedBolus.interfaceIDs.pumpId
database.extendedBolusDao.updateExistingEntry(running) database.extendedBolusDao.updateExistingEntry(running)