log updated TBR records
This commit is contained in:
parent
15a6d27349
commit
d131ceb4bd
2 changed files with 6 additions and 7 deletions
|
@ -271,7 +271,7 @@ class PumpSyncImplementation @Inject constructor(
|
||||||
.blockingGet()
|
.blockingGet()
|
||||||
.also { result ->
|
.also { result ->
|
||||||
result.inserted.forEach { aapsLogger.debug(LTag.DATABASE, "Inserted TemporaryBasal $it") }
|
result.inserted.forEach { aapsLogger.debug(LTag.DATABASE, "Inserted TemporaryBasal $it") }
|
||||||
result.updated.forEach { aapsLogger.debug(LTag.DATABASE, "Updated ${it.first} TemporaryBasal ${it.second}") }
|
result.updated.forEach { aapsLogger.debug(LTag.DATABASE, "Updated TemporaryBasal \n${it.first}\n${it.second}") }
|
||||||
return result.inserted.size > 0
|
return result.inserted.size > 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,20 +24,22 @@ class SyncPumpTemporaryBasalTransaction(
|
||||||
existing.duration != temporaryBasal.duration && existing.interfaceIDs.endId == null ||
|
existing.duration != temporaryBasal.duration && existing.interfaceIDs.endId == null ||
|
||||||
existing.type != type ?: existing.type
|
existing.type != type ?: existing.type
|
||||||
) {
|
) {
|
||||||
|
val old = existing.copy()
|
||||||
existing.timestamp = temporaryBasal.timestamp
|
existing.timestamp = temporaryBasal.timestamp
|
||||||
existing.rate = temporaryBasal.rate
|
existing.rate = temporaryBasal.rate
|
||||||
existing.duration = temporaryBasal.duration
|
existing.duration = temporaryBasal.duration
|
||||||
existing.type = type ?: existing.type
|
existing.type = type ?: existing.type
|
||||||
database.temporaryBasalDao.updateExistingEntry(existing)
|
database.temporaryBasalDao.updateExistingEntry(existing)
|
||||||
result.updated.add(Pair(Reason.EXISTING_ID, existing))
|
result.updated.add(Pair(old, existing))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val running = database.temporaryBasalDao.getTemporaryBasalActiveAt(temporaryBasal.timestamp).blockingGet()
|
val running = database.temporaryBasalDao.getTemporaryBasalActiveAt(temporaryBasal.timestamp).blockingGet()
|
||||||
if (running != null) {
|
if (running != null) {
|
||||||
|
val old = running.copy()
|
||||||
running.end = temporaryBasal.timestamp
|
running.end = temporaryBasal.timestamp
|
||||||
running.interfaceIDs.endId = temporaryBasal.interfaceIDs.pumpId
|
running.interfaceIDs.endId = temporaryBasal.interfaceIDs.pumpId
|
||||||
database.temporaryBasalDao.updateExistingEntry(running)
|
database.temporaryBasalDao.updateExistingEntry(running)
|
||||||
result.updated.add(Pair(Reason.ACTIVE, running))
|
result.updated.add(Pair(old, running))
|
||||||
}
|
}
|
||||||
database.temporaryBasalDao.insertNewEntry(temporaryBasal)
|
database.temporaryBasalDao.insertNewEntry(temporaryBasal)
|
||||||
result.inserted.add(temporaryBasal)
|
result.inserted.add(temporaryBasal)
|
||||||
|
@ -45,12 +47,9 @@ class SyncPumpTemporaryBasalTransaction(
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class Reason {
|
|
||||||
EXISTING_ID, ACTIVE
|
|
||||||
}
|
|
||||||
class TransactionResult {
|
class TransactionResult {
|
||||||
|
|
||||||
val inserted = mutableListOf<TemporaryBasal>()
|
val inserted = mutableListOf<TemporaryBasal>()
|
||||||
val updated = mutableListOf<Pair<Reason,TemporaryBasal>>()
|
val updated = mutableListOf<Pair<TemporaryBasal,TemporaryBasal>>()
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue