From d0e9761e703608cb17bf8c59e9b3ba63ae9a9a51 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 15 Nov 2021 23:00:04 +0100 Subject: [PATCH] fix ending EB --- .../database/transactions/SyncNsExtendedBolusTransaction.kt | 4 ++++ .../database/transactions/SyncPumpExtendedBolusTransaction.kt | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/database/src/main/java/info/nightscout/androidaps/database/transactions/SyncNsExtendedBolusTransaction.kt b/database/src/main/java/info/nightscout/androidaps/database/transactions/SyncNsExtendedBolusTransaction.kt index 4219ce6803..22522eb012 100644 --- a/database/src/main/java/info/nightscout/androidaps/database/transactions/SyncNsExtendedBolusTransaction.kt +++ b/database/src/main/java/info/nightscout/androidaps/database/transactions/SyncNsExtendedBolusTransaction.kt @@ -44,6 +44,8 @@ class SyncNsExtendedBolusTransaction(private val extendedBolus: ExtendedBolus) : result.updatedNsId.add(running) } else if (running != null) { // another running record. end current and insert new + val pctRun = (extendedBolus.timestamp - running.timestamp) / running.duration.toDouble() + running.amount *= pctRun running.end = extendedBolus.timestamp database.extendedBolusDao.updateExistingEntry(running) database.extendedBolusDao.insertNewEntry(extendedBolus) @@ -59,6 +61,8 @@ class SyncNsExtendedBolusTransaction(private val extendedBolus: ExtendedBolus) : // ending event val running = database.extendedBolusDao.getExtendedBolusActiveAt(extendedBolus.timestamp).blockingGet() if (running != null) { + val pctRun = (extendedBolus.timestamp - running.timestamp) / running.duration.toDouble() + running.amount *= pctRun running.end = extendedBolus.timestamp database.extendedBolusDao.updateExistingEntry(running) result.ended.add(running) diff --git a/database/src/main/java/info/nightscout/androidaps/database/transactions/SyncPumpExtendedBolusTransaction.kt b/database/src/main/java/info/nightscout/androidaps/database/transactions/SyncPumpExtendedBolusTransaction.kt index c90157c838..2cf424fe80 100644 --- a/database/src/main/java/info/nightscout/androidaps/database/transactions/SyncPumpExtendedBolusTransaction.kt +++ b/database/src/main/java/info/nightscout/androidaps/database/transactions/SyncPumpExtendedBolusTransaction.kt @@ -30,7 +30,7 @@ class SyncPumpExtendedBolusTransaction(private val extendedBolus: ExtendedBolus) val running = database.extendedBolusDao.getExtendedBolusActiveAt(extendedBolus.timestamp, extendedBolus.interfaceIDs.pumpType!!, extendedBolus.interfaceIDs.pumpSerial!!).blockingGet() if (running != null) { val pctRun = (extendedBolus.timestamp - running.timestamp) / running.duration.toDouble() - running.amount /= pctRun + running.amount *= pctRun running.end = extendedBolus.timestamp running.interfaceIDs.endId = extendedBolus.interfaceIDs.pumpId database.extendedBolusDao.updateExistingEntry(running)