fix PS timeshift NS upload

This commit is contained in:
Milos Kozak 2022-08-15 14:55:20 +02:00
parent d385fc3be0
commit 17d7464239

View file

@ -31,17 +31,18 @@ fun ProfileSwitch.toJson(isAdd: Boolean, dateUtil: DateUtil): JSONObject =
JSONObject() JSONObject()
.put("timeshift", timeshift) .put("timeshift", timeshift)
.put("percentage", percentage) .put("percentage", percentage)
.put("duration", T.msecs(duration).mins())
.put("profile", getCustomizedName()) .put("profile", getCustomizedName())
.put("originalProfileName", profileName) .put("originalProfileName", profileName)
.also { // remove customization to store original profileJson in toPureNsJson call .put("originalDuration", duration)
timeshift = 0
percentage = 100
}
.put("created_at", dateUtil.toISOString(timestamp)) .put("created_at", dateUtil.toISOString(timestamp))
.put("enteredBy", "openaps://" + "AndroidAPS") .put("enteredBy", "openaps://" + "AndroidAPS")
.put("isValid", isValid) .put("isValid", isValid)
.put("eventType", TherapyEvent.Type.PROFILE_SWITCH.text) .put("eventType", TherapyEvent.Type.PROFILE_SWITCH.text)
.put("duration", T.msecs(duration).mins()) .also { // remove customization to store original profileJson in toPureNsJson call
timeshift = 0
percentage = 100
}
.put("profileJson", ProfileSealed.PS(this).toPureNsJson(dateUtil).toString()) .put("profileJson", ProfileSealed.PS(this).toPureNsJson(dateUtil).toString())
.also { .also {
if (interfaceIDs.pumpId != null) it.put("pumpId", interfaceIDs.pumpId) if (interfaceIDs.pumpId != null) it.put("pumpId", interfaceIDs.pumpId)
@ -66,6 +67,7 @@ fun ProfileSwitch.toJson(isAdd: Boolean, dateUtil: DateUtil): JSONObject =
fun profileSwitchFromJson(jsonObject: JSONObject, dateUtil: DateUtil, activePlugin: ActivePlugin): ProfileSwitch? { fun profileSwitchFromJson(jsonObject: JSONObject, dateUtil: DateUtil, activePlugin: ActivePlugin): ProfileSwitch? {
val timestamp = JsonHelper.safeGetLongAllowNull(jsonObject, "mills", null) ?: return null val timestamp = JsonHelper.safeGetLongAllowNull(jsonObject, "mills", null) ?: return null
val duration = JsonHelper.safeGetLong(jsonObject, "duration") val duration = JsonHelper.safeGetLong(jsonObject, "duration")
val originalDuration = JsonHelper.safeGetLongAllowNull(jsonObject, "originalDuration")
val timeshift = JsonHelper.safeGetLong(jsonObject, "timeshift") val timeshift = JsonHelper.safeGetLong(jsonObject, "timeshift")
val percentage = JsonHelper.safeGetInt(jsonObject, "percentage", 100) val percentage = JsonHelper.safeGetInt(jsonObject, "percentage", 100)
val isValid = JsonHelper.safeGetBoolean(jsonObject, "isValid", true) val isValid = JsonHelper.safeGetBoolean(jsonObject, "isValid", true)
@ -94,9 +96,9 @@ fun profileSwitchFromJson(jsonObject: JSONObject, dateUtil: DateUtil, activePlug
targetBlocks = profileSealed.targetBlocks, targetBlocks = profileSealed.targetBlocks,
glucoseUnit = ProfileSwitch.GlucoseUnit.fromConstant(profileSealed.units), glucoseUnit = ProfileSwitch.GlucoseUnit.fromConstant(profileSealed.units),
profileName = originalProfileName ?: profileName, profileName = originalProfileName ?: profileName,
timeshift = T.hours(timeshift).msecs(), timeshift = timeshift,
percentage = percentage, percentage = percentage,
duration = T.mins(duration).msecs(), duration = originalDuration ?: T.mins(duration).msecs(),
insulinConfiguration = profileSealed.insulinConfiguration, insulinConfiguration = profileSealed.insulinConfiguration,
isValid = isValid isValid = isValid
).also { ).also {