sync BolusCalculatorResult in full mode
This commit is contained in:
parent
67b4eaee70
commit
7ba4c19298
1 changed files with 92 additions and 66 deletions
|
@ -85,14 +85,16 @@ class NSClientAddUpdateWorker(
|
||||||
.blockingGet()
|
.blockingGet()
|
||||||
.also { result ->
|
.also { result ->
|
||||||
result.inserted.forEach {
|
result.inserted.forEach {
|
||||||
uel.log(Action.BOLUS, Sources.NSClient,
|
uel.log(
|
||||||
|
Action.BOLUS, Sources.NSClient,
|
||||||
ValueWithUnit.Timestamp(it.timestamp),
|
ValueWithUnit.Timestamp(it.timestamp),
|
||||||
ValueWithUnit.Insulin(it.amount)
|
ValueWithUnit.Insulin(it.amount)
|
||||||
)
|
)
|
||||||
aapsLogger.debug(LTag.DATABASE, "Inserted bolus $it")
|
aapsLogger.debug(LTag.DATABASE, "Inserted bolus $it")
|
||||||
}
|
}
|
||||||
result.invalidated.forEach {
|
result.invalidated.forEach {
|
||||||
uel.log(Action.BOLUS_REMOVED, Sources.NSClient,
|
uel.log(
|
||||||
|
Action.BOLUS_REMOVED, Sources.NSClient,
|
||||||
ValueWithUnit.Timestamp(it.timestamp),
|
ValueWithUnit.Timestamp(it.timestamp),
|
||||||
ValueWithUnit.Insulin(it.amount)
|
ValueWithUnit.Insulin(it.amount)
|
||||||
)
|
)
|
||||||
|
@ -119,21 +121,24 @@ class NSClientAddUpdateWorker(
|
||||||
.blockingGet()
|
.blockingGet()
|
||||||
.also { result ->
|
.also { result ->
|
||||||
result.inserted.forEach {
|
result.inserted.forEach {
|
||||||
uel.log(Action.CARBS, Sources.NSClient,
|
uel.log(
|
||||||
|
Action.CARBS, Sources.NSClient,
|
||||||
ValueWithUnit.Timestamp(it.timestamp),
|
ValueWithUnit.Timestamp(it.timestamp),
|
||||||
ValueWithUnit.Gram(it.amount.toInt())
|
ValueWithUnit.Gram(it.amount.toInt())
|
||||||
)
|
)
|
||||||
aapsLogger.debug(LTag.DATABASE, "Inserted carbs $it")
|
aapsLogger.debug(LTag.DATABASE, "Inserted carbs $it")
|
||||||
}
|
}
|
||||||
result.invalidated.forEach {
|
result.invalidated.forEach {
|
||||||
uel.log(Action.CARBS_REMOVED, Sources.NSClient,
|
uel.log(
|
||||||
|
Action.CARBS_REMOVED, Sources.NSClient,
|
||||||
ValueWithUnit.Timestamp(it.timestamp),
|
ValueWithUnit.Timestamp(it.timestamp),
|
||||||
ValueWithUnit.Gram(it.amount.toInt())
|
ValueWithUnit.Gram(it.amount.toInt())
|
||||||
)
|
)
|
||||||
aapsLogger.debug(LTag.DATABASE, "Invalidated carbs $it")
|
aapsLogger.debug(LTag.DATABASE, "Invalidated carbs $it")
|
||||||
}
|
}
|
||||||
result.updated.forEach {
|
result.updated.forEach {
|
||||||
uel.log(Action.CARBS, Sources.NSClient,
|
uel.log(
|
||||||
|
Action.CARBS, Sources.NSClient,
|
||||||
ValueWithUnit.Timestamp(it.timestamp),
|
ValueWithUnit.Timestamp(it.timestamp),
|
||||||
ValueWithUnit.Gram(it.amount.toInt())
|
ValueWithUnit.Gram(it.amount.toInt())
|
||||||
)
|
)
|
||||||
|
@ -169,7 +174,8 @@ class NSClientAddUpdateWorker(
|
||||||
.blockingGet()
|
.blockingGet()
|
||||||
.also { result ->
|
.also { result ->
|
||||||
result.inserted.forEach { tt ->
|
result.inserted.forEach { tt ->
|
||||||
uel.log(Action.TT, Sources.NSClient,
|
uel.log(
|
||||||
|
Action.TT, Sources.NSClient,
|
||||||
ValueWithUnit.TherapyEventTTReason(tt.reason),
|
ValueWithUnit.TherapyEventTTReason(tt.reason),
|
||||||
ValueWithUnit.fromGlucoseUnit(tt.lowTarget, Constants.MGDL),
|
ValueWithUnit.fromGlucoseUnit(tt.lowTarget, Constants.MGDL),
|
||||||
ValueWithUnit.fromGlucoseUnit(tt.highTarget, Constants.MGDL).takeIf { tt.lowTarget != tt.highTarget },
|
ValueWithUnit.fromGlucoseUnit(tt.highTarget, Constants.MGDL).takeIf { tt.lowTarget != tt.highTarget },
|
||||||
|
@ -178,7 +184,8 @@ class NSClientAddUpdateWorker(
|
||||||
aapsLogger.debug(LTag.DATABASE, "Inserted TemporaryTarget $tt")
|
aapsLogger.debug(LTag.DATABASE, "Inserted TemporaryTarget $tt")
|
||||||
}
|
}
|
||||||
result.invalidated.forEach { tt ->
|
result.invalidated.forEach { tt ->
|
||||||
uel.log(Action.TT_REMOVED, Sources.NSClient,
|
uel.log(
|
||||||
|
Action.TT_REMOVED, Sources.NSClient,
|
||||||
ValueWithUnit.TherapyEventTTReason(tt.reason),
|
ValueWithUnit.TherapyEventTTReason(tt.reason),
|
||||||
ValueWithUnit.Mgdl(tt.lowTarget),
|
ValueWithUnit.Mgdl(tt.lowTarget),
|
||||||
ValueWithUnit.Mgdl(tt.highTarget).takeIf { tt.lowTarget != tt.highTarget },
|
ValueWithUnit.Mgdl(tt.highTarget).takeIf { tt.lowTarget != tt.highTarget },
|
||||||
|
@ -187,7 +194,8 @@ class NSClientAddUpdateWorker(
|
||||||
aapsLogger.debug(LTag.DATABASE, "Invalidated TemporaryTarget $tt")
|
aapsLogger.debug(LTag.DATABASE, "Invalidated TemporaryTarget $tt")
|
||||||
}
|
}
|
||||||
result.ended.forEach { tt ->
|
result.ended.forEach { tt ->
|
||||||
uel.log(Action.CANCEL_TT, Sources.NSClient,
|
uel.log(
|
||||||
|
Action.CANCEL_TT, Sources.NSClient,
|
||||||
ValueWithUnit.TherapyEventTTReason(tt.reason),
|
ValueWithUnit.TherapyEventTTReason(tt.reason),
|
||||||
ValueWithUnit.Mgdl(tt.lowTarget),
|
ValueWithUnit.Mgdl(tt.lowTarget),
|
||||||
ValueWithUnit.Mgdl(tt.highTarget).takeIf { tt.lowTarget != tt.highTarget },
|
ValueWithUnit.Mgdl(tt.highTarget).takeIf { tt.lowTarget != tt.highTarget },
|
||||||
|
@ -215,13 +223,17 @@ class NSClientAddUpdateWorker(
|
||||||
.blockingGet()
|
.blockingGet()
|
||||||
.also { result ->
|
.also { result ->
|
||||||
result.inserted.forEach {
|
result.inserted.forEach {
|
||||||
uel.log(Action.PROFILE_SWITCH, Sources.NSClient,
|
uel.log(
|
||||||
ValueWithUnit.Timestamp(it.timestamp))
|
Action.PROFILE_SWITCH, Sources.NSClient,
|
||||||
|
ValueWithUnit.Timestamp(it.timestamp)
|
||||||
|
)
|
||||||
aapsLogger.debug(LTag.DATABASE, "Inserted EffectiveProfileSwitch $it")
|
aapsLogger.debug(LTag.DATABASE, "Inserted EffectiveProfileSwitch $it")
|
||||||
}
|
}
|
||||||
result.invalidated.forEach {
|
result.invalidated.forEach {
|
||||||
uel.log(Action.PROFILE_SWITCH_REMOVED, Sources.NSClient,
|
uel.log(
|
||||||
ValueWithUnit.Timestamp(it.timestamp))
|
Action.PROFILE_SWITCH_REMOVED, Sources.NSClient,
|
||||||
|
ValueWithUnit.Timestamp(it.timestamp)
|
||||||
|
)
|
||||||
aapsLogger.debug(LTag.DATABASE, "Invalidated EffectiveProfileSwitch $it")
|
aapsLogger.debug(LTag.DATABASE, "Invalidated EffectiveProfileSwitch $it")
|
||||||
}
|
}
|
||||||
result.updatedNsId.forEach {
|
result.updatedNsId.forEach {
|
||||||
|
@ -231,7 +243,6 @@ class NSClientAddUpdateWorker(
|
||||||
} ?: aapsLogger.error("Error parsing EffectiveProfileSwitch json $json")
|
} ?: aapsLogger.error("Error parsing EffectiveProfileSwitch json $json")
|
||||||
}
|
}
|
||||||
eventType == TherapyEvent.Type.BOLUS_WIZARD.text ->
|
eventType == TherapyEvent.Type.BOLUS_WIZARD.text ->
|
||||||
if (config.NSCLIENT) {
|
|
||||||
bolusCalculatorResultFromJson(json)?.let { bolusCalculatorResult ->
|
bolusCalculatorResultFromJson(json)?.let { bolusCalculatorResult ->
|
||||||
repository.runTransactionForResult(SyncNsBolusCalculatorResultTransaction(bolusCalculatorResult))
|
repository.runTransactionForResult(SyncNsBolusCalculatorResultTransaction(bolusCalculatorResult))
|
||||||
.doOnError {
|
.doOnError {
|
||||||
|
@ -241,13 +252,15 @@ class NSClientAddUpdateWorker(
|
||||||
.blockingGet()
|
.blockingGet()
|
||||||
.also { result ->
|
.also { result ->
|
||||||
result.inserted.forEach {
|
result.inserted.forEach {
|
||||||
uel.log(Action.BOLUS_CALCULATOR_RESULT, Sources.NSClient,
|
uel.log(
|
||||||
|
Action.BOLUS_CALCULATOR_RESULT, Sources.NSClient,
|
||||||
ValueWithUnit.Timestamp(it.timestamp),
|
ValueWithUnit.Timestamp(it.timestamp),
|
||||||
)
|
)
|
||||||
aapsLogger.debug(LTag.DATABASE, "Inserted BolusCalculatorResult $it")
|
aapsLogger.debug(LTag.DATABASE, "Inserted BolusCalculatorResult $it")
|
||||||
}
|
}
|
||||||
result.invalidated.forEach {
|
result.invalidated.forEach {
|
||||||
uel.log(Action.BOLUS_CALCULATOR_RESULT_REMOVED, Sources.NSClient,
|
uel.log(
|
||||||
|
Action.BOLUS_CALCULATOR_RESULT_REMOVED, Sources.NSClient,
|
||||||
ValueWithUnit.Timestamp(it.timestamp),
|
ValueWithUnit.Timestamp(it.timestamp),
|
||||||
)
|
)
|
||||||
aapsLogger.debug(LTag.DATABASE, "Invalidated BolusCalculatorResult $it")
|
aapsLogger.debug(LTag.DATABASE, "Invalidated BolusCalculatorResult $it")
|
||||||
|
@ -257,7 +270,6 @@ class NSClientAddUpdateWorker(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} ?: aapsLogger.error("Error parsing BolusCalculatorResult json $json")
|
} ?: aapsLogger.error("Error parsing BolusCalculatorResult json $json")
|
||||||
}
|
|
||||||
eventType == TherapyEvent.Type.CANNULA_CHANGE.text ||
|
eventType == TherapyEvent.Type.CANNULA_CHANGE.text ||
|
||||||
eventType == TherapyEvent.Type.INSULIN_CHANGE.text ||
|
eventType == TherapyEvent.Type.INSULIN_CHANGE.text ||
|
||||||
eventType == TherapyEvent.Type.SENSOR_CHANGE.text ||
|
eventType == TherapyEvent.Type.SENSOR_CHANGE.text ||
|
||||||
|
@ -320,7 +332,8 @@ class NSClientAddUpdateWorker(
|
||||||
.blockingGet()
|
.blockingGet()
|
||||||
.also { result ->
|
.also { result ->
|
||||||
result.inserted.forEach {
|
result.inserted.forEach {
|
||||||
uel.log(Action.EXTENDED_BOLUS, Sources.NSClient,
|
uel.log(
|
||||||
|
Action.EXTENDED_BOLUS, Sources.NSClient,
|
||||||
ValueWithUnit.Timestamp(it.timestamp),
|
ValueWithUnit.Timestamp(it.timestamp),
|
||||||
ValueWithUnit.Insulin(it.amount),
|
ValueWithUnit.Insulin(it.amount),
|
||||||
ValueWithUnit.UnitPerHour(it.rate),
|
ValueWithUnit.UnitPerHour(it.rate),
|
||||||
|
@ -329,7 +342,8 @@ class NSClientAddUpdateWorker(
|
||||||
aapsLogger.debug(LTag.DATABASE, "Inserted ExtendedBolus $it")
|
aapsLogger.debug(LTag.DATABASE, "Inserted ExtendedBolus $it")
|
||||||
}
|
}
|
||||||
result.invalidated.forEach {
|
result.invalidated.forEach {
|
||||||
uel.log(Action.EXTENDED_BOLUS_REMOVED, Sources.NSClient,
|
uel.log(
|
||||||
|
Action.EXTENDED_BOLUS_REMOVED, Sources.NSClient,
|
||||||
ValueWithUnit.Timestamp(it.timestamp),
|
ValueWithUnit.Timestamp(it.timestamp),
|
||||||
ValueWithUnit.Insulin(it.amount),
|
ValueWithUnit.Insulin(it.amount),
|
||||||
ValueWithUnit.UnitPerHour(it.rate),
|
ValueWithUnit.UnitPerHour(it.rate),
|
||||||
|
@ -338,7 +352,8 @@ class NSClientAddUpdateWorker(
|
||||||
aapsLogger.debug(LTag.DATABASE, "Invalidated ExtendedBolus $it")
|
aapsLogger.debug(LTag.DATABASE, "Invalidated ExtendedBolus $it")
|
||||||
}
|
}
|
||||||
result.ended.forEach {
|
result.ended.forEach {
|
||||||
uel.log(Action.CANCEL_EXTENDED_BOLUS, Sources.NSClient,
|
uel.log(
|
||||||
|
Action.CANCEL_EXTENDED_BOLUS, Sources.NSClient,
|
||||||
ValueWithUnit.Timestamp(it.timestamp),
|
ValueWithUnit.Timestamp(it.timestamp),
|
||||||
ValueWithUnit.Insulin(it.amount),
|
ValueWithUnit.Insulin(it.amount),
|
||||||
ValueWithUnit.UnitPerHour(it.rate),
|
ValueWithUnit.UnitPerHour(it.rate),
|
||||||
|
@ -366,7 +381,8 @@ class NSClientAddUpdateWorker(
|
||||||
.blockingGet()
|
.blockingGet()
|
||||||
.also { result ->
|
.also { result ->
|
||||||
result.inserted.forEach {
|
result.inserted.forEach {
|
||||||
uel.log(Action.TEMP_BASAL, Sources.NSClient,
|
uel.log(
|
||||||
|
Action.TEMP_BASAL, Sources.NSClient,
|
||||||
ValueWithUnit.Timestamp(it.timestamp),
|
ValueWithUnit.Timestamp(it.timestamp),
|
||||||
if (it.isAbsolute) ValueWithUnit.UnitPerHour(it.rate) else ValueWithUnit.Percent(it.rate.toInt()),
|
if (it.isAbsolute) ValueWithUnit.UnitPerHour(it.rate) else ValueWithUnit.Percent(it.rate.toInt()),
|
||||||
ValueWithUnit.Minute(TimeUnit.MILLISECONDS.toMinutes(it.duration).toInt())
|
ValueWithUnit.Minute(TimeUnit.MILLISECONDS.toMinutes(it.duration).toInt())
|
||||||
|
@ -374,7 +390,8 @@ class NSClientAddUpdateWorker(
|
||||||
aapsLogger.debug(LTag.DATABASE, "Inserted TemporaryBasal $it")
|
aapsLogger.debug(LTag.DATABASE, "Inserted TemporaryBasal $it")
|
||||||
}
|
}
|
||||||
result.invalidated.forEach {
|
result.invalidated.forEach {
|
||||||
uel.log(Action.TEMP_BASAL_REMOVED, Sources.NSClient,
|
uel.log(
|
||||||
|
Action.TEMP_BASAL_REMOVED, Sources.NSClient,
|
||||||
ValueWithUnit.Timestamp(it.timestamp),
|
ValueWithUnit.Timestamp(it.timestamp),
|
||||||
if (it.isAbsolute) ValueWithUnit.UnitPerHour(it.rate) else ValueWithUnit.Percent(it.rate.toInt()),
|
if (it.isAbsolute) ValueWithUnit.UnitPerHour(it.rate) else ValueWithUnit.Percent(it.rate.toInt()),
|
||||||
ValueWithUnit.Minute(TimeUnit.MILLISECONDS.toMinutes(it.duration).toInt())
|
ValueWithUnit.Minute(TimeUnit.MILLISECONDS.toMinutes(it.duration).toInt())
|
||||||
|
@ -382,7 +399,8 @@ class NSClientAddUpdateWorker(
|
||||||
aapsLogger.debug(LTag.DATABASE, "Invalidated TemporaryBasal $it")
|
aapsLogger.debug(LTag.DATABASE, "Invalidated TemporaryBasal $it")
|
||||||
}
|
}
|
||||||
result.ended.forEach {
|
result.ended.forEach {
|
||||||
uel.log(Action.CANCEL_TEMP_BASAL, Sources.NSClient,
|
uel.log(
|
||||||
|
Action.CANCEL_TEMP_BASAL, Sources.NSClient,
|
||||||
ValueWithUnit.Timestamp(it.timestamp),
|
ValueWithUnit.Timestamp(it.timestamp),
|
||||||
if (it.isAbsolute) ValueWithUnit.UnitPerHour(it.rate) else ValueWithUnit.Percent(it.rate.toInt()),
|
if (it.isAbsolute) ValueWithUnit.UnitPerHour(it.rate) else ValueWithUnit.Percent(it.rate.toInt()),
|
||||||
ValueWithUnit.Minute(TimeUnit.MILLISECONDS.toMinutes(it.duration).toInt())
|
ValueWithUnit.Minute(TimeUnit.MILLISECONDS.toMinutes(it.duration).toInt())
|
||||||
|
@ -409,13 +427,17 @@ class NSClientAddUpdateWorker(
|
||||||
.blockingGet()
|
.blockingGet()
|
||||||
.also { result ->
|
.also { result ->
|
||||||
result.inserted.forEach {
|
result.inserted.forEach {
|
||||||
uel.log(Action.PROFILE_SWITCH, Sources.NSClient,
|
uel.log(
|
||||||
ValueWithUnit.Timestamp(it.timestamp))
|
Action.PROFILE_SWITCH, Sources.NSClient,
|
||||||
|
ValueWithUnit.Timestamp(it.timestamp)
|
||||||
|
)
|
||||||
aapsLogger.debug(LTag.DATABASE, "Inserted ProfileSwitch $it")
|
aapsLogger.debug(LTag.DATABASE, "Inserted ProfileSwitch $it")
|
||||||
}
|
}
|
||||||
result.invalidated.forEach {
|
result.invalidated.forEach {
|
||||||
uel.log(Action.PROFILE_SWITCH_REMOVED, Sources.NSClient,
|
uel.log(
|
||||||
ValueWithUnit.Timestamp(it.timestamp))
|
Action.PROFILE_SWITCH_REMOVED, Sources.NSClient,
|
||||||
|
ValueWithUnit.Timestamp(it.timestamp)
|
||||||
|
)
|
||||||
aapsLogger.debug(LTag.DATABASE, "Invalidated ProfileSwitch $it")
|
aapsLogger.debug(LTag.DATABASE, "Invalidated ProfileSwitch $it")
|
||||||
}
|
}
|
||||||
result.updatedNsId.forEach {
|
result.updatedNsId.forEach {
|
||||||
|
@ -435,21 +457,24 @@ class NSClientAddUpdateWorker(
|
||||||
.blockingGet()
|
.blockingGet()
|
||||||
.also { result ->
|
.also { result ->
|
||||||
result.inserted.forEach { oe ->
|
result.inserted.forEach { oe ->
|
||||||
uel.log(Action.LOOP_CHANGE, Sources.NSClient,
|
uel.log(
|
||||||
|
Action.LOOP_CHANGE, Sources.NSClient,
|
||||||
ValueWithUnit.OfflineEventReason(oe.reason),
|
ValueWithUnit.OfflineEventReason(oe.reason),
|
||||||
ValueWithUnit.Minute(TimeUnit.MILLISECONDS.toMinutes(oe.duration).toInt())
|
ValueWithUnit.Minute(TimeUnit.MILLISECONDS.toMinutes(oe.duration).toInt())
|
||||||
)
|
)
|
||||||
aapsLogger.debug(LTag.DATABASE, "Inserted OfflineEvent $oe")
|
aapsLogger.debug(LTag.DATABASE, "Inserted OfflineEvent $oe")
|
||||||
}
|
}
|
||||||
result.invalidated.forEach { oe ->
|
result.invalidated.forEach { oe ->
|
||||||
uel.log(Action.LOOP_REMOVED, Sources.NSClient,
|
uel.log(
|
||||||
|
Action.LOOP_REMOVED, Sources.NSClient,
|
||||||
ValueWithUnit.OfflineEventReason(oe.reason),
|
ValueWithUnit.OfflineEventReason(oe.reason),
|
||||||
ValueWithUnit.Minute(TimeUnit.MILLISECONDS.toMinutes(oe.duration).toInt())
|
ValueWithUnit.Minute(TimeUnit.MILLISECONDS.toMinutes(oe.duration).toInt())
|
||||||
)
|
)
|
||||||
aapsLogger.debug(LTag.DATABASE, "Invalidated OfflineEvent $oe")
|
aapsLogger.debug(LTag.DATABASE, "Invalidated OfflineEvent $oe")
|
||||||
}
|
}
|
||||||
result.ended.forEach { oe ->
|
result.ended.forEach { oe ->
|
||||||
uel.log(Action.LOOP_CHANGE, Sources.NSClient,
|
uel.log(
|
||||||
|
Action.LOOP_CHANGE, Sources.NSClient,
|
||||||
ValueWithUnit.OfflineEventReason(oe.reason),
|
ValueWithUnit.OfflineEventReason(oe.reason),
|
||||||
ValueWithUnit.Minute(TimeUnit.MILLISECONDS.toMinutes(oe.duration).toInt())
|
ValueWithUnit.Minute(TimeUnit.MILLISECONDS.toMinutes(oe.duration).toInt())
|
||||||
)
|
)
|
||||||
|
@ -472,7 +497,8 @@ class NSClientAddUpdateWorker(
|
||||||
val enteredBy = JsonHelper.safeGetString(json, "enteredBy", "")
|
val enteredBy = JsonHelper.safeGetString(json, "enteredBy", "")
|
||||||
val notes = JsonHelper.safeGetString(json, "notes", "")
|
val notes = JsonHelper.safeGetString(json, "notes", "")
|
||||||
if (date > now - 15 * 60 * 1000L && notes.isNotEmpty()
|
if (date > now - 15 * 60 * 1000L && notes.isNotEmpty()
|
||||||
&& enteredBy != sp.getString("careportal_enteredby", "AndroidAPS")) {
|
&& enteredBy != sp.getString("careportal_enteredby", "AndroidAPS")
|
||||||
|
) {
|
||||||
val defaultVal = config.NSCLIENT
|
val defaultVal = config.NSCLIENT
|
||||||
if (sp.getBoolean(R.string.key_ns_announcements, defaultVal)) {
|
if (sp.getBoolean(R.string.key_ns_announcements, defaultVal)) {
|
||||||
val announcement = Notification(Notification.NS_ANNOUNCEMENT, notes, Notification.ANNOUNCEMENT, 60)
|
val announcement = Notification(Notification.NS_ANNOUNCEMENT, notes, Notification.ANNOUNCEMENT, 60)
|
||||||
|
|
Loading…
Reference in a new issue