Merge pull request #2023 from Philoul/Fix/Fix_Autotune_Crash
Fix Autotune crashed
This commit is contained in:
commit
e9da50cefe
3 changed files with 18 additions and 16 deletions
|
@ -35,10 +35,8 @@ open class AutotuneIob @Inject constructor(
|
||||||
private val profileFunction: ProfileFunction,
|
private val profileFunction: ProfileFunction,
|
||||||
private val sp: SP,
|
private val sp: SP,
|
||||||
private val dateUtil: DateUtil,
|
private val dateUtil: DateUtil,
|
||||||
private val activePlugin: ActivePlugin,
|
|
||||||
private val autotuneFS: AutotuneFS
|
private val autotuneFS: AutotuneFS
|
||||||
) {
|
) {
|
||||||
|
|
||||||
private var nsTreatments = ArrayList<NsTreatment>()
|
private var nsTreatments = ArrayList<NsTreatment>()
|
||||||
private var dia: Double = Constants.defaultDIA
|
private var dia: Double = Constants.defaultDIA
|
||||||
var boluses: ArrayList<Bolus> = ArrayList()
|
var boluses: ArrayList<Bolus> = ArrayList()
|
||||||
|
@ -54,7 +52,11 @@ open class AutotuneIob @Inject constructor(
|
||||||
startBG = from
|
startBG = from
|
||||||
endBG = to
|
endBG = to
|
||||||
nsTreatments.clear()
|
nsTreatments.clear()
|
||||||
|
meals.clear()
|
||||||
|
boluses.clear()
|
||||||
tempBasals = ArrayList<TemporaryBasal>()
|
tempBasals = ArrayList<TemporaryBasal>()
|
||||||
|
if (profileFunction.getProfile(from - range()) == null)
|
||||||
|
return
|
||||||
initializeBgreadings(from, to)
|
initializeBgreadings(from, to)
|
||||||
initializeTreatmentData(from - range(), to)
|
initializeTreatmentData(from - range(), to)
|
||||||
initializeTempBasalData(from - range(), to, tunedProfile)
|
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))
|
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()
|
val tmpCarbs = repository.getCarbsDataFromTimeToTimeExpanded(from, to, false).blockingGet()
|
||||||
aapsLogger.debug(LTag.AUTOTUNE, "Nb treatments after query: " + tmpCarbs.size)
|
aapsLogger.debug(LTag.AUTOTUNE, "Nb treatments after query: " + tmpCarbs.size)
|
||||||
meals.clear()
|
|
||||||
boluses.clear()
|
|
||||||
var nbCarbs = 0
|
var nbCarbs = 0
|
||||||
for (i in tmpCarbs.indices) {
|
for (i in tmpCarbs.indices) {
|
||||||
val tp = tmpCarbs[i]
|
val tp = tmpCarbs[i]
|
||||||
|
@ -138,25 +138,19 @@ open class AutotuneIob @Inject constructor(
|
||||||
//nsTreatment is used only for export data
|
//nsTreatment is used only for export data
|
||||||
private fun initializeExtendedBolusData(from: Long, to: Long, tunedProfile: ATProfile) {
|
private fun initializeExtendedBolusData(from: Long, to: Long, tunedProfile: ATProfile) {
|
||||||
val extendedBoluses = repository.getExtendedBolusDataFromTimeToTime(from, to, false).blockingGet()
|
val extendedBoluses = repository.getExtendedBolusDataFromTimeToTime(from, to, false).blockingGet()
|
||||||
val pumpInterface = activePlugin.activePump
|
|
||||||
if (pumpInterface.isFakingTempsByExtendedBoluses) {
|
|
||||||
for (i in extendedBoluses.indices) {
|
for (i in extendedBoluses.indices) {
|
||||||
val eb = extendedBoluses[i]
|
val eb = extendedBoluses[i]
|
||||||
if (eb.isValid)
|
if (eb.isValid)
|
||||||
|
if (eb.isEmulatingTempBasal) {
|
||||||
profileFunction.getProfile(eb.timestamp)?.let {
|
profileFunction.getProfile(eb.timestamp)?.let {
|
||||||
toSplittedTimestampTB(eb.toTemporaryBasal(it), tunedProfile)
|
toSplittedTimestampTB(eb.toTemporaryBasal(it), tunedProfile)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
for (i in extendedBoluses.indices) {
|
|
||||||
val eb = extendedBoluses[i]
|
|
||||||
if (eb.isValid) {
|
|
||||||
nsTreatments.add(NsTreatment(eb))
|
nsTreatments.add(NsTreatment(eb))
|
||||||
boluses.addAll(convertToBoluses(eb))
|
boluses.addAll(convertToBoluses(eb))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// addNeutralTempBasal will add a fake neutral TBR (100%) to have correct basal rate in exported file for periods without TBR running
|
// addNeutralTempBasal will add a fake neutral TBR (100%) to have correct basal rate in exported file for periods without TBR running
|
||||||
// to be able to compare results between oref0 algo and aaps
|
// to be able to compare results between oref0 algo and aaps
|
||||||
|
|
|
@ -134,6 +134,15 @@ class AutotunePlugin @Inject constructor(
|
||||||
log("Tune day " + (i + 1) + " of " + daysBack)
|
log("Tune day " + (i + 1) + " of " + daysBack)
|
||||||
tunedProfile?.let { it ->
|
tunedProfile?.let { it ->
|
||||||
autotuneIob.initializeData(from, to, it) //autotuneIob contains BG and Treatments data from history (<=> query for ns-treatments and ns-entries)
|
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.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
|
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
|
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,
|
profileFunction,
|
||||||
sp,
|
sp,
|
||||||
dateUtil,
|
dateUtil,
|
||||||
activePlugin,
|
|
||||||
autotuneFS
|
autotuneFS
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue