This commit is contained in:
Milos Kozak 2023-08-30 12:15:38 +02:00
parent 394883165d
commit 49f29f348d
12 changed files with 24 additions and 141 deletions

View file

@ -65,7 +65,7 @@ import kotlin.math.roundToInt
fun <T : Any> runTransactionForResult(transaction: Transaction<T>): Single<T> { fun <T : Any> runTransactionForResult(transaction: Transaction<T>): Single<T> {
val changes = mutableListOf<DBEntry>() val changes = mutableListOf<DBEntry>()
return Single.fromCallable { return Single.fromCallable {
database.runInTransaction(Callable<T> { database.runInTransaction(Callable {
transaction.database = DelegatedAppDatabase(changes, database) transaction.database = DelegatedAppDatabase(changes, database)
transaction.run() transaction.run()
}) })
@ -85,7 +85,7 @@ import kotlin.math.roundToInt
removed.add(Pair("ExtendedBolus", database.extendedBolusDao.deleteOlderThan(than))) removed.add(Pair("ExtendedBolus", database.extendedBolusDao.deleteOlderThan(than)))
removed.add(Pair("Bolus", database.bolusDao.deleteOlderThan(than))) removed.add(Pair("Bolus", database.bolusDao.deleteOlderThan(than)))
removed.add(Pair("MultiWaveBolus", database.multiwaveBolusLinkDao.deleteOlderThan(than))) removed.add(Pair("MultiWaveBolus", database.multiwaveBolusLinkDao.deleteOlderThan(than)))
//removed.add(Pair("TotalDailyDose", database.totalDailyDoseDao.deleteOlderThan(than))) // keep TDD removed.add(Pair("TotalDailyDose", database.totalDailyDoseDao.deleteOlderThan(than)))
removed.add(Pair("Carbs", database.carbsDao.deleteOlderThan(than))) removed.add(Pair("Carbs", database.carbsDao.deleteOlderThan(than)))
removed.add(Pair("TemporaryTarget", database.temporaryTargetDao.deleteOlderThan(than))) removed.add(Pair("TemporaryTarget", database.temporaryTargetDao.deleteOlderThan(than)))
removed.add(Pair("ApsResultLink", database.apsResultLinkDao.deleteOlderThan(than))) removed.add(Pair("ApsResultLink", database.apsResultLinkDao.deleteOlderThan(than)))
@ -95,10 +95,10 @@ import kotlin.math.roundToInt
removed.add(Pair("EffectiveProfileSwitch", database.effectiveProfileSwitchDao.deleteOlderThan(than))) removed.add(Pair("EffectiveProfileSwitch", database.effectiveProfileSwitchDao.deleteOlderThan(than)))
removed.add(Pair("ProfileSwitch", database.profileSwitchDao.deleteOlderThan(than))) removed.add(Pair("ProfileSwitch", database.profileSwitchDao.deleteOlderThan(than)))
removed.add(Pair("ApsResult", database.apsResultDao.deleteOlderThan(than))) removed.add(Pair("ApsResult", database.apsResultDao.deleteOlderThan(than)))
//database.versionChangeDao.deleteOlderThan(than) // keep version history database.versionChangeDao.deleteOlderThan(than)
removed.add(Pair("UserEntry", database.userEntryDao.deleteOlderThan(than))) removed.add(Pair("UserEntry", database.userEntryDao.deleteOlderThan(than)))
removed.add(Pair("PreferenceChange", database.preferenceChangeDao.deleteOlderThan(than))) removed.add(Pair("PreferenceChange", database.preferenceChangeDao.deleteOlderThan(than)))
//database.foodDao.deleteOlderThan(than) // keep foods database.foodDao.deleteOlderThan(than)
removed.add(Pair("DeviceStatus", database.deviceStatusDao.deleteOlderThan(than))) removed.add(Pair("DeviceStatus", database.deviceStatusDao.deleteOlderThan(than)))
removed.add(Pair("OfflineEvent", database.offlineEventDao.deleteOlderThan(than))) removed.add(Pair("OfflineEvent", database.offlineEventDao.deleteOlderThan(than)))
removed.add(Pair("HeartRate", database.heartRateDao.deleteOlderThan(than))) removed.add(Pair("HeartRate", database.heartRateDao.deleteOlderThan(than)))
@ -110,7 +110,7 @@ import kotlin.math.roundToInt
removed.add(Pair("Bolus", database.bolusDao.deleteTrackedChanges())) removed.add(Pair("Bolus", database.bolusDao.deleteTrackedChanges()))
removed.add(Pair("ExtendedBolus", database.extendedBolusDao.deleteTrackedChanges())) removed.add(Pair("ExtendedBolus", database.extendedBolusDao.deleteTrackedChanges()))
removed.add(Pair("MultiWaveBolus", database.multiwaveBolusLinkDao.deleteTrackedChanges())) removed.add(Pair("MultiWaveBolus", database.multiwaveBolusLinkDao.deleteTrackedChanges()))
//removed.add(Pair("TotalDailyDose", database.totalDailyDoseDao.deleteTrackedChanges())) // keep TDD removed.add(Pair("TotalDailyDose", database.totalDailyDoseDao.deleteTrackedChanges()))
removed.add(Pair("Carbs", database.carbsDao.deleteTrackedChanges())) removed.add(Pair("Carbs", database.carbsDao.deleteTrackedChanges()))
removed.add(Pair("TemporaryTarget", database.temporaryTargetDao.deleteTrackedChanges())) removed.add(Pair("TemporaryTarget", database.temporaryTargetDao.deleteTrackedChanges()))
removed.add(Pair("ApsResultLink", database.apsResultLinkDao.deleteTrackedChanges())) removed.add(Pair("ApsResultLink", database.apsResultLinkDao.deleteTrackedChanges()))
@ -118,7 +118,7 @@ import kotlin.math.roundToInt
removed.add(Pair("EffectiveProfileSwitch", database.effectiveProfileSwitchDao.deleteTrackedChanges())) removed.add(Pair("EffectiveProfileSwitch", database.effectiveProfileSwitchDao.deleteTrackedChanges()))
removed.add(Pair("ProfileSwitch", database.profileSwitchDao.deleteTrackedChanges())) removed.add(Pair("ProfileSwitch", database.profileSwitchDao.deleteTrackedChanges()))
removed.add(Pair("ApsResult", database.apsResultDao.deleteTrackedChanges())) removed.add(Pair("ApsResult", database.apsResultDao.deleteTrackedChanges()))
//database.foodDao.deleteHistory() // keep food database.foodDao.deleteHistory()
removed.add(Pair("OfflineEvent", database.offlineEventDao.deleteTrackedChanges())) removed.add(Pair("OfflineEvent", database.offlineEventDao.deleteTrackedChanges()))
removed.add(Pair("HeartRate", database.heartRateDao.deleteTrackedChanges())) removed.add(Pair("HeartRate", database.heartRateDao.deleteTrackedChanges()))
} }
@ -148,6 +148,7 @@ import kotlin.math.roundToInt
fun findBgReadingByNSId(nsId: String): GlucoseValue? = fun findBgReadingByNSId(nsId: String): GlucoseValue? =
database.glucoseValueDao.findByNSId(nsId) database.glucoseValueDao.findByNSId(nsId)
@Suppress("unused")
fun getModifiedBgReadingsDataFromId(lastId: Long): Single<List<GlucoseValue>> = fun getModifiedBgReadingsDataFromId(lastId: Long): Single<List<GlucoseValue>> =
database.glucoseValueDao.getModifiedFrom(lastId) database.glucoseValueDao.getModifiedFrom(lastId)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
@ -179,14 +180,6 @@ import kotlin.math.roundToInt
} }
} }
fun getBgReadingsCorrespondingLastHistoryRecord(lastId: Long): GlucoseValue? =
database.glucoseValueDao.getLastHistoryRecord(lastId)
@Suppress("unused") // debug purpose only
fun getAllBgReadingsStartingFrom(lastId: Long): Single<List<GlucoseValue>> =
database.glucoseValueDao.getAllStartingFrom(lastId)
.subscribeOn(Schedulers.io())
// TEMP TARGETS // TEMP TARGETS
fun findTemporaryTargetByNSId(nsId: String): TemporaryTarget? = fun findTemporaryTargetByNSId(nsId: String): TemporaryTarget? =
database.temporaryTargetDao.findByNSId(nsId) database.temporaryTargetDao.findByNSId(nsId)
@ -210,10 +203,6 @@ import kotlin.math.roundToInt
} }
} }
fun compatGetTemporaryTargetData(): Single<List<TemporaryTarget>> =
database.temporaryTargetDao.getTemporaryTargetData()
.subscribeOn(Schedulers.io())
fun getTemporaryTargetDataFromTime(timestamp: Long, ascending: Boolean): Single<List<TemporaryTarget>> = fun getTemporaryTargetDataFromTime(timestamp: Long, ascending: Boolean): Single<List<TemporaryTarget>> =
database.temporaryTargetDao.getTemporaryTargetDataFromTime(timestamp) database.temporaryTargetDao.getTemporaryTargetDataFromTime(timestamp)
.map { if (!ascending) it.reversed() else it } .map { if (!ascending) it.reversed() else it }
@ -224,6 +213,7 @@ import kotlin.math.roundToInt
.map { if (!ascending) it.reversed() else it } .map { if (!ascending) it.reversed() else it }
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
@Suppress("unused")
fun getModifiedTemporaryTargetsDataFromId(lastId: Long): Single<List<TemporaryTarget>> = fun getModifiedTemporaryTargetsDataFromId(lastId: Long): Single<List<TemporaryTarget>> =
database.temporaryTargetDao.getModifiedFrom(lastId) database.temporaryTargetDao.getModifiedFrom(lastId)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
@ -240,10 +230,6 @@ import kotlin.math.roundToInt
database.temporaryTargetDao.getLastId() database.temporaryTargetDao.getLastId()
// USER ENTRY // USER ENTRY
fun getAllUserEntries(): Single<List<UserEntry>> =
database.userEntryDao.getAll()
.subscribeOn(Schedulers.io())
fun getUserEntryDataFromTime(timestamp: Long): Single<List<UserEntry>> = fun getUserEntryDataFromTime(timestamp: Long): Single<List<UserEntry>> =
database.userEntryDao.getUserEntryDataFromTime(timestamp) database.userEntryDao.getUserEntryDataFromTime(timestamp)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
@ -274,6 +260,7 @@ import kotlin.math.roundToInt
} }
} }
@Suppress("unused")
fun getModifiedProfileSwitchDataFromId(lastId: Long): Single<List<ProfileSwitch>> = fun getModifiedProfileSwitchDataFromId(lastId: Long): Single<List<ProfileSwitch>> =
database.profileSwitchDao.getModifiedFrom(lastId) database.profileSwitchDao.getModifiedFrom(lastId)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
@ -288,8 +275,7 @@ import kotlin.math.roundToInt
if (tps != null && ps != null) if (tps != null && ps != null)
return if (ps.timestamp > tps.timestamp) ps else tps return if (ps.timestamp > tps.timestamp) ps else tps
if (ps == null) return tps if (ps == null) return tps
if (tps == null) return ps return ps // if (tps == null)
return null
} }
fun getPermanentProfileSwitch(timestamp: Long): ProfileSwitch? = fun getPermanentProfileSwitch(timestamp: Long): ProfileSwitch? =
@ -340,6 +326,7 @@ import kotlin.math.roundToInt
} }
} }
@Suppress("unused")
fun getModifiedEffectiveProfileSwitchDataFromId(lastId: Long): Single<List<EffectiveProfileSwitch>> = fun getModifiedEffectiveProfileSwitchDataFromId(lastId: Long): Single<List<EffectiveProfileSwitch>> =
database.effectiveProfileSwitchDao.getModifiedFrom(lastId) database.effectiveProfileSwitchDao.getModifiedFrom(lastId)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
@ -400,6 +387,7 @@ import kotlin.math.roundToInt
} }
} }
@Suppress("unused")
fun getModifiedTherapyEventDataFromId(lastId: Long): Single<List<TherapyEvent>> = fun getModifiedTherapyEventDataFromId(lastId: Long): Single<List<TherapyEvent>> =
database.therapyEventDao.getModifiedFrom(lastId) database.therapyEventDao.getModifiedFrom(lastId)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
@ -430,14 +418,6 @@ import kotlin.math.roundToInt
database.therapyEventDao.getLastTherapyRecord(type, System.currentTimeMillis()).toWrappedSingle() database.therapyEventDao.getLastTherapyRecord(type, System.currentTimeMillis()).toWrappedSingle()
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
fun getTherapyEventByTimestamp(type: TherapyEvent.Type, timestamp: Long): TherapyEvent? =
database.therapyEventDao.findByTimestamp(type, timestamp)
fun compatGetTherapyEventDataFromTime(timestamp: Long, ascending: Boolean): Single<List<TherapyEvent>> =
database.therapyEventDao.compatGetTherapyEventDataFromTime(timestamp)
.map { if (!ascending) it.reversed() else it }
.subscribeOn(Schedulers.io())
fun compatGetTherapyEventDataFromToTime(from: Long, to: Long): Single<List<TherapyEvent>> = fun compatGetTherapyEventDataFromToTime(from: Long, to: Long): Single<List<TherapyEvent>> =
database.therapyEventDao.compatGetTherapyEventDataFromToTime(from, to) database.therapyEventDao.compatGetTherapyEventDataFromToTime(from, to)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
@ -446,9 +426,6 @@ import kotlin.math.roundToInt
database.therapyEventDao.getLastId() database.therapyEventDao.getLastId()
// FOOD // FOOD
fun findFoodByNSId(nsId: String): Food? =
database.foodDao.findByNSId(nsId)
/* /*
* returns a Pair of the next entity to sync and the ID of the "update". * returns a Pair of the next entity to sync and the ID of the "update".
* The update id might either be the entry id itself if it is a new entry - or the id * The update id might either be the entry id itself if it is a new entry - or the id
@ -468,6 +445,7 @@ import kotlin.math.roundToInt
} }
} }
@Suppress("unused")
fun getModifiedFoodDataFromId(lastId: Long): Single<List<Food>> = fun getModifiedFoodDataFromId(lastId: Long): Single<List<Food>> =
database.foodDao.getModifiedFrom(lastId) database.foodDao.getModifiedFrom(lastId)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
@ -476,6 +454,7 @@ import kotlin.math.roundToInt
database.foodDao.getFoodData() database.foodDao.getFoodData()
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
@Suppress("unused")
fun deleteAllFoods() = fun deleteAllFoods() =
database.foodDao.deleteAllEntries() database.foodDao.deleteAllEntries()
@ -505,6 +484,7 @@ import kotlin.math.roundToInt
} }
} }
@Suppress("unused")
fun getModifiedBolusesDataFromId(lastId: Long): Single<List<Bolus>> = fun getModifiedBolusesDataFromId(lastId: Long): Single<List<Bolus>> =
database.bolusDao.getModifiedFrom(lastId) database.bolusDao.getModifiedFrom(lastId)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
@ -540,11 +520,6 @@ import kotlin.math.roundToInt
.map { if (!ascending) it.reversed() else it } .map { if (!ascending) it.reversed() else it }
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
fun getBolusesIncludingInvalidFromTimeToTime(from: Long, to: Long, ascending: Boolean): Single<List<Bolus>> =
database.bolusDao.getBolusesIncludingInvalidFromTimeToTime(from, to)
.map { if (!ascending) it.reversed() else it }
.subscribeOn(Schedulers.io())
fun deleteAllBoluses() = fun deleteAllBoluses() =
database.bolusDao.deleteAllEntries() database.bolusDao.deleteAllEntries()
@ -570,9 +545,7 @@ import kotlin.math.roundToInt
} }
private fun Single<List<Carbs>>.expand() = this.map { it.map(::expandCarbs).flatten() } private fun Single<List<Carbs>>.expand() = this.map { it.map(::expandCarbs).flatten() }
private fun Single<List<Carbs>>.filterOutExtended() = this.map { it.filter { c -> c.duration == 0L } }
private fun Single<List<Carbs>>.fromTo(from: Long, to: Long) = this.map { it.filter { c -> c.timestamp in from..to } } private fun Single<List<Carbs>>.fromTo(from: Long, to: Long) = this.map { it.filter { c -> c.timestamp in from..to } }
private infix fun Single<List<Carbs>>.until(to: Long) = this.map { it.filter { c -> c.timestamp <= to } }
private fun Single<List<Carbs>>.from(start: Long) = this.map { it.filter { c -> c.timestamp >= start } } private fun Single<List<Carbs>>.from(start: Long) = this.map { it.filter { c -> c.timestamp >= start } }
private fun Single<List<Carbs>>.sort() = this.map { it.sortedBy { c -> c.timestamp } } private fun Single<List<Carbs>>.sort() = this.map { it.sortedBy { c -> c.timestamp } }
@ -595,13 +568,11 @@ import kotlin.math.roundToInt
} }
} }
@Suppress("unused")
fun getModifiedCarbsDataFromId(lastId: Long): Single<List<Carbs>> = fun getModifiedCarbsDataFromId(lastId: Long): Single<List<Carbs>> =
database.carbsDao.getModifiedFrom(lastId) database.carbsDao.getModifiedFrom(lastId)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
fun getCarbsByTimestamp(timestamp: Long): Carbs? =
database.carbsDao.findByTimestamp(timestamp)
fun getLastCarbsRecord(): Carbs? = fun getLastCarbsRecord(): Carbs? =
database.carbsDao.getLastCarbsRecord() database.carbsDao.getLastCarbsRecord()
@ -630,11 +601,6 @@ import kotlin.math.roundToInt
.map { if (!ascending) it.reversed() else it } .map { if (!ascending) it.reversed() else it }
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
fun getCarbsDataFromTimeToTime(from: Long, to: Long, ascending: Boolean): Single<List<Carbs>> =
database.carbsDao.getCarbsFromTimeToTime(from, to)
.map { if (!ascending) it.reversed() else it }
.subscribeOn(Schedulers.io())
fun getCarbsDataFromTimeToTimeExpanded(from: Long, to: Long, ascending: Boolean): Single<List<Carbs>> = fun getCarbsDataFromTimeToTimeExpanded(from: Long, to: Long, ascending: Boolean): Single<List<Carbs>> =
database.carbsDao.getCarbsFromTimeToTimeExpandable(from, to) database.carbsDao.getCarbsFromTimeToTimeExpandable(from, to)
.expand() .expand()
@ -648,21 +614,6 @@ import kotlin.math.roundToInt
.map { if (!ascending) it.reversed() else it } .map { if (!ascending) it.reversed() else it }
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
fun getCarbsIncludingInvalidFromTimeExpanded(timestamp: Long, ascending: Boolean): Single<List<Carbs>> =
database.carbsDao.getCarbsIncludingInvalidFromTimeExpandable(timestamp)
.expand()
.from(timestamp)
.map { if (!ascending) it.reversed() else it }
.subscribeOn(Schedulers.io())
fun getCarbsIncludingInvalidFromTimeToTimeExpanded(from: Long, to: Long, ascending: Boolean): Single<List<Carbs>> =
database.carbsDao.getCarbsIncludingInvalidFromTimeToTimeExpandable(from, to)
.expand()
.fromTo(from, to)
.sort()
.map { if (!ascending) it.reversed() else it }
.subscribeOn(Schedulers.io())
fun deleteAllCarbs() = fun deleteAllCarbs() =
database.carbsDao.deleteAllEntries() database.carbsDao.deleteAllEntries()
@ -692,6 +643,7 @@ import kotlin.math.roundToInt
} }
} }
@Suppress("unused")
fun getModifiedBolusCalculatorResultsDataFromId(lastId: Long): Single<List<BolusCalculatorResult>> = fun getModifiedBolusCalculatorResultsDataFromId(lastId: Long): Single<List<BolusCalculatorResult>> =
database.bolusCalculatorResultDao.getModifiedFrom(lastId) database.bolusCalculatorResultDao.getModifiedFrom(lastId)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
@ -757,14 +709,11 @@ import kotlin.math.roundToInt
} }
} }
@Suppress("unused")
fun getModifiedTemporaryBasalDataFromId(lastId: Long): Single<List<TemporaryBasal>> = fun getModifiedTemporaryBasalDataFromId(lastId: Long): Single<List<TemporaryBasal>> =
database.temporaryBasalDao.getModifiedFrom(lastId) database.temporaryBasalDao.getModifiedFrom(lastId)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
fun getTemporaryBasalsData(): Single<List<TemporaryBasal>> =
database.temporaryBasalDao.getTemporaryBasalData()
.subscribeOn(Schedulers.io())
fun getTemporaryBasalActiveAt(timestamp: Long): Single<ValueWrapper<TemporaryBasal>> = fun getTemporaryBasalActiveAt(timestamp: Long): Single<ValueWrapper<TemporaryBasal>> =
database.temporaryBasalDao.getTemporaryBasalActiveAt(timestamp) database.temporaryBasalDao.getTemporaryBasalActiveAt(timestamp)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
@ -789,11 +738,6 @@ import kotlin.math.roundToInt
.map { if (!ascending) it.reversed() else it } .map { if (!ascending) it.reversed() else it }
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
fun getTemporaryBasalsDataIncludingInvalidFromTimeToTime(from: Long, to: Long, ascending: Boolean): Single<List<TemporaryBasal>> =
database.temporaryBasalDao.getTemporaryBasalDataIncludingInvalidFromTimeToTime(from, to)
.map { if (!ascending) it.reversed() else it }
.subscribeOn(Schedulers.io())
fun getOldestTemporaryBasalRecord(): TemporaryBasal? = fun getOldestTemporaryBasalRecord(): TemporaryBasal? =
database.temporaryBasalDao.getOldestRecord() database.temporaryBasalDao.getOldestRecord()
@ -824,6 +768,7 @@ import kotlin.math.roundToInt
} }
} }
@Suppress("unused")
fun getModifiedExtendedBolusDataFromId(lastId: Long): Single<List<ExtendedBolus>> = fun getModifiedExtendedBolusDataFromId(lastId: Long): Single<List<ExtendedBolus>> =
database.extendedBolusDao.getModifiedFrom(lastId) database.extendedBolusDao.getModifiedFrom(lastId)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
@ -848,11 +793,6 @@ import kotlin.math.roundToInt
.map { if (!ascending) it.reversed() else it } .map { if (!ascending) it.reversed() else it }
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
fun getExtendedBolusDataIncludingInvalidFromTimeToTime(start: Long, end: Long, ascending: Boolean): Single<List<ExtendedBolus>> =
database.extendedBolusDao.getExtendedBolusDataIncludingInvalidFromTimeToTime(start, end)
.map { if (!ascending) it.reversed() else it }
.subscribeOn(Schedulers.io())
fun getOldestExtendedBolusRecord(): ExtendedBolus? = fun getOldestExtendedBolusRecord(): ExtendedBolus? =
database.extendedBolusDao.getOldestRecord() database.extendedBolusDao.getOldestRecord()
@ -897,25 +837,12 @@ import kotlin.math.roundToInt
} }
} }
fun compatGetOfflineEventData(): Single<List<OfflineEvent>> =
database.offlineEventDao.getOfflineEventData()
.subscribeOn(Schedulers.io())
fun getOfflineEventDataFromTime(timestamp: Long, ascending: Boolean): Single<List<OfflineEvent>> =
database.offlineEventDao.getOfflineEventDataFromTime(timestamp)
.map { if (!ascending) it.reversed() else it }
.subscribeOn(Schedulers.io())
fun getOfflineEventDataIncludingInvalidFromTime(timestamp: Long, ascending: Boolean): Single<List<OfflineEvent>> =
database.offlineEventDao.getOfflineEventDataIncludingInvalidFromTime(timestamp)
.map { if (!ascending) it.reversed() else it }
.subscribeOn(Schedulers.io())
fun getOfflineEventDataFromTimeToTime(start: Long, end: Long, ascending: Boolean): Single<List<OfflineEvent>> = fun getOfflineEventDataFromTimeToTime(start: Long, end: Long, ascending: Boolean): Single<List<OfflineEvent>> =
database.offlineEventDao.getOfflineEventDataFromTimeToTime(start, end) database.offlineEventDao.getOfflineEventDataFromTimeToTime(start, end)
.map { if (!ascending) it.reversed() else it } .map { if (!ascending) it.reversed() else it }
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
@Suppress("unused")
fun getModifiedOfflineEventsDataFromId(lastId: Long): Single<List<OfflineEvent>> = fun getModifiedOfflineEventsDataFromId(lastId: Long): Single<List<OfflineEvent>> =
database.offlineEventDao.getModifiedFrom(lastId) database.offlineEventDao.getModifiedFrom(lastId)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
@ -925,6 +852,7 @@ import kotlin.math.roundToInt
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.toWrappedSingle() .toWrappedSingle()
@Suppress("unused")
fun deleteAllOfflineEventEntries() = fun deleteAllOfflineEventEntries() =
database.offlineEventDao.deleteAllEntries() database.offlineEventDao.deleteAllEntries()

View file

@ -59,9 +59,6 @@ internal interface BolusDao : TraceableDao<Bolus> {
@Query("SELECT * FROM $TABLE_BOLUSES WHERE timestamp >= :timestamp AND referenceId IS NULL ORDER BY id DESC") @Query("SELECT * FROM $TABLE_BOLUSES WHERE timestamp >= :timestamp AND referenceId IS NULL ORDER BY id DESC")
fun getBolusesIncludingInvalidFromTime(timestamp: Long): Single<List<Bolus>> fun getBolusesIncludingInvalidFromTime(timestamp: Long): Single<List<Bolus>>
@Query("SELECT * FROM $TABLE_BOLUSES WHERE timestamp >= :from AND timestamp <= :to AND referenceId IS NULL ORDER BY id DESC")
fun getBolusesIncludingInvalidFromTimeToTime(from: Long, to: Long): Single<List<Bolus>>
// This query will be used with v3 to get all changed records // This query will be used with v3 to get all changed records
@Query("SELECT * FROM $TABLE_BOLUSES WHERE id > :id AND pumpId IS NOT NULL AND type <> :exclude AND referenceId IS NULL OR id IN (SELECT DISTINCT referenceId FROM $TABLE_BOLUSES WHERE id > :id) ORDER BY id ASC") @Query("SELECT * FROM $TABLE_BOLUSES WHERE id > :id AND pumpId IS NOT NULL AND type <> :exclude AND referenceId IS NULL OR id IN (SELECT DISTINCT referenceId FROM $TABLE_BOLUSES WHERE id > :id) ORDER BY id ASC")
fun getModifiedFrom(id: Long, exclude: Bolus.Type = Bolus.Type.PRIMING): Single<List<Bolus>> fun getModifiedFrom(id: Long, exclude: Bolus.Type = Bolus.Type.PRIMING): Single<List<Bolus>>

View file

@ -46,24 +46,15 @@ internal interface CarbsDao : TraceableDao<Carbs> {
@Query("SELECT * FROM $TABLE_CARBS WHERE isValid = 1 AND timestamp + duration >= :timestamp AND referenceId IS NULL ORDER BY id DESC") @Query("SELECT * FROM $TABLE_CARBS WHERE isValid = 1 AND timestamp + duration >= :timestamp AND referenceId IS NULL ORDER BY id DESC")
fun getCarbsFromTimeExpandable(timestamp: Long): Single<List<Carbs>> fun getCarbsFromTimeExpandable(timestamp: Long): Single<List<Carbs>>
@Query("SELECT * FROM $TABLE_CARBS WHERE isValid = 1 AND timestamp >= :from AND timestamp <= :to AND referenceId IS NULL ORDER BY id DESC")
fun getCarbsFromTimeToTime(from: Long, to: Long): Single<List<Carbs>>
@Query("SELECT * FROM $TABLE_CARBS WHERE isValid = 1 AND timestamp + duration > :from AND timestamp <= :to AND referenceId IS NULL ORDER BY id DESC") @Query("SELECT * FROM $TABLE_CARBS WHERE isValid = 1 AND timestamp + duration > :from AND timestamp <= :to AND referenceId IS NULL ORDER BY id DESC")
fun getCarbsFromTimeToTimeExpandable(from: Long, to: Long): Single<List<Carbs>> fun getCarbsFromTimeToTimeExpandable(from: Long, to: Long): Single<List<Carbs>>
@Query("SELECT * FROM $TABLE_CARBS WHERE timestamp >= :timestamp AND referenceId IS NULL ORDER BY id DESC") @Query("SELECT * FROM $TABLE_CARBS WHERE timestamp >= :timestamp AND referenceId IS NULL ORDER BY id DESC")
fun getCarbsIncludingInvalidFromTime(timestamp: Long): Single<List<Carbs>> fun getCarbsIncludingInvalidFromTime(timestamp: Long): Single<List<Carbs>>
@Query("SELECT * FROM $TABLE_CARBS WHERE timestamp + duration >= :timestamp AND referenceId IS NULL ORDER BY id DESC")
fun getCarbsIncludingInvalidFromTimeExpandable(timestamp: Long): Single<List<Carbs>>
@Query("SELECT * FROM $TABLE_CARBS WHERE timestamp >= :from AND timestamp <= :to AND referenceId IS NULL ORDER BY id DESC") @Query("SELECT * FROM $TABLE_CARBS WHERE timestamp >= :from AND timestamp <= :to AND referenceId IS NULL ORDER BY id DESC")
fun getCarbsIncludingInvalidFromTimeToTime(from: Long, to: Long): Single<List<Carbs>> fun getCarbsIncludingInvalidFromTimeToTime(from: Long, to: Long): Single<List<Carbs>>
@Query("SELECT * FROM $TABLE_CARBS WHERE timestamp + duration >= :from AND timestamp <= :to AND referenceId IS NULL ORDER BY id DESC")
fun getCarbsIncludingInvalidFromTimeToTimeExpandable(from: Long, to: Long): Single<List<Carbs>>
// This query will be used with v3 to get all changed records // This query will be used with v3 to get all changed records
@Query("SELECT * FROM $TABLE_CARBS WHERE id > :id AND referenceId IS NULL OR id IN (SELECT DISTINCT referenceId FROM $TABLE_CARBS WHERE id > :id) ORDER BY id ASC") @Query("SELECT * FROM $TABLE_CARBS WHERE id > :id AND referenceId IS NULL OR id IN (SELECT DISTINCT referenceId FROM $TABLE_CARBS WHERE id > :id) ORDER BY id ASC")
fun getModifiedFrom(id: Long): Single<List<Carbs>> fun getModifiedFrom(id: Long): Single<List<Carbs>>

View file

@ -53,9 +53,6 @@ internal interface ExtendedBolusDao : TraceableDao<ExtendedBolus> {
@Query("SELECT * FROM $TABLE_EXTENDED_BOLUSES WHERE timestamp >= :timestamp AND referenceId IS NULL ORDER BY timestamp ASC") @Query("SELECT * FROM $TABLE_EXTENDED_BOLUSES WHERE timestamp >= :timestamp AND referenceId IS NULL ORDER BY timestamp ASC")
fun getExtendedBolusDataIncludingInvalidFromTime(timestamp: Long): Single<List<ExtendedBolus>> fun getExtendedBolusDataIncludingInvalidFromTime(timestamp: Long): Single<List<ExtendedBolus>>
@Query("SELECT * FROM $TABLE_EXTENDED_BOLUSES WHERE timestamp >= :from AND timestamp <= :to AND referenceId IS NULL ORDER BY timestamp ASC")
fun getExtendedBolusDataIncludingInvalidFromTimeToTime(from: Long, to: Long): Single<List<ExtendedBolus>>
// This query will be used with v3 to get all changed records // This query will be used with v3 to get all changed records
@Query("SELECT * FROM $TABLE_EXTENDED_BOLUSES WHERE id > :id AND referenceId IS NULL OR id IN (SELECT DISTINCT referenceId FROM $TABLE_EXTENDED_BOLUSES WHERE id > :id) ORDER BY id ASC") @Query("SELECT * FROM $TABLE_EXTENDED_BOLUSES WHERE id > :id AND referenceId IS NULL OR id IN (SELECT DISTINCT referenceId FROM $TABLE_EXTENDED_BOLUSES WHERE id > :id) ORDER BY id ASC")
fun getModifiedFrom(id: Long): Single<List<ExtendedBolus>> fun getModifiedFrom(id: Long): Single<List<ExtendedBolus>>

View file

@ -43,12 +43,6 @@ internal interface GlucoseValueDao : TraceableDao<GlucoseValue> {
@Query("SELECT * FROM $TABLE_GLUCOSE_VALUES WHERE id > :lastId AND referenceId IS NULL ORDER BY timestamp ASC") @Query("SELECT * FROM $TABLE_GLUCOSE_VALUES WHERE id > :lastId AND referenceId IS NULL ORDER BY timestamp ASC")
fun getDataFromId(lastId: Long): Single<List<GlucoseValue>> fun getDataFromId(lastId: Long): Single<List<GlucoseValue>>
@Query("SELECT * FROM $TABLE_GLUCOSE_VALUES WHERE id >= :id")
fun getAllStartingFrom(id: Long): Single<List<GlucoseValue>>
@Query("SELECT * FROM $TABLE_GLUCOSE_VALUES WHERE referenceId = :id ORDER BY id DESC LIMIT 1")
fun getLastHistoryRecord(id: Long): GlucoseValue?
// This query will be used with v3 to get all changed records // This query will be used with v3 to get all changed records
@Query("SELECT * FROM $TABLE_GLUCOSE_VALUES WHERE id > :id AND referenceId IS NULL OR id IN (SELECT DISTINCT referenceId FROM $TABLE_GLUCOSE_VALUES WHERE id > :id) ORDER BY id ASC") @Query("SELECT * FROM $TABLE_GLUCOSE_VALUES WHERE id > :id AND referenceId IS NULL OR id IN (SELECT DISTINCT referenceId FROM $TABLE_GLUCOSE_VALUES WHERE id > :id) ORDER BY id ASC")
fun getModifiedFrom(id: Long): Single<List<GlucoseValue>> fun getModifiedFrom(id: Long): Single<List<GlucoseValue>>

View file

@ -31,18 +31,9 @@ internal interface OfflineEventDao : TraceableDao<OfflineEvent> {
@Query("SELECT * FROM $TABLE_OFFLINE_EVENTS WHERE timestamp <= :timestamp AND (timestamp + duration) > :timestamp AND referenceId IS NULL AND isValid = 1 ORDER BY timestamp DESC LIMIT 1") @Query("SELECT * FROM $TABLE_OFFLINE_EVENTS WHERE timestamp <= :timestamp AND (timestamp + duration) > :timestamp AND referenceId IS NULL AND isValid = 1 ORDER BY timestamp DESC LIMIT 1")
fun getOfflineEventActiveAt(timestamp: Long): Maybe<OfflineEvent> fun getOfflineEventActiveAt(timestamp: Long): Maybe<OfflineEvent>
@Query("SELECT * FROM $TABLE_OFFLINE_EVENTS WHERE timestamp >= :timestamp AND isValid = 1 AND referenceId IS NULL ORDER BY timestamp ASC")
fun getOfflineEventDataFromTime(timestamp: Long): Single<List<OfflineEvent>>
@Query("SELECT * FROM $TABLE_OFFLINE_EVENTS WHERE timestamp >= :timestamp AND referenceId IS NULL ORDER BY timestamp ASC")
fun getOfflineEventDataIncludingInvalidFromTime(timestamp: Long): Single<List<OfflineEvent>>
@Query("SELECT * FROM $TABLE_OFFLINE_EVENTS WHERE timestamp BETWEEN :start AND :end AND isValid = 1 AND referenceId IS NULL ORDER BY timestamp ASC") @Query("SELECT * FROM $TABLE_OFFLINE_EVENTS WHERE timestamp BETWEEN :start AND :end AND isValid = 1 AND referenceId IS NULL ORDER BY timestamp ASC")
fun getOfflineEventDataFromTimeToTime(start: Long, end: Long): Single<List<OfflineEvent>> fun getOfflineEventDataFromTimeToTime(start: Long, end: Long): Single<List<OfflineEvent>>
@Query("SELECT * FROM $TABLE_OFFLINE_EVENTS WHERE isValid = 1 AND referenceId IS NULL ORDER BY timestamp ASC")
fun getOfflineEventData(): Single<List<OfflineEvent>>
// This query will be used with v3 to get all changed records // This query will be used with v3 to get all changed records
@Query("SELECT * FROM $TABLE_OFFLINE_EVENTS WHERE id > :id AND referenceId IS NULL OR id IN (SELECT DISTINCT referenceId FROM $TABLE_OFFLINE_EVENTS WHERE id > :id) ORDER BY id ASC") @Query("SELECT * FROM $TABLE_OFFLINE_EVENTS WHERE id > :id AND referenceId IS NULL OR id IN (SELECT DISTINCT referenceId FROM $TABLE_OFFLINE_EVENTS WHERE id > :id) ORDER BY id ASC")
fun getModifiedFrom(id: Long): Single<List<OfflineEvent>> fun getModifiedFrom(id: Long): Single<List<OfflineEvent>>

View file

@ -62,12 +62,6 @@ internal interface TemporaryBasalDao : TraceableDao<TemporaryBasal> {
@Query("SELECT * FROM $TABLE_TEMPORARY_BASALS WHERE timestamp >= :timestamp AND referenceId IS NULL ORDER BY timestamp ASC") @Query("SELECT * FROM $TABLE_TEMPORARY_BASALS WHERE timestamp >= :timestamp AND referenceId IS NULL ORDER BY timestamp ASC")
fun getTemporaryBasalDataIncludingInvalidFromTime(timestamp: Long): Single<List<TemporaryBasal>> fun getTemporaryBasalDataIncludingInvalidFromTime(timestamp: Long): Single<List<TemporaryBasal>>
@Query("SELECT * FROM $TABLE_TEMPORARY_BASALS WHERE timestamp >= :from AND timestamp <= :to AND referenceId IS NULL ORDER BY timestamp ASC")
fun getTemporaryBasalDataIncludingInvalidFromTimeToTime(from: Long, to: Long): Single<List<TemporaryBasal>>
@Query("SELECT * FROM $TABLE_TEMPORARY_BASALS WHERE isValid = 1 AND referenceId IS NULL ORDER BY timestamp ASC")
fun getTemporaryBasalData(): Single<List<TemporaryBasal>>
@Query("SELECT * FROM $TABLE_TEMPORARY_BASALS WHERE referenceId = :id ORDER BY id DESC LIMIT 1") @Query("SELECT * FROM $TABLE_TEMPORARY_BASALS WHERE referenceId = :id ORDER BY id DESC LIMIT 1")
fun getLastHistoryRecord(id: Long): TemporaryBasal? fun getLastHistoryRecord(id: Long): TemporaryBasal?

View file

@ -37,9 +37,6 @@ internal interface TemporaryTargetDao : TraceableDao<TemporaryTarget> {
@Query("SELECT * FROM $TABLE_TEMPORARY_TARGETS WHERE timestamp >= :timestamp AND referenceId IS NULL ORDER BY timestamp ASC") @Query("SELECT * FROM $TABLE_TEMPORARY_TARGETS WHERE timestamp >= :timestamp AND referenceId IS NULL ORDER BY timestamp ASC")
fun getTemporaryTargetDataIncludingInvalidFromTime(timestamp: Long): Single<List<TemporaryTarget>> fun getTemporaryTargetDataIncludingInvalidFromTime(timestamp: Long): Single<List<TemporaryTarget>>
@Query("SELECT * FROM $TABLE_TEMPORARY_TARGETS WHERE isValid = 1 AND referenceId IS NULL ORDER BY timestamp ASC")
fun getTemporaryTargetData(): Single<List<TemporaryTarget>>
// This query will be used with v3 to get all changed records // This query will be used with v3 to get all changed records
@Query("SELECT * FROM $TABLE_TEMPORARY_TARGETS WHERE id > :id AND referenceId IS NULL OR id IN (SELECT DISTINCT referenceId FROM $TABLE_TEMPORARY_TARGETS WHERE id > :id) ORDER BY id ASC") @Query("SELECT * FROM $TABLE_TEMPORARY_TARGETS WHERE id > :id AND referenceId IS NULL OR id IN (SELECT DISTINCT referenceId FROM $TABLE_TEMPORARY_TARGETS WHERE id > :id) ORDER BY id ASC")
fun getModifiedFrom(id: Long): Single<List<TemporaryTarget>> fun getModifiedFrom(id: Long): Single<List<TemporaryTarget>>

View file

@ -46,9 +46,6 @@ internal interface TherapyEventDao : TraceableDao<TherapyEvent> {
@Query("SELECT * FROM $TABLE_THERAPY_EVENTS WHERE type = :type AND isValid = 1 AND timestamp <= :now ORDER BY timestamp DESC LIMIT 1") @Query("SELECT * FROM $TABLE_THERAPY_EVENTS WHERE type = :type AND isValid = 1 AND timestamp <= :now ORDER BY timestamp DESC LIMIT 1")
fun getLastTherapyRecord(type: TherapyEvent.Type, now: Long): Maybe<TherapyEvent> fun getLastTherapyRecord(type: TherapyEvent.Type, now: Long): Maybe<TherapyEvent>
@Query("SELECT * FROM $TABLE_THERAPY_EVENTS WHERE timestamp >= :timestamp AND isValid = 1 AND referenceId IS NULL ORDER BY timestamp ASC")
fun compatGetTherapyEventDataFromTime(timestamp: Long): Single<List<TherapyEvent>>
@Query("SELECT * FROM $TABLE_THERAPY_EVENTS WHERE timestamp >= :from AND timestamp <= :to AND isValid = 1 AND referenceId IS NULL ORDER BY timestamp ASC") @Query("SELECT * FROM $TABLE_THERAPY_EVENTS WHERE timestamp >= :from AND timestamp <= :to AND isValid = 1 AND referenceId IS NULL ORDER BY timestamp ASC")
fun compatGetTherapyEventDataFromToTime(from: Long, to: Long): Single<List<TherapyEvent>> fun compatGetTherapyEventDataFromToTime(from: Long, to: Long): Single<List<TherapyEvent>>

View file

@ -3,8 +3,9 @@ package info.nightscout.database.impl.daos
import androidx.room.Insert import androidx.room.Insert
import androidx.room.Update import androidx.room.Update
import info.nightscout.database.entities.interfaces.TraceableDBEntry import info.nightscout.database.entities.interfaces.TraceableDBEntry
import info.nightscout.database.impl.daos.workaround.TraceableDaoWorkaround
internal interface TraceableDao<T : TraceableDBEntry> : info.nightscout.database.impl.daos.workaround.TraceableDaoWorkaround<T> { internal interface TraceableDao<T : TraceableDBEntry> : TraceableDaoWorkaround<T> {
fun findById(id: Long): T? fun findById(id: Long): T?

View file

@ -17,9 +17,6 @@ interface UserEntryDao {
@Query("DELETE FROM $TABLE_USER_ENTRY WHERE timestamp < :than") @Query("DELETE FROM $TABLE_USER_ENTRY WHERE timestamp < :than")
fun deleteOlderThan(than: Long): Int fun deleteOlderThan(than: Long): Int
@Query("SELECT * FROM $TABLE_USER_ENTRY ORDER BY id DESC")
fun getAll(): Single<List<UserEntry>>
@Query("SELECT * FROM $TABLE_USER_ENTRY WHERE timestamp >= :timestamp ORDER BY id DESC") @Query("SELECT * FROM $TABLE_USER_ENTRY WHERE timestamp >= :timestamp ORDER BY id DESC")
fun getUserEntryDataFromTime(timestamp: Long): Single<List<UserEntry>> fun getUserEntryDataFromTime(timestamp: Long): Single<List<UserEntry>>

View file

@ -105,8 +105,7 @@ class TreatmentsTempTargetFragment : DaggerFragment(), MenuProvider {
uel.log(Action.TREATMENTS_NS_REFRESH, Sources.Treatments) uel.log(Action.TREATMENTS_NS_REFRESH, Sources.Treatments)
disposable += disposable +=
Completable.fromAction { Completable.fromAction {
repository.deleteAllEffectiveProfileSwitches() repository.deleteAllTempTargetEntries()
repository.deleteAllProfileSwitches()
} }
.subscribeOn(aapsSchedulers.io) .subscribeOn(aapsSchedulers.io)
.observeOn(aapsSchedulers.main) .observeOn(aapsSchedulers.main)