NSCv3: process NSTemporaryTarget
This commit is contained in:
parent
94af8a7106
commit
cade6405b3
8 changed files with 108 additions and 18 deletions
|
@ -4,17 +4,17 @@ import info.nightscout.sdk.localmodel.entry.NsUnits
|
||||||
|
|
||||||
data class NSTemporaryTarget(
|
data class NSTemporaryTarget(
|
||||||
override val date: Long,
|
override val date: Long,
|
||||||
override val device: String?,
|
override val device: String? = null,
|
||||||
override val identifier: String?,
|
override val identifier: String?,
|
||||||
override val units: NsUnits?,
|
override val units: NsUnits?,
|
||||||
override val srvModified: Long?,
|
override val srvModified: Long? = null,
|
||||||
override val srvCreated: Long?,
|
override val srvCreated: Long? = null,
|
||||||
override val utcOffset: Long,
|
override val utcOffset: Long,
|
||||||
override val subject: String?,
|
override val subject: String? = null,
|
||||||
override var isReadOnly: Boolean,
|
override var isReadOnly: Boolean = false,
|
||||||
override val isValid: Boolean,
|
override val isValid: Boolean = true,
|
||||||
override val eventType: EventType,
|
override val eventType: EventType,
|
||||||
override val notes: String?,
|
override val notes: String? = null,
|
||||||
override val pumpId: Long?,
|
override val pumpId: Long?,
|
||||||
override val endId: Long?,
|
override val endId: Long?,
|
||||||
override val pumpType: String?,
|
override val pumpType: String?,
|
||||||
|
|
|
@ -39,6 +39,7 @@ import info.nightscout.plugins.sync.nsclientV3.extensions.toNSCarbs
|
||||||
import info.nightscout.plugins.sync.nsclientV3.extensions.toNSEffectiveProfileSwitch
|
import info.nightscout.plugins.sync.nsclientV3.extensions.toNSEffectiveProfileSwitch
|
||||||
import info.nightscout.plugins.sync.nsclientV3.extensions.toNSProfileSwitch
|
import info.nightscout.plugins.sync.nsclientV3.extensions.toNSProfileSwitch
|
||||||
import info.nightscout.plugins.sync.nsclientV3.extensions.toNSTemporaryBasal
|
import info.nightscout.plugins.sync.nsclientV3.extensions.toNSTemporaryBasal
|
||||||
|
import info.nightscout.plugins.sync.nsclientV3.extensions.toNSTemporaryTarget
|
||||||
import info.nightscout.plugins.sync.nsclientV3.workers.LoadBgWorker
|
import info.nightscout.plugins.sync.nsclientV3.workers.LoadBgWorker
|
||||||
import info.nightscout.plugins.sync.nsclientV3.workers.LoadLastModificationWorker
|
import info.nightscout.plugins.sync.nsclientV3.workers.LoadLastModificationWorker
|
||||||
import info.nightscout.plugins.sync.nsclientV3.workers.LoadStatusWorker
|
import info.nightscout.plugins.sync.nsclientV3.workers.LoadStatusWorker
|
||||||
|
@ -326,7 +327,7 @@ class NSClientV3Plugin @Inject constructor(
|
||||||
is DataSyncSelector.PairBolus -> dataPair.value.toNSBolus()
|
is DataSyncSelector.PairBolus -> dataPair.value.toNSBolus()
|
||||||
is DataSyncSelector.PairCarbs -> dataPair.value.toNSCarbs()
|
is DataSyncSelector.PairCarbs -> dataPair.value.toNSCarbs()
|
||||||
// is DataSyncSelector.PairBolusCalculatorResult -> dataPair.value.toJson(false, dateUtil, profileFunction)
|
// is DataSyncSelector.PairBolusCalculatorResult -> dataPair.value.toJson(false, dateUtil, profileFunction)
|
||||||
// is DataSyncSelector.PairTemporaryTarget -> dataPair.value.toJson(false, profileFunction.getUnits(), dateUtil)
|
is DataSyncSelector.PairTemporaryTarget -> dataPair.value.toNSTemporaryTarget()
|
||||||
// is DataSyncSelector.PairFood -> dataPair.value.toJson(false)
|
// is DataSyncSelector.PairFood -> dataPair.value.toJson(false)
|
||||||
// is DataSyncSelector.PairGlucoseValue -> dataPair.value.toJson(false, dateUtil)
|
// is DataSyncSelector.PairGlucoseValue -> dataPair.value.toJson(false, dateUtil)
|
||||||
// is DataSyncSelector.PairTherapyEvent -> dataPair.value.toJson(false, dateUtil)
|
// is DataSyncSelector.PairTherapyEvent -> dataPair.value.toJson(false, dateUtil)
|
||||||
|
@ -370,6 +371,7 @@ class NSClientV3Plugin @Inject constructor(
|
||||||
}
|
}
|
||||||
dataSyncSelector.confirmLastBolusIdIfGreater(dataPair.id)
|
dataSyncSelector.confirmLastBolusIdIfGreater(dataPair.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
is DataSyncSelector.PairCarbs -> {
|
is DataSyncSelector.PairCarbs -> {
|
||||||
if (result.response == 201) { // created
|
if (result.response == 201) { // created
|
||||||
dataPair.value.interfaceIDs.nightscoutId = result.identifier
|
dataPair.value.interfaceIDs.nightscoutId = result.identifier
|
||||||
|
@ -379,11 +381,18 @@ class NSClientV3Plugin @Inject constructor(
|
||||||
dataSyncSelector.confirmLastCarbsIdIfGreater(dataPair.id)
|
dataSyncSelector.confirmLastCarbsIdIfGreater(dataPair.id)
|
||||||
}
|
}
|
||||||
// is DataSyncSelector.PairBolusCalculatorResult -> dataPair.value.toJson(false, dateUtil, profileFunction)
|
// is DataSyncSelector.PairBolusCalculatorResult -> dataPair.value.toJson(false, dateUtil, profileFunction)
|
||||||
// is DataSyncSelector.PairTemporaryTarget -> dataPair.value.toJson(false, profileFunction.getUnits(), dateUtil)
|
is DataSyncSelector.PairTemporaryTarget -> {
|
||||||
|
if (result.response == 201) { // created
|
||||||
|
dataPair.value.interfaceIDs.nightscoutId = result.identifier
|
||||||
|
storeDataForDb.nsIdTemporaryTargets.add(dataPair.value)
|
||||||
|
storeDataForDb.scheduleNsIdUpdate()
|
||||||
|
}
|
||||||
|
dataSyncSelector.confirmLastTempTargetsIdIfGreater(dataPair.id)
|
||||||
|
}
|
||||||
// is DataSyncSelector.PairFood -> dataPair.value.toJson(false)
|
// is DataSyncSelector.PairFood -> dataPair.value.toJson(false)
|
||||||
// is DataSyncSelector.PairGlucoseValue -> dataPair.value.toJson(false, dateUtil)
|
// is DataSyncSelector.PairGlucoseValue -> dataPair.value.toJson(false, dateUtil)
|
||||||
// is DataSyncSelector.PairTherapyEvent -> dataPair.value.toJson(false, dateUtil)
|
// is DataSyncSelector.PairTherapyEvent -> dataPair.value.toJson(false, dateUtil)
|
||||||
is DataSyncSelector.PairTemporaryBasal -> {
|
is DataSyncSelector.PairTemporaryBasal -> {
|
||||||
if (result.response == 201) { // created
|
if (result.response == 201) { // created
|
||||||
dataPair.value.interfaceIDs.nightscoutId = result.identifier
|
dataPair.value.interfaceIDs.nightscoutId = result.identifier
|
||||||
storeDataForDb.nsIdTemporaryBasals.add(dataPair.value)
|
storeDataForDb.nsIdTemporaryBasals.add(dataPair.value)
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package info.nightscout.plugins.sync.nsclientV3.extensions
|
package info.nightscout.plugins.sync.nsclientV3.extensions
|
||||||
|
|
||||||
import info.nightscout.database.entities.Bolus
|
import info.nightscout.database.entities.Bolus
|
||||||
import info.nightscout.database.entities.TherapyEvent
|
|
||||||
import info.nightscout.database.entities.embedments.InterfaceIDs
|
import info.nightscout.database.entities.embedments.InterfaceIDs
|
||||||
import info.nightscout.sdk.localmodel.treatment.EventType
|
import info.nightscout.sdk.localmodel.treatment.EventType
|
||||||
import info.nightscout.sdk.localmodel.treatment.NSBolus
|
import info.nightscout.sdk.localmodel.treatment.NSBolus
|
||||||
|
@ -28,7 +27,7 @@ fun NSBolus.BolusType?.toBolusType(): Bolus.Type =
|
||||||
|
|
||||||
fun Bolus.toNSBolus(): NSBolus =
|
fun Bolus.toNSBolus(): NSBolus =
|
||||||
NSBolus(
|
NSBolus(
|
||||||
eventType = EventType.fromString(if (type == Bolus.Type.SMB) TherapyEvent.Type.CORRECTION_BOLUS.text else TherapyEvent.Type.MEAL_BOLUS.text),
|
eventType = if (type == Bolus.Type.SMB) EventType.CORRECTION_BOLUS else EventType.MEAL_BOLUS,
|
||||||
isValid = isValid,
|
isValid = isValid,
|
||||||
date = timestamp,
|
date = timestamp,
|
||||||
utcOffset = utcOffset,
|
utcOffset = utcOffset,
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package info.nightscout.plugins.sync.nsclientV3.extensions
|
package info.nightscout.plugins.sync.nsclientV3.extensions
|
||||||
|
|
||||||
import info.nightscout.database.entities.Carbs
|
import info.nightscout.database.entities.Carbs
|
||||||
import info.nightscout.database.entities.TherapyEvent
|
|
||||||
import info.nightscout.database.entities.embedments.InterfaceIDs
|
import info.nightscout.database.entities.embedments.InterfaceIDs
|
||||||
import info.nightscout.sdk.localmodel.treatment.EventType
|
import info.nightscout.sdk.localmodel.treatment.EventType
|
||||||
import info.nightscout.sdk.localmodel.treatment.NSCarbs
|
import info.nightscout.sdk.localmodel.treatment.NSCarbs
|
||||||
|
@ -19,7 +18,7 @@ fun NSCarbs.toCarbs(): Carbs =
|
||||||
|
|
||||||
fun Carbs.toNSCarbs(): NSCarbs =
|
fun Carbs.toNSCarbs(): NSCarbs =
|
||||||
NSCarbs(
|
NSCarbs(
|
||||||
eventType = EventType.fromString(if (amount < 12) TherapyEvent.Type.CARBS_CORRECTION.text else TherapyEvent.Type.MEAL_BOLUS.text),
|
eventType = if (amount < 12) EventType.CARBS_CORRECTION else EventType.MEAL_BOLUS,
|
||||||
isValid = isValid,
|
isValid = isValid,
|
||||||
date = timestamp,
|
date = timestamp,
|
||||||
utcOffset = utcOffset,
|
utcOffset = utcOffset,
|
||||||
|
|
|
@ -5,7 +5,6 @@ import info.nightscout.core.extensions.getCustomizedName
|
||||||
import info.nightscout.core.extensions.pureProfileFromJson
|
import info.nightscout.core.extensions.pureProfileFromJson
|
||||||
import info.nightscout.core.profile.ProfileSealed
|
import info.nightscout.core.profile.ProfileSealed
|
||||||
import info.nightscout.database.entities.ProfileSwitch
|
import info.nightscout.database.entities.ProfileSwitch
|
||||||
import info.nightscout.database.entities.TherapyEvent
|
|
||||||
import info.nightscout.database.entities.embedments.InterfaceIDs
|
import info.nightscout.database.entities.embedments.InterfaceIDs
|
||||||
import info.nightscout.interfaces.plugin.ActivePlugin
|
import info.nightscout.interfaces.plugin.ActivePlugin
|
||||||
import info.nightscout.sdk.localmodel.treatment.EventType
|
import info.nightscout.sdk.localmodel.treatment.EventType
|
||||||
|
@ -46,7 +45,7 @@ fun ProfileSwitch.toNSProfileSwitch(dateUtil: DateUtil): NSProfileSwitch {
|
||||||
notCustomized.percentage = 100
|
notCustomized.percentage = 100
|
||||||
|
|
||||||
return NSProfileSwitch(
|
return NSProfileSwitch(
|
||||||
eventType = EventType.fromString(TherapyEvent.Type.PROFILE_SWITCH.text),
|
eventType = EventType.PROFILE_SWITCH,
|
||||||
isValid = isValid,
|
isValid = isValid,
|
||||||
date = timestamp,
|
date = timestamp,
|
||||||
utcOffset = utcOffset,
|
utcOffset = utcOffset,
|
||||||
|
|
|
@ -2,7 +2,6 @@ package info.nightscout.plugins.sync.nsclientV3.extensions
|
||||||
|
|
||||||
import info.nightscout.core.extensions.convertedToAbsolute
|
import info.nightscout.core.extensions.convertedToAbsolute
|
||||||
import info.nightscout.database.entities.TemporaryBasal
|
import info.nightscout.database.entities.TemporaryBasal
|
||||||
import info.nightscout.database.entities.TherapyEvent
|
|
||||||
import info.nightscout.database.entities.embedments.InterfaceIDs
|
import info.nightscout.database.entities.embedments.InterfaceIDs
|
||||||
import info.nightscout.interfaces.profile.Profile
|
import info.nightscout.interfaces.profile.Profile
|
||||||
import info.nightscout.sdk.localmodel.treatment.EventType
|
import info.nightscout.sdk.localmodel.treatment.EventType
|
||||||
|
@ -32,7 +31,7 @@ fun NSTemporaryBasal.Type?.toType(): TemporaryBasal.Type =
|
||||||
|
|
||||||
fun TemporaryBasal.toNSTemporaryBasal(profile: Profile): NSTemporaryBasal =
|
fun TemporaryBasal.toNSTemporaryBasal(profile: Profile): NSTemporaryBasal =
|
||||||
NSTemporaryBasal(
|
NSTemporaryBasal(
|
||||||
eventType = EventType.fromString(TherapyEvent.Type.TEMPORARY_BASAL.text),
|
eventType = EventType.TEMPORARY_BASAL,
|
||||||
isValid = isValid,
|
isValid = isValid,
|
||||||
date = timestamp,
|
date = timestamp,
|
||||||
utcOffset = utcOffset,
|
utcOffset = utcOffset,
|
||||||
|
|
|
@ -2,6 +2,8 @@ package info.nightscout.plugins.sync.nsclientV3.extensions
|
||||||
|
|
||||||
import info.nightscout.database.entities.TemporaryTarget
|
import info.nightscout.database.entities.TemporaryTarget
|
||||||
import info.nightscout.database.entities.embedments.InterfaceIDs
|
import info.nightscout.database.entities.embedments.InterfaceIDs
|
||||||
|
import info.nightscout.sdk.localmodel.entry.NsUnits
|
||||||
|
import info.nightscout.sdk.localmodel.treatment.EventType
|
||||||
import info.nightscout.sdk.localmodel.treatment.NSTemporaryTarget
|
import info.nightscout.sdk.localmodel.treatment.NSTemporaryTarget
|
||||||
|
|
||||||
fun NSTemporaryTarget.toTemporaryTarget(): TemporaryTarget =
|
fun NSTemporaryTarget.toTemporaryTarget(): TemporaryTarget =
|
||||||
|
@ -26,3 +28,32 @@ fun NSTemporaryTarget.Reason?.toReason(): TemporaryTarget.Reason =
|
||||||
NSTemporaryTarget.Reason.WEAR -> TemporaryTarget.Reason.WEAR
|
NSTemporaryTarget.Reason.WEAR -> TemporaryTarget.Reason.WEAR
|
||||||
null -> TemporaryTarget.Reason.CUSTOM
|
null -> TemporaryTarget.Reason.CUSTOM
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun TemporaryTarget.toNSTemporaryTarget(): NSTemporaryTarget =
|
||||||
|
NSTemporaryTarget(
|
||||||
|
eventType = EventType.TEMPORARY_TARGET,
|
||||||
|
isValid = isValid,
|
||||||
|
date = timestamp,
|
||||||
|
utcOffset = utcOffset,
|
||||||
|
reason = reason.toReason(),
|
||||||
|
targetTop = highTarget,
|
||||||
|
targetBottom = lowTarget,
|
||||||
|
units = NsUnits.MG_DL,
|
||||||
|
duration = duration,
|
||||||
|
identifier = interfaceIDs.nightscoutId,
|
||||||
|
pumpId = interfaceIDs.pumpId,
|
||||||
|
pumpType = interfaceIDs.pumpType?.name,
|
||||||
|
pumpSerial = interfaceIDs.pumpSerial,
|
||||||
|
endId = interfaceIDs.endId
|
||||||
|
)
|
||||||
|
|
||||||
|
fun TemporaryTarget.Reason?.toReason(): NSTemporaryTarget.Reason =
|
||||||
|
when (this) {
|
||||||
|
TemporaryTarget.Reason.CUSTOM -> NSTemporaryTarget.Reason.CUSTOM
|
||||||
|
TemporaryTarget.Reason.HYPOGLYCEMIA -> NSTemporaryTarget.Reason.HYPOGLYCEMIA
|
||||||
|
TemporaryTarget.Reason.ACTIVITY -> NSTemporaryTarget.Reason.ACTIVITY
|
||||||
|
TemporaryTarget.Reason.EATING_SOON -> NSTemporaryTarget.Reason.EATING_SOON
|
||||||
|
TemporaryTarget.Reason.AUTOMATION -> NSTemporaryTarget.Reason.AUTOMATION
|
||||||
|
TemporaryTarget.Reason.WEAR -> NSTemporaryTarget.Reason.WEAR
|
||||||
|
null -> NSTemporaryTarget.Reason.CUSTOM
|
||||||
|
}
|
|
@ -0,0 +1,54 @@
|
||||||
|
package info.nightscout.plugins.sync.nsclientV3.extensions
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.TestBaseWithProfile
|
||||||
|
import info.nightscout.database.entities.TemporaryTarget
|
||||||
|
import info.nightscout.database.entities.embedments.InterfaceIDs
|
||||||
|
import info.nightscout.sdk.localmodel.treatment.NSTemporaryTarget
|
||||||
|
import info.nightscout.sdk.mapper.convertToRemoteAndBack
|
||||||
|
import org.junit.jupiter.api.Assertions
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
|
@Suppress("SpellCheckingInspection")
|
||||||
|
internal class TemporaryTargetExtensionKtTest : TestBaseWithProfile() {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun toTemporaryTarget() {
|
||||||
|
var temporaryTarget = TemporaryTarget(
|
||||||
|
timestamp = 10000,
|
||||||
|
isValid = true,
|
||||||
|
reason = TemporaryTarget.Reason.ACTIVITY,
|
||||||
|
highTarget = 100.0,
|
||||||
|
lowTarget = 99.0,
|
||||||
|
duration = 3600000,
|
||||||
|
interfaceIDs_backing = InterfaceIDs(
|
||||||
|
nightscoutId = "nightscoutId",
|
||||||
|
pumpId = 11000,
|
||||||
|
pumpType = InterfaceIDs.PumpType.DANA_I,
|
||||||
|
pumpSerial = "bbbb"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
var temporaryTarget2 = (temporaryTarget.toNSTemporaryTarget().convertToRemoteAndBack() as NSTemporaryTarget).toTemporaryTarget()
|
||||||
|
Assertions.assertTrue(temporaryTarget.contentEqualsTo(temporaryTarget2))
|
||||||
|
Assertions.assertTrue(temporaryTarget.interfaceIdsEqualsTo(temporaryTarget2))
|
||||||
|
|
||||||
|
temporaryTarget = TemporaryTarget(
|
||||||
|
timestamp = 10000,
|
||||||
|
isValid = true,
|
||||||
|
reason = TemporaryTarget.Reason.CUSTOM,
|
||||||
|
highTarget = 150.0,
|
||||||
|
lowTarget = 150.0,
|
||||||
|
duration = 30000,
|
||||||
|
interfaceIDs_backing = InterfaceIDs(
|
||||||
|
nightscoutId = "nightscoutId",
|
||||||
|
pumpId = 11000,
|
||||||
|
pumpType = InterfaceIDs.PumpType.DANA_I,
|
||||||
|
pumpSerial = "bbbb"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
temporaryTarget2 = (temporaryTarget.toNSTemporaryTarget().convertToRemoteAndBack() as NSTemporaryTarget).toTemporaryTarget()
|
||||||
|
Assertions.assertTrue(temporaryTarget.contentEqualsTo(temporaryTarget2))
|
||||||
|
Assertions.assertTrue(temporaryTarget.interfaceIdsEqualsTo(temporaryTarget2))
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue