LocalInsulin -> autotune

This commit is contained in:
Milos Kozak 2022-11-10 14:58:53 +01:00
parent d0a240b417
commit 0442a9ae5b
10 changed files with 15 additions and 18 deletions

View file

@ -1,6 +1,5 @@
package info.nightscout.androidaps.extensions package info.nightscout.androidaps.extensions
import info.nightscout.androidaps.data.LocalInsulin
import info.nightscout.androidaps.interfaces.ActivePlugin import info.nightscout.androidaps.interfaces.ActivePlugin
import info.nightscout.androidaps.interfaces.Insulin import info.nightscout.androidaps.interfaces.Insulin
import info.nightscout.database.entities.Bolus import info.nightscout.database.entities.Bolus
@ -11,9 +10,3 @@ fun Bolus.iobCalc(activePlugin: ActivePlugin, time: Long, dia: Double): Iob {
val insulinInterface: Insulin = activePlugin.activeInsulin val insulinInterface: Insulin = activePlugin.activeInsulin
return insulinInterface.iobCalcForTreatment(this, time, dia) return insulinInterface.iobCalcForTreatment(this, time, dia)
} }
// Add specific calculation for Autotune (reference localInsulin for Peak/dia)
fun Bolus.iobCalc(time: Long, localInsulin: LocalInsulin): Iob {
if (!isValid || type == Bolus.Type.PRIMING ) return Iob()
return localInsulin.iobCalcForTreatment(this, time)
}

View file

@ -1,13 +1,13 @@
package info.nightscout.plugins.general.autotune package info.nightscout.plugins.general.autotune
import info.nightscout.androidaps.data.LocalInsulin
import info.nightscout.interfaces.utils.Round import info.nightscout.interfaces.utils.Round
import info.nightscout.plugins.R import info.nightscout.plugins.R
import info.nightscout.plugins.general.autotune.data.ATProfile import info.nightscout.plugins.general.autotune.data.ATProfile
import info.nightscout.plugins.general.autotune.data.LocalInsulin
import info.nightscout.plugins.general.autotune.data.PreppedGlucose import info.nightscout.plugins.general.autotune.data.PreppedGlucose
import info.nightscout.plugins.utils.Percentile import info.nightscout.plugins.utils.Percentile
import info.nightscout.shared.sharedPreferences.SP import info.nightscout.shared.sharedPreferences.SP
import java.util.* import java.util.Calendar
import javax.inject.Inject import javax.inject.Inject
import javax.inject.Singleton import javax.inject.Singleton
import kotlin.math.max import kotlin.math.max

View file

@ -19,7 +19,6 @@ import android.widget.TableRow
import android.widget.TextView import android.widget.TextView
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import dagger.android.support.DaggerFragment import dagger.android.support.DaggerFragment
import info.nightscout.androidaps.data.LocalInsulin
import info.nightscout.androidaps.data.ProfileSealed import info.nightscout.androidaps.data.ProfileSealed
import info.nightscout.androidaps.dialogs.ProfileViewerDialog import info.nightscout.androidaps.dialogs.ProfileViewerDialog
import info.nightscout.androidaps.interfaces.ActivePlugin import info.nightscout.androidaps.interfaces.ActivePlugin
@ -38,6 +37,7 @@ import info.nightscout.interfaces.utils.Round
import info.nightscout.plugins.R import info.nightscout.plugins.R
import info.nightscout.plugins.databinding.AutotuneFragmentBinding import info.nightscout.plugins.databinding.AutotuneFragmentBinding
import info.nightscout.plugins.general.autotune.data.ATProfile import info.nightscout.plugins.general.autotune.data.ATProfile
import info.nightscout.plugins.general.autotune.data.LocalInsulin
import info.nightscout.plugins.general.autotune.events.EventAutotuneUpdateGui import info.nightscout.plugins.general.autotune.events.EventAutotuneUpdateGui
import info.nightscout.plugins.profile.ProfilePlugin import info.nightscout.plugins.profile.ProfilePlugin
import info.nightscout.rx.AapsSchedulers import info.nightscout.rx.AapsSchedulers

View file

@ -1,8 +1,6 @@
package info.nightscout.plugins.general.autotune package info.nightscout.plugins.general.autotune
import info.nightscout.androidaps.data.LocalInsulin
import info.nightscout.androidaps.extensions.durationInMinutes import info.nightscout.androidaps.extensions.durationInMinutes
import info.nightscout.androidaps.extensions.iobCalc
import info.nightscout.androidaps.extensions.toJson import info.nightscout.androidaps.extensions.toJson
import info.nightscout.androidaps.extensions.toTemporaryBasal import info.nightscout.androidaps.extensions.toTemporaryBasal
import info.nightscout.androidaps.interfaces.Profile import info.nightscout.androidaps.interfaces.Profile
@ -17,10 +15,12 @@ import info.nightscout.database.entities.TherapyEvent
import info.nightscout.database.entities.embedments.InterfaceIDs import info.nightscout.database.entities.embedments.InterfaceIDs
import info.nightscout.database.impl.AppRepository import info.nightscout.database.impl.AppRepository
import info.nightscout.interfaces.Constants import info.nightscout.interfaces.Constants
import info.nightscout.interfaces.iob.Iob
import info.nightscout.interfaces.iob.IobTotal import info.nightscout.interfaces.iob.IobTotal
import info.nightscout.interfaces.utils.Round import info.nightscout.interfaces.utils.Round
import info.nightscout.plugins.R import info.nightscout.plugins.R
import info.nightscout.plugins.general.autotune.data.ATProfile import info.nightscout.plugins.general.autotune.data.ATProfile
import info.nightscout.plugins.general.autotune.data.LocalInsulin
import info.nightscout.plugins.sync.nsclient.extensions.toJson import info.nightscout.plugins.sync.nsclient.extensions.toJson
import info.nightscout.rx.logging.AAPSLogger import info.nightscout.rx.logging.AAPSLogger
import info.nightscout.rx.logging.LTag import info.nightscout.rx.logging.LTag
@ -247,6 +247,11 @@ open class AutotuneIob @Inject constructor(
open fun getIOB(time: Long, localInsulin: LocalInsulin): IobTotal = open fun getIOB(time: Long, localInsulin: LocalInsulin): IobTotal =
getCalculationToTimeTreatments(time, localInsulin).round() getCalculationToTimeTreatments(time, localInsulin).round()
// Add specific calculation for Autotune (reference localInsulin for Peak/dia)
fun Bolus.iobCalc(time: Long, localInsulin: LocalInsulin): Iob {
if (!isValid || type == Bolus.Type.PRIMING ) return Iob()
return localInsulin.iobCalcForTreatment(this, time)
}
private fun getCalculationToTimeTreatments(time: Long, localInsulin: LocalInsulin): IobTotal { private fun getCalculationToTimeTreatments(time: Long, localInsulin: LocalInsulin): IobTotal {
val total = IobTotal(time) val total = IobTotal(time)
val detailedLog = sp.getBoolean(R.string.key_autotune_additional_log, false) val detailedLog = sp.getBoolean(R.string.key_autotune_additional_log, false)

View file

@ -2,7 +2,6 @@ package info.nightscout.plugins.general.autotune
import android.view.View import android.view.View
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.data.LocalInsulin
import info.nightscout.androidaps.data.ProfileSealed import info.nightscout.androidaps.data.ProfileSealed
import info.nightscout.androidaps.interfaces.ActivePlugin import info.nightscout.androidaps.interfaces.ActivePlugin
import info.nightscout.androidaps.interfaces.Insulin import info.nightscout.androidaps.interfaces.Insulin
@ -22,6 +21,7 @@ import info.nightscout.interfaces.utils.JsonHelper
import info.nightscout.interfaces.utils.MidnightTime import info.nightscout.interfaces.utils.MidnightTime
import info.nightscout.plugins.R import info.nightscout.plugins.R
import info.nightscout.plugins.general.autotune.data.ATProfile import info.nightscout.plugins.general.autotune.data.ATProfile
import info.nightscout.plugins.general.autotune.data.LocalInsulin
import info.nightscout.plugins.general.autotune.data.PreppedGlucose import info.nightscout.plugins.general.autotune.data.PreppedGlucose
import info.nightscout.plugins.general.autotune.events.EventAutotuneUpdateGui import info.nightscout.plugins.general.autotune.events.EventAutotuneUpdateGui
import info.nightscout.plugins.profile.ProfilePlugin import info.nightscout.plugins.profile.ProfilePlugin

View file

@ -1,6 +1,5 @@
package info.nightscout.plugins.general.autotune package info.nightscout.plugins.general.autotune
import info.nightscout.androidaps.data.LocalInsulin
import info.nightscout.database.entities.Bolus import info.nightscout.database.entities.Bolus
import info.nightscout.database.entities.Carbs import info.nightscout.database.entities.Carbs
import info.nightscout.database.entities.GlucoseValue import info.nightscout.database.entities.GlucoseValue
@ -11,6 +10,7 @@ import info.nightscout.plugins.general.autotune.data.ATProfile
import info.nightscout.plugins.general.autotune.data.BGDatum import info.nightscout.plugins.general.autotune.data.BGDatum
import info.nightscout.plugins.general.autotune.data.CRDatum import info.nightscout.plugins.general.autotune.data.CRDatum
import info.nightscout.plugins.general.autotune.data.DiaDeviation import info.nightscout.plugins.general.autotune.data.DiaDeviation
import info.nightscout.plugins.general.autotune.data.LocalInsulin
import info.nightscout.plugins.general.autotune.data.PeakDeviation import info.nightscout.plugins.general.autotune.data.PeakDeviation
import info.nightscout.plugins.general.autotune.data.PreppedGlucose import info.nightscout.plugins.general.autotune.data.PreppedGlucose
import info.nightscout.shared.sharedPreferences.SP import info.nightscout.shared.sharedPreferences.SP

View file

@ -1,7 +1,6 @@
package info.nightscout.plugins.general.autotune.data package info.nightscout.plugins.general.autotune.data
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.data.LocalInsulin
import info.nightscout.androidaps.data.ProfileSealed import info.nightscout.androidaps.data.ProfileSealed
import info.nightscout.androidaps.data.PureProfile import info.nightscout.androidaps.data.PureProfile
import info.nightscout.androidaps.extensions.blockValueBySeconds import info.nightscout.androidaps.extensions.blockValueBySeconds

View file

@ -1,4 +1,4 @@
package info.nightscout.androidaps.data package info.nightscout.plugins.general.autotune.data
import info.nightscout.database.entities.Bolus import info.nightscout.database.entities.Bolus
import info.nightscout.interfaces.iob.Iob import info.nightscout.interfaces.iob.Iob

View file

@ -2,7 +2,6 @@ package info.nightscout.plugins.general.autotune
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.TestBaseWithProfile import info.nightscout.androidaps.TestBaseWithProfile
import info.nightscout.androidaps.data.LocalInsulin
import info.nightscout.androidaps.data.ProfileSealed import info.nightscout.androidaps.data.ProfileSealed
import info.nightscout.androidaps.data.PureProfile import info.nightscout.androidaps.data.PureProfile
import info.nightscout.database.entities.data.Block import info.nightscout.database.entities.data.Block
@ -11,6 +10,7 @@ import info.nightscout.interfaces.GlucoseUnit
import info.nightscout.interfaces.utils.JsonHelper import info.nightscout.interfaces.utils.JsonHelper
import info.nightscout.plugins.R import info.nightscout.plugins.R
import info.nightscout.plugins.general.autotune.data.ATProfile import info.nightscout.plugins.general.autotune.data.ATProfile
import info.nightscout.plugins.general.autotune.data.LocalInsulin
import info.nightscout.plugins.general.autotune.data.PreppedGlucose import info.nightscout.plugins.general.autotune.data.PreppedGlucose
import info.nightscout.shared.sharedPreferences.SP import info.nightscout.shared.sharedPreferences.SP
import info.nightscout.shared.utils.DateUtil import info.nightscout.shared.utils.DateUtil

View file

@ -2,7 +2,6 @@ package info.nightscout.plugins.general.autotune
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.TestBaseWithProfile import info.nightscout.androidaps.TestBaseWithProfile
import info.nightscout.androidaps.data.LocalInsulin
import info.nightscout.androidaps.data.ProfileSealed import info.nightscout.androidaps.data.ProfileSealed
import info.nightscout.androidaps.data.PureProfile import info.nightscout.androidaps.data.PureProfile
import info.nightscout.androidaps.extensions.shiftBlock import info.nightscout.androidaps.extensions.shiftBlock
@ -18,6 +17,7 @@ import info.nightscout.interfaces.iob.IobTotal
import info.nightscout.interfaces.utils.JsonHelper import info.nightscout.interfaces.utils.JsonHelper
import info.nightscout.plugins.R import info.nightscout.plugins.R
import info.nightscout.plugins.general.autotune.data.ATProfile import info.nightscout.plugins.general.autotune.data.ATProfile
import info.nightscout.plugins.general.autotune.data.LocalInsulin
import info.nightscout.plugins.general.autotune.data.PreppedGlucose import info.nightscout.plugins.general.autotune.data.PreppedGlucose
import info.nightscout.rx.logging.AAPSLogger import info.nightscout.rx.logging.AAPSLogger
import info.nightscout.shared.sharedPreferences.SP import info.nightscout.shared.sharedPreferences.SP