From 0abbf55e90321fc90b695a1ba8a73ba7f539da02 Mon Sep 17 00:00:00 2001 From: Philoul Date: Wed, 8 Jun 2022 00:34:53 +0200 Subject: [PATCH] Fix Crash L137 --- .../general/autotune/AutotunePlugin.kt | 44 ++++++++++--------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/autotune/AutotunePlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/autotune/AutotunePlugin.kt index 699611fe87..588c846be2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/autotune/AutotunePlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/autotune/AutotunePlugin.kt @@ -143,37 +143,39 @@ class AutotunePlugin @Inject constructor( currentCalcDay++ log("Tune day " + (i + 1) + " of " + daysBack + " (" + currentCalcDay + " of " + calcDays + ")") - tunedProfile?.let { tunedProfile -> - autotuneIob.initializeData(from, to, tunedProfile) //autotuneIob contains BG and Treatments data from history (<=> query for ns-treatments and ns-entries) + tunedProfile?.let { it -> + autotuneIob.initializeData(from, to, it) //autotuneIob contains BG and Treatments data from history (<=> query for ns-treatments and ns-entries) autotuneFS.exportEntries(autotuneIob) //<=> ns-entries.yyyymmdd.json files exported for results compare with oref0 autotune on virtual machine autotuneFS.exportTreatments(autotuneIob) //<=> ns-treatments.yyyymmdd.json files exported for results compare with oref0 autotune on virtual machine (include treatments ,tempBasal and extended - preppedGlucose = autotunePrep.categorize(tunedProfile) //<=> autotune.yyyymmdd.json files exported for results compare with oref0 autotune on virtual machine + preppedGlucose = autotunePrep.categorize(it) //<=> autotune.yyyymmdd.json files exported for results compare with oref0 autotune on virtual machine + preppedGlucose?.let { preppedGlucose -> //preppedGlucose and tunedProfile should never be null here + autotuneFS.exportPreppedGlucose(preppedGlucose) + tunedProfile = autotuneCore.tuneAllTheThings(preppedGlucose, it, pumpProfile).also { tunedProfile -> + autotuneFS.exportTunedProfile(tunedProfile!!) //<=> newprofile.yyyymmdd.json files exported for results compare with oref0 autotune on virtual machine + if (currentCalcDay < calcDays) { + log("Partial result for day ${i + 1}".trimIndent()) + result = rh.gs(R.string.autotune_partial_result, currentCalcDay, calcDays) + rxBus.send(EventAutotuneUpdateGui()) + } + logResult = showResults(tunedProfile, pumpProfile) + if (detailedLog) + autotuneFS.exportLog(lastRun, i + 1) + } + } + ?: { + log("preppedGlucose is null on day ${i + 1}") + tunedProfile = null + } } - - if (preppedGlucose == null || tunedProfile == null) { + if (tunedProfile == null) { result = rh.gs(R.string.autotune_error) - log(result) + log("TunedProfile is null on day ${i + 1}") calculationRunning = false rxBus.send(EventAutotuneUpdateGui()) - tunedProfile = null autotuneFS.exportResult(result) autotuneFS.exportLogAndZip(lastRun) return result } - preppedGlucose?.let { preppedGlucose -> //preppedGlucose and tunedProfile should never be null here - autotuneFS.exportPreppedGlucose(preppedGlucose) - tunedProfile = autotuneCore.tuneAllTheThings(preppedGlucose, tunedProfile!!, pumpProfile) - } - // localInsulin = LocalInsulin("TunedInsulin", tunedProfile!!.peak, tunedProfile!!.dia) // Todo: Add tune Insulin option - autotuneFS.exportTunedProfile(tunedProfile!!) //<=> newprofile.yyyymmdd.json files exported for results compare with oref0 autotune on virtual machine - if (currentCalcDay < calcDays) { - log("Partial result for day ${i + 1}".trimIndent()) - result = rh.gs(R.string.autotune_partial_result, currentCalcDay, calcDays) - rxBus.send(EventAutotuneUpdateGui()) - } - logResult = showResults(tunedProfile, pumpProfile) - if (detailedLog) - autotuneFS.exportLog(lastRun, i + 1) } } result = rh.gs(R.string.autotune_result, dateUtil.dateAndTimeString(lastRun))