NSC: process nsId updates at once
This commit is contained in:
parent
114710b292
commit
85f170f17d
41 changed files with 700 additions and 565 deletions
|
@ -1,7 +1,48 @@
|
|||
package info.nightscout.interfaces.nsclient
|
||||
|
||||
import info.nightscout.database.entities.Bolus
|
||||
import info.nightscout.database.entities.BolusCalculatorResult
|
||||
import info.nightscout.database.entities.Carbs
|
||||
import info.nightscout.database.entities.DeviceStatus
|
||||
import info.nightscout.database.entities.EffectiveProfileSwitch
|
||||
import info.nightscout.database.entities.ExtendedBolus
|
||||
import info.nightscout.database.entities.Food
|
||||
import info.nightscout.database.entities.GlucoseValue
|
||||
import info.nightscout.database.entities.OfflineEvent
|
||||
import info.nightscout.database.entities.ProfileSwitch
|
||||
import info.nightscout.database.entities.TemporaryBasal
|
||||
import info.nightscout.database.entities.TemporaryTarget
|
||||
import info.nightscout.database.entities.TherapyEvent
|
||||
import info.nightscout.database.transactions.TransactionGlucoseValue
|
||||
|
||||
interface StoreDataForDb {
|
||||
val glucoseValues: MutableList<TransactionGlucoseValue>
|
||||
val boluses: MutableList<Bolus>
|
||||
val carbs: MutableList<Carbs>
|
||||
val temporaryTargets: MutableList<TemporaryTarget>
|
||||
val effectiveProfileSwitches: MutableList<EffectiveProfileSwitch>
|
||||
val bolusCalculatorResults: MutableList<BolusCalculatorResult>
|
||||
val therapyEvents: MutableList<TherapyEvent>
|
||||
val extendedBoluses: MutableList<ExtendedBolus>
|
||||
val temporaryBasals: MutableList<TemporaryBasal>
|
||||
val profileSwitches: MutableList<ProfileSwitch>
|
||||
val offlineEvents: MutableList<OfflineEvent>
|
||||
|
||||
val nsIdGlucoseValues: MutableList<GlucoseValue>
|
||||
val nsIdBoluses: MutableList<Bolus>
|
||||
val nsIdCarbs: MutableList<Carbs>
|
||||
val nsIdFoods: MutableList<Food>
|
||||
val nsIdTemporaryTargets: MutableList<TemporaryTarget>
|
||||
val nsIdEffectiveProfileSwitches: MutableList<EffectiveProfileSwitch>
|
||||
val nsIdBolusCalculatorResults: MutableList<BolusCalculatorResult>
|
||||
val nsIdTherapyEvents: MutableList<TherapyEvent>
|
||||
val nsIdExtendedBoluses: MutableList<ExtendedBolus>
|
||||
val nsIdTemporaryBasals: MutableList<TemporaryBasal>
|
||||
val nsIdProfileSwitches: MutableList<ProfileSwitch>
|
||||
val nsIdOfflineEvents: MutableList<OfflineEvent>
|
||||
val nsIdDeviceStatuses: MutableList<DeviceStatus>
|
||||
|
||||
fun storeTreatmentsToDb()
|
||||
fun storeGlucoseValuesToDb()
|
||||
fun scheduleNsIdUpdate()
|
||||
}
|
|
@ -40,81 +40,42 @@ interface DataSyncSelector {
|
|||
fun resetToNextFullSync()
|
||||
|
||||
fun confirmLastBolusIdIfGreater(lastSynced: Long)
|
||||
fun changedBoluses(): List<Bolus>
|
||||
|
||||
// Until NS v3
|
||||
fun processChangedBolusesCompat()
|
||||
|
||||
fun confirmLastCarbsIdIfGreater(lastSynced: Long)
|
||||
fun changedCarbs(): List<Carbs>
|
||||
|
||||
// Until NS v3
|
||||
fun processChangedCarbsCompat()
|
||||
|
||||
fun confirmLastBolusCalculatorResultsIdIfGreater(lastSynced: Long)
|
||||
fun changedBolusCalculatorResults(): List<BolusCalculatorResult>
|
||||
|
||||
// Until NS v3
|
||||
fun processChangedBolusCalculatorResultsCompat()
|
||||
|
||||
fun confirmLastTempTargetsIdIfGreater(lastSynced: Long)
|
||||
fun changedTempTargets(): List<TemporaryTarget>
|
||||
|
||||
// Until NS v3
|
||||
fun processChangedTempTargetsCompat()
|
||||
|
||||
fun confirmLastGlucoseValueIdIfGreater(lastSynced: Long)
|
||||
fun changedGlucoseValues(): List<GlucoseValue>
|
||||
|
||||
// Until NS v3
|
||||
fun processChangedGlucoseValuesCompat()
|
||||
|
||||
fun confirmLastTherapyEventIdIfGreater(lastSynced: Long)
|
||||
fun changedTherapyEvents(): List<TherapyEvent>
|
||||
|
||||
// Until NS v3
|
||||
fun processChangedTherapyEventsCompat()
|
||||
|
||||
fun confirmLastFoodIdIfGreater(lastSynced: Long)
|
||||
fun changedFoods(): List<Food>
|
||||
|
||||
// Until NS v3
|
||||
fun processChangedFoodsCompat()
|
||||
|
||||
fun confirmLastDeviceStatusIdIfGreater(lastSynced: Long)
|
||||
fun changedDeviceStatuses(): List<DeviceStatus>
|
||||
|
||||
// Until NS v3
|
||||
fun processChangedDeviceStatusesCompat()
|
||||
|
||||
fun confirmLastTemporaryBasalIdIfGreater(lastSynced: Long)
|
||||
fun changedTemporaryBasals(): List<TemporaryBasal>
|
||||
|
||||
// Until NS v3
|
||||
fun processChangedTemporaryBasalsCompat()
|
||||
|
||||
fun confirmLastExtendedBolusIdIfGreater(lastSynced: Long)
|
||||
fun changedExtendedBoluses(): List<ExtendedBolus>
|
||||
|
||||
// Until NS v3
|
||||
fun processChangedExtendedBolusesCompat()
|
||||
|
||||
fun confirmLastProfileSwitchIdIfGreater(lastSynced: Long)
|
||||
fun changedProfileSwitch(): List<ProfileSwitch>
|
||||
|
||||
// Until NS v3
|
||||
fun processChangedProfileSwitchesCompat()
|
||||
|
||||
fun confirmLastEffectiveProfileSwitchIdIfGreater(lastSynced: Long)
|
||||
fun changedEffectiveProfileSwitch(): List<EffectiveProfileSwitch>
|
||||
|
||||
// Until NS v3
|
||||
fun processChangedEffectiveProfileSwitchesCompat()
|
||||
|
||||
fun confirmLastOfflineEventIdIfGreater(lastSynced: Long)
|
||||
fun changedOfflineEvents(): List<OfflineEvent>
|
||||
|
||||
// Until NS v3
|
||||
fun processChangedOfflineEventsCompat()
|
||||
|
||||
fun confirmLastProfileStore(lastSynced: Long)
|
||||
|
|
|
@ -2,7 +2,6 @@ package info.nightscout.interfaces.sync
|
|||
|
||||
import android.text.Spanned
|
||||
import info.nightscout.interfaces.nsclient.NSAlarm
|
||||
import org.json.JSONObject
|
||||
|
||||
interface NsClient : Sync {
|
||||
enum class Version {
|
||||
|
@ -23,6 +22,6 @@ interface NsClient : Sync {
|
|||
|
||||
fun resetToFullSync()
|
||||
|
||||
fun dbAdd(collection: String, originalObject: DataSyncSelector.DataPair, progress: String)
|
||||
fun dbUpdate(collection: String, originalObject: DataSyncSelector.DataPair, progress: String)
|
||||
fun dbAdd(collection: String, dataPair: DataSyncSelector.DataPair, progress: String)
|
||||
fun dbUpdate(collection: String, dataPair: DataSyncSelector.DataPair, progress: String)
|
||||
}
|
|
@ -4,14 +4,14 @@ import info.nightscout.sdk.localmodel.entry.NsUnits
|
|||
|
||||
data class NSBolus(
|
||||
override val date: Long,
|
||||
override val device: String?,
|
||||
override val identifier: String,
|
||||
override val units: NsUnits?,
|
||||
override val srvModified: Long?,
|
||||
override val srvCreated: Long?,
|
||||
override val device: String?= null,
|
||||
override val identifier: String?,
|
||||
override val units: NsUnits?= null,
|
||||
override val srvModified: Long? = null,
|
||||
override val srvCreated: Long? = null,
|
||||
override val utcOffset: Long,
|
||||
override val subject: String?,
|
||||
override var isReadOnly: Boolean,
|
||||
override val subject: String? = null,
|
||||
override var isReadOnly: Boolean = false,
|
||||
override val isValid: Boolean,
|
||||
override val eventType: EventType,
|
||||
override val notes: String?,
|
||||
|
|
|
@ -6,7 +6,7 @@ import org.json.JSONObject
|
|||
data class NSBolusWizard(
|
||||
override val date: Long,
|
||||
override val device: String?,
|
||||
override val identifier: String,
|
||||
override val identifier: String?,
|
||||
override val units: NsUnits?,
|
||||
override val srvModified: Long?,
|
||||
override val srvCreated: Long?,
|
||||
|
|
|
@ -5,7 +5,7 @@ import info.nightscout.sdk.localmodel.entry.NsUnits
|
|||
data class NSCarbs(
|
||||
override val date: Long,
|
||||
override val device: String?,
|
||||
override val identifier: String,
|
||||
override val identifier: String?,
|
||||
override val units: NsUnits?,
|
||||
override val srvModified: Long?,
|
||||
override val srvCreated: Long?,
|
||||
|
|
|
@ -6,7 +6,7 @@ import org.json.JSONObject
|
|||
data class NSEffectiveProfileSwitch(
|
||||
override val date: Long,
|
||||
override val device: String?,
|
||||
override val identifier: String,
|
||||
override val identifier: String?,
|
||||
override val units: NsUnits?,
|
||||
override val srvModified: Long?,
|
||||
override val srvCreated: Long?,
|
||||
|
|
|
@ -5,7 +5,7 @@ import info.nightscout.sdk.localmodel.entry.NsUnits
|
|||
data class NSExtendedBolus(
|
||||
override val date: Long,
|
||||
override val device: String?,
|
||||
override val identifier: String,
|
||||
override val identifier: String?,
|
||||
override val units: NsUnits?,
|
||||
override val srvModified: Long?,
|
||||
override val srvCreated: Long?,
|
||||
|
|
|
@ -5,7 +5,7 @@ import info.nightscout.sdk.localmodel.entry.NsUnits
|
|||
data class NSOfflineEvent(
|
||||
override val date: Long,
|
||||
override val device: String?,
|
||||
override val identifier: String,
|
||||
override val identifier: String?,
|
||||
override val units: NsUnits?,
|
||||
override val srvModified: Long?,
|
||||
override val srvCreated: Long?,
|
||||
|
|
|
@ -6,7 +6,7 @@ import org.json.JSONObject
|
|||
data class NSProfileSwitch(
|
||||
override val date: Long,
|
||||
override val device: String?,
|
||||
override val identifier: String,
|
||||
override val identifier: String?,
|
||||
override val units: NsUnits?,
|
||||
override val srvModified: Long?,
|
||||
override val srvCreated: Long?,
|
||||
|
|
|
@ -6,7 +6,7 @@ import org.json.JSONObject
|
|||
data class NSTemporaryBasal(
|
||||
override val date: Long,
|
||||
override val device: String?,
|
||||
override val identifier: String,
|
||||
override val identifier: String?,
|
||||
override val units: NsUnits?,
|
||||
override val srvModified: Long?,
|
||||
override val srvCreated: Long?,
|
||||
|
|
|
@ -5,7 +5,7 @@ import info.nightscout.sdk.localmodel.entry.NsUnits
|
|||
data class NSTemporaryTarget(
|
||||
override val date: Long,
|
||||
override val device: String?,
|
||||
override val identifier: String,
|
||||
override val identifier: String?,
|
||||
override val units: NsUnits?,
|
||||
override val srvModified: Long?,
|
||||
override val srvCreated: Long?,
|
||||
|
|
|
@ -6,7 +6,7 @@ import info.nightscout.sdk.localmodel.entry.NsUnits
|
|||
data class NSTherapyEvent(
|
||||
override val date: Long,
|
||||
override val device: String?,
|
||||
override val identifier: String,
|
||||
override val identifier: String?,
|
||||
override val units: NsUnits?,
|
||||
override val srvModified: Long?,
|
||||
override val srvCreated: Long?,
|
||||
|
|
|
@ -5,7 +5,7 @@ import info.nightscout.sdk.localmodel.entry.NsUnits
|
|||
interface NSTreatment {
|
||||
val date: Long
|
||||
val device: String?
|
||||
val identifier: String
|
||||
val identifier: String?
|
||||
val units: NsUnits?
|
||||
val eventType: EventType
|
||||
val srvModified: Long?
|
||||
|
|
|
@ -17,7 +17,7 @@ import org.json.JSONObject
|
|||
*
|
||||
* */
|
||||
internal data class RemoteTreatment(
|
||||
@SerializedName("identifier") val identifier: String, // string Main addressing, required field that identifies document in the collection. The client should not create the identifier, the server automatically assigns it when the document is inserted.
|
||||
@SerializedName("identifier") val identifier: String?, // string Main addressing, required field that identifies document in the collection. The client should not create the identifier, the server automatically assigns it when the document is inserted.
|
||||
@SerializedName("date") val date: Long? = null, // integer($int64) or string required timestamp when the record or event occurred, you can choose from three input formats Unix epoch in milliseconds (1525383610088), Unix epoch in seconds (1525383610), ISO 8601 with optional timezone ('2018-05-03T21:40:10.088Z' or '2018-05-03T23:40:10.088+02:00')
|
||||
@SerializedName("mills") val mills: Long? = null, // integer($int64) or string required timestamp when the record or event occurred, you can choose from three input formats Unix
|
||||
@SerializedName("timestamp") val timestamp: Long? = null, // integer($int64) or string required timestamp when the record or event occurred, you can choose from three input formats Unix epoch in milliseconds (1525383610088), Unix epoch in seconds (1525383610), ISO 8601 with optional timezone ('2018-05-03T21:40:10.088Z' or '2018-05-03T23:40:10.088+02:00')
|
||||
|
|
|
@ -2,13 +2,23 @@ package info.nightscout.database.impl.transactions
|
|||
|
||||
import info.nightscout.database.entities.BolusCalculatorResult
|
||||
|
||||
class UpdateNsIdBolusCalculatorResultTransaction(val bolusCalculatorResult: BolusCalculatorResult) : Transaction<Unit>() {
|
||||
class UpdateNsIdBolusCalculatorResultTransaction(private val bolusCalculatorResults: List<BolusCalculatorResult>) : Transaction<UpdateNsIdBolusCalculatorResultTransaction.TransactionResult>() {
|
||||
|
||||
override fun run() {
|
||||
val current = database.bolusCalculatorResultDao.findById(bolusCalculatorResult.id)
|
||||
if (current != null && current.interfaceIDs.nightscoutId != bolusCalculatorResult.interfaceIDs.nightscoutId) {
|
||||
current.interfaceIDs.nightscoutId = bolusCalculatorResult.interfaceIDs.nightscoutId
|
||||
database.bolusCalculatorResultDao.updateExistingEntry(current)
|
||||
val result = TransactionResult()
|
||||
override fun run(): TransactionResult {
|
||||
for (bolusCalculatorResult in bolusCalculatorResults) {
|
||||
val current = database.bolusCalculatorResultDao.findById(bolusCalculatorResult.id)
|
||||
if (current != null && current.interfaceIDs.nightscoutId != bolusCalculatorResult.interfaceIDs.nightscoutId) {
|
||||
current.interfaceIDs.nightscoutId = bolusCalculatorResult.interfaceIDs.nightscoutId
|
||||
database.bolusCalculatorResultDao.updateExistingEntry(current)
|
||||
result.updatedNsId.add(current)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
class TransactionResult {
|
||||
|
||||
val updatedNsId = mutableListOf<BolusCalculatorResult>()
|
||||
}
|
||||
}
|
|
@ -2,13 +2,23 @@ package info.nightscout.database.impl.transactions
|
|||
|
||||
import info.nightscout.database.entities.Bolus
|
||||
|
||||
class UpdateNsIdBolusTransaction(val bolus: Bolus) : Transaction<Unit>() {
|
||||
class UpdateNsIdBolusTransaction(private val boluses: List<Bolus>) : Transaction<UpdateNsIdBolusTransaction.TransactionResult>() {
|
||||
|
||||
override fun run() {
|
||||
val current = database.bolusDao.findById(bolus.id)
|
||||
if (current != null && current.interfaceIDs.nightscoutId != bolus.interfaceIDs.nightscoutId) {
|
||||
current.interfaceIDs.nightscoutId = bolus.interfaceIDs.nightscoutId
|
||||
database.bolusDao.updateExistingEntry(current)
|
||||
val result = TransactionResult()
|
||||
override fun run(): TransactionResult {
|
||||
for (bolus in boluses) {
|
||||
val current = database.bolusDao.findById(bolus.id)
|
||||
if (current != null && current.interfaceIDs.nightscoutId != bolus.interfaceIDs.nightscoutId) {
|
||||
current.interfaceIDs.nightscoutId = bolus.interfaceIDs.nightscoutId
|
||||
database.bolusDao.updateExistingEntry(current)
|
||||
result.updatedNsId.add(current)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
class TransactionResult {
|
||||
|
||||
val updatedNsId = mutableListOf<Bolus>()
|
||||
}
|
||||
}
|
|
@ -2,13 +2,23 @@ package info.nightscout.database.impl.transactions
|
|||
|
||||
import info.nightscout.database.entities.Carbs
|
||||
|
||||
class UpdateNsIdCarbsTransaction(val carbs: Carbs) : Transaction<Unit>() {
|
||||
class UpdateNsIdCarbsTransaction(private val carbs: List<Carbs>) : Transaction<UpdateNsIdCarbsTransaction.TransactionResult>() {
|
||||
|
||||
override fun run() {
|
||||
val current = database.carbsDao.findById(carbs.id)
|
||||
if (current != null && current.interfaceIDs.nightscoutId != carbs.interfaceIDs.nightscoutId) {
|
||||
current.interfaceIDs.nightscoutId = carbs.interfaceIDs.nightscoutId
|
||||
database.carbsDao.updateExistingEntry(current)
|
||||
val result = TransactionResult()
|
||||
override fun run(): TransactionResult {
|
||||
for (carb in carbs) {
|
||||
val current = database.carbsDao.findById(carb.id)
|
||||
if (current != null && current.interfaceIDs.nightscoutId != carb.interfaceIDs.nightscoutId) {
|
||||
current.interfaceIDs.nightscoutId = carb.interfaceIDs.nightscoutId
|
||||
database.carbsDao.updateExistingEntry(current)
|
||||
result.updatedNsId.add(current)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
class TransactionResult {
|
||||
|
||||
val updatedNsId = mutableListOf<Carbs>()
|
||||
}
|
||||
}
|
|
@ -2,13 +2,23 @@ package info.nightscout.database.impl.transactions
|
|||
|
||||
import info.nightscout.database.entities.DeviceStatus
|
||||
|
||||
class UpdateNsIdDeviceStatusTransaction(val deviceStatus: DeviceStatus) : Transaction<Unit>() {
|
||||
class UpdateNsIdDeviceStatusTransaction(private val deviceStatuses: List<DeviceStatus>) : Transaction<UpdateNsIdDeviceStatusTransaction.TransactionResult>() {
|
||||
|
||||
override fun run() {
|
||||
val current = database.deviceStatusDao.findById(deviceStatus.id)
|
||||
if (current != null && current.interfaceIDs.nightscoutId != deviceStatus.interfaceIDs.nightscoutId) {
|
||||
current.interfaceIDs.nightscoutId = deviceStatus.interfaceIDs.nightscoutId
|
||||
database.deviceStatusDao.update(current)
|
||||
val result = TransactionResult()
|
||||
override fun run(): TransactionResult {
|
||||
for (deviceStatus in deviceStatuses) {
|
||||
val current = database.deviceStatusDao.findById(deviceStatus.id)
|
||||
if (current != null && current.interfaceIDs.nightscoutId != deviceStatus.interfaceIDs.nightscoutId) {
|
||||
current.interfaceIDs.nightscoutId = deviceStatus.interfaceIDs.nightscoutId
|
||||
database.deviceStatusDao.update(current)
|
||||
result.updatedNsId.add(current)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
class TransactionResult {
|
||||
|
||||
val updatedNsId = mutableListOf<DeviceStatus>()
|
||||
}
|
||||
}
|
|
@ -2,13 +2,23 @@ package info.nightscout.database.impl.transactions
|
|||
|
||||
import info.nightscout.database.entities.EffectiveProfileSwitch
|
||||
|
||||
class UpdateNsIdEffectiveProfileSwitchTransaction(val effectiveProfileSwitch: EffectiveProfileSwitch) : Transaction<Unit>() {
|
||||
class UpdateNsIdEffectiveProfileSwitchTransaction(private val effectiveProfileSwitches: List<EffectiveProfileSwitch>) : Transaction<UpdateNsIdEffectiveProfileSwitchTransaction.TransactionResult>() {
|
||||
|
||||
override fun run() {
|
||||
val current = database.effectiveProfileSwitchDao.findById(effectiveProfileSwitch.id)
|
||||
if (current != null && current.interfaceIDs.nightscoutId != effectiveProfileSwitch.interfaceIDs.nightscoutId) {
|
||||
current.interfaceIDs.nightscoutId = effectiveProfileSwitch.interfaceIDs.nightscoutId
|
||||
database.effectiveProfileSwitchDao.updateExistingEntry(current)
|
||||
val result = TransactionResult()
|
||||
override fun run(): TransactionResult {
|
||||
for (effectiveProfileSwitch in effectiveProfileSwitches) {
|
||||
val current = database.effectiveProfileSwitchDao.findById(effectiveProfileSwitch.id)
|
||||
if (current != null && current.interfaceIDs.nightscoutId != effectiveProfileSwitch.interfaceIDs.nightscoutId) {
|
||||
current.interfaceIDs.nightscoutId = effectiveProfileSwitch.interfaceIDs.nightscoutId
|
||||
database.effectiveProfileSwitchDao.updateExistingEntry(current)
|
||||
result.updatedNsId.add(current)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
class TransactionResult {
|
||||
|
||||
val updatedNsId = mutableListOf<EffectiveProfileSwitch>()
|
||||
}
|
||||
}
|
|
@ -2,13 +2,23 @@ package info.nightscout.database.impl.transactions
|
|||
|
||||
import info.nightscout.database.entities.ExtendedBolus
|
||||
|
||||
class UpdateNsIdExtendedBolusTransaction(val bolus: ExtendedBolus) : Transaction<Unit>() {
|
||||
class UpdateNsIdExtendedBolusTransaction(val boluses: List<ExtendedBolus>) : Transaction<UpdateNsIdExtendedBolusTransaction.TransactionResult>() {
|
||||
|
||||
override fun run() {
|
||||
val current = database.extendedBolusDao.findById(bolus.id)
|
||||
if (current != null && current.interfaceIDs.nightscoutId != bolus.interfaceIDs.nightscoutId) {
|
||||
current.interfaceIDs.nightscoutId = bolus.interfaceIDs.nightscoutId
|
||||
database.extendedBolusDao.updateExistingEntry(current)
|
||||
val result = TransactionResult()
|
||||
override fun run(): TransactionResult {
|
||||
for (bolus in boluses) {
|
||||
val current = database.extendedBolusDao.findById(bolus.id)
|
||||
if (current != null && current.interfaceIDs.nightscoutId != bolus.interfaceIDs.nightscoutId) {
|
||||
current.interfaceIDs.nightscoutId = bolus.interfaceIDs.nightscoutId
|
||||
database.extendedBolusDao.updateExistingEntry(current)
|
||||
result.updatedNsId.add(current)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
class TransactionResult {
|
||||
|
||||
val updatedNsId = mutableListOf<ExtendedBolus>()
|
||||
}
|
||||
}
|
|
@ -2,13 +2,24 @@ package info.nightscout.database.impl.transactions
|
|||
|
||||
import info.nightscout.database.entities.Food
|
||||
|
||||
class UpdateNsIdFoodTransaction(val food: Food) : Transaction<Unit>() {
|
||||
class UpdateNsIdFoodTransaction(private val foods: List<Food>) : Transaction<UpdateNsIdFoodTransaction.TransactionResult>() {
|
||||
|
||||
override fun run() {
|
||||
val current = database.foodDao.findById(food.id)
|
||||
if (current != null && current.interfaceIDs.nightscoutId != food.interfaceIDs.nightscoutId) {
|
||||
current.interfaceIDs.nightscoutId = food.interfaceIDs.nightscoutId
|
||||
database.foodDao.updateExistingEntry(current)
|
||||
val result = TransactionResult()
|
||||
|
||||
override fun run(): TransactionResult {
|
||||
for (food in foods) {
|
||||
val current = database.foodDao.findById(food.id)
|
||||
if (current != null && current.interfaceIDs.nightscoutId != food.interfaceIDs.nightscoutId) {
|
||||
current.interfaceIDs.nightscoutId = food.interfaceIDs.nightscoutId
|
||||
database.foodDao.updateExistingEntry(current)
|
||||
result.updatedNsId.add(current)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
class TransactionResult {
|
||||
|
||||
val updatedNsId = mutableListOf<Food>()
|
||||
}
|
||||
}
|
|
@ -2,13 +2,23 @@ package info.nightscout.database.impl.transactions
|
|||
|
||||
import info.nightscout.database.entities.GlucoseValue
|
||||
|
||||
class UpdateNsIdGlucoseValueTransaction(val glucoseValue: GlucoseValue) : Transaction<Unit>() {
|
||||
class UpdateNsIdGlucoseValueTransaction(private val glucoseValues: List<GlucoseValue>) : Transaction<UpdateNsIdGlucoseValueTransaction.TransactionResult>() {
|
||||
|
||||
override fun run() {
|
||||
val current = database.glucoseValueDao.findById(glucoseValue.id)
|
||||
if (current != null && current.interfaceIDs.nightscoutId != glucoseValue.interfaceIDs.nightscoutId) {
|
||||
current.interfaceIDs.nightscoutId = glucoseValue.interfaceIDs.nightscoutId
|
||||
database.glucoseValueDao.updateExistingEntry(current)
|
||||
val result = TransactionResult()
|
||||
override fun run(): TransactionResult {
|
||||
for (glucoseValue in glucoseValues) {
|
||||
val current = database.glucoseValueDao.findById(glucoseValue.id)
|
||||
if (current != null && current.interfaceIDs.nightscoutId != glucoseValue.interfaceIDs.nightscoutId) {
|
||||
current.interfaceIDs.nightscoutId = glucoseValue.interfaceIDs.nightscoutId
|
||||
database.glucoseValueDao.updateExistingEntry(current)
|
||||
result.updatedNsId.add(current)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
class TransactionResult {
|
||||
|
||||
val updatedNsId = mutableListOf<GlucoseValue>()
|
||||
}
|
||||
}
|
|
@ -2,13 +2,23 @@ package info.nightscout.database.impl.transactions
|
|||
|
||||
import info.nightscout.database.entities.OfflineEvent
|
||||
|
||||
class UpdateNsIdOfflineEventTransaction(val offlineEvent: OfflineEvent) : Transaction<Unit>() {
|
||||
class UpdateNsIdOfflineEventTransaction(private val offlineEvents: List<OfflineEvent>) : Transaction<UpdateNsIdOfflineEventTransaction.TransactionResult>() {
|
||||
|
||||
override fun run() {
|
||||
val current = database.offlineEventDao.findById(offlineEvent.id)
|
||||
if (current != null && current.interfaceIDs.nightscoutId != offlineEvent.interfaceIDs.nightscoutId) {
|
||||
current.interfaceIDs.nightscoutId = offlineEvent.interfaceIDs.nightscoutId
|
||||
database.offlineEventDao.updateExistingEntry(current)
|
||||
val result = TransactionResult()
|
||||
override fun run(): TransactionResult {
|
||||
for (offlineEvent in offlineEvents) {
|
||||
val current = database.offlineEventDao.findById(offlineEvent.id)
|
||||
if (current != null && current.interfaceIDs.nightscoutId != offlineEvent.interfaceIDs.nightscoutId) {
|
||||
current.interfaceIDs.nightscoutId = offlineEvent.interfaceIDs.nightscoutId
|
||||
database.offlineEventDao.updateExistingEntry(current)
|
||||
result.updatedNsId.add(current)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
class TransactionResult {
|
||||
|
||||
val updatedNsId = mutableListOf<OfflineEvent>()
|
||||
}
|
||||
}
|
|
@ -2,13 +2,23 @@ package info.nightscout.database.impl.transactions
|
|||
|
||||
import info.nightscout.database.entities.ProfileSwitch
|
||||
|
||||
class UpdateNsIdProfileSwitchTransaction(val profileSwitch: ProfileSwitch) : Transaction<Unit>() {
|
||||
class UpdateNsIdProfileSwitchTransaction(val profileSwitches: List<ProfileSwitch>) : Transaction<UpdateNsIdProfileSwitchTransaction.TransactionResult>() {
|
||||
|
||||
override fun run() {
|
||||
val current = database.profileSwitchDao.findById(profileSwitch.id)
|
||||
if (current != null && current.interfaceIDs.nightscoutId != profileSwitch.interfaceIDs.nightscoutId) {
|
||||
current.interfaceIDs.nightscoutId = profileSwitch.interfaceIDs.nightscoutId
|
||||
database.profileSwitchDao.updateExistingEntry(current)
|
||||
val result = TransactionResult()
|
||||
override fun run(): TransactionResult {
|
||||
for (profileSwitch in profileSwitches) {
|
||||
val current = database.profileSwitchDao.findById(profileSwitch.id)
|
||||
if (current != null && current.interfaceIDs.nightscoutId != profileSwitch.interfaceIDs.nightscoutId) {
|
||||
current.interfaceIDs.nightscoutId = profileSwitch.interfaceIDs.nightscoutId
|
||||
database.profileSwitchDao.updateExistingEntry(current)
|
||||
result.updatedNsId.add(current)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
class TransactionResult {
|
||||
|
||||
val updatedNsId = mutableListOf<ProfileSwitch>()
|
||||
}
|
||||
}
|
|
@ -2,13 +2,23 @@ package info.nightscout.database.impl.transactions
|
|||
|
||||
import info.nightscout.database.entities.TemporaryBasal
|
||||
|
||||
class UpdateNsIdTemporaryBasalTransaction(val temporaryBasal: TemporaryBasal) : Transaction<Unit>() {
|
||||
class UpdateNsIdTemporaryBasalTransaction(private val temporaryBasals: List<TemporaryBasal>) : Transaction<UpdateNsIdTemporaryBasalTransaction.TransactionResult>() {
|
||||
|
||||
override fun run() {
|
||||
val current = database.temporaryBasalDao.findById(temporaryBasal.id)
|
||||
if (current != null && current.interfaceIDs.nightscoutId != temporaryBasal.interfaceIDs.nightscoutId) {
|
||||
current.interfaceIDs.nightscoutId = temporaryBasal.interfaceIDs.nightscoutId
|
||||
database.temporaryBasalDao.updateExistingEntry(current)
|
||||
val result = TransactionResult()
|
||||
override fun run(): TransactionResult {
|
||||
for (temporaryBasal in temporaryBasals) {
|
||||
val current = database.temporaryBasalDao.findById(temporaryBasal.id)
|
||||
if (current != null && current.interfaceIDs.nightscoutId != temporaryBasal.interfaceIDs.nightscoutId) {
|
||||
current.interfaceIDs.nightscoutId = temporaryBasal.interfaceIDs.nightscoutId
|
||||
database.temporaryBasalDao.updateExistingEntry(current)
|
||||
result.updatedNsId.add(current)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
class TransactionResult {
|
||||
|
||||
val updatedNsId = mutableListOf<TemporaryBasal>()
|
||||
}
|
||||
}
|
|
@ -2,13 +2,23 @@ package info.nightscout.database.impl.transactions
|
|||
|
||||
import info.nightscout.database.entities.TemporaryTarget
|
||||
|
||||
class UpdateNsIdTemporaryTargetTransaction(val temporaryTarget: TemporaryTarget) : Transaction<Unit>() {
|
||||
class UpdateNsIdTemporaryTargetTransaction(private val temporaryTargets: List<TemporaryTarget>) : Transaction<UpdateNsIdTemporaryTargetTransaction.TransactionResult>() {
|
||||
|
||||
override fun run() {
|
||||
val current = database.temporaryTargetDao.findById(temporaryTarget.id)
|
||||
if (current != null && current.interfaceIDs.nightscoutId != temporaryTarget.interfaceIDs.nightscoutId) {
|
||||
current.interfaceIDs.nightscoutId = temporaryTarget.interfaceIDs.nightscoutId
|
||||
database.temporaryTargetDao.updateExistingEntry(current)
|
||||
val result = TransactionResult()
|
||||
override fun run(): TransactionResult {
|
||||
for (temporaryTarget in temporaryTargets) {
|
||||
val current = database.temporaryTargetDao.findById(temporaryTarget.id)
|
||||
if (current != null && current.interfaceIDs.nightscoutId != temporaryTarget.interfaceIDs.nightscoutId) {
|
||||
current.interfaceIDs.nightscoutId = temporaryTarget.interfaceIDs.nightscoutId
|
||||
database.temporaryTargetDao.updateExistingEntry(current)
|
||||
result.updatedNsId.add(current)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
class TransactionResult {
|
||||
|
||||
val updatedNsId = mutableListOf<TemporaryTarget>()
|
||||
}
|
||||
}
|
|
@ -2,13 +2,23 @@ package info.nightscout.database.impl.transactions
|
|||
|
||||
import info.nightscout.database.entities.TherapyEvent
|
||||
|
||||
class UpdateNsIdTherapyEventTransaction(val therapyEvent: TherapyEvent) : Transaction<Unit>() {
|
||||
class UpdateNsIdTherapyEventTransaction(val therapyEvents: List<TherapyEvent>) : Transaction<UpdateNsIdTherapyEventTransaction.TransactionResult>() {
|
||||
|
||||
override fun run() {
|
||||
val current = database.therapyEventDao.findById(therapyEvent.id)
|
||||
if (current != null && current.interfaceIDs.nightscoutId != therapyEvent.interfaceIDs.nightscoutId) {
|
||||
current.interfaceIDs.nightscoutId = therapyEvent.interfaceIDs.nightscoutId
|
||||
database.therapyEventDao.updateExistingEntry(current)
|
||||
val result = TransactionResult()
|
||||
override fun run(): TransactionResult {
|
||||
for (therapyEvent in therapyEvents) {
|
||||
val current = database.therapyEventDao.findById(therapyEvent.id)
|
||||
if (current != null && current.interfaceIDs.nightscoutId != therapyEvent.interfaceIDs.nightscoutId) {
|
||||
current.interfaceIDs.nightscoutId = therapyEvent.interfaceIDs.nightscoutId
|
||||
database.therapyEventDao.updateExistingEntry(current)
|
||||
result.updatedNsId.add(current)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
class TransactionResult {
|
||||
|
||||
val updatedNsId = mutableListOf<TherapyEvent>()
|
||||
}
|
||||
}
|
|
@ -7,8 +7,10 @@ import info.nightscout.core.utils.worker.LoggingWorker
|
|||
import info.nightscout.database.entities.Bolus
|
||||
import info.nightscout.database.entities.BolusCalculatorResult
|
||||
import info.nightscout.database.entities.Carbs
|
||||
import info.nightscout.database.entities.DeviceStatus
|
||||
import info.nightscout.database.entities.EffectiveProfileSwitch
|
||||
import info.nightscout.database.entities.ExtendedBolus
|
||||
import info.nightscout.database.entities.Food
|
||||
import info.nightscout.database.entities.GlucoseValue
|
||||
import info.nightscout.database.entities.OfflineEvent
|
||||
import info.nightscout.database.entities.ProfileSwitch
|
||||
|
@ -29,6 +31,19 @@ import info.nightscout.database.impl.transactions.SyncNsProfileSwitchTransaction
|
|||
import info.nightscout.database.impl.transactions.SyncNsTemporaryBasalTransaction
|
||||
import info.nightscout.database.impl.transactions.SyncNsTemporaryTargetTransaction
|
||||
import info.nightscout.database.impl.transactions.SyncNsTherapyEventTransaction
|
||||
import info.nightscout.database.impl.transactions.UpdateNsIdBolusCalculatorResultTransaction
|
||||
import info.nightscout.database.impl.transactions.UpdateNsIdBolusTransaction
|
||||
import info.nightscout.database.impl.transactions.UpdateNsIdCarbsTransaction
|
||||
import info.nightscout.database.impl.transactions.UpdateNsIdDeviceStatusTransaction
|
||||
import info.nightscout.database.impl.transactions.UpdateNsIdEffectiveProfileSwitchTransaction
|
||||
import info.nightscout.database.impl.transactions.UpdateNsIdExtendedBolusTransaction
|
||||
import info.nightscout.database.impl.transactions.UpdateNsIdFoodTransaction
|
||||
import info.nightscout.database.impl.transactions.UpdateNsIdGlucoseValueTransaction
|
||||
import info.nightscout.database.impl.transactions.UpdateNsIdOfflineEventTransaction
|
||||
import info.nightscout.database.impl.transactions.UpdateNsIdProfileSwitchTransaction
|
||||
import info.nightscout.database.impl.transactions.UpdateNsIdTemporaryBasalTransaction
|
||||
import info.nightscout.database.impl.transactions.UpdateNsIdTemporaryTargetTransaction
|
||||
import info.nightscout.database.impl.transactions.UpdateNsIdTherapyEventTransaction
|
||||
import info.nightscout.database.transactions.TransactionGlucoseValue
|
||||
import info.nightscout.interfaces.Config
|
||||
import info.nightscout.interfaces.Constants
|
||||
|
@ -55,6 +70,8 @@ import info.nightscout.sdk.localmodel.treatment.NSTemporaryTarget
|
|||
import info.nightscout.sdk.localmodel.treatment.NSTherapyEvent
|
||||
import info.nightscout.shared.sharedPreferences.SP
|
||||
import info.nightscout.shared.utils.DateUtil
|
||||
import java.util.concurrent.Executors
|
||||
import java.util.concurrent.ScheduledFuture
|
||||
import java.util.concurrent.TimeUnit
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
@ -75,17 +92,30 @@ class StoreDataForDbImpl @Inject constructor(
|
|||
) : StoreDataForDb {
|
||||
|
||||
override val glucoseValues: MutableList<TransactionGlucoseValue> = mutableListOf()
|
||||
override val boluses: MutableList<Bolus> = mutableListOf()
|
||||
override val carbs: MutableList<Carbs> = mutableListOf()
|
||||
override val temporaryTargets: MutableList<TemporaryTarget> = mutableListOf()
|
||||
override val effectiveProfileSwitches: MutableList<EffectiveProfileSwitch> = mutableListOf()
|
||||
override val bolusCalculatorResults: MutableList<BolusCalculatorResult> = mutableListOf()
|
||||
override val therapyEvents: MutableList<TherapyEvent> = mutableListOf()
|
||||
override val extendedBoluses: MutableList<ExtendedBolus> = mutableListOf()
|
||||
override val temporaryBasals: MutableList<TemporaryBasal> = mutableListOf()
|
||||
override val profileSwitches: MutableList<ProfileSwitch> = mutableListOf()
|
||||
override val offlineEvents: MutableList<OfflineEvent> = mutableListOf()
|
||||
|
||||
val boluses: MutableList<Bolus> = mutableListOf()
|
||||
val carbs: MutableList<Carbs> = mutableListOf()
|
||||
val temporaryTargets: MutableList<TemporaryTarget> = mutableListOf()
|
||||
val effectiveProfileSwitches: MutableList<EffectiveProfileSwitch> = mutableListOf()
|
||||
val bolusCalculatorResults: MutableList<BolusCalculatorResult> = mutableListOf()
|
||||
val therapyEvents: MutableList<TherapyEvent> = mutableListOf()
|
||||
val extendedBoluses: MutableList<ExtendedBolus> = mutableListOf()
|
||||
val temporaryBasals: MutableList<TemporaryBasal> = mutableListOf()
|
||||
val profileSwitches: MutableList<ProfileSwitch> = mutableListOf()
|
||||
val offlineEvents: MutableList<OfflineEvent> = mutableListOf()
|
||||
override val nsIdGlucoseValues: MutableList<GlucoseValue> = mutableListOf()
|
||||
override val nsIdBoluses: MutableList<Bolus> = mutableListOf()
|
||||
override val nsIdCarbs: MutableList<Carbs> = mutableListOf()
|
||||
override val nsIdFoods: MutableList<Food> = mutableListOf()
|
||||
override val nsIdTemporaryTargets: MutableList<TemporaryTarget> = mutableListOf()
|
||||
override val nsIdEffectiveProfileSwitches: MutableList<EffectiveProfileSwitch> = mutableListOf()
|
||||
override val nsIdBolusCalculatorResults: MutableList<BolusCalculatorResult> = mutableListOf()
|
||||
override val nsIdTherapyEvents: MutableList<TherapyEvent> = mutableListOf()
|
||||
override val nsIdExtendedBoluses: MutableList<ExtendedBolus> = mutableListOf()
|
||||
override val nsIdTemporaryBasals: MutableList<TemporaryBasal> = mutableListOf()
|
||||
override val nsIdProfileSwitches: MutableList<ProfileSwitch> = mutableListOf()
|
||||
override val nsIdOfflineEvents: MutableList<OfflineEvent> = mutableListOf()
|
||||
override val nsIdDeviceStatuses: MutableList<DeviceStatus> = mutableListOf()
|
||||
|
||||
private val userEntries: MutableList<UserEntry> = mutableListOf()
|
||||
|
||||
|
@ -103,7 +133,7 @@ class StoreDataForDbImpl @Inject constructor(
|
|||
params: WorkerParameters
|
||||
) : LoggingWorker(context, params) {
|
||||
|
||||
@Inject lateinit var storeDataForDb: StoreDataForDbImpl
|
||||
@Inject lateinit var storeDataForDb: StoreDataForDb
|
||||
|
||||
override fun doWorkAndLog(): Result {
|
||||
storeDataForDb.storeGlucoseValuesToDb()
|
||||
|
@ -115,7 +145,7 @@ class StoreDataForDbImpl @Inject constructor(
|
|||
if (containsKey(key)) merge(key, 1, Long::plus)
|
||||
else put(key, 1)
|
||||
|
||||
private fun storeGlucoseValuesToDb() {
|
||||
override fun storeGlucoseValuesToDb() {
|
||||
rxBus.send(EventNSClientNewLog("PROCESSING BG", ""))
|
||||
|
||||
if (glucoseValues.isNotEmpty())
|
||||
|
@ -151,7 +181,7 @@ class StoreDataForDbImpl @Inject constructor(
|
|||
rxBus.send(EventNSClientNewLog("DONE BG", ""))
|
||||
}
|
||||
|
||||
fun storeTreatmentsToDb() {
|
||||
override fun storeTreatmentsToDb() {
|
||||
rxBus.send(EventNSClientNewLog("PROCESSING TR", ""))
|
||||
|
||||
if (boluses.isNotEmpty())
|
||||
|
@ -731,6 +761,168 @@ class StoreDataForDbImpl @Inject constructor(
|
|||
rxBus.send(EventNSClientNewLog("DONE TR", ""))
|
||||
}
|
||||
|
||||
private val eventWorker = Executors.newSingleThreadScheduledExecutor()
|
||||
private var scheduledEventPost: ScheduledFuture<*>? = null
|
||||
override fun scheduleNsIdUpdate() {
|
||||
class PostRunnable : Runnable {
|
||||
|
||||
override fun run() {
|
||||
aapsLogger.debug(LTag.CORE, "Firing updateNsIds")
|
||||
scheduledEventPost = null
|
||||
updateNsIds()
|
||||
}
|
||||
}
|
||||
// cancel waiting task to prevent sending multiple posts
|
||||
scheduledEventPost?.cancel(false)
|
||||
val task: Runnable = PostRunnable()
|
||||
scheduledEventPost = eventWorker.schedule(task, 30, TimeUnit.SECONDS)
|
||||
}
|
||||
|
||||
private fun updateNsIds() {
|
||||
repository.runTransactionForResult(UpdateNsIdTemporaryTargetTransaction(nsIdTemporaryTargets))
|
||||
.doOnError { error ->
|
||||
aapsLogger.error(LTag.DATABASE, "Updated nsId of TemporaryTarget failed", error)
|
||||
}
|
||||
.blockingGet()
|
||||
.also { result ->
|
||||
result.updatedNsId.forEach {
|
||||
aapsLogger.debug(LTag.DATABASE, "Updated nsId of TemporaryTarget $it")
|
||||
}
|
||||
}
|
||||
|
||||
repository.runTransactionForResult(UpdateNsIdGlucoseValueTransaction(nsIdGlucoseValues))
|
||||
.doOnError { error ->
|
||||
aapsLogger.error(LTag.DATABASE, "Updated nsId of GlucoseValue failed", error)
|
||||
}
|
||||
.blockingGet()
|
||||
.also { result ->
|
||||
result.updatedNsId.forEach {
|
||||
aapsLogger.debug(LTag.DATABASE, "Updated nsId of GlucoseValue $it")
|
||||
}
|
||||
}
|
||||
|
||||
repository.runTransactionForResult(UpdateNsIdFoodTransaction(nsIdFoods))
|
||||
.doOnError { error ->
|
||||
aapsLogger.error(LTag.DATABASE, "Updated nsId of Food failed", error)
|
||||
}
|
||||
.blockingGet()
|
||||
.also { result ->
|
||||
result.updatedNsId.forEach {
|
||||
aapsLogger.debug(LTag.DATABASE, "Updated nsId of Food $it")
|
||||
}
|
||||
}
|
||||
|
||||
repository.runTransactionForResult(UpdateNsIdTherapyEventTransaction(nsIdTherapyEvents))
|
||||
.doOnError { error ->
|
||||
aapsLogger.error(LTag.DATABASE, "Updated nsId of TherapyEvent failed", error)
|
||||
}
|
||||
.blockingGet()
|
||||
.also { result ->
|
||||
result.updatedNsId.forEach {
|
||||
aapsLogger.debug(LTag.DATABASE, "Updated nsId of TherapyEvent $it")
|
||||
}
|
||||
}
|
||||
|
||||
repository.runTransactionForResult(UpdateNsIdBolusTransaction(nsIdBoluses))
|
||||
.doOnError { error ->
|
||||
aapsLogger.error(LTag.DATABASE, "Updated nsId of Bolus failed", error)
|
||||
}
|
||||
.blockingGet()
|
||||
.also { result ->
|
||||
result.updatedNsId.forEach {
|
||||
aapsLogger.debug(LTag.DATABASE, "Updated nsId of Bolus $it")
|
||||
}
|
||||
}
|
||||
|
||||
repository.runTransactionForResult(UpdateNsIdCarbsTransaction(nsIdCarbs))
|
||||
.doOnError { error ->
|
||||
aapsLogger.error(LTag.DATABASE, "Updated nsId of Carbs failed", error)
|
||||
}
|
||||
.blockingGet()
|
||||
.also { result ->
|
||||
result.updatedNsId.forEach {
|
||||
aapsLogger.debug(LTag.DATABASE, "Updated nsId of Carbs $it")
|
||||
}
|
||||
}
|
||||
|
||||
repository.runTransactionForResult(UpdateNsIdBolusCalculatorResultTransaction(nsIdBolusCalculatorResults))
|
||||
.doOnError { error ->
|
||||
aapsLogger.error(LTag.DATABASE, "Updated nsId of BolusCalculatorResult failed", error)
|
||||
}
|
||||
.blockingGet()
|
||||
.also { result ->
|
||||
result.updatedNsId.forEach {
|
||||
aapsLogger.debug(LTag.DATABASE, "Updated nsId of BolusCalculatorResult $it")
|
||||
}
|
||||
}
|
||||
|
||||
repository.runTransactionForResult(UpdateNsIdTemporaryBasalTransaction(nsIdTemporaryBasals))
|
||||
.doOnError { error ->
|
||||
aapsLogger.error(LTag.DATABASE, "Updated nsId of TemporaryBasal failed", error)
|
||||
}
|
||||
.blockingGet()
|
||||
.also { result ->
|
||||
result.updatedNsId.forEach {
|
||||
aapsLogger.debug(LTag.DATABASE, "Updated nsId of TemporaryBasal $it")
|
||||
}
|
||||
}
|
||||
|
||||
repository.runTransactionForResult(UpdateNsIdExtendedBolusTransaction(nsIdExtendedBoluses))
|
||||
.doOnError { error ->
|
||||
aapsLogger.error(LTag.DATABASE, "Updated nsId of ExtendedBolus failed", error)
|
||||
}
|
||||
.blockingGet()
|
||||
.also { result ->
|
||||
result.updatedNsId.forEach {
|
||||
aapsLogger.debug(LTag.DATABASE, "Updated nsId of ExtendedBolus $it")
|
||||
}
|
||||
}
|
||||
|
||||
repository.runTransactionForResult(UpdateNsIdProfileSwitchTransaction(nsIdProfileSwitches))
|
||||
.doOnError { error ->
|
||||
aapsLogger.error(LTag.DATABASE, "Updated nsId of ProfileSwitch failed", error)
|
||||
}
|
||||
.blockingGet()
|
||||
.also { result ->
|
||||
result.updatedNsId.forEach {
|
||||
aapsLogger.debug(LTag.DATABASE, "Updated nsId of ProfileSwitch $it")
|
||||
}
|
||||
}
|
||||
|
||||
repository.runTransactionForResult(UpdateNsIdEffectiveProfileSwitchTransaction(nsIdEffectiveProfileSwitches))
|
||||
.doOnError { error ->
|
||||
aapsLogger.error(LTag.DATABASE, "Updated nsId of EffectiveProfileSwitch failed", error)
|
||||
}
|
||||
.blockingGet()
|
||||
.also { result ->
|
||||
result.updatedNsId.forEach {
|
||||
aapsLogger.debug(LTag.DATABASE, "Updated nsId of EffectiveProfileSwitch $it")
|
||||
}
|
||||
}
|
||||
|
||||
repository.runTransactionForResult(UpdateNsIdDeviceStatusTransaction(nsIdDeviceStatuses))
|
||||
.doOnError { error ->
|
||||
aapsLogger.error(LTag.DATABASE, "Updated nsId of DeviceStatus failed", error)
|
||||
}
|
||||
.blockingGet()
|
||||
.also { result ->
|
||||
result.updatedNsId.forEach {
|
||||
aapsLogger.debug(LTag.DATABASE, "Updated nsId of DeviceStatus $it")
|
||||
}
|
||||
}
|
||||
|
||||
repository.runTransactionForResult(UpdateNsIdOfflineEventTransaction(nsIdOfflineEvents))
|
||||
.doOnError { error ->
|
||||
aapsLogger.error(LTag.DATABASE, "Updated nsId of OfflineEvent failed", error)
|
||||
}
|
||||
.blockingGet()
|
||||
.also { result ->
|
||||
result.updatedNsId.forEach {
|
||||
aapsLogger.debug(LTag.DATABASE, "Updated nsId of OfflineEvent $it")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun sendLog(item: String, clazz: String) {
|
||||
inserted[clazz]?.let {
|
||||
rxBus.send(EventNSClientNewLog("INSERT", "$item $it"))
|
||||
|
|
|
@ -1,19 +1,6 @@
|
|||
package info.nightscout.plugins.sync.nsclient
|
||||
|
||||
import info.nightscout.database.ValueWrapper
|
||||
import info.nightscout.database.entities.Bolus
|
||||
import info.nightscout.database.entities.BolusCalculatorResult
|
||||
import info.nightscout.database.entities.Carbs
|
||||
import info.nightscout.database.entities.DeviceStatus
|
||||
import info.nightscout.database.entities.EffectiveProfileSwitch
|
||||
import info.nightscout.database.entities.ExtendedBolus
|
||||
import info.nightscout.database.entities.Food
|
||||
import info.nightscout.database.entities.GlucoseValue
|
||||
import info.nightscout.database.entities.OfflineEvent
|
||||
import info.nightscout.database.entities.ProfileSwitch
|
||||
import info.nightscout.database.entities.TemporaryBasal
|
||||
import info.nightscout.database.entities.TemporaryTarget
|
||||
import info.nightscout.database.entities.TherapyEvent
|
||||
import info.nightscout.database.impl.AppRepository
|
||||
import info.nightscout.interfaces.plugin.ActivePlugin
|
||||
import info.nightscout.interfaces.profile.ProfileFunction
|
||||
|
@ -118,17 +105,6 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
// Prepared for v3 (returns all modified after)
|
||||
override fun changedBoluses(): List<Bolus> {
|
||||
val startId = sp.getLong(R.string.key_ns_bolus_last_synced_id, 0)
|
||||
return appRepository.getModifiedBolusesDataFromId(startId)
|
||||
.blockingGet()
|
||||
.filter { it.type != Bolus.Type.PRIMING }
|
||||
.also {
|
||||
aapsLogger.debug(LTag.NSCLIENT, "Loading Bolus data for sync from $startId. Records ${it.size}")
|
||||
}
|
||||
}
|
||||
|
||||
override tailrec fun processChangedBolusesCompat() {
|
||||
val lastDbIdWrapped = appRepository.getLastBolusIdWrapped().blockingGet()
|
||||
val lastDbId = if (lastDbIdWrapped is ValueWrapper.Existing) lastDbIdWrapped.value else 0L
|
||||
|
@ -139,18 +115,18 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
}
|
||||
queueCounter.bolusesRemaining = lastDbId - startId
|
||||
appRepository.getNextSyncElementBolus(startId).blockingGet()?.let { bolus ->
|
||||
aapsLogger.info(LTag.NSCLIENT, "Loading Bolus data Start: $startId ID: ${bolus.first.id} HistoryID: ${bolus.second.id} ")
|
||||
aapsLogger.info(LTag.NSCLIENT, "Loading Bolus data Start: $startId ${bolus.first} forID: ${bolus.second.id} ")
|
||||
when {
|
||||
// new record with existing NS id => must be coming from NS => ignore
|
||||
bolus.first.id == bolus.second.id && bolus.first.interfaceIDs.nightscoutId != null -> {
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring Bolus. Loaded from NS: ${bolus.first.id} HistoryID: ${bolus.second.id} ")
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring Bolus. Loaded from NS: ${bolus.second.id} ")
|
||||
confirmLastBolusIdIfGreater(bolus.second.id)
|
||||
processChangedBolusesCompat()
|
||||
return
|
||||
}
|
||||
// only NsId changed, no need to upload
|
||||
bolus.first.onlyNsIdAdded(bolus.second) -> {
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring Bolus. Only NS id changed ID: ${bolus.first.id} HistoryID: ${bolus.second.id} ")
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring Bolus. Only NS id changed: ${bolus.second.id} ")
|
||||
confirmLastBolusIdIfGreater(bolus.second.id)
|
||||
processChangedBolusesCompat()
|
||||
return
|
||||
|
@ -181,14 +157,6 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
// Prepared for v3 (returns all modified after)
|
||||
override fun changedCarbs(): List<Carbs> {
|
||||
val startId = sp.getLong(R.string.key_ns_carbs_last_synced_id, 0)
|
||||
return appRepository.getModifiedCarbsDataFromId(startId).blockingGet().also {
|
||||
aapsLogger.debug(LTag.NSCLIENT, "Loading Carbs data for sync from $startId. Records ${it.size}")
|
||||
}
|
||||
}
|
||||
|
||||
override tailrec fun processChangedCarbsCompat() {
|
||||
val lastDbIdWrapped = appRepository.getLastCarbsIdWrapped().blockingGet()
|
||||
val lastDbId = if (lastDbIdWrapped is ValueWrapper.Existing) lastDbIdWrapped.value else 0L
|
||||
|
@ -199,18 +167,18 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
}
|
||||
queueCounter.carbsRemaining = lastDbId - startId
|
||||
appRepository.getNextSyncElementCarbs(startId).blockingGet()?.let { carb ->
|
||||
aapsLogger.info(LTag.NSCLIENT, "Loading Carbs data Start: $startId ID: ${carb.first.id} HistoryID: ${carb.second.id} ")
|
||||
aapsLogger.info(LTag.NSCLIENT, "Loading Carbs data Start: $startId ${carb.first} forID: ${carb.second.id} ")
|
||||
when {
|
||||
// new record with existing NS id => must be coming from NS => ignore
|
||||
carb.first.id == carb.second.id && carb.first.interfaceIDs.nightscoutId != null -> {
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring Carbs. Loaded from NS: ${carb.first.id} HistoryID: ${carb.second.id} ")
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring Carbs. Loaded from NS: ${carb.second.id} ")
|
||||
confirmLastCarbsIdIfGreater(carb.second.id)
|
||||
processChangedCarbsCompat()
|
||||
return
|
||||
}
|
||||
// only NsId changed, no need to upload
|
||||
carb.first.onlyNsIdAdded(carb.second) -> {
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring Carbs. Only NS id changed ID: ${carb.first.id} HistoryID: ${carb.second.id} ")
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring Carbs. Only NS id changed ID: ${carb.second.id} ")
|
||||
confirmLastCarbsIdIfGreater(carb.second.id)
|
||||
processChangedCarbsCompat()
|
||||
return
|
||||
|
@ -237,14 +205,6 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
// Prepared for v3 (returns all modified after)
|
||||
override fun changedBolusCalculatorResults(): List<BolusCalculatorResult> {
|
||||
val startId = sp.getLong(R.string.key_ns_bolus_calculator_result_last_synced_id, 0)
|
||||
return appRepository.getModifiedBolusCalculatorResultsDataFromId(startId).blockingGet().also {
|
||||
aapsLogger.debug(LTag.NSCLIENT, "Loading BolusCalculatorResult data for sync from $startId. Records ${it.size}")
|
||||
}
|
||||
}
|
||||
|
||||
override tailrec fun processChangedBolusCalculatorResultsCompat() {
|
||||
val lastDbIdWrapped = appRepository.getLastBolusCalculatorResultIdWrapped().blockingGet()
|
||||
val lastDbId = if (lastDbIdWrapped is ValueWrapper.Existing) lastDbIdWrapped.value else 0L
|
||||
|
@ -255,18 +215,18 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
}
|
||||
queueCounter.bcrRemaining = lastDbId - startId
|
||||
appRepository.getNextSyncElementBolusCalculatorResult(startId).blockingGet()?.let { bolusCalculatorResult ->
|
||||
aapsLogger.info(LTag.NSCLIENT, "Loading BolusCalculatorResult data Start: $startId ID: ${bolusCalculatorResult.first.id} HistoryID: ${bolusCalculatorResult.second.id} ")
|
||||
aapsLogger.info(LTag.NSCLIENT, "Loading BolusCalculatorResult data Start: $startId ${bolusCalculatorResult.first} forID: ${bolusCalculatorResult.second.id} ")
|
||||
when {
|
||||
// new record with existing NS id => must be coming from NS => ignore
|
||||
bolusCalculatorResult.first.id == bolusCalculatorResult.second.id && bolusCalculatorResult.first.interfaceIDs.nightscoutId != null -> {
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring BolusCalculatorResult. Loaded from NS: ${bolusCalculatorResult.first.id} HistoryID: ${bolusCalculatorResult.second.id} ")
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring BolusCalculatorResult. Loaded from NS: ${bolusCalculatorResult.second.id} ")
|
||||
confirmLastBolusCalculatorResultsIdIfGreater(bolusCalculatorResult.second.id)
|
||||
processChangedBolusCalculatorResultsCompat()
|
||||
return
|
||||
}
|
||||
// only NsId changed, no need to upload
|
||||
bolusCalculatorResult.first.onlyNsIdAdded(bolusCalculatorResult.second) -> {
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring BolusCalculatorResult. Only NS id changed ID: ${bolusCalculatorResult.first.id} HistoryID: ${bolusCalculatorResult.second.id} ")
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring BolusCalculatorResult. Only NS id changed ID: ${bolusCalculatorResult.second.id} ")
|
||||
confirmLastBolusCalculatorResultsIdIfGreater(bolusCalculatorResult.second.id)
|
||||
processChangedBolusCalculatorResultsCompat()
|
||||
return
|
||||
|
@ -296,14 +256,6 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
// Prepared for v3 (returns all modified after)
|
||||
override fun changedTempTargets(): List<TemporaryTarget> {
|
||||
val startId = sp.getLong(R.string.key_ns_temporary_target_last_synced_id, 0)
|
||||
return appRepository.getModifiedTemporaryTargetsDataFromId(startId).blockingGet().also {
|
||||
aapsLogger.debug(LTag.NSCLIENT, "Loading TemporaryTarget data for sync from $startId. Records ${it.size}")
|
||||
}
|
||||
}
|
||||
|
||||
override tailrec fun processChangedTempTargetsCompat() {
|
||||
val lastDbIdWrapped = appRepository.getLastTempTargetIdWrapped().blockingGet()
|
||||
val lastDbId = if (lastDbIdWrapped is ValueWrapper.Existing) lastDbIdWrapped.value else 0L
|
||||
|
@ -314,18 +266,18 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
}
|
||||
queueCounter.ttsRemaining = lastDbId - startId
|
||||
appRepository.getNextSyncElementTemporaryTarget(startId).blockingGet()?.let { tt ->
|
||||
aapsLogger.info(LTag.NSCLIENT, "Loading TemporaryTarget data Start: $startId ID: ${tt.first.id} HistoryID: ${tt.second.id} ")
|
||||
aapsLogger.info(LTag.NSCLIENT, "Loading TemporaryTarget data Start: $startId ${tt.first} forID: ${tt.second.id} ")
|
||||
when {
|
||||
// new record with existing NS id => must be coming from NS => ignore
|
||||
tt.first.id == tt.second.id && tt.first.interfaceIDs.nightscoutId != null -> {
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring TemporaryTarget. Loaded from NS: ${tt.first.id} HistoryID: ${tt.second.id} ")
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring TemporaryTarget. Loaded from NS: ${tt.second.id} ")
|
||||
confirmLastTempTargetsIdIfGreater(tt.second.id)
|
||||
processChangedTempTargetsCompat()
|
||||
return
|
||||
}
|
||||
// only NsId changed, no need to upload
|
||||
tt.first.onlyNsIdAdded(tt.second) -> {
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring TemporaryTarget. Only NS id changed ID: ${tt.first.id} HistoryID: ${tt.second.id} ")
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring TemporaryTarget. Only NS id changed ID: ${tt.second.id} ")
|
||||
confirmLastTempTargetsIdIfGreater(tt.second.id)
|
||||
processChangedTempTargetsCompat()
|
||||
return
|
||||
|
@ -356,14 +308,6 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
// Prepared for v3 (returns all modified after)
|
||||
override fun changedFoods(): List<Food> {
|
||||
val startId = sp.getLong(R.string.key_ns_food_last_synced_id, 0)
|
||||
return appRepository.getModifiedFoodDataFromId(startId).blockingGet().also {
|
||||
aapsLogger.debug(LTag.NSCLIENT, "Loading Food data for sync from $startId. Records ${it.size}")
|
||||
}
|
||||
}
|
||||
|
||||
override tailrec fun processChangedFoodsCompat() {
|
||||
val lastDbIdWrapped = appRepository.getLastFoodIdWrapped().blockingGet()
|
||||
val lastDbId = if (lastDbIdWrapped is ValueWrapper.Existing) lastDbIdWrapped.value else 0L
|
||||
|
@ -374,18 +318,18 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
}
|
||||
queueCounter.foodsRemaining = lastDbId - startId
|
||||
appRepository.getNextSyncElementFood(startId).blockingGet()?.let { food ->
|
||||
aapsLogger.info(LTag.NSCLIENT, "Loading Food data Start: $startId ID: ${food.first.id} HistoryID: ${food.second} ")
|
||||
aapsLogger.info(LTag.NSCLIENT, "Loading Food data Start: $startId ${food.first} forID: ${food.second.id} ")
|
||||
when {
|
||||
// new record with existing NS id => must be coming from NS => ignore
|
||||
food.first.id == food.second.id && food.first.interfaceIDs.nightscoutId != null -> {
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring Food. Loaded from NS: ${food.first.id} HistoryID: ${food.second.id} ")
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring Food. Loaded from NS: ${food.second.id} ")
|
||||
confirmLastFoodIdIfGreater(food.second.id)
|
||||
processChangedFoodsCompat()
|
||||
return
|
||||
}
|
||||
// only NsId changed, no need to upload
|
||||
food.first.onlyNsIdAdded(food.second) -> {
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring Food. Only NS id changed ID: ${food.first.id} HistoryID: ${food.second.id} ")
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring Food. Only NS id changed ID: ${food.second.id} ")
|
||||
confirmLastFoodIdIfGreater(food.second.id)
|
||||
processChangedFoodsCompat()
|
||||
return
|
||||
|
@ -412,14 +356,6 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
// Prepared for v3 (returns all modified after)
|
||||
override fun changedGlucoseValues(): List<GlucoseValue> {
|
||||
val startId = sp.getLong(R.string.key_ns_glucose_value_last_synced_id, 0)
|
||||
return appRepository.getModifiedBgReadingsDataFromId(startId).blockingGet().also {
|
||||
aapsLogger.debug(LTag.NSCLIENT, "Loading GlucoseValue data for sync from $startId . Records ${it.size}")
|
||||
}
|
||||
}
|
||||
|
||||
override tailrec fun processChangedGlucoseValuesCompat() {
|
||||
val lastDbIdWrapped = appRepository.getLastGlucoseValueIdWrapped().blockingGet()
|
||||
val lastDbId = if (lastDbIdWrapped is ValueWrapper.Existing) lastDbIdWrapped.value else 0L
|
||||
|
@ -430,19 +366,19 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
}
|
||||
queueCounter.gvsRemaining = lastDbId - startId
|
||||
appRepository.getNextSyncElementGlucoseValue(startId).blockingGet()?.let { gv ->
|
||||
aapsLogger.info(LTag.NSCLIENT, "Loading GlucoseValue data ID: ${gv.first.id} HistoryID: ${gv.second.id} ")
|
||||
aapsLogger.info(LTag.NSCLIENT, "Loading GlucoseValue data Start: $startId ${gv.first} forID: ${gv.second.id} ")
|
||||
if (activePlugin.activeBgSource.shouldUploadToNs(gv.first)) {
|
||||
when {
|
||||
// new record with existing NS id => must be coming from NS => ignore
|
||||
gv.first.id == gv.second.id && gv.first.interfaceIDs.nightscoutId != null -> {
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring GlucoseValue. Loaded from NS: ${gv.first.id} HistoryID: ${gv.second.id} ")
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring GlucoseValue. Loaded from NS: ${gv.second.id} ")
|
||||
confirmLastGlucoseValueIdIfGreater(gv.second.id)
|
||||
processChangedGlucoseValuesCompat()
|
||||
return
|
||||
}
|
||||
// only NsId changed, no need to upload
|
||||
gv.first.onlyNsIdAdded(gv.second) -> {
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring GlucoseValue. Only NS id changed ID: ${gv.first.id} HistoryID: ${gv.second.id} ")
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring GlucoseValue. Only NS id changed ID: ${gv.second.id} ")
|
||||
confirmLastGlucoseValueIdIfGreater(gv.second.id)
|
||||
processChangedGlucoseValuesCompat()
|
||||
return
|
||||
|
@ -473,14 +409,6 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
// Prepared for v3 (returns all modified after)
|
||||
override fun changedTherapyEvents(): List<TherapyEvent> {
|
||||
val startId = sp.getLong(R.string.key_ns_therapy_event_last_synced_id, 0)
|
||||
return appRepository.getModifiedTherapyEventDataFromId(startId).blockingGet().also {
|
||||
aapsLogger.debug(LTag.NSCLIENT, "Loading TherapyEvents data for sync from $startId. Records ${it.size}")
|
||||
}
|
||||
}
|
||||
|
||||
override tailrec fun processChangedTherapyEventsCompat() {
|
||||
val lastDbIdWrapped = appRepository.getLastTherapyEventIdWrapped().blockingGet()
|
||||
val lastDbId = if (lastDbIdWrapped is ValueWrapper.Existing) lastDbIdWrapped.value else 0L
|
||||
|
@ -491,18 +419,18 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
}
|
||||
queueCounter.tesRemaining = lastDbId - startId
|
||||
appRepository.getNextSyncElementTherapyEvent(startId).blockingGet()?.let { te ->
|
||||
aapsLogger.info(LTag.NSCLIENT, "Loading TherapyEvents data Start: $startId ID: ${te.first.id} HistoryID: ${te.second} ")
|
||||
aapsLogger.info(LTag.NSCLIENT, "Loading TherapyEvents data Start: $startId ${te.first} forID: ${te.second.id} ")
|
||||
when {
|
||||
// new record with existing NS id => must be coming from NS => ignore
|
||||
te.first.id == te.second.id && te.first.interfaceIDs.nightscoutId != null -> {
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring TherapyEvent. Loaded from NS: ${te.first.id} HistoryID: ${te.second.id} ")
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring TherapyEvent. Loaded from NS: ${te.second.id} ")
|
||||
confirmLastTherapyEventIdIfGreater(te.second.id)
|
||||
processChangedTherapyEventsCompat()
|
||||
return
|
||||
}
|
||||
// only NsId changed, no need to upload
|
||||
te.first.onlyNsIdAdded(te.second) -> {
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring TherapyEvent. Only NS id changed ID: ${te.first.id} HistoryID: ${te.second.id} ")
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring TherapyEvent. Only NS id changed ID: ${te.second.id} ")
|
||||
confirmLastTherapyEventIdIfGreater(te.second.id)
|
||||
processChangedTherapyEventsCompat()
|
||||
return
|
||||
|
@ -529,13 +457,6 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
override fun changedDeviceStatuses(): List<DeviceStatus> {
|
||||
val startId = sp.getLong(R.string.key_ns_device_status_last_synced_id, 0)
|
||||
return appRepository.getModifiedDeviceStatusDataFromId(startId).blockingGet().also {
|
||||
aapsLogger.debug(LTag.NSCLIENT, "Loading DeviceStatus data for sync from $startId. Records ${it.size}")
|
||||
}
|
||||
}
|
||||
|
||||
override fun processChangedDeviceStatusesCompat() {
|
||||
val lastDbIdWrapped = appRepository.getLastDeviceStatusIdWrapped().blockingGet()
|
||||
val lastDbId = if (lastDbIdWrapped is ValueWrapper.Existing) lastDbIdWrapped.value else 0L
|
||||
|
@ -546,7 +467,7 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
}
|
||||
queueCounter.dssRemaining = lastDbId - startId
|
||||
appRepository.getNextSyncElementDeviceStatus(startId).blockingGet()?.let { deviceStatus ->
|
||||
aapsLogger.info(LTag.NSCLIENT, "Loading DeviceStatus data Start: $startId ID: ${deviceStatus.id}")
|
||||
aapsLogger.info(LTag.NSCLIENT, "Loading DeviceStatus data Start: $startId $deviceStatus")
|
||||
when {
|
||||
// without nsId = create new
|
||||
deviceStatus.interfaceIDs.nightscoutId == null ->
|
||||
|
@ -565,14 +486,6 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
// Prepared for v3 (returns all modified after)
|
||||
override fun changedTemporaryBasals(): List<TemporaryBasal> {
|
||||
val startId = sp.getLong(R.string.key_ns_temporary_basal_last_synced_id, 0)
|
||||
return appRepository.getModifiedTemporaryBasalDataFromId(startId).blockingGet().also {
|
||||
aapsLogger.debug(LTag.NSCLIENT, "Loading TemporaryBasal data for sync from $startId. Records ${it.size}")
|
||||
}
|
||||
}
|
||||
|
||||
override tailrec fun processChangedTemporaryBasalsCompat() {
|
||||
val lastDbIdWrapped = appRepository.getLastTemporaryBasalIdWrapped().blockingGet()
|
||||
val lastDbId = if (lastDbIdWrapped is ValueWrapper.Existing) lastDbIdWrapped.value else 0L
|
||||
|
@ -583,18 +496,18 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
}
|
||||
queueCounter.tbrsRemaining = lastDbId - startId
|
||||
appRepository.getNextSyncElementTemporaryBasal(startId).blockingGet()?.let { tb ->
|
||||
aapsLogger.info(LTag.NSCLIENT, "Loading TemporaryBasal data Start: $startId ID: ${tb.first.id} HistoryID: ${tb.second} ")
|
||||
aapsLogger.info(LTag.NSCLIENT, "Loading TemporaryBasal data Start: $startId ${tb.first} forID: ${tb.second.id} ")
|
||||
when {
|
||||
// new record with existing NS id => must be coming from NS => ignore
|
||||
tb.first.id == tb.second.id && tb.first.interfaceIDs.nightscoutId != null -> {
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring TemporaryBasal. Loaded from NS: ${tb.first.id} HistoryID: ${tb.second.id} ")
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring TemporaryBasal. Loaded from NS: ${tb.second.id} ")
|
||||
confirmLastTemporaryBasalIdIfGreater(tb.second.id)
|
||||
processChangedTemporaryBasalsCompat()
|
||||
return
|
||||
}
|
||||
// only NsId changed, no need to upload
|
||||
tb.first.onlyNsIdAdded(tb.second) -> {
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring TemporaryBasal. Only NS id changed ID: ${tb.first.id} HistoryID: ${tb.second.id} ")
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring TemporaryBasal. Only NS id changed ID: ${tb.second.id} ")
|
||||
confirmLastTemporaryBasalIdIfGreater(tb.second.id)
|
||||
processChangedTemporaryBasalsCompat()
|
||||
return
|
||||
|
@ -625,14 +538,6 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
// Prepared for v3 (returns all modified after)
|
||||
override fun changedExtendedBoluses(): List<ExtendedBolus> {
|
||||
val startId = sp.getLong(R.string.key_ns_extended_bolus_last_synced_id, 0)
|
||||
return appRepository.getModifiedExtendedBolusDataFromId(startId).blockingGet().also {
|
||||
aapsLogger.debug(LTag.NSCLIENT, "Loading ExtendedBolus data for sync from $startId. Records ${it.size}")
|
||||
}
|
||||
}
|
||||
|
||||
override tailrec fun processChangedExtendedBolusesCompat() {
|
||||
val lastDbIdWrapped = appRepository.getLastExtendedBolusIdWrapped().blockingGet()
|
||||
val lastDbId = if (lastDbIdWrapped is ValueWrapper.Existing) lastDbIdWrapped.value else 0L
|
||||
|
@ -643,20 +548,20 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
}
|
||||
queueCounter.ebsRemaining = lastDbId - startId
|
||||
appRepository.getNextSyncElementExtendedBolus(startId).blockingGet()?.let { eb ->
|
||||
aapsLogger.info(LTag.NSCLIENT, "Loading ExtendedBolus data Start: $startId ID: ${eb.first.id} HistoryID: ${eb.second} ")
|
||||
aapsLogger.info(LTag.NSCLIENT, "Loading ExtendedBolus data Start: $startId ${eb.first} forID: ${eb.second.id} ")
|
||||
val profile = profileFunction.getProfile(eb.first.timestamp)
|
||||
if (profile != null) {
|
||||
when {
|
||||
// new record with existing NS id => must be coming from NS => ignore
|
||||
eb.first.id == eb.second.id && eb.first.interfaceIDs.nightscoutId != null -> {
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring ExtendedBolus. Loaded from NS: ${eb.first.id} HistoryID: ${eb.second.id} ")
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring ExtendedBolus. Loaded from NS: ${eb.second.id} ")
|
||||
confirmLastExtendedBolusIdIfGreater(eb.second.id)
|
||||
processChangedExtendedBolusesCompat()
|
||||
return
|
||||
}
|
||||
// only NsId changed, no need to upload
|
||||
eb.first.onlyNsIdAdded(eb.second) -> {
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring ExtendedBolus. Only NS id changed ID: ${eb.first.id} HistoryID: ${eb.second.id} ")
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring ExtendedBolus. Only NS id changed ID: ${eb.second.id} ")
|
||||
confirmLastExtendedBolusIdIfGreater(eb.second.id)
|
||||
processChangedExtendedBolusesCompat()
|
||||
return
|
||||
|
@ -678,7 +583,7 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
}
|
||||
return
|
||||
} else {
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring ExtendedBolus. No profile: ${eb.first.id} HistoryID: ${eb.second.id} ")
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring ExtendedBolus. No profile: ${eb.second.id} ")
|
||||
confirmLastExtendedBolusIdIfGreater(eb.second.id)
|
||||
processChangedExtendedBolusesCompat()
|
||||
return
|
||||
|
@ -693,13 +598,6 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
override fun changedProfileSwitch(): List<ProfileSwitch> {
|
||||
val startId = sp.getLong(R.string.key_ns_profile_switch_last_synced_id, 0)
|
||||
return appRepository.getModifiedProfileSwitchDataFromId(startId).blockingGet().also {
|
||||
aapsLogger.debug(LTag.NSCLIENT, "Loading ProfileSwitch data for sync from $startId. Records ${it.size}")
|
||||
}
|
||||
}
|
||||
|
||||
override tailrec fun processChangedProfileSwitchesCompat() {
|
||||
val lastDbIdWrapped = appRepository.getLastProfileSwitchIdWrapped().blockingGet()
|
||||
val lastDbId = if (lastDbIdWrapped is ValueWrapper.Existing) lastDbIdWrapped.value else 0L
|
||||
|
@ -710,18 +608,18 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
}
|
||||
queueCounter.pssRemaining = lastDbId - startId
|
||||
appRepository.getNextSyncElementProfileSwitch(startId).blockingGet()?.let { ps ->
|
||||
aapsLogger.info(LTag.NSCLIENT, "Loading ProfileSwitch data Start: $startId ID: ${ps.first.id} HistoryID: ${ps.second} ")
|
||||
aapsLogger.info(LTag.NSCLIENT, "Loading ProfileSwitch data Start: $startId ${ps.first} forID: ${ps.second.id} ")
|
||||
when {
|
||||
// new record with existing NS id => must be coming from NS => ignore
|
||||
ps.first.id == ps.second.id && ps.first.interfaceIDs.nightscoutId != null -> {
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring ProfileSwitch. Loaded from NS: ${ps.first.id} HistoryID: ${ps.second.id} ")
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring ProfileSwitch. Loaded from NS: ${ps.second.id} ")
|
||||
confirmLastProfileSwitchIdIfGreater(ps.second.id)
|
||||
processChangedProfileSwitchesCompat()
|
||||
return
|
||||
}
|
||||
// only NsId changed, no need to upload
|
||||
ps.first.onlyNsIdAdded(ps.second) -> {
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring ProfileSwitch. Only NS id changed ID: ${ps.first.id} HistoryID: ${ps.second.id} ")
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring ProfileSwitch. Only NS id changed ID: ${ps.second.id} ")
|
||||
confirmLastProfileSwitchIdIfGreater(ps.second.id)
|
||||
processChangedProfileSwitchesCompat()
|
||||
return
|
||||
|
@ -748,13 +646,6 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
override fun changedEffectiveProfileSwitch(): List<EffectiveProfileSwitch> {
|
||||
val startId = sp.getLong(R.string.key_ns_effective_profile_switch_last_synced_id, 0)
|
||||
return appRepository.getModifiedEffectiveProfileSwitchDataFromId(startId).blockingGet().also {
|
||||
aapsLogger.debug(LTag.NSCLIENT, "Loading EffectiveProfileSwitch data for sync from $startId. Records ${it.size}")
|
||||
}
|
||||
}
|
||||
|
||||
override tailrec fun processChangedEffectiveProfileSwitchesCompat() {
|
||||
val lastDbIdWrapped = appRepository.getLastEffectiveProfileSwitchIdWrapped().blockingGet()
|
||||
val lastDbId = if (lastDbIdWrapped is ValueWrapper.Existing) lastDbIdWrapped.value else 0L
|
||||
|
@ -765,18 +656,18 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
}
|
||||
queueCounter.epssRemaining = lastDbId - startId
|
||||
appRepository.getNextSyncElementEffectiveProfileSwitch(startId).blockingGet()?.let { ps ->
|
||||
aapsLogger.info(LTag.NSCLIENT, "Loading EffectiveProfileSwitch data Start: $startId ID: ${ps.first.id} HistoryID: ${ps.second} ")
|
||||
aapsLogger.info(LTag.NSCLIENT, "Loading EffectiveProfileSwitch data Start: $startId ${ps.first} forID: ${ps.second.id} ")
|
||||
when {
|
||||
// new record with existing NS id => must be coming from NS => ignore
|
||||
ps.first.id == ps.second.id && ps.first.interfaceIDs.nightscoutId != null -> {
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring EffectiveProfileSwitch. Loaded from NS: ${ps.first.id} HistoryID: ${ps.second.id} ")
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring EffectiveProfileSwitch. Loaded from NS: ${ps.second.id} ")
|
||||
confirmLastEffectiveProfileSwitchIdIfGreater(ps.second.id)
|
||||
processChangedEffectiveProfileSwitchesCompat()
|
||||
return
|
||||
}
|
||||
// only NsId changed, no need to upload
|
||||
ps.first.onlyNsIdAdded(ps.second) -> {
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring EffectiveProfileSwitch. Only NS id changed ID: ${ps.first.id} HistoryID: ${ps.second.id} ")
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring EffectiveProfileSwitch. Only NS id changed ID: ${ps.second.id} ")
|
||||
confirmLastEffectiveProfileSwitchIdIfGreater(ps.second.id)
|
||||
processChangedEffectiveProfileSwitchesCompat()
|
||||
return
|
||||
|
@ -807,14 +698,6 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
// Prepared for v3 (returns all modified after)
|
||||
override fun changedOfflineEvents(): List<OfflineEvent> {
|
||||
val startId = sp.getLong(R.string.key_ns_offline_event_last_synced_id, 0)
|
||||
return appRepository.getModifiedOfflineEventsDataFromId(startId).blockingGet().also {
|
||||
aapsLogger.debug(LTag.NSCLIENT, "Loading OfflineEvent data for sync from $startId. Records ${it.size}")
|
||||
}
|
||||
}
|
||||
|
||||
override tailrec fun processChangedOfflineEventsCompat() {
|
||||
val lastDbIdWrapped = appRepository.getLastOfflineEventIdWrapped().blockingGet()
|
||||
val lastDbId = if (lastDbIdWrapped is ValueWrapper.Existing) lastDbIdWrapped.value else 0L
|
||||
|
@ -825,18 +708,18 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
}
|
||||
queueCounter.oesRemaining = lastDbId - startId
|
||||
appRepository.getNextSyncElementOfflineEvent(startId).blockingGet()?.let { oe ->
|
||||
aapsLogger.info(LTag.NSCLIENT, "Loading OfflineEvent data Start: $startId ID: ${oe.first.id} HistoryID: ${oe.second} ")
|
||||
aapsLogger.info(LTag.NSCLIENT, "Loading OfflineEvent data Start: $startId ${oe.first} forID: ${oe.second.id} ")
|
||||
when {
|
||||
// new record with existing NS id => must be coming from NS => ignore
|
||||
oe.first.id == oe.second.id && oe.first.interfaceIDs.nightscoutId != null -> {
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring OfflineEvent. Loaded from NS: ${oe.first.id} HistoryID: ${oe.second.id} ")
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring OfflineEvent. Loaded from NS: ${oe.second.id} ")
|
||||
confirmLastOfflineEventIdIfGreater(oe.second.id)
|
||||
processChangedOfflineEventsCompat()
|
||||
return
|
||||
}
|
||||
// only NsId changed, no need to upload
|
||||
oe.first.onlyNsIdAdded(oe.second) -> {
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring OfflineEvent. Only NS id changed ID: ${oe.first.id} HistoryID: ${oe.second.id} ")
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring OfflineEvent. Only NS id changed ID: ${oe.second.id} ")
|
||||
confirmLastOfflineEventIdIfGreater(oe.second.id)
|
||||
processChangedOfflineEventsCompat()
|
||||
return
|
||||
|
|
|
@ -242,60 +242,60 @@ class NSClientPlugin @Inject constructor(
|
|||
dataSyncSelector.resetToNextFullSync()
|
||||
}
|
||||
|
||||
override fun dbAdd(collection: String, originalObject: DataSyncSelector.DataPair, progress: String) {
|
||||
when (originalObject) {
|
||||
is DataSyncSelector.PairBolus -> originalObject.value.toJson(true, dateUtil)
|
||||
is DataSyncSelector.PairCarbs -> originalObject.value.toJson(true, dateUtil)
|
||||
is DataSyncSelector.PairBolusCalculatorResult -> originalObject.value.toJson(true, dateUtil, profileFunction)
|
||||
is DataSyncSelector.PairTemporaryTarget -> originalObject.value.toJson(true, profileFunction.getUnits(), dateUtil)
|
||||
is DataSyncSelector.PairFood -> originalObject.value.toJson(true)
|
||||
is DataSyncSelector.PairGlucoseValue -> originalObject.value.toJson(true, dateUtil)
|
||||
is DataSyncSelector.PairTherapyEvent -> originalObject.value.toJson(true, dateUtil)
|
||||
is DataSyncSelector.PairDeviceStatus -> originalObject.value.toJson(dateUtil)
|
||||
is DataSyncSelector.PairTemporaryBasal -> originalObject.value.toJson(true, profileFunction.getProfile(originalObject.value.timestamp), dateUtil)
|
||||
is DataSyncSelector.PairExtendedBolus -> originalObject.value.toJson(true, profileFunction.getProfile(originalObject.value.timestamp), dateUtil)
|
||||
is DataSyncSelector.PairProfileSwitch -> originalObject.value.toJson(true, dateUtil)
|
||||
is DataSyncSelector.PairEffectiveProfileSwitch -> originalObject.value.toJson(true, dateUtil)
|
||||
is DataSyncSelector.PairOfflineEvent -> originalObject.value.toJson(true, dateUtil)
|
||||
is DataSyncSelector.PairProfileStore -> originalObject.value
|
||||
override fun dbAdd(collection: String, dataPair: DataSyncSelector.DataPair, progress: String) {
|
||||
when (dataPair) {
|
||||
is DataSyncSelector.PairBolus -> dataPair.value.toJson(true, dateUtil)
|
||||
is DataSyncSelector.PairCarbs -> dataPair.value.toJson(true, dateUtil)
|
||||
is DataSyncSelector.PairBolusCalculatorResult -> dataPair.value.toJson(true, dateUtil, profileFunction)
|
||||
is DataSyncSelector.PairTemporaryTarget -> dataPair.value.toJson(true, profileFunction.getUnits(), dateUtil)
|
||||
is DataSyncSelector.PairFood -> dataPair.value.toJson(true)
|
||||
is DataSyncSelector.PairGlucoseValue -> dataPair.value.toJson(true, dateUtil)
|
||||
is DataSyncSelector.PairTherapyEvent -> dataPair.value.toJson(true, dateUtil)
|
||||
is DataSyncSelector.PairDeviceStatus -> dataPair.value.toJson(dateUtil)
|
||||
is DataSyncSelector.PairTemporaryBasal -> dataPair.value.toJson(true, profileFunction.getProfile(dataPair.value.timestamp), dateUtil)
|
||||
is DataSyncSelector.PairExtendedBolus -> dataPair.value.toJson(true, profileFunction.getProfile(dataPair.value.timestamp), dateUtil)
|
||||
is DataSyncSelector.PairProfileSwitch -> dataPair.value.toJson(true, dateUtil)
|
||||
is DataSyncSelector.PairEffectiveProfileSwitch -> dataPair.value.toJson(true, dateUtil)
|
||||
is DataSyncSelector.PairOfflineEvent -> dataPair.value.toJson(true, dateUtil)
|
||||
is DataSyncSelector.PairProfileStore -> dataPair.value
|
||||
else -> null
|
||||
}?.let { data ->
|
||||
nsClientService?.dbAdd(collection, data, originalObject, progress)
|
||||
nsClientService?.dbAdd(collection, data, dataPair, progress)
|
||||
}
|
||||
}
|
||||
|
||||
override fun dbUpdate(collection: String, originalObject: DataSyncSelector.DataPair, progress: String) {
|
||||
val id = when (originalObject) {
|
||||
is DataSyncSelector.PairBolus -> originalObject.value.interfaceIDs.nightscoutId
|
||||
is DataSyncSelector.PairCarbs -> originalObject.value.interfaceIDs.nightscoutId
|
||||
is DataSyncSelector.PairBolusCalculatorResult -> originalObject.value.interfaceIDs.nightscoutId
|
||||
is DataSyncSelector.PairTemporaryTarget -> originalObject.value.interfaceIDs.nightscoutId
|
||||
is DataSyncSelector.PairFood -> originalObject.value.interfaceIDs.nightscoutId
|
||||
is DataSyncSelector.PairGlucoseValue -> originalObject.value.interfaceIDs.nightscoutId
|
||||
is DataSyncSelector.PairTherapyEvent -> originalObject.value.interfaceIDs.nightscoutId
|
||||
is DataSyncSelector.PairTemporaryBasal -> originalObject.value.interfaceIDs.nightscoutId
|
||||
is DataSyncSelector.PairExtendedBolus -> originalObject.value.interfaceIDs.nightscoutId
|
||||
is DataSyncSelector.PairProfileSwitch -> originalObject.value.interfaceIDs.nightscoutId
|
||||
is DataSyncSelector.PairEffectiveProfileSwitch -> originalObject.value.interfaceIDs.nightscoutId
|
||||
is DataSyncSelector.PairOfflineEvent -> originalObject.value.interfaceIDs.nightscoutId
|
||||
override fun dbUpdate(collection: String, dataPair: DataSyncSelector.DataPair, progress: String) {
|
||||
val id = when (dataPair) {
|
||||
is DataSyncSelector.PairBolus -> dataPair.value.interfaceIDs.nightscoutId
|
||||
is DataSyncSelector.PairCarbs -> dataPair.value.interfaceIDs.nightscoutId
|
||||
is DataSyncSelector.PairBolusCalculatorResult -> dataPair.value.interfaceIDs.nightscoutId
|
||||
is DataSyncSelector.PairTemporaryTarget -> dataPair.value.interfaceIDs.nightscoutId
|
||||
is DataSyncSelector.PairFood -> dataPair.value.interfaceIDs.nightscoutId
|
||||
is DataSyncSelector.PairGlucoseValue -> dataPair.value.interfaceIDs.nightscoutId
|
||||
is DataSyncSelector.PairTherapyEvent -> dataPair.value.interfaceIDs.nightscoutId
|
||||
is DataSyncSelector.PairTemporaryBasal -> dataPair.value.interfaceIDs.nightscoutId
|
||||
is DataSyncSelector.PairExtendedBolus -> dataPair.value.interfaceIDs.nightscoutId
|
||||
is DataSyncSelector.PairProfileSwitch -> dataPair.value.interfaceIDs.nightscoutId
|
||||
is DataSyncSelector.PairEffectiveProfileSwitch -> dataPair.value.interfaceIDs.nightscoutId
|
||||
is DataSyncSelector.PairOfflineEvent -> dataPair.value.interfaceIDs.nightscoutId
|
||||
else -> throw IllegalStateException()
|
||||
}
|
||||
when (originalObject) {
|
||||
is DataSyncSelector.PairBolus -> originalObject.value.toJson(false, dateUtil)
|
||||
is DataSyncSelector.PairCarbs -> originalObject.value.toJson(false, dateUtil)
|
||||
is DataSyncSelector.PairBolusCalculatorResult -> originalObject.value.toJson(false, dateUtil, profileFunction)
|
||||
is DataSyncSelector.PairTemporaryTarget -> originalObject.value.toJson(false, profileFunction.getUnits(), dateUtil)
|
||||
is DataSyncSelector.PairFood -> originalObject.value.toJson(false)
|
||||
is DataSyncSelector.PairGlucoseValue -> originalObject.value.toJson(false, dateUtil)
|
||||
is DataSyncSelector.PairTherapyEvent -> originalObject.value.toJson(false, dateUtil)
|
||||
is DataSyncSelector.PairTemporaryBasal -> originalObject.value.toJson(false, profileFunction.getProfile(originalObject.value.timestamp), dateUtil)
|
||||
is DataSyncSelector.PairExtendedBolus -> originalObject.value.toJson(false, profileFunction.getProfile(originalObject.value.timestamp), dateUtil)
|
||||
is DataSyncSelector.PairProfileSwitch -> originalObject.value.toJson(false, dateUtil)
|
||||
is DataSyncSelector.PairEffectiveProfileSwitch -> originalObject.value.toJson(false, dateUtil)
|
||||
is DataSyncSelector.PairOfflineEvent -> originalObject.value.toJson(false, dateUtil)
|
||||
when (dataPair) {
|
||||
is DataSyncSelector.PairBolus -> dataPair.value.toJson(false, dateUtil)
|
||||
is DataSyncSelector.PairCarbs -> dataPair.value.toJson(false, dateUtil)
|
||||
is DataSyncSelector.PairBolusCalculatorResult -> dataPair.value.toJson(false, dateUtil, profileFunction)
|
||||
is DataSyncSelector.PairTemporaryTarget -> dataPair.value.toJson(false, profileFunction.getUnits(), dateUtil)
|
||||
is DataSyncSelector.PairFood -> dataPair.value.toJson(false)
|
||||
is DataSyncSelector.PairGlucoseValue -> dataPair.value.toJson(false, dateUtil)
|
||||
is DataSyncSelector.PairTherapyEvent -> dataPair.value.toJson(false, dateUtil)
|
||||
is DataSyncSelector.PairTemporaryBasal -> dataPair.value.toJson(false, profileFunction.getProfile(dataPair.value.timestamp), dateUtil)
|
||||
is DataSyncSelector.PairExtendedBolus -> dataPair.value.toJson(false, profileFunction.getProfile(dataPair.value.timestamp), dateUtil)
|
||||
is DataSyncSelector.PairProfileSwitch -> dataPair.value.toJson(false, dateUtil)
|
||||
is DataSyncSelector.PairEffectiveProfileSwitch -> dataPair.value.toJson(false, dateUtil)
|
||||
is DataSyncSelector.PairOfflineEvent -> dataPair.value.toJson(false, dateUtil)
|
||||
else -> null
|
||||
}?.let { data ->
|
||||
nsClientService?.dbUpdate(collection, id, data, originalObject, progress)
|
||||
nsClientService?.dbUpdate(collection, id, data, dataPair, progress)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,10 +1,15 @@
|
|||
package info.nightscout.plugins.sync.nsclient.acks
|
||||
|
||||
import androidx.work.OneTimeWorkRequest
|
||||
import info.nightscout.core.utils.receivers.DataWorkerStorage
|
||||
import info.nightscout.plugins.sync.nsclient.services.NSClientService
|
||||
import info.nightscout.plugins.sync.nsclient.workers.NSClientAddAckWorker
|
||||
import info.nightscout.rx.bus.RxBus
|
||||
import info.nightscout.rx.events.Event
|
||||
import info.nightscout.rx.events.EventNSClientRestart
|
||||
import info.nightscout.rx.logging.AAPSLogger
|
||||
import info.nightscout.rx.logging.LTag
|
||||
import info.nightscout.shared.utils.DateUtil
|
||||
import io.socket.client.Ack
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONObject
|
||||
|
@ -12,11 +17,13 @@ import org.json.JSONObject
|
|||
class NSAddAck(
|
||||
private val aapsLogger: AAPSLogger,
|
||||
private val rxBus: RxBus,
|
||||
private val nsClientService: NSClientService,
|
||||
private val dateUtil: DateUtil,
|
||||
private val dataWorkerStorage: DataWorkerStorage,
|
||||
val originalObject: Any? = null
|
||||
) : Event(), Ack {
|
||||
|
||||
var id: String? = null
|
||||
private var nsClientID: String? = null
|
||||
var json: JSONObject? = null
|
||||
override fun call(vararg args: Any) {
|
||||
// Regular response
|
||||
|
@ -27,11 +34,8 @@ class NSAddAck(
|
|||
response = responseArray.getJSONObject(0)
|
||||
id = response.getString("_id")
|
||||
json = response
|
||||
if (response.has("NSCLIENT_ID")) {
|
||||
nsClientID = response.getString("NSCLIENT_ID")
|
||||
}
|
||||
}
|
||||
rxBus.send(this)
|
||||
processAddAck()
|
||||
return
|
||||
} catch (e: Exception) {
|
||||
aapsLogger.error("Unhandled exception", e)
|
||||
|
@ -51,4 +55,13 @@ class NSAddAck(
|
|||
aapsLogger.error("Unhandled exception", e)
|
||||
}
|
||||
}
|
||||
|
||||
private fun processAddAck() {
|
||||
nsClientService.lastAckTime = dateUtil.now()
|
||||
dataWorkerStorage.enqueue(
|
||||
OneTimeWorkRequest.Builder(NSClientAddAckWorker::class.java)
|
||||
.setInputData(dataWorkerStorage.storeInputData(this))
|
||||
.build()
|
||||
)
|
||||
}
|
||||
}
|
|
@ -1,9 +1,14 @@
|
|||
package info.nightscout.plugins.sync.nsclient.acks
|
||||
|
||||
import androidx.work.OneTimeWorkRequest
|
||||
import info.nightscout.core.utils.receivers.DataWorkerStorage
|
||||
import info.nightscout.plugins.sync.nsclient.services.NSClientService
|
||||
import info.nightscout.plugins.sync.nsclient.workers.NSClientUpdateRemoveAckWorker
|
||||
import info.nightscout.rx.bus.RxBus
|
||||
import info.nightscout.rx.events.Event
|
||||
import info.nightscout.rx.logging.AAPSLogger
|
||||
import info.nightscout.rx.logging.LTag
|
||||
import info.nightscout.shared.utils.DateUtil
|
||||
import io.socket.client.Ack
|
||||
import org.json.JSONException
|
||||
import org.json.JSONObject
|
||||
|
@ -16,6 +21,9 @@ class NSUpdateAck(
|
|||
var _id: String,
|
||||
private val aapsLogger: AAPSLogger,
|
||||
private val rxBus: RxBus,
|
||||
private val nsClientService: NSClientService,
|
||||
private val dateUtil: DateUtil,
|
||||
private val dataWorkerStorage: DataWorkerStorage,
|
||||
val originalObject: Any? = null
|
||||
) : Event(), Ack {
|
||||
|
||||
|
@ -29,9 +37,18 @@ class NSUpdateAck(
|
|||
result = true
|
||||
aapsLogger.debug(LTag.NSCLIENT, "Internal error: Missing _id returned on dbUpdate ack")
|
||||
}
|
||||
rxBus.send(this)
|
||||
processUpdateAck()
|
||||
} catch (e: JSONException) {
|
||||
aapsLogger.error("Unhandled exception", e)
|
||||
}
|
||||
}
|
||||
|
||||
private fun processUpdateAck() {
|
||||
nsClientService.lastAckTime = dateUtil.now()
|
||||
dataWorkerStorage.enqueue(
|
||||
OneTimeWorkRequest.Builder(NSClientUpdateRemoveAckWorker::class.java)
|
||||
.setInputData(dataWorkerStorage.storeInputData(this))
|
||||
.build()
|
||||
)
|
||||
}
|
||||
}
|
|
@ -39,10 +39,8 @@ import info.nightscout.plugins.sync.nsclient.acks.NSAuthAck
|
|||
import info.nightscout.plugins.sync.nsclient.acks.NSUpdateAck
|
||||
import info.nightscout.plugins.sync.nsclient.data.AlarmAck
|
||||
import info.nightscout.plugins.sync.nsclient.data.NSDeviceStatusHandler
|
||||
import info.nightscout.plugins.sync.nsclient.workers.NSClientAddAckWorker
|
||||
import info.nightscout.plugins.sync.nsclient.workers.NSClientAddUpdateWorker
|
||||
import info.nightscout.plugins.sync.nsclient.workers.NSClientMbgWorker
|
||||
import info.nightscout.plugins.sync.nsclient.workers.NSClientUpdateRemoveAckWorker
|
||||
import info.nightscout.plugins.sync.nsclientV3.NSClientV3Plugin
|
||||
import info.nightscout.rx.AapsSchedulers
|
||||
import info.nightscout.rx.bus.RxBus
|
||||
|
@ -110,7 +108,7 @@ class NSClientService : DaggerService() {
|
|||
private var nsAPISecret = ""
|
||||
private var nsDevice = ""
|
||||
private val nsHours = 48
|
||||
private var lastAckTime: Long = 0
|
||||
internal var lastAckTime: Long = 0
|
||||
private var nsApiHashCode = ""
|
||||
private val reconnections = ArrayList<Long>()
|
||||
|
||||
|
@ -167,14 +165,6 @@ class NSClientService : DaggerService() {
|
|||
.toObservable(NSAuthAck::class.java)
|
||||
.observeOn(aapsSchedulers.io)
|
||||
.subscribe({ ack -> processAuthAck(ack) }, fabricPrivacy::logException)
|
||||
disposable += rxBus
|
||||
.toObservable(NSUpdateAck::class.java)
|
||||
.observeOn(aapsSchedulers.io)
|
||||
.subscribe({ ack -> processUpdateAck(ack) }, fabricPrivacy::logException)
|
||||
disposable += rxBus
|
||||
.toObservable(NSAddAck::class.java)
|
||||
.observeOn(aapsSchedulers.io)
|
||||
.subscribe({ ack -> processAddAck(ack) }, fabricPrivacy::logException)
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
|
@ -183,24 +173,6 @@ class NSClientService : DaggerService() {
|
|||
if (wakeLock?.isHeld == true) wakeLock?.release()
|
||||
}
|
||||
|
||||
private fun processAddAck(ack: NSAddAck) {
|
||||
lastAckTime = dateUtil.now()
|
||||
dataWorkerStorage.enqueue(
|
||||
OneTimeWorkRequest.Builder(NSClientAddAckWorker::class.java)
|
||||
.setInputData(dataWorkerStorage.storeInputData(ack))
|
||||
.build()
|
||||
)
|
||||
}
|
||||
|
||||
private fun processUpdateAck(ack: NSUpdateAck) {
|
||||
lastAckTime = dateUtil.now()
|
||||
dataWorkerStorage.enqueue(
|
||||
OneTimeWorkRequest.Builder(NSClientUpdateRemoveAckWorker::class.java)
|
||||
.setInputData(dataWorkerStorage.storeInputData(ack))
|
||||
.build()
|
||||
)
|
||||
}
|
||||
|
||||
private fun processAuthAck(ack: NSAuthAck) {
|
||||
var connectionStatus = "Authenticated ("
|
||||
if (ack.read) connectionStatus += "R"
|
||||
|
@ -605,7 +577,7 @@ class NSClientService : DaggerService() {
|
|||
message.put("collection", collection)
|
||||
message.put("_id", _id)
|
||||
message.put("data", data)
|
||||
socket?.emit("dbUpdate", message, NSUpdateAck("dbUpdate", _id, aapsLogger, rxBus, originalObject))
|
||||
socket?.emit("dbUpdate", message, NSUpdateAck("dbUpdate", _id, aapsLogger, rxBus, this, dateUtil, dataWorkerStorage, originalObject))
|
||||
rxBus.send(
|
||||
EventNSClientNewLog(
|
||||
"DBUPDATE $collection", "Sent " + originalObject.javaClass.simpleName + " " +
|
||||
|
@ -623,7 +595,7 @@ class NSClientService : DaggerService() {
|
|||
val message = JSONObject()
|
||||
message.put("collection", collection)
|
||||
message.put("data", data)
|
||||
socket?.emit("dbAdd", message, NSAddAck(aapsLogger, rxBus, originalObject))
|
||||
socket?.emit("dbAdd", message, NSAddAck(aapsLogger, rxBus, this, dateUtil, dataWorkerStorage, originalObject))
|
||||
rxBus.send(EventNSClientNewLog("DBADD $collection", "Sent " + originalObject.javaClass.simpleName + " " + data + " " + progress))
|
||||
} catch (e: JSONException) {
|
||||
aapsLogger.error("Unhandled exception", e)
|
||||
|
|
|
@ -7,19 +7,7 @@ import androidx.work.workDataOf
|
|||
import info.nightscout.core.utils.receivers.DataWorkerStorage
|
||||
import info.nightscout.core.utils.worker.LoggingWorker
|
||||
import info.nightscout.database.impl.AppRepository
|
||||
import info.nightscout.database.impl.transactions.UpdateNsIdBolusCalculatorResultTransaction
|
||||
import info.nightscout.database.impl.transactions.UpdateNsIdBolusTransaction
|
||||
import info.nightscout.database.impl.transactions.UpdateNsIdCarbsTransaction
|
||||
import info.nightscout.database.impl.transactions.UpdateNsIdDeviceStatusTransaction
|
||||
import info.nightscout.database.impl.transactions.UpdateNsIdEffectiveProfileSwitchTransaction
|
||||
import info.nightscout.database.impl.transactions.UpdateNsIdExtendedBolusTransaction
|
||||
import info.nightscout.database.impl.transactions.UpdateNsIdFoodTransaction
|
||||
import info.nightscout.database.impl.transactions.UpdateNsIdGlucoseValueTransaction
|
||||
import info.nightscout.database.impl.transactions.UpdateNsIdOfflineEventTransaction
|
||||
import info.nightscout.database.impl.transactions.UpdateNsIdProfileSwitchTransaction
|
||||
import info.nightscout.database.impl.transactions.UpdateNsIdTemporaryBasalTransaction
|
||||
import info.nightscout.database.impl.transactions.UpdateNsIdTemporaryTargetTransaction
|
||||
import info.nightscout.database.impl.transactions.UpdateNsIdTherapyEventTransaction
|
||||
import info.nightscout.interfaces.nsclient.StoreDataForDb
|
||||
import info.nightscout.interfaces.sync.DataSyncSelector
|
||||
import info.nightscout.interfaces.sync.DataSyncSelector.PairBolus
|
||||
import info.nightscout.interfaces.sync.DataSyncSelector.PairBolusCalculatorResult
|
||||
|
@ -39,7 +27,6 @@ import info.nightscout.plugins.sync.nsclient.acks.NSAddAck
|
|||
import info.nightscout.rx.AapsSchedulers
|
||||
import info.nightscout.rx.bus.RxBus
|
||||
import info.nightscout.rx.events.EventNSClientNewLog
|
||||
import info.nightscout.rx.logging.LTag
|
||||
import info.nightscout.shared.sharedPreferences.SP
|
||||
import javax.inject.Inject
|
||||
|
||||
|
@ -54,30 +41,22 @@ class NSClientAddAckWorker(
|
|||
@Inject lateinit var dataSyncSelector: DataSyncSelector
|
||||
@Inject lateinit var aapsSchedulers: AapsSchedulers
|
||||
@Inject lateinit var sp: SP
|
||||
@Inject lateinit var storeDataForDb: StoreDataForDb
|
||||
|
||||
override fun doWorkAndLog(): Result {
|
||||
var ret = Result.success()
|
||||
|
||||
val ack = dataWorkerStorage.pickupObject(inputData.getLong(DataWorkerStorage.STORE_KEY, -1)) as NSAddAck?
|
||||
?: return Result.failure(workDataOf("Error" to "missing input data"))
|
||||
|
||||
if (sp.getBoolean(R.string.key_ns_sync_slow, false)) SystemClock.sleep(1000)
|
||||
val ret = Result.success(workDataOf("ProcessedData" to ack.originalObject.toString()))
|
||||
|
||||
when (ack.originalObject) {
|
||||
is PairTemporaryTarget -> {
|
||||
val pair = ack.originalObject
|
||||
pair.value.interfaceIDs.nightscoutId = ack.id
|
||||
repository.runTransactionForResult(UpdateNsIdTemporaryTargetTransaction(pair.value))
|
||||
.doOnError { error ->
|
||||
aapsLogger.error(LTag.DATABASE, "Updated ns id of TemporaryTarget failed", error)
|
||||
ret = Result.failure((workDataOf("Error" to error.toString())))
|
||||
}
|
||||
.doOnSuccess {
|
||||
ret = Result.success(workDataOf("ProcessedData" to pair.toString()))
|
||||
aapsLogger.debug(LTag.DATABASE, "Updated ns id of TemporaryTarget " + pair.value)
|
||||
dataSyncSelector.confirmLastTempTargetsIdIfGreater(pair.updateRecordId)
|
||||
}
|
||||
.blockingGet()
|
||||
storeDataForDb.nsIdTemporaryTargets.add(pair.value)
|
||||
dataSyncSelector.confirmLastTempTargetsIdIfGreater(pair.updateRecordId)
|
||||
storeDataForDb.scheduleNsIdUpdate()
|
||||
rxBus.send(EventNSClientNewLog("DBADD", "Acked TemporaryTarget " + pair.value.interfaceIDs.nightscoutId))
|
||||
// Send new if waiting
|
||||
dataSyncSelector.processChangedTempTargetsCompat()
|
||||
|
@ -86,17 +65,9 @@ class NSClientAddAckWorker(
|
|||
is PairGlucoseValue -> {
|
||||
val pair = ack.originalObject
|
||||
pair.value.interfaceIDs.nightscoutId = ack.id
|
||||
repository.runTransactionForResult(UpdateNsIdGlucoseValueTransaction(pair.value))
|
||||
.doOnError { error ->
|
||||
aapsLogger.error(LTag.DATABASE, "Updated ns id of GlucoseValue failed", error)
|
||||
ret = Result.failure((workDataOf("Error" to error.toString())))
|
||||
}
|
||||
.doOnSuccess {
|
||||
ret = Result.success(workDataOf("ProcessedData" to pair.toString()))
|
||||
aapsLogger.debug(LTag.DATABASE, "Updated ns id of GlucoseValue " + pair.value)
|
||||
dataSyncSelector.confirmLastGlucoseValueIdIfGreater(pair.updateRecordId)
|
||||
}
|
||||
.blockingGet()
|
||||
storeDataForDb.nsIdGlucoseValues.add(pair.value)
|
||||
dataSyncSelector.confirmLastGlucoseValueIdIfGreater(pair.updateRecordId)
|
||||
storeDataForDb.scheduleNsIdUpdate()
|
||||
rxBus.send(EventNSClientNewLog("DBADD", "Acked GlucoseValue " + pair.value.interfaceIDs.nightscoutId))
|
||||
// Send new if waiting
|
||||
dataSyncSelector.processChangedGlucoseValuesCompat()
|
||||
|
@ -105,17 +76,9 @@ class NSClientAddAckWorker(
|
|||
is PairFood -> {
|
||||
val pair = ack.originalObject
|
||||
pair.value.interfaceIDs.nightscoutId = ack.id
|
||||
repository.runTransactionForResult(UpdateNsIdFoodTransaction(pair.value))
|
||||
.doOnError { error ->
|
||||
aapsLogger.error(LTag.DATABASE, "Updated ns id of Food failed", error)
|
||||
ret = Result.failure((workDataOf("Error" to error.toString())))
|
||||
}
|
||||
.doOnSuccess {
|
||||
ret = Result.success(workDataOf("ProcessedData" to pair.toString()))
|
||||
aapsLogger.debug(LTag.DATABASE, "Updated ns id of Food " + pair.value)
|
||||
dataSyncSelector.confirmLastFoodIdIfGreater(pair.updateRecordId)
|
||||
}
|
||||
.blockingGet()
|
||||
storeDataForDb.nsIdFoods.add(pair.value)
|
||||
dataSyncSelector.confirmLastFoodIdIfGreater(pair.updateRecordId)
|
||||
storeDataForDb.scheduleNsIdUpdate()
|
||||
rxBus.send(EventNSClientNewLog("DBADD", "Acked Food " + pair.value.interfaceIDs.nightscoutId))
|
||||
// Send new if waiting
|
||||
dataSyncSelector.processChangedFoodsCompat()
|
||||
|
@ -124,17 +87,9 @@ class NSClientAddAckWorker(
|
|||
is PairTherapyEvent -> {
|
||||
val pair = ack.originalObject
|
||||
pair.value.interfaceIDs.nightscoutId = ack.id
|
||||
repository.runTransactionForResult(UpdateNsIdTherapyEventTransaction(pair.value))
|
||||
.doOnError { error ->
|
||||
aapsLogger.error(LTag.DATABASE, "Updated ns id of TherapyEvent failed", error)
|
||||
ret = Result.failure((workDataOf("Error" to error.toString())))
|
||||
}
|
||||
.doOnSuccess {
|
||||
ret = Result.success(workDataOf("ProcessedData" to pair.toString()))
|
||||
aapsLogger.debug(LTag.DATABASE, "Updated ns id of TherapyEvent " + pair.value)
|
||||
dataSyncSelector.confirmLastTherapyEventIdIfGreater(pair.updateRecordId)
|
||||
}
|
||||
.blockingGet()
|
||||
storeDataForDb.nsIdTherapyEvents.add(pair.value)
|
||||
dataSyncSelector.confirmLastTherapyEventIdIfGreater(pair.updateRecordId)
|
||||
storeDataForDb.scheduleNsIdUpdate()
|
||||
rxBus.send(EventNSClientNewLog("DBADD", "Acked TherapyEvent " + pair.value.interfaceIDs.nightscoutId))
|
||||
// Send new if waiting
|
||||
dataSyncSelector.processChangedTherapyEventsCompat()
|
||||
|
@ -143,17 +98,9 @@ class NSClientAddAckWorker(
|
|||
is PairBolus -> {
|
||||
val pair = ack.originalObject
|
||||
pair.value.interfaceIDs.nightscoutId = ack.id
|
||||
repository.runTransactionForResult(UpdateNsIdBolusTransaction(pair.value))
|
||||
.doOnError { error ->
|
||||
aapsLogger.error(LTag.DATABASE, "Updated ns id of Bolus failed", error)
|
||||
ret = Result.failure((workDataOf("Error" to error.toString())))
|
||||
}
|
||||
.doOnSuccess {
|
||||
ret = Result.success(workDataOf("ProcessedData" to pair.toString()))
|
||||
aapsLogger.debug(LTag.DATABASE, "Updated ns id of Bolus " + pair.value)
|
||||
dataSyncSelector.confirmLastBolusIdIfGreater(pair.updateRecordId)
|
||||
}
|
||||
.blockingGet()
|
||||
storeDataForDb.nsIdBoluses.add(pair.value)
|
||||
dataSyncSelector.confirmLastBolusIdIfGreater(pair.updateRecordId)
|
||||
storeDataForDb.scheduleNsIdUpdate()
|
||||
rxBus.send(EventNSClientNewLog("DBADD", "Acked Bolus " + pair.value.interfaceIDs.nightscoutId))
|
||||
// Send new if waiting
|
||||
dataSyncSelector.processChangedBolusesCompat()
|
||||
|
@ -162,17 +109,9 @@ class NSClientAddAckWorker(
|
|||
is PairCarbs -> {
|
||||
val pair = ack.originalObject
|
||||
pair.value.interfaceIDs.nightscoutId = ack.id
|
||||
repository.runTransactionForResult(UpdateNsIdCarbsTransaction(pair.value))
|
||||
.doOnError { error ->
|
||||
aapsLogger.error(LTag.DATABASE, "Updated ns id of Carbs failed", error)
|
||||
ret = Result.failure((workDataOf("Error" to error.toString())))
|
||||
}
|
||||
.doOnSuccess {
|
||||
ret = Result.success(workDataOf("ProcessedData" to pair.toString()))
|
||||
aapsLogger.debug(LTag.DATABASE, "Updated ns id of Carbs " + pair.value)
|
||||
dataSyncSelector.confirmLastCarbsIdIfGreater(pair.updateRecordId)
|
||||
}
|
||||
.blockingGet()
|
||||
storeDataForDb.nsIdCarbs.add(pair.value)
|
||||
dataSyncSelector.confirmLastCarbsIdIfGreater(pair.updateRecordId)
|
||||
storeDataForDb.scheduleNsIdUpdate()
|
||||
rxBus.send(EventNSClientNewLog("DBADD", "Acked Carbs " + pair.value.interfaceIDs.nightscoutId))
|
||||
// Send new if waiting
|
||||
dataSyncSelector.processChangedCarbsCompat()
|
||||
|
@ -181,17 +120,9 @@ class NSClientAddAckWorker(
|
|||
is PairBolusCalculatorResult -> {
|
||||
val pair = ack.originalObject
|
||||
pair.value.interfaceIDs.nightscoutId = ack.id
|
||||
repository.runTransactionForResult(UpdateNsIdBolusCalculatorResultTransaction(pair.value))
|
||||
.doOnError { error ->
|
||||
aapsLogger.error(LTag.DATABASE, "Updated ns id of BolusCalculatorResult failed", error)
|
||||
ret = Result.failure((workDataOf("Error" to error.toString())))
|
||||
}
|
||||
.doOnSuccess {
|
||||
ret = Result.success(workDataOf("ProcessedData" to pair.toString()))
|
||||
aapsLogger.debug(LTag.DATABASE, "Updated ns id of BolusCalculatorResult " + pair.value)
|
||||
dataSyncSelector.confirmLastBolusCalculatorResultsIdIfGreater(pair.updateRecordId)
|
||||
}
|
||||
.blockingGet()
|
||||
storeDataForDb.nsIdBolusCalculatorResults.add(pair.value)
|
||||
dataSyncSelector.confirmLastBolusCalculatorResultsIdIfGreater(pair.updateRecordId)
|
||||
storeDataForDb.scheduleNsIdUpdate()
|
||||
rxBus.send(EventNSClientNewLog("DBADD", "Acked BolusCalculatorResult " + pair.value.interfaceIDs.nightscoutId))
|
||||
// Send new if waiting
|
||||
dataSyncSelector.processChangedBolusCalculatorResultsCompat()
|
||||
|
@ -200,17 +131,9 @@ class NSClientAddAckWorker(
|
|||
is PairTemporaryBasal -> {
|
||||
val pair = ack.originalObject
|
||||
pair.value.interfaceIDs.nightscoutId = ack.id
|
||||
repository.runTransactionForResult(UpdateNsIdTemporaryBasalTransaction(pair.value))
|
||||
.doOnError { error ->
|
||||
aapsLogger.error(LTag.DATABASE, "Updated ns id of TemporaryBasal failed", error)
|
||||
ret = Result.failure((workDataOf("Error" to error.toString())))
|
||||
}
|
||||
.doOnSuccess {
|
||||
ret = Result.success(workDataOf("ProcessedData" to pair.toString()))
|
||||
aapsLogger.debug(LTag.DATABASE, "Updated ns id of TemporaryBasal " + pair.value)
|
||||
dataSyncSelector.confirmLastTemporaryBasalIdIfGreater(pair.updateRecordId)
|
||||
}
|
||||
.blockingGet()
|
||||
storeDataForDb.nsIdTemporaryBasals.add(pair.value)
|
||||
dataSyncSelector.confirmLastTemporaryBasalIdIfGreater(pair.updateRecordId)
|
||||
storeDataForDb.scheduleNsIdUpdate()
|
||||
rxBus.send(EventNSClientNewLog("DBADD", "Acked TemporaryBasal " + pair.value.interfaceIDs.nightscoutId))
|
||||
// Send new if waiting
|
||||
dataSyncSelector.processChangedTemporaryBasalsCompat()
|
||||
|
@ -219,17 +142,9 @@ class NSClientAddAckWorker(
|
|||
is PairExtendedBolus -> {
|
||||
val pair = ack.originalObject
|
||||
pair.value.interfaceIDs.nightscoutId = ack.id
|
||||
repository.runTransactionForResult(UpdateNsIdExtendedBolusTransaction(pair.value))
|
||||
.doOnError { error ->
|
||||
aapsLogger.error(LTag.DATABASE, "Updated ns id of ExtendedBolus failed", error)
|
||||
ret = Result.failure((workDataOf("Error" to error.toString())))
|
||||
}
|
||||
.doOnSuccess {
|
||||
ret = Result.success(workDataOf("ProcessedData" to pair.toString()))
|
||||
aapsLogger.debug(LTag.DATABASE, "Updated ns id of ExtendedBolus " + pair.value)
|
||||
dataSyncSelector.confirmLastExtendedBolusIdIfGreater(pair.updateRecordId)
|
||||
}
|
||||
.blockingGet()
|
||||
storeDataForDb.nsIdExtendedBoluses.add(pair.value)
|
||||
dataSyncSelector.confirmLastExtendedBolusIdIfGreater(pair.updateRecordId)
|
||||
storeDataForDb.scheduleNsIdUpdate()
|
||||
rxBus.send(EventNSClientNewLog("DBADD", "Acked ExtendedBolus " + pair.value.interfaceIDs.nightscoutId))
|
||||
// Send new if waiting
|
||||
dataSyncSelector.processChangedExtendedBolusesCompat()
|
||||
|
@ -238,17 +153,9 @@ class NSClientAddAckWorker(
|
|||
is PairProfileSwitch -> {
|
||||
val pair = ack.originalObject
|
||||
pair.value.interfaceIDs.nightscoutId = ack.id
|
||||
repository.runTransactionForResult(UpdateNsIdProfileSwitchTransaction(pair.value))
|
||||
.doOnError { error ->
|
||||
aapsLogger.error(LTag.DATABASE, "Updated ns id of ProfileSwitch failed", error)
|
||||
ret = Result.failure((workDataOf("Error" to error.toString())))
|
||||
}
|
||||
.doOnSuccess {
|
||||
ret = Result.success(workDataOf("ProcessedData" to pair.toString()))
|
||||
aapsLogger.debug(LTag.DATABASE, "Updated ns id of ProfileSwitch " + pair.value)
|
||||
dataSyncSelector.confirmLastProfileSwitchIdIfGreater(pair.updateRecordId)
|
||||
}
|
||||
.blockingGet()
|
||||
storeDataForDb.nsIdProfileSwitches.add(pair.value)
|
||||
dataSyncSelector.confirmLastProfileSwitchIdIfGreater(pair.updateRecordId)
|
||||
storeDataForDb.scheduleNsIdUpdate()
|
||||
rxBus.send(EventNSClientNewLog("DBADD", "Acked ProfileSwitch " + pair.value.interfaceIDs.nightscoutId))
|
||||
// Send new if waiting
|
||||
dataSyncSelector.processChangedProfileSwitchesCompat()
|
||||
|
@ -257,37 +164,21 @@ class NSClientAddAckWorker(
|
|||
is PairEffectiveProfileSwitch -> {
|
||||
val pair = ack.originalObject
|
||||
pair.value.interfaceIDs.nightscoutId = ack.id
|
||||
repository.runTransactionForResult(UpdateNsIdEffectiveProfileSwitchTransaction(pair.value))
|
||||
.doOnError { error ->
|
||||
aapsLogger.error(LTag.DATABASE, "Updated ns id of EffectiveProfileSwitch failed", error)
|
||||
ret = Result.failure((workDataOf("Error" to error.toString())))
|
||||
}
|
||||
.doOnSuccess {
|
||||
ret = Result.success(workDataOf("ProcessedData" to pair.toString()))
|
||||
aapsLogger.debug(LTag.DATABASE, "Updated ns id of EffectiveProfileSwitch " + pair.value)
|
||||
dataSyncSelector.confirmLastEffectiveProfileSwitchIdIfGreater(pair.updateRecordId)
|
||||
}
|
||||
.blockingGet()
|
||||
storeDataForDb.nsIdEffectiveProfileSwitches.add(pair.value)
|
||||
dataSyncSelector.confirmLastEffectiveProfileSwitchIdIfGreater(pair.updateRecordId)
|
||||
storeDataForDb.scheduleNsIdUpdate()
|
||||
rxBus.send(EventNSClientNewLog("DBADD", "Acked EffectiveProfileSwitch " + pair.value.interfaceIDs.nightscoutId))
|
||||
// Send new if waiting
|
||||
dataSyncSelector.processChangedEffectiveProfileSwitchesCompat()
|
||||
}
|
||||
|
||||
is DataSyncSelector.PairDeviceStatus -> {
|
||||
val deviceStatus = ack.originalObject
|
||||
deviceStatus.value.interfaceIDs.nightscoutId = ack.id
|
||||
repository.runTransactionForResult(UpdateNsIdDeviceStatusTransaction(deviceStatus.value))
|
||||
.doOnError { error ->
|
||||
aapsLogger.error(LTag.DATABASE, "Updated ns id of DeviceStatus failed", error)
|
||||
ret = Result.failure((workDataOf("Error" to error.toString())))
|
||||
}
|
||||
.doOnSuccess {
|
||||
ret = Result.success(workDataOf("ProcessedData" to deviceStatus.toString()))
|
||||
aapsLogger.debug(LTag.DATABASE, "Updated ns id of DeviceStatus $deviceStatus")
|
||||
dataSyncSelector.confirmLastDeviceStatusIdIfGreater(deviceStatus.value.id)
|
||||
}
|
||||
.blockingGet()
|
||||
rxBus.send(EventNSClientNewLog("DBADD", "Acked DeviceStatus " + deviceStatus.value.interfaceIDs.nightscoutId))
|
||||
val pair = ack.originalObject
|
||||
pair.value.interfaceIDs.nightscoutId = ack.id
|
||||
storeDataForDb.nsIdDeviceStatuses.add(pair.value)
|
||||
dataSyncSelector.confirmLastDeviceStatusIdIfGreater(pair.value.id)
|
||||
storeDataForDb.scheduleNsIdUpdate()
|
||||
rxBus.send(EventNSClientNewLog("DBADD", "Acked DeviceStatus " + pair.value.interfaceIDs.nightscoutId))
|
||||
// Send new if waiting
|
||||
dataSyncSelector.processChangedDeviceStatusesCompat()
|
||||
}
|
||||
|
@ -300,17 +191,9 @@ class NSClientAddAckWorker(
|
|||
is PairOfflineEvent -> {
|
||||
val pair = ack.originalObject
|
||||
pair.value.interfaceIDs.nightscoutId = ack.id
|
||||
repository.runTransactionForResult(UpdateNsIdOfflineEventTransaction(pair.value))
|
||||
.doOnError { error ->
|
||||
aapsLogger.error(LTag.DATABASE, "Updated ns id of OfflineEvent failed", error)
|
||||
ret = Result.failure((workDataOf("Error" to error.toString())))
|
||||
}
|
||||
.doOnSuccess {
|
||||
ret = Result.success(workDataOf("ProcessedData" to pair.toString()))
|
||||
aapsLogger.debug(LTag.DATABASE, "Updated ns id of OfflineEvent " + pair.value)
|
||||
dataSyncSelector.confirmLastOfflineEventIdIfGreater(pair.updateRecordId)
|
||||
}
|
||||
.blockingGet()
|
||||
storeDataForDb.nsIdOfflineEvents.add(pair.value)
|
||||
dataSyncSelector.confirmLastOfflineEventIdIfGreater(pair.updateRecordId)
|
||||
storeDataForDb.scheduleNsIdUpdate()
|
||||
rxBus.send(EventNSClientNewLog("DBADD", "Acked OfflineEvent " + pair.value.interfaceIDs.nightscoutId))
|
||||
// Send new if waiting
|
||||
dataSyncSelector.processChangedOfflineEventsCompat()
|
||||
|
|
|
@ -11,11 +11,11 @@ import info.nightscout.database.impl.AppRepository
|
|||
import info.nightscout.interfaces.Config
|
||||
import info.nightscout.interfaces.XDripBroadcast
|
||||
import info.nightscout.interfaces.logging.UserEntryLogger
|
||||
import info.nightscout.interfaces.nsclient.StoreDataForDb
|
||||
import info.nightscout.interfaces.plugin.ActivePlugin
|
||||
import info.nightscout.interfaces.pump.VirtualPump
|
||||
import info.nightscout.interfaces.utils.JsonHelper
|
||||
import info.nightscout.plugins.sync.R
|
||||
import info.nightscout.plugins.sync.nsShared.StoreDataForDbImpl
|
||||
import info.nightscout.plugins.sync.nsclient.extensions.bolusFromJson
|
||||
import info.nightscout.plugins.sync.nsclient.extensions.carbsFromJson
|
||||
import info.nightscout.plugins.sync.nsclient.extensions.effectiveProfileSwitchFromJson
|
||||
|
@ -46,7 +46,7 @@ class NSClientAddUpdateWorker(
|
|||
@Inject lateinit var rxBus: RxBus
|
||||
@Inject lateinit var uel: UserEntryLogger
|
||||
@Inject lateinit var xDripBroadcast: XDripBroadcast
|
||||
@Inject lateinit var storeDataForDb: StoreDataForDbImpl
|
||||
@Inject lateinit var storeDataForDb: StoreDataForDb
|
||||
|
||||
override fun doWorkAndLog(): Result {
|
||||
val treatments = dataWorkerStorage.pickupJSONArray(inputData.getLong(DataWorkerStorage.STORE_KEY, -1))
|
||||
|
|
|
@ -6,7 +6,7 @@ import androidx.work.workDataOf
|
|||
import info.nightscout.core.utils.receivers.DataWorkerStorage
|
||||
import info.nightscout.core.utils.worker.LoggingWorker
|
||||
import info.nightscout.interfaces.Config
|
||||
import info.nightscout.plugins.sync.nsShared.StoreDataForDbImpl
|
||||
import info.nightscout.interfaces.nsclient.StoreDataForDb
|
||||
import info.nightscout.plugins.sync.nsclient.data.NSMbg
|
||||
import info.nightscout.plugins.sync.nsclient.extensions.therapyEventFromNsMbg
|
||||
import info.nightscout.shared.sharedPreferences.SP
|
||||
|
@ -20,7 +20,7 @@ class NSClientMbgWorker(
|
|||
@Inject lateinit var dataWorkerStorage: DataWorkerStorage
|
||||
@Inject lateinit var sp: SP
|
||||
@Inject lateinit var config: Config
|
||||
@Inject lateinit var storeDataForDb: StoreDataForDbImpl
|
||||
@Inject lateinit var storeDataForDb: StoreDataForDb
|
||||
|
||||
override fun doWorkAndLog(): Result {
|
||||
val ret = Result.success()
|
||||
|
|
|
@ -29,8 +29,7 @@ import info.nightscout.plugins.sync.nsShared.NSClientFragment
|
|||
import info.nightscout.plugins.sync.nsShared.events.EventNSClientResend
|
||||
import info.nightscout.plugins.sync.nsShared.events.EventNSClientUpdateGUI
|
||||
import info.nightscout.plugins.sync.nsclient.NsClientReceiverDelegate
|
||||
import info.nightscout.plugins.sync.nsclient.data.AlarmAck
|
||||
import info.nightscout.plugins.sync.nsclient.services.NSClientService
|
||||
import info.nightscout.plugins.sync.nsclientV3.extensions.toNSBolus
|
||||
import info.nightscout.plugins.sync.nsclientV3.workers.LoadBgWorker
|
||||
import info.nightscout.plugins.sync.nsclientV3.workers.LoadLastModificationWorker
|
||||
import info.nightscout.plugins.sync.nsclientV3.workers.LoadStatusWorker
|
||||
|
@ -52,9 +51,9 @@ import info.nightscout.shared.utils.DateUtil
|
|||
import info.nightscout.shared.utils.T
|
||||
import io.reactivex.rxjava3.disposables.CompositeDisposable
|
||||
import io.reactivex.rxjava3.kotlin.plusAssign
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.serialization.decodeFromString
|
||||
import kotlinx.serialization.json.Json
|
||||
import org.json.JSONObject
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
import kotlin.math.max
|
||||
|
@ -302,13 +301,31 @@ class NSClientV3Plugin @Inject constructor(
|
|||
storeLastFetched()
|
||||
}
|
||||
|
||||
override fun dbAdd(collection: String, originalObject: DataSyncSelector.DataPair, progress: String) {
|
||||
if (collection == "treatments") {
|
||||
//val result = nsAndroidClient.createTreatment()
|
||||
override fun dbAdd(collection: String, dataPair: DataSyncSelector.DataPair, progress: String) {
|
||||
when (dataPair) {
|
||||
is DataSyncSelector.PairBolus -> dataPair.value.toNSBolus()
|
||||
// is DataSyncSelector.PairCarbs -> dataPair.value.toJson(false, dateUtil)
|
||||
// is DataSyncSelector.PairBolusCalculatorResult -> dataPair.value.toJson(false, dateUtil, profileFunction)
|
||||
// is DataSyncSelector.PairTemporaryTarget -> dataPair.value.toJson(false, profileFunction.getUnits(), dateUtil)
|
||||
// is DataSyncSelector.PairFood -> dataPair.value.toJson(false)
|
||||
// is DataSyncSelector.PairGlucoseValue -> dataPair.value.toJson(false, dateUtil)
|
||||
// is DataSyncSelector.PairTherapyEvent -> dataPair.value.toJson(false, dateUtil)
|
||||
// is DataSyncSelector.PairTemporaryBasal -> dataPair.value.toJson(false, profileFunction.getProfile(dataPair.value.timestamp), dateUtil)
|
||||
// is DataSyncSelector.PairExtendedBolus -> dataPair.value.toJson(false, profileFunction.getProfile(dataPair.value.timestamp), dateUtil)
|
||||
// is DataSyncSelector.PairProfileSwitch -> dataPair.value.toJson(false, dateUtil)
|
||||
// is DataSyncSelector.PairEffectiveProfileSwitch -> dataPair.value.toJson(false, dateUtil)
|
||||
// is DataSyncSelector.PairOfflineEvent -> dataPair.value.toJson(false, dateUtil)
|
||||
else -> null
|
||||
}?.let { data ->
|
||||
runBlocking {
|
||||
if (collection == "treatments") {
|
||||
val result = nsAndroidClient.createTreatment(data)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun dbUpdate(collection: String, originalObject: DataSyncSelector.DataPair, progress: String) {
|
||||
override fun dbUpdate(collection: String, dataPair: DataSyncSelector.DataPair, progress: String) {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
package info.nightscout.plugins.sync.nsclientV3.extensions
|
||||
|
||||
import info.nightscout.database.entities.Bolus
|
||||
import info.nightscout.database.entities.TherapyEvent
|
||||
import info.nightscout.database.entities.embedments.InterfaceIDs
|
||||
import info.nightscout.sdk.localmodel.treatment.EventType
|
||||
import info.nightscout.sdk.localmodel.treatment.NSBolus
|
||||
|
||||
fun NSBolus.toBolus(): Bolus =
|
||||
|
@ -21,4 +23,28 @@ fun NSBolus.BolusType?.toBolusType(): Bolus.Type =
|
|||
NSBolus.BolusType.SMB -> Bolus.Type.SMB
|
||||
NSBolus.BolusType.PRIMING -> Bolus.Type.PRIMING
|
||||
null -> Bolus.Type.NORMAL
|
||||
}
|
||||
|
||||
fun Bolus.toNSBolus(): NSBolus =
|
||||
NSBolus(
|
||||
eventType = EventType.fromString(if (type == Bolus.Type.SMB) TherapyEvent.Type.CORRECTION_BOLUS.text else TherapyEvent.Type.MEAL_BOLUS.text),
|
||||
isValid = isValid,
|
||||
date = timestamp,
|
||||
utcOffset = utcOffset,
|
||||
insulin = amount,
|
||||
type = type.toBolusType(),
|
||||
notes = notes,
|
||||
identifier = interfaceIDs.nightscoutId,
|
||||
pumpId = interfaceIDs.pumpId,
|
||||
pumpType = interfaceIDs.pumpType?.name,
|
||||
pumpSerial = interfaceIDs.pumpSerial,
|
||||
endId = interfaceIDs.endId
|
||||
)
|
||||
|
||||
fun Bolus.Type?.toBolusType(): NSBolus.BolusType =
|
||||
when (this) {
|
||||
Bolus.Type.NORMAL -> NSBolus.BolusType.NORMAL
|
||||
Bolus.Type.SMB -> NSBolus.BolusType.SMB
|
||||
Bolus.Type.PRIMING -> NSBolus.BolusType.PRIMING
|
||||
null -> NSBolus.BolusType.NORMAL
|
||||
}
|
|
@ -8,7 +8,7 @@ import androidx.work.WorkerParameters
|
|||
import androidx.work.workDataOf
|
||||
import info.nightscout.core.utils.receivers.DataWorkerStorage
|
||||
import info.nightscout.core.utils.worker.LoggingWorker
|
||||
import info.nightscout.plugins.sync.nsShared.StoreDataForDbImpl
|
||||
import info.nightscout.interfaces.nsclient.StoreDataForDb
|
||||
import info.nightscout.plugins.sync.nsclientV3.NSClientV3Plugin
|
||||
import info.nightscout.rx.bus.RxBus
|
||||
import info.nightscout.rx.events.EventNSClientNewLog
|
||||
|
@ -26,7 +26,7 @@ class LoadTreatmentsWorker(
|
|||
@Inject lateinit var context: Context
|
||||
@Inject lateinit var nsClientV3Plugin: NSClientV3Plugin
|
||||
@Inject lateinit var dateUtil: DateUtil
|
||||
@Inject lateinit var storeDataForDb: StoreDataForDbImpl
|
||||
@Inject lateinit var storeDataForDb: StoreDataForDb
|
||||
|
||||
override fun doWorkAndLog(): Result {
|
||||
var ret = Result.success()
|
||||
|
|
|
@ -10,9 +10,9 @@ import info.nightscout.interfaces.Config
|
|||
import info.nightscout.interfaces.Constants
|
||||
import info.nightscout.interfaces.XDripBroadcast
|
||||
import info.nightscout.interfaces.logging.UserEntryLogger
|
||||
import info.nightscout.interfaces.nsclient.StoreDataForDb
|
||||
import info.nightscout.interfaces.plugin.ActivePlugin
|
||||
import info.nightscout.plugins.sync.R
|
||||
import info.nightscout.plugins.sync.nsShared.StoreDataForDbImpl
|
||||
import info.nightscout.plugins.sync.nsclientV3.extensions.toBolus
|
||||
import info.nightscout.plugins.sync.nsclientV3.extensions.toBolusCalculatorResult
|
||||
import info.nightscout.plugins.sync.nsclientV3.extensions.toCarbs
|
||||
|
@ -54,7 +54,7 @@ class ProcessTreatmentsWorker(
|
|||
@Inject lateinit var rxBus: RxBus
|
||||
@Inject lateinit var uel: UserEntryLogger
|
||||
@Inject lateinit var xDripBroadcast: XDripBroadcast
|
||||
@Inject lateinit var storeDataForDb: StoreDataForDbImpl
|
||||
@Inject lateinit var storeDataForDb: StoreDataForDb
|
||||
|
||||
override fun doWorkAndLog(): Result {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
|
|
Loading…
Reference in a new issue