Merge pull request #2023 from Philoul/Fix/Fix_Autotune_Crash
Fix Autotune crashed
This commit is contained in:
commit
e9da50cefe
|
@ -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<NsTreatment>()
|
||||
private var dia: Double = Constants.defaultDIA
|
||||
var boluses: ArrayList<Bolus> = ArrayList()
|
||||
|
@ -54,7 +52,11 @@ open class AutotuneIob @Inject constructor(
|
|||
startBG = from
|
||||
endBG = to
|
||||
nsTreatments.clear()
|
||||
meals.clear()
|
||||
boluses.clear()
|
||||
tempBasals = ArrayList<TemporaryBasal>()
|
||||
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]
|
||||
|
@ -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))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -317,7 +317,6 @@ class AutotunePrepTest : TestBaseWithProfile() {
|
|||
profileFunction,
|
||||
sp,
|
||||
dateUtil,
|
||||
activePlugin,
|
||||
autotuneFS
|
||||
) {
|
||||
|
||||
|
|
Loading…
Reference in a new issue