Merge branch 'dev2_dana_combo_only' into Fix_NSClient_UseAbsolute
This commit is contained in:
commit
60cae5c2bd
|
@ -75,21 +75,21 @@ class DataSyncSelectorImplementation @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var lastBolusId = -1L
|
||||||
|
private var lastBolusTime = -1L
|
||||||
override fun processChangedBolusesCompat(): Boolean {
|
override fun processChangedBolusesCompat(): Boolean {
|
||||||
val startId = sp.getLong(R.string.key_ns_bolus_last_synced_id, 0)
|
val startId = sp.getLong(R.string.key_ns_bolus_last_synced_id, 0)
|
||||||
|
if (startId == lastBolusId && dateUtil.now() - lastBolusTime < 5000) return false
|
||||||
|
lastBolusId = startId
|
||||||
|
lastBolusTime = dateUtil.now()
|
||||||
appRepository.getNextSyncElementBolus(startId).blockingGet()?.let { bolus ->
|
appRepository.getNextSyncElementBolus(startId).blockingGet()?.let { bolus ->
|
||||||
aapsLogger.info(LTag.DATABASE, "Loading Bolus data Start: $startId ID: ${bolus.first.id} HistoryID: ${bolus.second} ")
|
aapsLogger.info(LTag.DATABASE, "Loading Bolus data Start: $startId ID: ${bolus.first.id} HistoryID: ${bolus.second} ")
|
||||||
when {
|
when {
|
||||||
// removed and not uploaded yet = ignore
|
// without nsId = create new
|
||||||
!bolus.first.isValid && bolus.first.interfaceIDs.nightscoutId == null -> Any()
|
bolus.first.interfaceIDs.nightscoutId == null ->
|
||||||
// removed and already uploaded = send for removal
|
|
||||||
!bolus.first.isValid && bolus.first.interfaceIDs.nightscoutId != null ->
|
|
||||||
nsClientPlugin.nsClientService?.dbRemove("treatments", bolus.first.interfaceIDs.nightscoutId, DataSyncSelector.PairBolus(bolus.first, bolus.second))
|
|
||||||
// existing without nsId = create new
|
|
||||||
bolus.first.isValid && bolus.first.interfaceIDs.nightscoutId == null ->
|
|
||||||
nsClientPlugin.nsClientService?.dbAdd("treatments", bolus.first.toJson(dateUtil), DataSyncSelector.PairBolus(bolus.first, bolus.second))
|
nsClientPlugin.nsClientService?.dbAdd("treatments", bolus.first.toJson(dateUtil), DataSyncSelector.PairBolus(bolus.first, bolus.second))
|
||||||
// existing with nsId = update
|
// with nsId = update
|
||||||
bolus.first.isValid && bolus.first.interfaceIDs.nightscoutId != null ->
|
bolus.first.interfaceIDs.nightscoutId != null ->
|
||||||
nsClientPlugin.nsClientService?.dbUpdate("treatments", bolus.first.interfaceIDs.nightscoutId, bolus.first.toJson(dateUtil), DataSyncSelector.PairBolus(bolus.first, bolus.second))
|
nsClientPlugin.nsClientService?.dbUpdate("treatments", bolus.first.interfaceIDs.nightscoutId, bolus.first.toJson(dateUtil), DataSyncSelector.PairBolus(bolus.first, bolus.second))
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
@ -112,21 +112,21 @@ class DataSyncSelectorImplementation @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var lastCarbsId = -1L
|
||||||
|
private var lastCarbsTime = -1L
|
||||||
override fun processChangedCarbsCompat(): Boolean {
|
override fun processChangedCarbsCompat(): Boolean {
|
||||||
val startId = sp.getLong(R.string.key_ns_carbs_last_synced_id, 0)
|
val startId = sp.getLong(R.string.key_ns_carbs_last_synced_id, 0)
|
||||||
|
if (startId == lastCarbsId && dateUtil.now() - lastCarbsTime < 5000) return false
|
||||||
|
lastCarbsId = startId
|
||||||
|
lastCarbsTime = dateUtil.now()
|
||||||
appRepository.getNextSyncElementCarbs(startId).blockingGet()?.let { carb ->
|
appRepository.getNextSyncElementCarbs(startId).blockingGet()?.let { carb ->
|
||||||
aapsLogger.info(LTag.DATABASE, "Loading Carbs data Start: $startId ID: ${carb.first.id} HistoryID: ${carb.second} ")
|
aapsLogger.info(LTag.DATABASE, "Loading Carbs data Start: $startId ID: ${carb.first.id} HistoryID: ${carb.second} ")
|
||||||
when {
|
when {
|
||||||
// removed and not uploaded yet = ignore
|
// without nsId = create new
|
||||||
!carb.first.isValid && carb.first.interfaceIDs.nightscoutId == null -> Any()
|
carb.first.interfaceIDs.nightscoutId == null ->
|
||||||
// removed and already uploaded = send for removal
|
|
||||||
!carb.first.isValid && carb.first.interfaceIDs.nightscoutId != null ->
|
|
||||||
nsClientPlugin.nsClientService?.dbRemove("treatments", carb.first.interfaceIDs.nightscoutId, DataSyncSelector.PairCarbs(carb.first, carb.second))
|
|
||||||
// existing without nsId = create new
|
|
||||||
carb.first.isValid && carb.first.interfaceIDs.nightscoutId == null ->
|
|
||||||
nsClientPlugin.nsClientService?.dbAdd("treatments", carb.first.toJson(dateUtil), DataSyncSelector.PairCarbs(carb.first, carb.second))
|
nsClientPlugin.nsClientService?.dbAdd("treatments", carb.first.toJson(dateUtil), DataSyncSelector.PairCarbs(carb.first, carb.second))
|
||||||
// existing with nsId = update
|
// with nsId = update
|
||||||
carb.first.isValid && carb.first.interfaceIDs.nightscoutId != null ->
|
carb.first.interfaceIDs.nightscoutId != null ->
|
||||||
nsClientPlugin.nsClientService?.dbUpdate("treatments", carb.first.interfaceIDs.nightscoutId, carb.first.toJson(dateUtil), DataSyncSelector.PairCarbs(carb.first, carb.second))
|
nsClientPlugin.nsClientService?.dbUpdate("treatments", carb.first.interfaceIDs.nightscoutId, carb.first.toJson(dateUtil), DataSyncSelector.PairCarbs(carb.first, carb.second))
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
@ -149,21 +149,21 @@ class DataSyncSelectorImplementation @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var lastBcrId = -1L
|
||||||
|
private var lastBcrTime = -1L
|
||||||
override fun processChangedBolusCalculatorResultsCompat(): Boolean {
|
override fun processChangedBolusCalculatorResultsCompat(): Boolean {
|
||||||
val startId = sp.getLong(R.string.key_ns_bolus_calculator_result_last_synced_id, 0)
|
val startId = sp.getLong(R.string.key_ns_bolus_calculator_result_last_synced_id, 0)
|
||||||
|
if (startId == lastBcrId && dateUtil.now() - lastBcrTime < 5000) return false
|
||||||
|
lastBcrId = startId
|
||||||
|
lastBcrTime = dateUtil.now()
|
||||||
appRepository.getNextSyncElementBolusCalculatorResult(startId).blockingGet()?.let { bolusCalculatorResult ->
|
appRepository.getNextSyncElementBolusCalculatorResult(startId).blockingGet()?.let { bolusCalculatorResult ->
|
||||||
aapsLogger.info(LTag.DATABASE, "Loading BolusCalculatorResult data Start: $startId ID: ${bolusCalculatorResult.first.id} HistoryID: ${bolusCalculatorResult.second} ")
|
aapsLogger.info(LTag.DATABASE, "Loading BolusCalculatorResult data Start: $startId ID: ${bolusCalculatorResult.first.id} HistoryID: ${bolusCalculatorResult.second} ")
|
||||||
when {
|
when {
|
||||||
// removed and not uploaded yet = ignore
|
// without nsId = create new
|
||||||
!bolusCalculatorResult.first.isValid && bolusCalculatorResult.first.interfaceIDs.nightscoutId == null -> Any()
|
bolusCalculatorResult.first.interfaceIDs.nightscoutId == null ->
|
||||||
// removed and already uploaded = send for removal
|
|
||||||
!bolusCalculatorResult.first.isValid && bolusCalculatorResult.first.interfaceIDs.nightscoutId != null ->
|
|
||||||
nsClientPlugin.nsClientService?.dbRemove("treatments", bolusCalculatorResult.first.interfaceIDs.nightscoutId, DataSyncSelector.PairBolusCalculatorResult(bolusCalculatorResult.first, bolusCalculatorResult.second))
|
|
||||||
// existing without nsId = create new
|
|
||||||
bolusCalculatorResult.first.isValid && bolusCalculatorResult.first.interfaceIDs.nightscoutId == null ->
|
|
||||||
nsClientPlugin.nsClientService?.dbAdd("treatments", bolusCalculatorResult.first.toJson(dateUtil), DataSyncSelector.PairBolusCalculatorResult(bolusCalculatorResult.first, bolusCalculatorResult.second))
|
nsClientPlugin.nsClientService?.dbAdd("treatments", bolusCalculatorResult.first.toJson(dateUtil), DataSyncSelector.PairBolusCalculatorResult(bolusCalculatorResult.first, bolusCalculatorResult.second))
|
||||||
// existing with nsId = update
|
// with nsId = update
|
||||||
bolusCalculatorResult.first.isValid && bolusCalculatorResult.first.interfaceIDs.nightscoutId != null ->
|
bolusCalculatorResult.first.interfaceIDs.nightscoutId != null ->
|
||||||
nsClientPlugin.nsClientService?.dbUpdate("treatments", bolusCalculatorResult.first.interfaceIDs.nightscoutId, bolusCalculatorResult.first.toJson(dateUtil), DataSyncSelector.PairBolusCalculatorResult(bolusCalculatorResult.first, bolusCalculatorResult.second))
|
nsClientPlugin.nsClientService?.dbUpdate("treatments", bolusCalculatorResult.first.interfaceIDs.nightscoutId, bolusCalculatorResult.first.toJson(dateUtil), DataSyncSelector.PairBolusCalculatorResult(bolusCalculatorResult.first, bolusCalculatorResult.second))
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
@ -186,21 +186,21 @@ class DataSyncSelectorImplementation @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var lastTtId = -1L
|
||||||
|
private var lastTtTime = -1L
|
||||||
override fun processChangedTempTargetsCompat(): Boolean {
|
override fun processChangedTempTargetsCompat(): Boolean {
|
||||||
val startId = sp.getLong(R.string.key_ns_temporary_target_last_synced_id, 0)
|
val startId = sp.getLong(R.string.key_ns_temporary_target_last_synced_id, 0)
|
||||||
|
if (startId == lastTtId && dateUtil.now() - lastTtTime < 5000) return false
|
||||||
|
lastTtId = startId
|
||||||
|
lastTtTime = dateUtil.now()
|
||||||
appRepository.getNextSyncElementTemporaryTarget(startId).blockingGet()?.let { tt ->
|
appRepository.getNextSyncElementTemporaryTarget(startId).blockingGet()?.let { tt ->
|
||||||
aapsLogger.info(LTag.DATABASE, "Loading TemporaryTarget data Start: $startId ID: ${tt.first.id} HistoryID: ${tt.second} ")
|
aapsLogger.info(LTag.DATABASE, "Loading TemporaryTarget data Start: $startId ID: ${tt.first.id} HistoryID: ${tt.second} ")
|
||||||
when {
|
when {
|
||||||
// removed and not uploaded yet = ignore
|
// without nsId = create new
|
||||||
!tt.first.isValid && tt.first.interfaceIDs.nightscoutId == null -> Any()
|
tt.first.interfaceIDs.nightscoutId == null ->
|
||||||
// removed and already uploaded = send for removal
|
|
||||||
!tt.first.isValid && tt.first.interfaceIDs.nightscoutId != null ->
|
|
||||||
nsClientPlugin.nsClientService?.dbRemove("treatments", tt.first.interfaceIDs.nightscoutId, DataSyncSelector.PairTemporaryTarget(tt.first, tt.second))
|
|
||||||
// existing without nsId = create new
|
|
||||||
tt.first.isValid && tt.first.interfaceIDs.nightscoutId == null ->
|
|
||||||
nsClientPlugin.nsClientService?.dbAdd("treatments", tt.first.toJson(profileFunction.getUnits(), dateUtil), DataSyncSelector.PairTemporaryTarget(tt.first, tt.second))
|
nsClientPlugin.nsClientService?.dbAdd("treatments", tt.first.toJson(profileFunction.getUnits(), dateUtil), DataSyncSelector.PairTemporaryTarget(tt.first, tt.second))
|
||||||
// existing with nsId = update
|
// existing with nsId = update
|
||||||
tt.first.isValid && tt.first.interfaceIDs.nightscoutId != null ->
|
tt.first.interfaceIDs.nightscoutId != null ->
|
||||||
nsClientPlugin.nsClientService?.dbUpdate("treatments", tt.first.interfaceIDs.nightscoutId, tt.first.toJson(profileFunction.getUnits(), dateUtil), DataSyncSelector.PairTemporaryTarget(tt.first, tt.second))
|
nsClientPlugin.nsClientService?.dbUpdate("treatments", tt.first.interfaceIDs.nightscoutId, tt.first.toJson(profileFunction.getUnits(), dateUtil), DataSyncSelector.PairTemporaryTarget(tt.first, tt.second))
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
@ -223,22 +223,22 @@ class DataSyncSelectorImplementation @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var lastFoodId = -1L
|
||||||
|
private var lastFoodTime = -1L
|
||||||
override fun processChangedFoodsCompat(): Boolean {
|
override fun processChangedFoodsCompat(): Boolean {
|
||||||
val startId = sp.getLong(R.string.key_ns_food_last_synced_id, 0)
|
val startId = sp.getLong(R.string.key_ns_food_last_synced_id, 0)
|
||||||
appRepository.getNextSyncElementFood(startId).blockingGet()?.let { tt ->
|
if (startId == lastFoodId && dateUtil.now() - lastFoodTime < 5000) return false
|
||||||
aapsLogger.info(LTag.DATABASE, "Loading Food data Start: $startId ID: ${tt.first.id} HistoryID: ${tt.second} ")
|
lastFoodId = startId
|
||||||
|
lastFoodTime = dateUtil.now()
|
||||||
|
appRepository.getNextSyncElementFood(startId).blockingGet()?.let { food ->
|
||||||
|
aapsLogger.info(LTag.DATABASE, "Loading Food data Start: $startId ID: ${food.first.id} HistoryID: ${food.second} ")
|
||||||
when {
|
when {
|
||||||
// removed and not uploaded yet = ignore
|
// without nsId = create new
|
||||||
!tt.first.isValid && tt.first.interfaceIDs.nightscoutId == null -> Any()
|
food.first.interfaceIDs.nightscoutId == null ->
|
||||||
// removed and already uploaded = send for removal
|
nsClientPlugin.nsClientService?.dbAdd("food", food.first.toJson(), DataSyncSelector.PairFood(food.first, food.second))
|
||||||
!tt.first.isValid && tt.first.interfaceIDs.nightscoutId != null ->
|
// with nsId = update
|
||||||
nsClientPlugin.nsClientService?.dbRemove("food", tt.first.interfaceIDs.nightscoutId, DataSyncSelector.PairFood(tt.first, tt.second))
|
food.first.interfaceIDs.nightscoutId != null ->
|
||||||
// existing without nsId = create new
|
nsClientPlugin.nsClientService?.dbUpdate("food", food.first.interfaceIDs.nightscoutId, food.first.toJson(), DataSyncSelector.PairFood(food.first, food.second))
|
||||||
tt.first.isValid && tt.first.interfaceIDs.nightscoutId == null ->
|
|
||||||
nsClientPlugin.nsClientService?.dbAdd("food", tt.first.toJson(), DataSyncSelector.PairFood(tt.first, tt.second))
|
|
||||||
// existing with nsId = update
|
|
||||||
tt.first.isValid && tt.first.interfaceIDs.nightscoutId != null ->
|
|
||||||
nsClientPlugin.nsClientService?.dbUpdate("food", tt.first.interfaceIDs.nightscoutId, tt.first.toJson(), DataSyncSelector.PairFood(tt.first, tt.second))
|
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -260,22 +260,22 @@ class DataSyncSelectorImplementation @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var lastGvId = -1L
|
||||||
|
private var lastGvTime = -1L
|
||||||
override fun processChangedGlucoseValuesCompat(): Boolean {
|
override fun processChangedGlucoseValuesCompat(): Boolean {
|
||||||
val startId = sp.getLong(R.string.key_ns_glucose_value_last_synced_id, 0)
|
val startId = sp.getLong(R.string.key_ns_glucose_value_last_synced_id, 0)
|
||||||
|
if (startId == lastGvId && dateUtil.now() - lastGvTime < 5000) return false
|
||||||
|
lastGvId = startId
|
||||||
|
lastGvTime = dateUtil.now()
|
||||||
appRepository.getNextSyncElementGlucoseValue(startId).blockingGet()?.let { gv ->
|
appRepository.getNextSyncElementGlucoseValue(startId).blockingGet()?.let { gv ->
|
||||||
aapsLogger.info(LTag.DATABASE, "Loading GlucoseValue data Start: $startId ID: ${gv.first.id} HistoryID: ${gv.second} ")
|
aapsLogger.info(LTag.DATABASE, "Loading GlucoseValue data Start: $startId ID: ${gv.first.id} HistoryID: ${gv.second} ")
|
||||||
if (activePlugin.activeBgSource.shouldUploadToNs(gv.first)) {
|
if (activePlugin.activeBgSource.shouldUploadToNs(gv.first)) {
|
||||||
when {
|
when {
|
||||||
// removed and not uploaded yet = ignore
|
// without nsId = create new
|
||||||
!gv.first.isValid && gv.first.interfaceIDs.nightscoutId == null -> Any()
|
gv.first.interfaceIDs.nightscoutId == null ->
|
||||||
// removed and already uploaded = send for removal
|
|
||||||
!gv.first.isValid && gv.first.interfaceIDs.nightscoutId != null ->
|
|
||||||
nsClientPlugin.nsClientService?.dbRemove("entries", gv.first.interfaceIDs.nightscoutId, DataSyncSelector.PairGlucoseValue(gv.first, gv.second))
|
|
||||||
// existing without nsId = create new
|
|
||||||
gv.first.isValid && gv.first.interfaceIDs.nightscoutId == null ->
|
|
||||||
nsClientPlugin.nsClientService?.dbAdd("entries", gv.first.toJson(dateUtil), DataSyncSelector.PairGlucoseValue(gv.first, gv.second))
|
nsClientPlugin.nsClientService?.dbAdd("entries", gv.first.toJson(dateUtil), DataSyncSelector.PairGlucoseValue(gv.first, gv.second))
|
||||||
// existing with nsId = update
|
// with nsId = update
|
||||||
gv.first.isValid && gv.first.interfaceIDs.nightscoutId != null ->
|
gv.first.interfaceIDs.nightscoutId != null ->
|
||||||
nsClientPlugin.nsClientService?.dbUpdate("entries", gv.first.interfaceIDs.nightscoutId, gv.first.toJson(dateUtil), DataSyncSelector.PairGlucoseValue(gv.first, gv.second))
|
nsClientPlugin.nsClientService?.dbUpdate("entries", gv.first.interfaceIDs.nightscoutId, gv.first.toJson(dateUtil), DataSyncSelector.PairGlucoseValue(gv.first, gv.second))
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
@ -299,22 +299,22 @@ class DataSyncSelectorImplementation @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var lastTeId = -1L
|
||||||
|
private var lastTeTime = -1L
|
||||||
override fun processChangedTherapyEventsCompat(): Boolean {
|
override fun processChangedTherapyEventsCompat(): Boolean {
|
||||||
val startId = sp.getLong(R.string.key_ns_therapy_event_last_synced_id, 0)
|
val startId = sp.getLong(R.string.key_ns_therapy_event_last_synced_id, 0)
|
||||||
appRepository.getNextSyncElementTherapyEvent(startId).blockingGet()?.let { tt ->
|
if (startId == lastTeId && dateUtil.now() - lastTeTime < 5000) return false
|
||||||
aapsLogger.info(LTag.DATABASE, "Loading TherapyEvents data Start: $startId ID: ${tt.first.id} HistoryID: ${tt.second} ")
|
lastTeId = startId
|
||||||
|
lastTeTime = dateUtil.now()
|
||||||
|
appRepository.getNextSyncElementTherapyEvent(startId).blockingGet()?.let { te ->
|
||||||
|
aapsLogger.info(LTag.DATABASE, "Loading TherapyEvents data Start: $startId ID: ${te.first.id} HistoryID: ${te.second} ")
|
||||||
when {
|
when {
|
||||||
// removed and not uploaded yet = ignore
|
// without nsId = create new
|
||||||
!tt.first.isValid && tt.first.interfaceIDs.nightscoutId == null -> Any()
|
te.first.interfaceIDs.nightscoutId == null ->
|
||||||
// removed and already uploaded = send for removal
|
nsClientPlugin.nsClientService?.dbAdd("treatments", te.first.toJson(), DataSyncSelector.PairTherapyEvent(te.first, te.second))
|
||||||
!tt.first.isValid && tt.first.interfaceIDs.nightscoutId != null ->
|
// nsId = update
|
||||||
nsClientPlugin.nsClientService?.dbRemove("treatments", tt.first.interfaceIDs.nightscoutId, DataSyncSelector.PairTherapyEvent(tt.first, tt.second))
|
te.first.interfaceIDs.nightscoutId != null ->
|
||||||
// existing without nsId = create new
|
nsClientPlugin.nsClientService?.dbUpdate("treatments", te.first.interfaceIDs.nightscoutId, te.first.toJson(), DataSyncSelector.PairTherapyEvent(te.first, te.second))
|
||||||
tt.first.isValid && tt.first.interfaceIDs.nightscoutId == null ->
|
|
||||||
nsClientPlugin.nsClientService?.dbAdd("treatments", tt.first.toJson(), DataSyncSelector.PairTherapyEvent(tt.first, tt.second))
|
|
||||||
// existing with nsId = update
|
|
||||||
tt.first.isValid && tt.first.interfaceIDs.nightscoutId != null ->
|
|
||||||
nsClientPlugin.nsClientService?.dbUpdate("treatments", tt.first.interfaceIDs.nightscoutId, tt.first.toJson(), DataSyncSelector.PairTherapyEvent(tt.first, tt.second))
|
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -335,8 +335,13 @@ class DataSyncSelectorImplementation @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var lastDsId = -1L
|
||||||
|
private var lastDsTime = -1L
|
||||||
override fun processChangedDeviceStatusesCompat(): Boolean {
|
override fun processChangedDeviceStatusesCompat(): Boolean {
|
||||||
val startId = sp.getLong(R.string.key_ns_device_status_last_synced_id, 0)
|
val startId = sp.getLong(R.string.key_ns_device_status_last_synced_id, 0)
|
||||||
|
if (startId == lastDsId && dateUtil.now() - lastDsTime < 5000) return false
|
||||||
|
lastDsId = startId
|
||||||
|
lastDsTime = dateUtil.now()
|
||||||
appRepository.getNextSyncElementDeviceStatus(startId).blockingGet()?.let { deviceStatus ->
|
appRepository.getNextSyncElementDeviceStatus(startId).blockingGet()?.let { deviceStatus ->
|
||||||
aapsLogger.info(LTag.DATABASE, "Loading DeviceStatus data Start: $startId ID: ${deviceStatus.id}")
|
aapsLogger.info(LTag.DATABASE, "Loading DeviceStatus data Start: $startId ID: ${deviceStatus.id}")
|
||||||
when {
|
when {
|
||||||
|
@ -366,23 +371,23 @@ class DataSyncSelectorImplementation @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var lastTbrId = -1L
|
||||||
|
private var lastTbrTime = -1L
|
||||||
override fun processChangedTemporaryBasalsCompat(): Boolean {
|
override fun processChangedTemporaryBasalsCompat(): Boolean {
|
||||||
val startId = sp.getLong(R.string.key_ns_temporary_basal_last_synced_id, 0)
|
|
||||||
val useAbsolute = sp.getBoolean(R.string.key_ns_sync_use_absolute, false)
|
val useAbsolute = sp.getBoolean(R.string.key_ns_sync_use_absolute, false)
|
||||||
|
val startId = sp.getLong(R.string.key_ns_temporary_basal_last_synced_id, 0)
|
||||||
|
if (startId == lastTbrId && dateUtil.now() - lastTbrTime < 5000) return false
|
||||||
|
lastTbrId = startId
|
||||||
|
lastTbrTime = dateUtil.now()
|
||||||
appRepository.getNextSyncElementTemporaryBasal(startId).blockingGet()?.let { tb ->
|
appRepository.getNextSyncElementTemporaryBasal(startId).blockingGet()?.let { tb ->
|
||||||
aapsLogger.info(LTag.DATABASE, "Loading TemporaryBasal data Start: $startId ID: ${tb.first.id} HistoryID: ${tb.second} ")
|
aapsLogger.info(LTag.DATABASE, "Loading TemporaryBasal data Start: $startId ID: ${tb.first.id} HistoryID: ${tb.second} ")
|
||||||
profileFunction.getProfile(tb.first.timestamp)?.let { profile ->
|
profileFunction.getProfile(tb.first.timestamp)?.let { profile ->
|
||||||
when {
|
when {
|
||||||
// removed and not uploaded yet = ignore
|
// without nsId = create new
|
||||||
!tb.first.isValid && tb.first.interfaceIDs.nightscoutId == null -> Any()
|
tb.first.interfaceIDs.nightscoutId == null ->
|
||||||
// removed and already uploaded = send for removal
|
|
||||||
!tb.first.isValid && tb.first.interfaceIDs.nightscoutId != null ->
|
|
||||||
nsClientPlugin.nsClientService?.dbRemove("treatments", tb.first.interfaceIDs.nightscoutId, DataSyncSelector.PairTemporaryBasal(tb.first, tb.second))
|
|
||||||
// existing without nsId = create new
|
|
||||||
tb.first.isValid && tb.first.interfaceIDs.nightscoutId == null ->
|
|
||||||
nsClientPlugin.nsClientService?.dbAdd("treatments", tb.first.toJson(profile, dateUtil, useAbsolute), DataSyncSelector.PairTemporaryBasal(tb.first, tb.second))
|
nsClientPlugin.nsClientService?.dbAdd("treatments", tb.first.toJson(profile, dateUtil, useAbsolute), DataSyncSelector.PairTemporaryBasal(tb.first, tb.second))
|
||||||
// existing with nsId = update
|
// with nsId = update
|
||||||
tb.first.isValid && tb.first.interfaceIDs.nightscoutId != null ->
|
tb.first.interfaceIDs.nightscoutId != null ->
|
||||||
nsClientPlugin.nsClientService?.dbUpdate("treatments", tb.first.interfaceIDs.nightscoutId, tb.first.toJson(profile, dateUtil, useAbsolute), DataSyncSelector.PairTemporaryBasal(tb.first, tb.second))
|
nsClientPlugin.nsClientService?.dbUpdate("treatments", tb.first.interfaceIDs.nightscoutId, tb.first.toJson(profile, dateUtil, useAbsolute), DataSyncSelector.PairTemporaryBasal(tb.first, tb.second))
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
@ -406,23 +411,23 @@ class DataSyncSelectorImplementation @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var lastEbId = -1L
|
||||||
|
private var lastEbTime = -1L
|
||||||
override fun processChangedExtendedBolusesCompat(): Boolean {
|
override fun processChangedExtendedBolusesCompat(): Boolean {
|
||||||
val startId = sp.getLong(R.string.key_ns_extended_bolus_last_synced_id, 0)
|
|
||||||
val useAbsolute = sp.getBoolean(R.string.key_ns_sync_use_absolute, false)
|
val useAbsolute = sp.getBoolean(R.string.key_ns_sync_use_absolute, false)
|
||||||
|
val startId = sp.getLong(R.string.key_ns_extended_bolus_last_synced_id, 0)
|
||||||
|
if (startId == lastEbId && dateUtil.now() - lastEbTime < 5000) return false
|
||||||
|
lastEbId = startId
|
||||||
|
lastEbTime = dateUtil.now()
|
||||||
appRepository.getNextSyncElementExtendedBolus(startId).blockingGet()?.let { eb ->
|
appRepository.getNextSyncElementExtendedBolus(startId).blockingGet()?.let { eb ->
|
||||||
aapsLogger.info(LTag.DATABASE, "Loading ExtendedBolus data Start: $startId ID: ${eb.first.id} HistoryID: ${eb.second} ")
|
aapsLogger.info(LTag.DATABASE, "Loading ExtendedBolus data Start: $startId ID: ${eb.first.id} HistoryID: ${eb.second} ")
|
||||||
profileFunction.getProfile(eb.first.timestamp)?.let { profile ->
|
profileFunction.getProfile(eb.first.timestamp)?.let { profile ->
|
||||||
when {
|
when {
|
||||||
// removed and not uploaded yet = ignore
|
// without nsId = create new
|
||||||
!eb.first.isValid && eb.first.interfaceIDs.nightscoutId == null -> Any()
|
eb.first.interfaceIDs.nightscoutId == null ->
|
||||||
// removed and already uploaded = send for removal
|
|
||||||
!eb.first.isValid && eb.first.interfaceIDs.nightscoutId != null ->
|
|
||||||
nsClientPlugin.nsClientService?.dbRemove("treatments", eb.first.interfaceIDs.nightscoutId, DataSyncSelector.PairExtendedBolus(eb.first, eb.second))
|
|
||||||
// existing without nsId = create new
|
|
||||||
eb.first.isValid && eb.first.interfaceIDs.nightscoutId == null ->
|
|
||||||
nsClientPlugin.nsClientService?.dbAdd("treatments", eb.first.toJson(profile, dateUtil, useAbsolute), DataSyncSelector.PairExtendedBolus(eb.first, eb.second))
|
nsClientPlugin.nsClientService?.dbAdd("treatments", eb.first.toJson(profile, dateUtil, useAbsolute), DataSyncSelector.PairExtendedBolus(eb.first, eb.second))
|
||||||
// existing with nsId = update
|
// with nsId = update
|
||||||
eb.first.isValid && eb.first.interfaceIDs.nightscoutId != null ->
|
eb.first.interfaceIDs.nightscoutId != null ->
|
||||||
nsClientPlugin.nsClientService?.dbUpdate("treatments", eb.first.interfaceIDs.nightscoutId, eb.first.toJson(profile, dateUtil, useAbsolute), DataSyncSelector.PairExtendedBolus(eb.first, eb.second))
|
nsClientPlugin.nsClientService?.dbUpdate("treatments", eb.first.interfaceIDs.nightscoutId, eb.first.toJson(profile, dateUtil, useAbsolute), DataSyncSelector.PairExtendedBolus(eb.first, eb.second))
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
@ -445,22 +450,22 @@ class DataSyncSelectorImplementation @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var lastPsId = -1L
|
||||||
|
private var lastPsTime = -1L
|
||||||
override fun processChangedProfileSwitchesCompat(): Boolean {
|
override fun processChangedProfileSwitchesCompat(): Boolean {
|
||||||
val startId = sp.getLong(R.string.key_ns_profile_switch_last_synced_id, 0)
|
val startId = sp.getLong(R.string.key_ns_profile_switch_last_synced_id, 0)
|
||||||
appRepository.getNextSyncElementProfileSwitch(startId).blockingGet()?.let { eb ->
|
if (startId == lastPsId && dateUtil.now() - lastPsTime < 5000) return false
|
||||||
aapsLogger.info(LTag.DATABASE, "Loading ProfileSwitch data Start: $startId ID: ${eb.first.id} HistoryID: ${eb.second} ")
|
lastPsId = startId
|
||||||
|
lastPsTime = dateUtil.now()
|
||||||
|
appRepository.getNextSyncElementProfileSwitch(startId).blockingGet()?.let { ps ->
|
||||||
|
aapsLogger.info(LTag.DATABASE, "Loading ProfileSwitch data Start: $startId ID: ${ps.first.id} HistoryID: ${ps.second} ")
|
||||||
when {
|
when {
|
||||||
// removed and not uploaded yet = ignore
|
// without nsId = create new
|
||||||
!eb.first.isValid && eb.first.interfaceIDs.nightscoutId == null -> Any()
|
ps.first.interfaceIDs.nightscoutId == null ->
|
||||||
// removed and already uploaded = send for removal
|
nsClientPlugin.nsClientService?.dbAdd("treatments", ps.first.toJson(dateUtil), DataSyncSelector.PairProfileSwitch(ps.first, ps.second))
|
||||||
!eb.first.isValid && eb.first.interfaceIDs.nightscoutId != null ->
|
// with nsId = update
|
||||||
nsClientPlugin.nsClientService?.dbRemove("treatments", eb.first.interfaceIDs.nightscoutId, DataSyncSelector.PairProfileSwitch(eb.first, eb.second))
|
ps.first.interfaceIDs.nightscoutId != null ->
|
||||||
// existing without nsId = create new
|
nsClientPlugin.nsClientService?.dbUpdate("treatments", ps.first.interfaceIDs.nightscoutId, ps.first.toJson(dateUtil), DataSyncSelector.PairProfileSwitch(ps.first, ps.second))
|
||||||
eb.first.isValid && eb.first.interfaceIDs.nightscoutId == null ->
|
|
||||||
nsClientPlugin.nsClientService?.dbAdd("treatments", eb.first.toJson(dateUtil), DataSyncSelector.PairProfileSwitch(eb.first, eb.second))
|
|
||||||
// existing with nsId = update
|
|
||||||
eb.first.isValid && eb.first.interfaceIDs.nightscoutId != null ->
|
|
||||||
nsClientPlugin.nsClientService?.dbUpdate("treatments", eb.first.interfaceIDs.nightscoutId, eb.first.toJson(dateUtil), DataSyncSelector.PairProfileSwitch(eb.first, eb.second))
|
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,7 @@ class NSClientUpdateRemoveAckWorker(
|
||||||
is PairTemporaryTarget -> {
|
is PairTemporaryTarget -> {
|
||||||
val pair = ack.originalObject
|
val pair = ack.originalObject
|
||||||
dataSyncSelector.confirmLastTempTargetsIdIfGreater(pair.updateRecordId)
|
dataSyncSelector.confirmLastTempTargetsIdIfGreater(pair.updateRecordId)
|
||||||
rxBus.send(EventNSClientNewLog("DBUPDATE/DBREMOVE", "Acked TemporaryTarget" + ack._id))
|
rxBus.send(EventNSClientNewLog("DBUPDATE", "Acked TemporaryTarget" + ack._id))
|
||||||
// Send new if waiting
|
// Send new if waiting
|
||||||
dataSyncSelector.processChangedTempTargetsCompat()
|
dataSyncSelector.processChangedTempTargetsCompat()
|
||||||
ret = Result.success(workDataOf("ProcessedData" to pair.toString()))
|
ret = Result.success(workDataOf("ProcessedData" to pair.toString()))
|
||||||
|
@ -48,7 +48,7 @@ class NSClientUpdateRemoveAckWorker(
|
||||||
is PairGlucoseValue -> {
|
is PairGlucoseValue -> {
|
||||||
val pair = ack.originalObject
|
val pair = ack.originalObject
|
||||||
dataSyncSelector.confirmLastGlucoseValueIdIfGreater(pair.updateRecordId)
|
dataSyncSelector.confirmLastGlucoseValueIdIfGreater(pair.updateRecordId)
|
||||||
rxBus.send(EventNSClientNewLog("DBUPDATE/DBREMOVE", "Acked GlucoseValue " + ack._id))
|
rxBus.send(EventNSClientNewLog("DBUPDATE", "Acked GlucoseValue " + ack._id))
|
||||||
// Send new if waiting
|
// Send new if waiting
|
||||||
dataSyncSelector.processChangedGlucoseValuesCompat()
|
dataSyncSelector.processChangedGlucoseValuesCompat()
|
||||||
ret = Result.success(workDataOf("ProcessedData" to pair.toString()))
|
ret = Result.success(workDataOf("ProcessedData" to pair.toString()))
|
||||||
|
@ -57,7 +57,7 @@ class NSClientUpdateRemoveAckWorker(
|
||||||
is PairFood -> {
|
is PairFood -> {
|
||||||
val pair = ack.originalObject
|
val pair = ack.originalObject
|
||||||
dataSyncSelector.confirmLastFoodIdIfGreater(pair.updateRecordId)
|
dataSyncSelector.confirmLastFoodIdIfGreater(pair.updateRecordId)
|
||||||
rxBus.send(EventNSClientNewLog("DBUPDATE/DBREMOVE", "Acked Food " + ack._id))
|
rxBus.send(EventNSClientNewLog("DBUPDATE", "Acked Food " + ack._id))
|
||||||
// Send new if waiting
|
// Send new if waiting
|
||||||
dataSyncSelector.processChangedFoodsCompat()
|
dataSyncSelector.processChangedFoodsCompat()
|
||||||
ret = Result.success(workDataOf("ProcessedData" to pair.toString()))
|
ret = Result.success(workDataOf("ProcessedData" to pair.toString()))
|
||||||
|
@ -66,7 +66,7 @@ class NSClientUpdateRemoveAckWorker(
|
||||||
is PairTherapyEvent -> {
|
is PairTherapyEvent -> {
|
||||||
val pair = ack.originalObject
|
val pair = ack.originalObject
|
||||||
dataSyncSelector.confirmLastTherapyEventIdIfGreater(pair.updateRecordId)
|
dataSyncSelector.confirmLastTherapyEventIdIfGreater(pair.updateRecordId)
|
||||||
rxBus.send(EventNSClientNewLog("DBUPDATE/DBREMOVE", "Acked TherapyEvent " + ack._id))
|
rxBus.send(EventNSClientNewLog("DBUPDATE", "Acked TherapyEvent " + ack._id))
|
||||||
// Send new if waiting
|
// Send new if waiting
|
||||||
dataSyncSelector.processChangedTherapyEventsCompat()
|
dataSyncSelector.processChangedTherapyEventsCompat()
|
||||||
ret = Result.success(workDataOf("ProcessedData" to pair.toString()))
|
ret = Result.success(workDataOf("ProcessedData" to pair.toString()))
|
||||||
|
@ -75,7 +75,7 @@ class NSClientUpdateRemoveAckWorker(
|
||||||
is PairBolus -> {
|
is PairBolus -> {
|
||||||
val pair = ack.originalObject
|
val pair = ack.originalObject
|
||||||
dataSyncSelector.confirmLastBolusIdIfGreater(pair.updateRecordId)
|
dataSyncSelector.confirmLastBolusIdIfGreater(pair.updateRecordId)
|
||||||
rxBus.send(EventNSClientNewLog("DBUPDATE/DBREMOVE", "Acked Bolus " + ack._id))
|
rxBus.send(EventNSClientNewLog("DBUPDATE", "Acked Bolus " + ack._id))
|
||||||
// Send new if waiting
|
// Send new if waiting
|
||||||
dataSyncSelector.processChangedBolusesCompat()
|
dataSyncSelector.processChangedBolusesCompat()
|
||||||
ret = Result.success(workDataOf("ProcessedData" to pair.toString()))
|
ret = Result.success(workDataOf("ProcessedData" to pair.toString()))
|
||||||
|
@ -84,7 +84,7 @@ class NSClientUpdateRemoveAckWorker(
|
||||||
is PairCarbs -> {
|
is PairCarbs -> {
|
||||||
val pair = ack.originalObject
|
val pair = ack.originalObject
|
||||||
dataSyncSelector.confirmLastCarbsIdIfGreater(pair.updateRecordId)
|
dataSyncSelector.confirmLastCarbsIdIfGreater(pair.updateRecordId)
|
||||||
rxBus.send(EventNSClientNewLog("DBUPDATE/DBREMOVE", "Acked Carbs " + ack._id))
|
rxBus.send(EventNSClientNewLog("DBUPDATE", "Acked Carbs " + ack._id))
|
||||||
// Send new if waiting
|
// Send new if waiting
|
||||||
dataSyncSelector.processChangedCarbsCompat()
|
dataSyncSelector.processChangedCarbsCompat()
|
||||||
ret = Result.success(workDataOf("ProcessedData" to pair.toString()))
|
ret = Result.success(workDataOf("ProcessedData" to pair.toString()))
|
||||||
|
@ -93,7 +93,7 @@ class NSClientUpdateRemoveAckWorker(
|
||||||
is PairBolusCalculatorResult -> {
|
is PairBolusCalculatorResult -> {
|
||||||
val pair = ack.originalObject
|
val pair = ack.originalObject
|
||||||
dataSyncSelector.confirmLastBolusCalculatorResultsIdIfGreater(pair.updateRecordId)
|
dataSyncSelector.confirmLastBolusCalculatorResultsIdIfGreater(pair.updateRecordId)
|
||||||
rxBus.send(EventNSClientNewLog("DBUPDATE/DBREMOVE", "Acked BolusCalculatorResult " + ack._id))
|
rxBus.send(EventNSClientNewLog("DBUPDATE", "Acked BolusCalculatorResult " + ack._id))
|
||||||
// Send new if waiting
|
// Send new if waiting
|
||||||
dataSyncSelector.processChangedBolusCalculatorResultsCompat()
|
dataSyncSelector.processChangedBolusCalculatorResultsCompat()
|
||||||
ret = Result.success(workDataOf("ProcessedData" to pair.toString()))
|
ret = Result.success(workDataOf("ProcessedData" to pair.toString()))
|
||||||
|
@ -102,7 +102,7 @@ class NSClientUpdateRemoveAckWorker(
|
||||||
is PairTemporaryBasal -> {
|
is PairTemporaryBasal -> {
|
||||||
val pair = ack.originalObject
|
val pair = ack.originalObject
|
||||||
dataSyncSelector.confirmLastTemporaryBasalIdIfGreater(pair.updateRecordId)
|
dataSyncSelector.confirmLastTemporaryBasalIdIfGreater(pair.updateRecordId)
|
||||||
rxBus.send(EventNSClientNewLog("DBUPDATE/DBREMOVE", "Acked TemporaryBasal " + ack._id))
|
rxBus.send(EventNSClientNewLog("DBUPDATE", "Acked TemporaryBasal " + ack._id))
|
||||||
// Send new if waiting
|
// Send new if waiting
|
||||||
dataSyncSelector.processChangedTemporaryBasalsCompat()
|
dataSyncSelector.processChangedTemporaryBasalsCompat()
|
||||||
ret = Result.success(workDataOf("ProcessedData" to pair.toString()))
|
ret = Result.success(workDataOf("ProcessedData" to pair.toString()))
|
||||||
|
@ -111,7 +111,7 @@ class NSClientUpdateRemoveAckWorker(
|
||||||
is PairExtendedBolus -> {
|
is PairExtendedBolus -> {
|
||||||
val pair = ack.originalObject
|
val pair = ack.originalObject
|
||||||
dataSyncSelector.confirmLastExtendedBolusIdIfGreater(pair.updateRecordId)
|
dataSyncSelector.confirmLastExtendedBolusIdIfGreater(pair.updateRecordId)
|
||||||
rxBus.send(EventNSClientNewLog("DBUPDATE/DBREMOVE", "Acked ExtendedBolus " + ack._id))
|
rxBus.send(EventNSClientNewLog("DBUPDATE", "Acked ExtendedBolus " + ack._id))
|
||||||
// Send new if waiting
|
// Send new if waiting
|
||||||
dataSyncSelector.processChangedExtendedBolusesCompat()
|
dataSyncSelector.processChangedExtendedBolusesCompat()
|
||||||
ret = Result.success(workDataOf("ProcessedData" to pair.toString()))
|
ret = Result.success(workDataOf("ProcessedData" to pair.toString()))
|
||||||
|
@ -120,7 +120,7 @@ class NSClientUpdateRemoveAckWorker(
|
||||||
is PairProfileSwitch -> {
|
is PairProfileSwitch -> {
|
||||||
val pair = ack.originalObject
|
val pair = ack.originalObject
|
||||||
dataSyncSelector.confirmLastProfileSwitchIdIfGreater(pair.updateRecordId)
|
dataSyncSelector.confirmLastProfileSwitchIdIfGreater(pair.updateRecordId)
|
||||||
rxBus.send(EventNSClientNewLog("DBUPDATE/DBREMOVE", "Acked ProfileSwitch " + ack._id))
|
rxBus.send(EventNSClientNewLog("DBUPDATE", "Acked ProfileSwitch " + ack._id))
|
||||||
// Send new if waiting
|
// Send new if waiting
|
||||||
dataSyncSelector.processChangedProfileSwitchesCompat()
|
dataSyncSelector.processChangedProfileSwitchesCompat()
|
||||||
ret = Result.success(workDataOf("ProcessedData" to pair.toString()))
|
ret = Result.success(workDataOf("ProcessedData" to pair.toString()))
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package info.nightscout.androidaps.plugins.general.nsclient.services
|
package info.nightscout.androidaps.plugins.general.nsclient.services
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.*
|
import android.os.*
|
||||||
import androidx.work.OneTimeWorkRequest
|
import androidx.work.OneTimeWorkRequest
|
||||||
|
@ -83,6 +85,7 @@ class NSClientService : DaggerService() {
|
||||||
@Inject lateinit var repository: AppRepository
|
@Inject lateinit var repository: AppRepository
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
private const val WATCHDOG_INTERVAL_MINUTES = 2
|
private const val WATCHDOG_INTERVAL_MINUTES = 2
|
||||||
private const val WATCHDOG_RECONNECT_IN = 15
|
private const val WATCHDOG_RECONNECT_IN = 15
|
||||||
private const val WATCHDOG_MAX_CONNECTIONS = 5
|
private const val WATCHDOG_MAX_CONNECTIONS = 5
|
||||||
|
@ -90,7 +93,7 @@ class NSClientService : DaggerService() {
|
||||||
|
|
||||||
private val disposable = CompositeDisposable()
|
private val disposable = CompositeDisposable()
|
||||||
|
|
||||||
// public PowerManager.WakeLock mWakeLock;
|
private var wakeLock: PowerManager.WakeLock? = null
|
||||||
private val binder: IBinder = LocalBinder()
|
private val binder: IBinder = LocalBinder()
|
||||||
private var handler: Handler? = null
|
private var handler: Handler? = null
|
||||||
private var socket: Socket? = null
|
private var socket: Socket? = null
|
||||||
|
@ -108,11 +111,12 @@ class NSClientService : DaggerService() {
|
||||||
var hasWriteAuth = false
|
var hasWriteAuth = false
|
||||||
var nsURL = ""
|
var nsURL = ""
|
||||||
var latestDateInReceivedData: Long = 0
|
var latestDateInReceivedData: Long = 0
|
||||||
|
|
||||||
|
@SuppressLint("WakelockTimeout")
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
// PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
|
wakeLock = (getSystemService(Context.POWER_SERVICE) as PowerManager).newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "AndroidAPS:NSClientService")
|
||||||
// mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "AndroidAPS:NSClientService");
|
wakeLock?.acquire()
|
||||||
// mWakeLock.acquire();
|
|
||||||
initialize()
|
initialize()
|
||||||
disposable.add(rxBus
|
disposable.add(rxBus
|
||||||
.toObservable(EventConfigBuilderChange::class.java)
|
.toObservable(EventConfigBuilderChange::class.java)
|
||||||
|
@ -175,7 +179,7 @@ class NSClientService : DaggerService() {
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
disposable.clear()
|
disposable.clear()
|
||||||
// if (mWakeLock.isHeld()) mWakeLock.release();
|
if (wakeLock?.isHeld == true) wakeLock?.release()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun processAddAck(ack: NSAddAck) {
|
private fun processAddAck(ack: NSAddAck) {
|
||||||
|
@ -449,10 +453,10 @@ class NSClientService : DaggerService() {
|
||||||
}
|
}
|
||||||
private val onDataUpdate = Emitter.Listener { args ->
|
private val onDataUpdate = Emitter.Listener { args ->
|
||||||
handler?.post {
|
handler?.post {
|
||||||
val powerManager = getSystemService(POWER_SERVICE) as PowerManager
|
// val powerManager = getSystemService(POWER_SERVICE) as PowerManager
|
||||||
val wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
|
// val wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
|
||||||
"AndroidAPS:NSClientService_onDataUpdate")
|
// "AndroidAPS:NSClientService_onDataUpdate")
|
||||||
wakeLock.acquire(3000)
|
// wakeLock.acquire(3000)
|
||||||
try {
|
try {
|
||||||
val data = args[0] as JSONObject
|
val data = args[0] as JSONObject
|
||||||
try {
|
try {
|
||||||
|
@ -585,7 +589,7 @@ class NSClientService : DaggerService() {
|
||||||
}
|
}
|
||||||
//rxBus.send(new EventNSClientNewLog("NSCLIENT", "onDataUpdate end");
|
//rxBus.send(new EventNSClientNewLog("NSCLIENT", "onDataUpdate end");
|
||||||
} finally {
|
} finally {
|
||||||
if (wakeLock.isHeld) wakeLock.release()
|
// if (wakeLock.isHeld) wakeLock.release()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -605,20 +609,6 @@ class NSClientService : DaggerService() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun dbRemove(collection: String, _id: String?, originalObject: Any) {
|
|
||||||
try {
|
|
||||||
if (_id == null) return
|
|
||||||
if (!isConnected || !hasWriteAuth) return
|
|
||||||
val message = JSONObject()
|
|
||||||
message.put("collection", collection)
|
|
||||||
message.put("_id", _id)
|
|
||||||
socket?.emit("dbRemove", message, NSUpdateAck("dbRemove", _id, aapsLogger, rxBus, originalObject))
|
|
||||||
rxBus.send(EventNSClientNewLog("DBREMOVE $collection", "Sent " + originalObject.javaClass.simpleName + " " + _id))
|
|
||||||
} catch (e: JSONException) {
|
|
||||||
aapsLogger.error("Unhandled exception", e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun dbAdd(collection: String, data: JSONObject, originalObject: Any) {
|
fun dbAdd(collection: String, data: JSONObject, originalObject: Any) {
|
||||||
try {
|
try {
|
||||||
if (!isConnected || !hasWriteAuth) return
|
if (!isConnected || !hasWriteAuth) return
|
||||||
|
@ -646,16 +636,16 @@ class NSClientService : DaggerService() {
|
||||||
aapsLogger.debug(LTag.NSCLIENT, "Skipping resend by lastAckTime: " + (System.currentTimeMillis() - lastAckTime) / 1000L + " sec")
|
aapsLogger.debug(LTag.NSCLIENT, "Skipping resend by lastAckTime: " + (System.currentTimeMillis() - lastAckTime) / 1000L + " sec")
|
||||||
return@post
|
return@post
|
||||||
}
|
}
|
||||||
val powerManager = getSystemService(POWER_SERVICE) as PowerManager
|
// val powerManager = getSystemService(POWER_SERVICE) as PowerManager
|
||||||
val wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
|
// val wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
|
||||||
"AndroidAPS:NSClientService_onDataUpdate")
|
// "AndroidAPS:NSClientService_onDataUpdate")
|
||||||
wakeLock.acquire(mins(10).msecs())
|
// wakeLock.acquire(mins(10).msecs())
|
||||||
try {
|
try {
|
||||||
rxBus.send(EventNSClientNewLog("QUEUE", "Resend started: $reason"))
|
rxBus.send(EventNSClientNewLog("QUEUE", "Resend started: $reason"))
|
||||||
dataSyncSelector.doUpload()
|
dataSyncSelector.doUpload()
|
||||||
rxBus.send(EventNSClientNewLog("QUEUE", "Resend ended: $reason"))
|
rxBus.send(EventNSClientNewLog("QUEUE", "Resend ended: $reason"))
|
||||||
} finally {
|
} finally {
|
||||||
if (wakeLock.isHeld) wakeLock.release()
|
// if (wakeLock.isHeld) wakeLock.release()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,8 +25,8 @@ fun ProfileSwitch.toJson(dateUtil: DateUtil): JSONObject =
|
||||||
.put("duration", T.msecs(duration).mins())
|
.put("duration", T.msecs(duration).mins())
|
||||||
.put("profile", getCustomizedName())
|
.put("profile", getCustomizedName())
|
||||||
.put("profileJson", ProfileSealed.PS(this).toPureNsJson(dateUtil).toString())
|
.put("profileJson", ProfileSealed.PS(this).toPureNsJson(dateUtil).toString())
|
||||||
.put("timeshift", T.msecs(timeshift).hours())
|
.put("timeshift", 0)
|
||||||
.put("percentage", percentage)
|
.put("percentage", 100) // customization already applied to json
|
||||||
.also {
|
.also {
|
||||||
if (interfaceIDs.pumpId != null) it.put("pumpId", interfaceIDs.pumpId)
|
if (interfaceIDs.pumpId != null) it.put("pumpId", interfaceIDs.pumpId)
|
||||||
if (interfaceIDs.pumpType != null) it.put("pumpType", interfaceIDs.pumpType!!.name)
|
if (interfaceIDs.pumpType != null) it.put("pumpType", interfaceIDs.pumpType!!.name)
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -6,7 +6,7 @@ import androidx.room.TypeConverters
|
||||||
import info.nightscout.androidaps.database.daos.*
|
import info.nightscout.androidaps.database.daos.*
|
||||||
import info.nightscout.androidaps.database.entities.*
|
import info.nightscout.androidaps.database.entities.*
|
||||||
|
|
||||||
const val DATABASE_VERSION = 18
|
const val DATABASE_VERSION = 20
|
||||||
|
|
||||||
@Database(version = DATABASE_VERSION,
|
@Database(version = DATABASE_VERSION,
|
||||||
entities = [APSResult::class, Bolus::class, BolusCalculatorResult::class, Carbs::class,
|
entities = [APSResult::class, Bolus::class, BolusCalculatorResult::class, Carbs::class,
|
||||||
|
|
|
@ -18,7 +18,16 @@ import java.util.*
|
||||||
entity = Bolus::class,
|
entity = Bolus::class,
|
||||||
parentColumns = ["id"],
|
parentColumns = ["id"],
|
||||||
childColumns = ["referenceId"])],
|
childColumns = ["referenceId"])],
|
||||||
indices = [Index("referenceId"), Index("timestamp")])
|
indices = [
|
||||||
|
Index("id"),
|
||||||
|
Index("isValid"),
|
||||||
|
Index("temporaryId"),
|
||||||
|
Index("pumpId"),
|
||||||
|
Index("pumpSerial"),
|
||||||
|
Index("pumpType"),
|
||||||
|
Index("referenceId"),
|
||||||
|
Index("timestamp")
|
||||||
|
])
|
||||||
data class Bolus(
|
data class Bolus(
|
||||||
@PrimaryKey(autoGenerate = true)
|
@PrimaryKey(autoGenerate = true)
|
||||||
override var id: Long = 0,
|
override var id: Long = 0,
|
||||||
|
|
|
@ -12,7 +12,12 @@ import java.util.TimeZone
|
||||||
entity = BolusCalculatorResult::class,
|
entity = BolusCalculatorResult::class,
|
||||||
parentColumns = ["id"],
|
parentColumns = ["id"],
|
||||||
childColumns = ["referenceId"])],
|
childColumns = ["referenceId"])],
|
||||||
indices = [Index("referenceId"), Index("timestamp")])
|
indices = [
|
||||||
|
Index("referenceId"),
|
||||||
|
Index("timestamp"),
|
||||||
|
Index("id"),
|
||||||
|
Index("isValid")
|
||||||
|
])
|
||||||
data class BolusCalculatorResult(
|
data class BolusCalculatorResult(
|
||||||
@PrimaryKey(autoGenerate = true)
|
@PrimaryKey(autoGenerate = true)
|
||||||
override var id: Long = 0,
|
override var id: Long = 0,
|
||||||
|
|
|
@ -16,7 +16,13 @@ import java.util.*
|
||||||
entity = Carbs::class,
|
entity = Carbs::class,
|
||||||
parentColumns = ["id"],
|
parentColumns = ["id"],
|
||||||
childColumns = ["referenceId"])],
|
childColumns = ["referenceId"])],
|
||||||
indices = [Index("referenceId"), Index("timestamp")])
|
indices = [
|
||||||
|
Index("id"),
|
||||||
|
Index("isValid"),
|
||||||
|
Index("nightscoutId"),
|
||||||
|
Index("referenceId"),
|
||||||
|
Index("timestamp")
|
||||||
|
])
|
||||||
data class Carbs(
|
data class Carbs(
|
||||||
@PrimaryKey(autoGenerate = true)
|
@PrimaryKey(autoGenerate = true)
|
||||||
override var id: Long = 0,
|
override var id: Long = 0,
|
||||||
|
|
|
@ -11,7 +11,11 @@ import java.util.*
|
||||||
|
|
||||||
@Entity(tableName = TABLE_DEVICE_STATUS,
|
@Entity(tableName = TABLE_DEVICE_STATUS,
|
||||||
foreignKeys = [],
|
foreignKeys = [],
|
||||||
indices = [Index("timestamp")])
|
indices = [
|
||||||
|
Index("id"),
|
||||||
|
Index("nightscoutId"),
|
||||||
|
Index("timestamp")
|
||||||
|
])
|
||||||
data class DeviceStatus(
|
data class DeviceStatus(
|
||||||
@PrimaryKey(autoGenerate = true)
|
@PrimaryKey(autoGenerate = true)
|
||||||
var id: Long = 0,
|
var id: Long = 0,
|
||||||
|
|
|
@ -19,7 +19,12 @@ import java.util.*
|
||||||
entity = EffectiveProfileSwitch::class,
|
entity = EffectiveProfileSwitch::class,
|
||||||
parentColumns = ["id"],
|
parentColumns = ["id"],
|
||||||
childColumns = ["referenceId"])],
|
childColumns = ["referenceId"])],
|
||||||
indices = [Index("referenceId"), Index("timestamp")])
|
indices = [
|
||||||
|
Index("id"),
|
||||||
|
Index("referenceId"),
|
||||||
|
Index("timestamp"),
|
||||||
|
Index("isValid")
|
||||||
|
])
|
||||||
data class EffectiveProfileSwitch(
|
data class EffectiveProfileSwitch(
|
||||||
@PrimaryKey(autoGenerate = true)
|
@PrimaryKey(autoGenerate = true)
|
||||||
override var id: Long = 0,
|
override var id: Long = 0,
|
||||||
|
@ -45,7 +50,7 @@ data class EffectiveProfileSwitch(
|
||||||
var originalEnd: Long,
|
var originalEnd: Long,
|
||||||
@Embedded
|
@Embedded
|
||||||
var insulinConfiguration: InsulinConfiguration
|
var insulinConfiguration: InsulinConfiguration
|
||||||
) : TraceableDBEntry, DBEntryWithTime{
|
) : TraceableDBEntry, DBEntryWithTime {
|
||||||
|
|
||||||
enum class GlucoseUnit {
|
enum class GlucoseUnit {
|
||||||
MGDL,
|
MGDL,
|
||||||
|
|
|
@ -16,7 +16,16 @@ import java.util.*
|
||||||
entity = ExtendedBolus::class,
|
entity = ExtendedBolus::class,
|
||||||
parentColumns = ["id"],
|
parentColumns = ["id"],
|
||||||
childColumns = ["referenceId"])],
|
childColumns = ["referenceId"])],
|
||||||
indices = [Index("referenceId"), Index("timestamp")])
|
indices = [
|
||||||
|
Index("id"),
|
||||||
|
Index("isValid"),
|
||||||
|
Index("endId"),
|
||||||
|
Index("pumpSerial"),
|
||||||
|
Index("pumpId"),
|
||||||
|
Index("pumpType"),
|
||||||
|
Index("referenceId"),
|
||||||
|
Index("timestamp")
|
||||||
|
])
|
||||||
data class ExtendedBolus(
|
data class ExtendedBolus(
|
||||||
@PrimaryKey(autoGenerate = true)
|
@PrimaryKey(autoGenerate = true)
|
||||||
override var id: Long = 0,
|
override var id: Long = 0,
|
||||||
|
|
|
@ -14,7 +14,12 @@ import info.nightscout.androidaps.database.interfaces.TraceableDBEntry
|
||||||
entity = Food::class,
|
entity = Food::class,
|
||||||
parentColumns = ["id"],
|
parentColumns = ["id"],
|
||||||
childColumns = ["referenceId"])],
|
childColumns = ["referenceId"])],
|
||||||
indices = [Index("referenceId")])
|
indices = [
|
||||||
|
Index("id"),
|
||||||
|
Index("nightscoutId"),
|
||||||
|
Index("referenceId"),
|
||||||
|
Index("isValid")
|
||||||
|
])
|
||||||
data class Food(
|
data class Food(
|
||||||
@PrimaryKey(autoGenerate = true)
|
@PrimaryKey(autoGenerate = true)
|
||||||
override var id: Long = 0,
|
override var id: Long = 0,
|
||||||
|
|
|
@ -13,7 +13,13 @@ import java.util.TimeZone
|
||||||
entity = GlucoseValue::class,
|
entity = GlucoseValue::class,
|
||||||
parentColumns = ["id"],
|
parentColumns = ["id"],
|
||||||
childColumns = ["referenceId"])],
|
childColumns = ["referenceId"])],
|
||||||
indices = [Index("referenceId"), Index("timestamp")])
|
indices = [
|
||||||
|
Index("id"),
|
||||||
|
Index("nightscoutId"),
|
||||||
|
Index("sourceSensor"),
|
||||||
|
Index("referenceId"),
|
||||||
|
Index("timestamp")
|
||||||
|
])
|
||||||
data class GlucoseValue(
|
data class GlucoseValue(
|
||||||
@PrimaryKey(autoGenerate = true)
|
@PrimaryKey(autoGenerate = true)
|
||||||
override var id: Long = 0,
|
override var id: Long = 0,
|
||||||
|
|
|
@ -19,7 +19,13 @@ import java.util.*
|
||||||
entity = ProfileSwitch::class,
|
entity = ProfileSwitch::class,
|
||||||
parentColumns = ["id"],
|
parentColumns = ["id"],
|
||||||
childColumns = ["referenceId"])],
|
childColumns = ["referenceId"])],
|
||||||
indices = [Index("referenceId"), Index("timestamp")])
|
indices = [
|
||||||
|
Index("referenceId"),
|
||||||
|
Index("timestamp"),
|
||||||
|
Index("isValid"),
|
||||||
|
Index("id"),
|
||||||
|
Index("nightscoutId")
|
||||||
|
])
|
||||||
data class ProfileSwitch(
|
data class ProfileSwitch(
|
||||||
@PrimaryKey(autoGenerate = true)
|
@PrimaryKey(autoGenerate = true)
|
||||||
override var id: Long = 0,
|
override var id: Long = 0,
|
||||||
|
@ -47,6 +53,7 @@ data class ProfileSwitch(
|
||||||
enum class GlucoseUnit {
|
enum class GlucoseUnit {
|
||||||
MGDL,
|
MGDL,
|
||||||
MMOL;
|
MMOL;
|
||||||
companion object {}
|
|
||||||
|
companion object
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -16,7 +16,17 @@ import java.util.*
|
||||||
entity = TemporaryBasal::class,
|
entity = TemporaryBasal::class,
|
||||||
parentColumns = ["id"],
|
parentColumns = ["id"],
|
||||||
childColumns = ["referenceId"])],
|
childColumns = ["referenceId"])],
|
||||||
indices = [Index("referenceId"), Index("timestamp")])
|
indices = [
|
||||||
|
Index("id"),
|
||||||
|
Index("isValid"),
|
||||||
|
Index("nightscoutId"),
|
||||||
|
Index("pumpType"),
|
||||||
|
Index("endId"),
|
||||||
|
Index("pumpSerial"),
|
||||||
|
Index("temporaryId"),
|
||||||
|
Index("referenceId"),
|
||||||
|
Index("timestamp")
|
||||||
|
])
|
||||||
data class TemporaryBasal(
|
data class TemporaryBasal(
|
||||||
@PrimaryKey(autoGenerate = true)
|
@PrimaryKey(autoGenerate = true)
|
||||||
override var id: Long = 0,
|
override var id: Long = 0,
|
||||||
|
|
|
@ -17,7 +17,13 @@ import java.util.*
|
||||||
entity = TemporaryTarget::class,
|
entity = TemporaryTarget::class,
|
||||||
parentColumns = ["id"],
|
parentColumns = ["id"],
|
||||||
childColumns = ["referenceId"])],
|
childColumns = ["referenceId"])],
|
||||||
indices = [Index("referenceId"), Index("timestamp")])
|
indices = [
|
||||||
|
Index("id"),
|
||||||
|
Index("isValid"),
|
||||||
|
Index("nightscoutId"),
|
||||||
|
Index("referenceId"),
|
||||||
|
Index("timestamp")
|
||||||
|
])
|
||||||
data class TemporaryTarget(
|
data class TemporaryTarget(
|
||||||
@PrimaryKey(autoGenerate = true)
|
@PrimaryKey(autoGenerate = true)
|
||||||
override var id: Long = 0,
|
override var id: Long = 0,
|
||||||
|
|
|
@ -17,7 +17,14 @@ import java.util.*
|
||||||
entity = TherapyEvent::class,
|
entity = TherapyEvent::class,
|
||||||
parentColumns = ["id"],
|
parentColumns = ["id"],
|
||||||
childColumns = ["referenceId"])],
|
childColumns = ["referenceId"])],
|
||||||
indices = [Index("referenceId"), Index("timestamp")])
|
indices = [
|
||||||
|
Index("id"),
|
||||||
|
Index("type"),
|
||||||
|
Index("nightscoutId"),
|
||||||
|
Index("isValid"),
|
||||||
|
Index("referenceId"),
|
||||||
|
Index("timestamp")
|
||||||
|
])
|
||||||
data class TherapyEvent(
|
data class TherapyEvent(
|
||||||
@PrimaryKey(autoGenerate = true)
|
@PrimaryKey(autoGenerate = true)
|
||||||
override var id: Long = 0,
|
override var id: Long = 0,
|
||||||
|
|
|
@ -16,7 +16,15 @@ import java.util.*
|
||||||
entity = TotalDailyDose::class,
|
entity = TotalDailyDose::class,
|
||||||
parentColumns = ["id"],
|
parentColumns = ["id"],
|
||||||
childColumns = ["referenceId"])],
|
childColumns = ["referenceId"])],
|
||||||
indices = [Index("referenceId"), Index("timestamp")])
|
indices = [
|
||||||
|
Index("id"),
|
||||||
|
Index("pumpId"),
|
||||||
|
Index("pumpType"),
|
||||||
|
Index("pumpSerial"),
|
||||||
|
Index("isValid"),
|
||||||
|
Index("referenceId"),
|
||||||
|
Index("timestamp")
|
||||||
|
])
|
||||||
data class TotalDailyDose(
|
data class TotalDailyDose(
|
||||||
@PrimaryKey(autoGenerate = true)
|
@PrimaryKey(autoGenerate = true)
|
||||||
override var id: Long = 0,
|
override var id: Long = 0,
|
||||||
|
|
|
@ -1,13 +1,18 @@
|
||||||
package info.nightscout.androidaps.database.entities
|
package info.nightscout.androidaps.database.entities
|
||||||
|
|
||||||
import androidx.room.Entity
|
import androidx.room.Entity
|
||||||
|
import androidx.room.Index
|
||||||
import androidx.room.PrimaryKey
|
import androidx.room.PrimaryKey
|
||||||
import info.nightscout.androidaps.database.TABLE_USER_ENTRY
|
import info.nightscout.androidaps.database.TABLE_USER_ENTRY
|
||||||
import info.nightscout.androidaps.database.interfaces.DBEntry
|
import info.nightscout.androidaps.database.interfaces.DBEntry
|
||||||
import info.nightscout.androidaps.database.interfaces.DBEntryWithTime
|
import info.nightscout.androidaps.database.interfaces.DBEntryWithTime
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
@Entity(tableName = TABLE_USER_ENTRY)
|
@Entity(tableName = TABLE_USER_ENTRY,
|
||||||
|
indices = [
|
||||||
|
Index("source"),
|
||||||
|
Index("timestamp")
|
||||||
|
])
|
||||||
data class UserEntry(
|
data class UserEntry(
|
||||||
@PrimaryKey(autoGenerate = true)
|
@PrimaryKey(autoGenerate = true)
|
||||||
override var id: Long = 0L,
|
override var id: Long = 0L,
|
||||||
|
|
|
@ -0,0 +1,187 @@
|
||||||
|
{
|
||||||
|
"formatVersion": 1,
|
||||||
|
"database": {
|
||||||
|
"version": 2,
|
||||||
|
"identityHash": "391daa1e25629bafef27e6247e788e74",
|
||||||
|
"entities": [
|
||||||
|
{
|
||||||
|
"tableName": "insightBolusIDs",
|
||||||
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `timestamp` INTEGER NOT NULL, `pumpSerial` TEXT, `bolusID` INTEGER, `startID` INTEGER, `endID` INTEGER)",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "id",
|
||||||
|
"columnName": "id",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "timestamp",
|
||||||
|
"columnName": "timestamp",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "pumpSerial",
|
||||||
|
"columnName": "pumpSerial",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "bolusID",
|
||||||
|
"columnName": "bolusID",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "startID",
|
||||||
|
"columnName": "startID",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "endID",
|
||||||
|
"columnName": "endID",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": false
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primaryKey": {
|
||||||
|
"columnNames": [
|
||||||
|
"id"
|
||||||
|
],
|
||||||
|
"autoGenerate": true
|
||||||
|
},
|
||||||
|
"indices": [
|
||||||
|
{
|
||||||
|
"name": "index_insightBolusIDs_bolusID",
|
||||||
|
"unique": false,
|
||||||
|
"columnNames": [
|
||||||
|
"bolusID"
|
||||||
|
],
|
||||||
|
"createSql": "CREATE INDEX IF NOT EXISTS `index_insightBolusIDs_bolusID` ON `${TABLE_NAME}` (`bolusID`)"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "index_insightBolusIDs_pumpSerial",
|
||||||
|
"unique": false,
|
||||||
|
"columnNames": [
|
||||||
|
"pumpSerial"
|
||||||
|
],
|
||||||
|
"createSql": "CREATE INDEX IF NOT EXISTS `index_insightBolusIDs_pumpSerial` ON `${TABLE_NAME}` (`pumpSerial`)"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "index_insightBolusIDs_timestamp",
|
||||||
|
"unique": false,
|
||||||
|
"columnNames": [
|
||||||
|
"timestamp"
|
||||||
|
],
|
||||||
|
"createSql": "CREATE INDEX IF NOT EXISTS `index_insightBolusIDs_timestamp` ON `${TABLE_NAME}` (`timestamp`)"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"foreignKeys": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"tableName": "insightHistoryOffsets",
|
||||||
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`pumpSerial` TEXT NOT NULL, `offset` INTEGER NOT NULL, PRIMARY KEY(`pumpSerial`))",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "pumpSerial",
|
||||||
|
"columnName": "pumpSerial",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "offset",
|
||||||
|
"columnName": "offset",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primaryKey": {
|
||||||
|
"columnNames": [
|
||||||
|
"pumpSerial"
|
||||||
|
],
|
||||||
|
"autoGenerate": false
|
||||||
|
},
|
||||||
|
"indices": [
|
||||||
|
{
|
||||||
|
"name": "index_insightHistoryOffsets_pumpSerial",
|
||||||
|
"unique": false,
|
||||||
|
"columnNames": [
|
||||||
|
"pumpSerial"
|
||||||
|
],
|
||||||
|
"createSql": "CREATE INDEX IF NOT EXISTS `index_insightHistoryOffsets_pumpSerial` ON `${TABLE_NAME}` (`pumpSerial`)"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"foreignKeys": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"tableName": "insightPumpIDs",
|
||||||
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`timestamp` INTEGER NOT NULL, `eventType` TEXT NOT NULL, `pumpSerial` TEXT, `eventID` INTEGER NOT NULL, PRIMARY KEY(`eventID`))",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "timestamp",
|
||||||
|
"columnName": "timestamp",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "eventType",
|
||||||
|
"columnName": "eventType",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "pumpSerial",
|
||||||
|
"columnName": "pumpSerial",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "eventID",
|
||||||
|
"columnName": "eventID",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primaryKey": {
|
||||||
|
"columnNames": [
|
||||||
|
"eventID"
|
||||||
|
],
|
||||||
|
"autoGenerate": false
|
||||||
|
},
|
||||||
|
"indices": [
|
||||||
|
{
|
||||||
|
"name": "index_insightPumpIDs_timestamp",
|
||||||
|
"unique": false,
|
||||||
|
"columnNames": [
|
||||||
|
"timestamp"
|
||||||
|
],
|
||||||
|
"createSql": "CREATE INDEX IF NOT EXISTS `index_insightPumpIDs_timestamp` ON `${TABLE_NAME}` (`timestamp`)"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "index_insightPumpIDs_pumpSerial",
|
||||||
|
"unique": false,
|
||||||
|
"columnNames": [
|
||||||
|
"pumpSerial"
|
||||||
|
],
|
||||||
|
"createSql": "CREATE INDEX IF NOT EXISTS `index_insightPumpIDs_pumpSerial` ON `${TABLE_NAME}` (`pumpSerial`)"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "index_insightPumpIDs_eventType",
|
||||||
|
"unique": false,
|
||||||
|
"columnNames": [
|
||||||
|
"eventType"
|
||||||
|
],
|
||||||
|
"createSql": "CREATE INDEX IF NOT EXISTS `index_insightPumpIDs_eventType` ON `${TABLE_NAME}` (`eventType`)"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"foreignKeys": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"views": [],
|
||||||
|
"setupQueries": [
|
||||||
|
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
|
||||||
|
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '391daa1e25629bafef27e6247e788e74')"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,7 +5,11 @@ import androidx.room.Index
|
||||||
import androidx.room.PrimaryKey
|
import androidx.room.PrimaryKey
|
||||||
|
|
||||||
@Entity(tableName = DATABASE_INSIGHT_BOLUS_IDS,
|
@Entity(tableName = DATABASE_INSIGHT_BOLUS_IDS,
|
||||||
indices = [Index("bolusID")])
|
indices = [
|
||||||
|
Index("bolusID"),
|
||||||
|
Index("pumpSerial"),
|
||||||
|
Index("timestamp")
|
||||||
|
])
|
||||||
data class InsightBolusID(
|
data class InsightBolusID(
|
||||||
var timestamp: Long,
|
var timestamp: Long,
|
||||||
val pumpSerial: String? = null,
|
val pumpSerial: String? = null,
|
||||||
|
|
|
@ -22,7 +22,7 @@ abstract class InsightDatabase : RoomDatabase() {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
const val VERSION = 1
|
const val VERSION = 2
|
||||||
|
|
||||||
fun build(context: Context) =
|
fun build(context: Context) =
|
||||||
Room.databaseBuilder(
|
Room.databaseBuilder(
|
||||||
|
|
|
@ -5,7 +5,11 @@ import androidx.room.Index
|
||||||
import androidx.room.PrimaryKey
|
import androidx.room.PrimaryKey
|
||||||
|
|
||||||
@Entity(tableName = DATABASE_INSIGHT_PUMP_IDS,
|
@Entity(tableName = DATABASE_INSIGHT_PUMP_IDS,
|
||||||
indices = [Index("timestamp")])
|
indices = [
|
||||||
|
Index("timestamp"),
|
||||||
|
Index("pumpSerial"),
|
||||||
|
Index("eventType")
|
||||||
|
])
|
||||||
data class InsightPumpID(
|
data class InsightPumpID(
|
||||||
var timestamp: Long,
|
var timestamp: Long,
|
||||||
var eventType: EventType = EventType.None,
|
var eventType: EventType = EventType.None,
|
||||||
|
|
Loading…
Reference in a new issue