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