From f22c8ca642be6bb686e389edf8e888801d061419 Mon Sep 17 00:00:00 2001 From: Philoul Date: Tue, 16 Aug 2022 22:34:33 +0200 Subject: [PATCH 1/3] Fix ExtendedBolus and EmulatingTempBasal --- .../plugins/general/autotune/AutotuneIob.kt | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/autotune/AutotuneIob.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/autotune/AutotuneIob.kt index 6b29491848..64d83359c8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/autotune/AutotuneIob.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/autotune/AutotuneIob.kt @@ -138,23 +138,17 @@ open class AutotuneIob @Inject constructor( //nsTreatment is used only for export data private fun initializeExtendedBolusData(from: Long, to: Long, tunedProfile: ATProfile) { val extendedBoluses = repository.getExtendedBolusDataFromTimeToTime(from, to, false).blockingGet() - val pumpInterface = activePlugin.activePump - if (pumpInterface.isFakingTempsByExtendedBoluses) { - for (i in extendedBoluses.indices) { - val eb = extendedBoluses[i] - if (eb.isValid) + for (i in extendedBoluses.indices) { + val eb = extendedBoluses[i] + if (eb.isValid) + if (eb.isEmulatingTempBasal) { profileFunction.getProfile(eb.timestamp)?.let { toSplittedTimestampTB(eb.toTemporaryBasal(it), tunedProfile) } - } - } else { - for (i in extendedBoluses.indices) { - val eb = extendedBoluses[i] - if (eb.isValid) { + } else { nsTreatments.add(NsTreatment(eb)) boluses.addAll(convertToBoluses(eb)) } - } } } From 0af05deae9e6f51fc8fd096f660c5180a346cb62 Mon Sep 17 00:00:00 2001 From: Philoul Date: Tue, 16 Aug 2022 23:06:28 +0200 Subject: [PATCH 2/3] Abort Autotune Run if no valid profile on first selected day --- .../androidaps/plugins/general/autotune/AutotuneIob.kt | 8 ++++---- .../plugins/general/autotune/AutotunePlugin.kt | 9 +++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/autotune/AutotuneIob.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/autotune/AutotuneIob.kt index 64d83359c8..649838a0b0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/autotune/AutotuneIob.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/autotune/AutotuneIob.kt @@ -35,10 +35,8 @@ open class AutotuneIob @Inject constructor( private val profileFunction: ProfileFunction, private val sp: SP, private val dateUtil: DateUtil, - private val activePlugin: ActivePlugin, private val autotuneFS: AutotuneFS ) { - private var nsTreatments = ArrayList() private var dia: Double = Constants.defaultDIA var boluses: ArrayList = ArrayList() @@ -54,7 +52,11 @@ open class AutotuneIob @Inject constructor( startBG = from endBG = to nsTreatments.clear() + meals.clear() + boluses.clear() tempBasals = ArrayList() + if (profileFunction.getProfile(from - range()) == null) + return initializeBgreadings(from, to) initializeTreatmentData(from - range(), to) initializeTempBasalData(from - range(), to, tunedProfile) @@ -91,8 +93,6 @@ open class AutotuneIob @Inject constructor( aapsLogger.debug(LTag.AUTOTUNE, "Check BG date: BG Size: " + glucose.size + " OldestBG: " + dateUtil.dateAndTimeAndSecondsString(oldestBgDate) + " to: " + dateUtil.dateAndTimeAndSecondsString(to)) val tmpCarbs = repository.getCarbsDataFromTimeToTimeExpanded(from, to, false).blockingGet() aapsLogger.debug(LTag.AUTOTUNE, "Nb treatments after query: " + tmpCarbs.size) - meals.clear() - boluses.clear() var nbCarbs = 0 for (i in tmpCarbs.indices) { val tp = tmpCarbs[i] 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 38c9781de6..6690cc3235 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 @@ -134,6 +134,15 @@ class AutotunePlugin @Inject constructor( log("Tune day " + (i + 1) + " of " + daysBack) tunedProfile?.let { it -> autotuneIob.initializeData(from, to, it) //autotuneIob contains BG and Treatments data from history (<=> query for ns-treatments and ns-entries) + if (autotuneIob.boluses.size == 0) { + result = rh.gs(R.string.autotune_error) + log("No basal data on day ${i + 1}") + autotuneFS.exportResult(result) + autotuneFS.exportLogAndZip(lastRun) + rxBus.send(EventAutotuneUpdateGui()) + calculationRunning = false + return + } 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(it) //<=> autotune.yyyymmdd.json files exported for results compare with oref0 autotune on virtual machine From b1be726cc3bdde731bb97548f850b8c9178b6d1b Mon Sep 17 00:00:00 2001 From: Philoul Date: Wed, 17 Aug 2022 08:09:42 +0200 Subject: [PATCH 3/3] Autotune Fix Unit tests --- .../androidaps/plugins/general/autotune/AutotunePrepTest.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/autotune/AutotunePrepTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/general/autotune/AutotunePrepTest.kt index ea797d8566..764be8bb56 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/general/autotune/AutotunePrepTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/autotune/AutotunePrepTest.kt @@ -317,7 +317,6 @@ class AutotunePrepTest : TestBaseWithProfile() { profileFunction, sp, dateUtil, - activePlugin, autotuneFS ) {