NSC: better TBR sync
This commit is contained in:
parent
d7a4740e7d
commit
682628e845
1 changed files with 23 additions and 18 deletions
|
@ -70,11 +70,11 @@ fun TemporaryBasal.toJson(isAdd: Boolean, profile: Profile, dateUtil: DateUtil):
|
||||||
.put("isValid", isValid)
|
.put("isValid", isValid)
|
||||||
.put("duration", T.msecs(duration).mins())
|
.put("duration", T.msecs(duration).mins())
|
||||||
.put("durationInMilliseconds", duration) // rounded duration leads to different basal IOB
|
.put("durationInMilliseconds", duration) // rounded duration leads to different basal IOB
|
||||||
.put("rate", rate)
|
|
||||||
.put("type", type.name)
|
.put("type", type.name)
|
||||||
.put("isAbsolute", isAbsolute)
|
.put("rate", convertedToAbsolute(timestamp, profile)) // generated by OpenAPS, for compatibility
|
||||||
.put("absolute", convertedToAbsolute(timestamp, profile))
|
|
||||||
.also {
|
.also {
|
||||||
|
if (isAbsolute) it.put("absolute", rate)
|
||||||
|
else it.put("percent", rate - 100)
|
||||||
if (interfaceIDs.pumpId != null) it.put("pumpId", interfaceIDs.pumpId)
|
if (interfaceIDs.pumpId != null) it.put("pumpId", interfaceIDs.pumpId)
|
||||||
if (interfaceIDs.endId != null) it.put("endId", interfaceIDs.endId)
|
if (interfaceIDs.endId != null) it.put("endId", interfaceIDs.endId)
|
||||||
if (interfaceIDs.pumpType != null) it.put("pumpType", interfaceIDs.pumpType!!.name)
|
if (interfaceIDs.pumpType != null) it.put("pumpType", interfaceIDs.pumpType!!.name)
|
||||||
|
@ -82,11 +82,9 @@ fun TemporaryBasal.toJson(isAdd: Boolean, profile: Profile, dateUtil: DateUtil):
|
||||||
if (isAdd && interfaceIDs.nightscoutId != null) it.put("_id", interfaceIDs.nightscoutId)
|
if (isAdd && interfaceIDs.nightscoutId != null) it.put("_id", interfaceIDs.nightscoutId)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("IfThenToElvis")
|
@Suppress("IfThenToElvis", "CascadeIf")
|
||||||
fun temporaryBasalFromJson(jsonObject: JSONObject): TemporaryBasal? {
|
fun temporaryBasalFromJson(jsonObject: JSONObject): TemporaryBasal? {
|
||||||
val timestamp = JsonHelper.safeGetLongAllowNull(jsonObject, "mills", null) ?: return null
|
val timestamp = JsonHelper.safeGetLongAllowNull(jsonObject, "mills", null) ?: return null
|
||||||
var rate = JsonHelper.safeGetDoubleAllowNull(jsonObject, "rate")
|
|
||||||
var isAbsolute = JsonHelper.safeGetBooleanAllowNull(jsonObject, "isAbsolute")
|
|
||||||
val percent = JsonHelper.safeGetDoubleAllowNull(jsonObject, "percent")
|
val percent = JsonHelper.safeGetDoubleAllowNull(jsonObject, "percent")
|
||||||
val absolute = JsonHelper.safeGetDoubleAllowNull(jsonObject, "absolute")
|
val absolute = JsonHelper.safeGetDoubleAllowNull(jsonObject, "absolute")
|
||||||
val duration = JsonHelper.safeGetLongAllowNull(jsonObject, "duration") ?: return null
|
val duration = JsonHelper.safeGetLongAllowNull(jsonObject, "duration") ?: return null
|
||||||
|
@ -99,17 +97,16 @@ fun temporaryBasalFromJson(jsonObject: JSONObject): TemporaryBasal? {
|
||||||
val pumpType = InterfaceIDs.PumpType.fromString(JsonHelper.safeGetStringAllowNull(jsonObject, "pumpType", null))
|
val pumpType = InterfaceIDs.PumpType.fromString(JsonHelper.safeGetStringAllowNull(jsonObject, "pumpType", null))
|
||||||
val pumpSerial = JsonHelper.safeGetStringAllowNull(jsonObject, "pumpSerial", null)
|
val pumpSerial = JsonHelper.safeGetStringAllowNull(jsonObject, "pumpSerial", null)
|
||||||
|
|
||||||
if (rate == null) {
|
val rate: Double
|
||||||
if (absolute != null) {
|
val isAbsolute: Boolean
|
||||||
rate = absolute
|
if (absolute != null) {
|
||||||
isAbsolute = true
|
rate = absolute
|
||||||
} else if (percent != null) {
|
isAbsolute = true
|
||||||
rate = percent + 100
|
} else if (percent != null) {
|
||||||
isAbsolute = false
|
rate = percent + 100
|
||||||
} else return null
|
isAbsolute = false
|
||||||
}
|
} else return null
|
||||||
if (isAbsolute == null) return null
|
if (duration == 0L && durationInMilliseconds == null) return null
|
||||||
if (duration == 0L) return null
|
|
||||||
if (timestamp == 0L) return null
|
if (timestamp == 0L) return null
|
||||||
|
|
||||||
return TemporaryBasal(
|
return TemporaryBasal(
|
||||||
|
@ -173,7 +170,15 @@ fun TemporaryBasal.iobCalc(time: Long, profile: Profile, insulinInterface: Insul
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
fun TemporaryBasal.iobCalc(time: Long, profile: Profile, lastAutosensResult: AutosensResult, exercise_mode: Boolean, half_basal_exercise_target: Int, isTempTarget: Boolean, insulinInterface: Insulin): IobTotal {
|
fun TemporaryBasal.iobCalc(
|
||||||
|
time: Long,
|
||||||
|
profile: Profile,
|
||||||
|
lastAutosensResult: AutosensResult,
|
||||||
|
exercise_mode: Boolean,
|
||||||
|
half_basal_exercise_target: Int,
|
||||||
|
isTempTarget: Boolean,
|
||||||
|
insulinInterface: Insulin
|
||||||
|
): IobTotal {
|
||||||
val result = IobTotal(time)
|
val result = IobTotal(time)
|
||||||
val realDuration = getPassedDurationToTimeInMinutes(time)
|
val realDuration = getPassedDurationToTimeInMinutes(time)
|
||||||
var netBasalAmount = 0.0
|
var netBasalAmount = 0.0
|
||||||
|
|
Loading…
Reference in a new issue