Improve APS result logging

This commit is contained in:
Milos Kozak 2021-06-02 16:54:58 +02:00
parent fedba23405
commit f74955d062

View file

@ -30,6 +30,7 @@ import kotlin.math.max
/** /**
* Created by mike on 09.06.2016. * Created by mike on 09.06.2016.
*/ */
@Suppress("LeakingThis")
open class APSResult @Inject constructor(val injector: HasAndroidInjector) { open class APSResult @Inject constructor(val injector: HasAndroidInjector) {
@Inject lateinit var aapsLogger: AAPSLogger @Inject lateinit var aapsLogger: AAPSLogger
@ -42,7 +43,7 @@ open class APSResult @Inject constructor(val injector: HasAndroidInjector) {
@Inject lateinit var dateUtil: DateUtil @Inject lateinit var dateUtil: DateUtil
var date: Long = 0 var date: Long = 0
var reason: String? = null var reason: String = ""
var rate = 0.0 var rate = 0.0
var percent = 0 var percent = 0
var usePercent = false var usePercent = false
@ -102,16 +103,16 @@ open class APSResult @Inject constructor(val injector: HasAndroidInjector) {
val pump = activePlugin.activePump val pump = activePlugin.activePump
if (isChangeRequested) { if (isChangeRequested) {
// rate // rate
var ret: String = if (rate == 0.0 && duration == 0) "${resourceHelper.gs(R.string.canceltemp)}\n" var ret: String = if (rate == 0.0 && duration == 0) "${resourceHelper.gs(R.string.canceltemp)} "
else if (rate == -1.0) "${resourceHelper.gs(R.string.let_temp_basal_run)}\n" else if (rate == -1.0) "${resourceHelper.gs(R.string.let_temp_basal_run)}\n"
else if (usePercent) "${resourceHelper.gs(R.string.rate)}: ${DecimalFormatter.to2Decimal(percent.toDouble())}% (${DecimalFormatter.to2Decimal(percent * pump.baseBasalRate / 100.0)} U/h)\n" + else if (usePercent) "${resourceHelper.gs(R.string.rate)}: ${DecimalFormatter.to2Decimal(percent.toDouble())}% (${DecimalFormatter.to2Decimal(percent * pump.baseBasalRate / 100.0)} U/h) " +
"${resourceHelper.gs(R.string.duration)}: ${DecimalFormatter.to2Decimal(duration.toDouble())} min\n" "${resourceHelper.gs(R.string.duration)}: ${DecimalFormatter.to2Decimal(duration.toDouble())} min "
else "${resourceHelper.gs(R.string.rate)}: ${DecimalFormatter.to2Decimal(rate)} U/h (${DecimalFormatter.to2Decimal(rate / pump.baseBasalRate * 100)}%) " + else "${resourceHelper.gs(R.string.rate)}: ${DecimalFormatter.to2Decimal(rate)} U/h (${DecimalFormatter.to2Decimal(rate / pump.baseBasalRate * 100)}%) " +
"${resourceHelper.gs(R.string.duration)}: ${DecimalFormatter.to2Decimal(duration.toDouble())} min\n" "${resourceHelper.gs(R.string.duration)}: ${DecimalFormatter.to2Decimal(duration.toDouble())} min "
// smb // smb
if (smb != 0.0) ret += "SMB: ${DecimalFormatter.toPumpSupportedBolus(smb, activePlugin.activePump, resourceHelper)}\n" if (smb != 0.0) ret += "SMB: ${DecimalFormatter.toPumpSupportedBolus(smb, activePlugin.activePump, resourceHelper)} "
if (isCarbsRequired) { if (isCarbsRequired) {
ret += "$carbsRequiredText\n" ret += "$carbsRequiredText "
} }
// reason // reason
@ -140,7 +141,7 @@ open class APSResult @Inject constructor(val injector: HasAndroidInjector) {
} }
// reason // reason
ret += "<b>" + resourceHelper.gs(R.string.reason) + "</b>: " + reason!!.replace("<", "&lt;").replace(">", "&gt;") ret += "<b>" + resourceHelper.gs(R.string.reason) + "</b>: " + reason.replace("<", "&lt;").replace(">", "&gt;")
return fromHtml(ret) return fromHtml(ret)
} }
return if (isCarbsRequired) { return if (isCarbsRequired) {
@ -156,7 +157,7 @@ open class APSResult @Inject constructor(val injector: HasAndroidInjector) {
protected fun doClone(newResult: APSResult) { protected fun doClone(newResult: APSResult) {
newResult.date = date newResult.date = date
newResult.reason = if (reason != null) reason else null newResult.reason = reason
newResult.rate = rate newResult.rate = rate
newResult.duration = duration newResult.duration = duration
newResult.tempBasalRequested = tempBasalRequested newResult.tempBasalRequested = tempBasalRequested