Merge pull request #1747 from Philoul/Fix/ATCrashlytics

Fix Autotune Crashes
This commit is contained in:
Milos Kozak 2022-05-19 13:09:09 +02:00 committed by GitHub
commit 12466b1951
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View file

@ -312,7 +312,8 @@ class AutotuneFragment : DaggerFragment() {
binding.autotuneCompare.visibility = View.VISIBLE
}
else -> {
binding.autotuneRun.visibility = View.VISIBLE
if (profile.isValid)
binding.autotuneRun.visibility = View.VISIBLE
binding.autotuneCheckInputProfile.visibility = View.VISIBLE
}
}
@ -337,7 +338,8 @@ class AutotuneFragment : DaggerFragment() {
warning = rh.gs(R.string.profileswitch_ismissing)
return warning
}
profileFunction.getProfile()?.let {
profileFunction.getProfile()?.let { currentProfile ->
profile = ATProfile(profileStore.getSpecificProfile(profileName)?.let { ProfileSealed.Pure(it) } ?:currentProfile, LocalInsulin(""), injector)
if (!profile.isValid) return rh.gs(R.string.autotune_profile_invalid)
if (profile.icSize > 1) {
warning += nl + rh.gs(R.string.autotune_ic_warning, profile.icSize, profile.ic)

View file

@ -235,11 +235,15 @@ class ATProfile(profile: Profile, var localInsulin: LocalInsulin, val injector:
isValid = profile.isValid
if (isValid) {
//initialize tuned value with current profile values
var minBasal = 1.0
for (h in 0..23) {
basal[h] = Round.roundTo(profile.basalBlocks.blockValueBySeconds(T.hours(h.toLong()).secs().toInt(), 1.0, 0), 0.001)
minBasal = Math.min(minBasal, basal[h])
}
ic = avgIC
isf = avgISF
if (ic * isf * minBasal == 0.0) // Additional validity check to avoid error later in AutotunePrep
isValid = false
pumpProfile = profile
pumpProfileAvgIC = avgIC
pumpProfileAvgISF = avgISF