IobTotal -> interfaces
This commit is contained in:
parent
28d6a73c2f
commit
d0a240b417
33 changed files with 231 additions and 201 deletions
|
@ -34,6 +34,7 @@ import info.nightscout.androidaps.utils.protection.ProtectionCheck
|
||||||
import info.nightscout.androidaps.utils.protection.ProtectionCheck.Protection.BOLUS
|
import info.nightscout.androidaps.utils.protection.ProtectionCheck.Protection.BOLUS
|
||||||
import info.nightscout.androidaps.utils.wizard.BolusWizard
|
import info.nightscout.androidaps.utils.wizard.BolusWizard
|
||||||
import info.nightscout.core.fabric.FabricPrivacy
|
import info.nightscout.core.fabric.FabricPrivacy
|
||||||
|
import info.nightscout.core.iob.round
|
||||||
import info.nightscout.database.impl.AppRepository
|
import info.nightscout.database.impl.AppRepository
|
||||||
import info.nightscout.database.impl.ValueWrapper
|
import info.nightscout.database.impl.ValueWrapper
|
||||||
import info.nightscout.interfaces.Constants
|
import info.nightscout.interfaces.Constants
|
||||||
|
|
|
@ -2,7 +2,6 @@ package info.nightscout.androidaps.plugins.aps.openAPSAMA
|
||||||
|
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.androidaps.R
|
import info.nightscout.androidaps.R
|
||||||
import info.nightscout.androidaps.data.IobTotal
|
|
||||||
import info.nightscout.androidaps.extensions.convertedToAbsolute
|
import info.nightscout.androidaps.extensions.convertedToAbsolute
|
||||||
import info.nightscout.androidaps.extensions.getPassedDurationToTimeInMinutes
|
import info.nightscout.androidaps.extensions.getPassedDurationToTimeInMinutes
|
||||||
import info.nightscout.androidaps.extensions.plannedRemainingMinutes
|
import info.nightscout.androidaps.extensions.plannedRemainingMinutes
|
||||||
|
@ -17,6 +16,7 @@ import info.nightscout.androidaps.plugins.aps.loop.ScriptReader
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus
|
||||||
import info.nightscout.interfaces.GlucoseUnit
|
import info.nightscout.interfaces.GlucoseUnit
|
||||||
import info.nightscout.interfaces.aps.SMBDefaults
|
import info.nightscout.interfaces.aps.SMBDefaults
|
||||||
|
import info.nightscout.interfaces.iob.IobTotal
|
||||||
import info.nightscout.interfaces.iob.MealData
|
import info.nightscout.interfaces.iob.MealData
|
||||||
import info.nightscout.rx.logging.AAPSLogger
|
import info.nightscout.rx.logging.AAPSLogger
|
||||||
import info.nightscout.rx.logging.LTag
|
import info.nightscout.rx.logging.LTag
|
||||||
|
|
|
@ -2,7 +2,6 @@ package info.nightscout.androidaps.plugins.aps.openAPSSMB
|
||||||
|
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.androidaps.R
|
import info.nightscout.androidaps.R
|
||||||
import info.nightscout.androidaps.data.IobTotal
|
|
||||||
import info.nightscout.androidaps.extensions.convertedToAbsolute
|
import info.nightscout.androidaps.extensions.convertedToAbsolute
|
||||||
import info.nightscout.androidaps.extensions.getPassedDurationToTimeInMinutes
|
import info.nightscout.androidaps.extensions.getPassedDurationToTimeInMinutes
|
||||||
import info.nightscout.androidaps.extensions.plannedRemainingMinutes
|
import info.nightscout.androidaps.extensions.plannedRemainingMinutes
|
||||||
|
@ -18,6 +17,7 @@ import info.nightscout.androidaps.plugins.aps.loop.ScriptReader
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus
|
||||||
import info.nightscout.interfaces.GlucoseUnit
|
import info.nightscout.interfaces.GlucoseUnit
|
||||||
import info.nightscout.interfaces.aps.SMBDefaults
|
import info.nightscout.interfaces.aps.SMBDefaults
|
||||||
|
import info.nightscout.interfaces.iob.IobTotal
|
||||||
import info.nightscout.interfaces.iob.MealData
|
import info.nightscout.interfaces.iob.MealData
|
||||||
import info.nightscout.rx.logging.AAPSLogger
|
import info.nightscout.rx.logging.AAPSLogger
|
||||||
import info.nightscout.rx.logging.LTag
|
import info.nightscout.rx.logging.LTag
|
||||||
|
|
|
@ -2,7 +2,6 @@ package info.nightscout.androidaps.plugins.aps.openAPSSMBDynamicISF
|
||||||
|
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.androidaps.R
|
import info.nightscout.androidaps.R
|
||||||
import info.nightscout.androidaps.data.IobTotal
|
|
||||||
import info.nightscout.androidaps.extensions.convertedToAbsolute
|
import info.nightscout.androidaps.extensions.convertedToAbsolute
|
||||||
import info.nightscout.androidaps.extensions.getPassedDurationToTimeInMinutes
|
import info.nightscout.androidaps.extensions.getPassedDurationToTimeInMinutes
|
||||||
import info.nightscout.androidaps.extensions.plannedRemainingMinutes
|
import info.nightscout.androidaps.extensions.plannedRemainingMinutes
|
||||||
|
@ -20,6 +19,7 @@ import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus
|
||||||
import info.nightscout.database.impl.AppRepository
|
import info.nightscout.database.impl.AppRepository
|
||||||
import info.nightscout.interfaces.GlucoseUnit
|
import info.nightscout.interfaces.GlucoseUnit
|
||||||
import info.nightscout.interfaces.aps.SMBDefaults
|
import info.nightscout.interfaces.aps.SMBDefaults
|
||||||
|
import info.nightscout.interfaces.iob.IobTotal
|
||||||
import info.nightscout.interfaces.iob.MealData
|
import info.nightscout.interfaces.iob.MealData
|
||||||
import info.nightscout.interfaces.utils.Round
|
import info.nightscout.interfaces.utils.Round
|
||||||
import info.nightscout.rx.logging.AAPSLogger
|
import info.nightscout.rx.logging.AAPSLogger
|
||||||
|
|
|
@ -18,6 +18,7 @@ import info.nightscout.androidaps.receivers.Intents
|
||||||
import info.nightscout.androidaps.receivers.ReceiverStatusStore
|
import info.nightscout.androidaps.receivers.ReceiverStatusStore
|
||||||
import info.nightscout.androidaps.utils.DefaultValueHelper
|
import info.nightscout.androidaps.utils.DefaultValueHelper
|
||||||
import info.nightscout.core.fabric.FabricPrivacy
|
import info.nightscout.core.fabric.FabricPrivacy
|
||||||
|
import info.nightscout.core.iob.round
|
||||||
import info.nightscout.interfaces.Config
|
import info.nightscout.interfaces.Config
|
||||||
import info.nightscout.interfaces.plugin.PluginBase
|
import info.nightscout.interfaces.plugin.PluginBase
|
||||||
import info.nightscout.interfaces.plugin.PluginDescription
|
import info.nightscout.interfaces.plugin.PluginDescription
|
||||||
|
|
|
@ -18,6 +18,7 @@ import info.nightscout.androidaps.interfaces.ProfileFunction
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatusProvider
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatusProvider
|
||||||
import info.nightscout.androidaps.utils.DecimalFormatter
|
import info.nightscout.androidaps.utils.DecimalFormatter
|
||||||
import info.nightscout.core.fabric.FabricPrivacy
|
import info.nightscout.core.fabric.FabricPrivacy
|
||||||
|
import info.nightscout.core.iob.round
|
||||||
import info.nightscout.interfaces.Constants
|
import info.nightscout.interfaces.Constants
|
||||||
import info.nightscout.interfaces.NotificationHolder
|
import info.nightscout.interfaces.NotificationHolder
|
||||||
import info.nightscout.interfaces.plugin.PluginBase
|
import info.nightscout.interfaces.plugin.PluginBase
|
||||||
|
|
|
@ -31,6 +31,7 @@ import info.nightscout.androidaps.utils.wizard.BolusWizard
|
||||||
import info.nightscout.androidaps.utils.wizard.QuickWizard
|
import info.nightscout.androidaps.utils.wizard.QuickWizard
|
||||||
import info.nightscout.androidaps.utils.wizard.QuickWizardEntry
|
import info.nightscout.androidaps.utils.wizard.QuickWizardEntry
|
||||||
import info.nightscout.core.fabric.FabricPrivacy
|
import info.nightscout.core.fabric.FabricPrivacy
|
||||||
|
import info.nightscout.core.iob.round
|
||||||
import info.nightscout.database.entities.Bolus
|
import info.nightscout.database.entities.Bolus
|
||||||
import info.nightscout.database.entities.GlucoseValue
|
import info.nightscout.database.entities.GlucoseValue
|
||||||
import info.nightscout.database.entities.TemporaryBasal
|
import info.nightscout.database.entities.TemporaryBasal
|
||||||
|
|
|
@ -4,7 +4,6 @@ import androidx.collection.LongSparseArray
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.androidaps.R
|
import info.nightscout.androidaps.R
|
||||||
import info.nightscout.androidaps.annotations.OpenForTesting
|
import info.nightscout.androidaps.annotations.OpenForTesting
|
||||||
import info.nightscout.androidaps.data.IobTotal
|
|
||||||
import info.nightscout.androidaps.events.EventEffectiveProfileSwitchChanged
|
import info.nightscout.androidaps.events.EventEffectiveProfileSwitchChanged
|
||||||
import info.nightscout.androidaps.events.EventNewBG
|
import info.nightscout.androidaps.events.EventNewBG
|
||||||
import info.nightscout.androidaps.events.EventNewHistoryData
|
import info.nightscout.androidaps.events.EventNewHistoryData
|
||||||
|
@ -21,6 +20,11 @@ import info.nightscout.androidaps.plugins.iob.iobCobCalculator.data.AutosensData
|
||||||
import info.nightscout.androidaps.utils.DecimalFormatter
|
import info.nightscout.androidaps.utils.DecimalFormatter
|
||||||
import info.nightscout.androidaps.workflow.CalculationWorkflow
|
import info.nightscout.androidaps.workflow.CalculationWorkflow
|
||||||
import info.nightscout.core.fabric.FabricPrivacy
|
import info.nightscout.core.fabric.FabricPrivacy
|
||||||
|
import info.nightscout.core.iob.combine
|
||||||
|
import info.nightscout.core.iob.copy
|
||||||
|
import info.nightscout.core.iob.determineBasalJson
|
||||||
|
import info.nightscout.core.iob.plus
|
||||||
|
import info.nightscout.core.iob.round
|
||||||
import info.nightscout.database.entities.Bolus
|
import info.nightscout.database.entities.Bolus
|
||||||
import info.nightscout.database.entities.ExtendedBolus
|
import info.nightscout.database.entities.ExtendedBolus
|
||||||
import info.nightscout.database.entities.TemporaryBasal
|
import info.nightscout.database.entities.TemporaryBasal
|
||||||
|
@ -28,6 +32,7 @@ import info.nightscout.database.entities.interfaces.end
|
||||||
import info.nightscout.database.impl.AppRepository
|
import info.nightscout.database.impl.AppRepository
|
||||||
import info.nightscout.database.impl.ValueWrapper
|
import info.nightscout.database.impl.ValueWrapper
|
||||||
import info.nightscout.interfaces.Constants
|
import info.nightscout.interfaces.Constants
|
||||||
|
import info.nightscout.interfaces.iob.IobTotal
|
||||||
import info.nightscout.interfaces.iob.MealData
|
import info.nightscout.interfaces.iob.MealData
|
||||||
import info.nightscout.interfaces.plugin.PluginBase
|
import info.nightscout.interfaces.plugin.PluginBase
|
||||||
import info.nightscout.interfaces.plugin.PluginDescription
|
import info.nightscout.interfaces.plugin.PluginDescription
|
||||||
|
|
|
@ -20,6 +20,7 @@ import info.nightscout.androidaps.logging.UserEntryLogger
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatusProvider
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatusProvider
|
||||||
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
|
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
|
||||||
|
import info.nightscout.core.iob.round
|
||||||
import info.nightscout.database.entities.BolusCalculatorResult
|
import info.nightscout.database.entities.BolusCalculatorResult
|
||||||
import info.nightscout.database.entities.OfflineEvent
|
import info.nightscout.database.entities.OfflineEvent
|
||||||
import info.nightscout.database.entities.TemporaryTarget
|
import info.nightscout.database.entities.TemporaryTarget
|
||||||
|
|
|
@ -8,6 +8,7 @@ import info.nightscout.androidaps.interfaces.Loop
|
||||||
import info.nightscout.androidaps.interfaces.Profile
|
import info.nightscout.androidaps.interfaces.Profile
|
||||||
import info.nightscout.androidaps.interfaces.ProfileFunction
|
import info.nightscout.androidaps.interfaces.ProfileFunction
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatusProvider
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatusProvider
|
||||||
|
import info.nightscout.core.iob.round
|
||||||
import info.nightscout.database.entities.GlucoseValue
|
import info.nightscout.database.entities.GlucoseValue
|
||||||
import info.nightscout.database.impl.AppRepository
|
import info.nightscout.database.impl.AppRepository
|
||||||
import info.nightscout.database.impl.ValueWrapper
|
import info.nightscout.database.impl.ValueWrapper
|
||||||
|
|
|
@ -10,13 +10,8 @@ import com.jjoe64.graphview.series.BarGraphSeries
|
||||||
import com.jjoe64.graphview.series.LineGraphSeries
|
import com.jjoe64.graphview.series.LineGraphSeries
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.androidaps.R
|
import info.nightscout.androidaps.R
|
||||||
import info.nightscout.androidaps.data.IobTotal
|
|
||||||
import info.nightscout.database.impl.AppRepository
|
|
||||||
import info.nightscout.database.impl.ValueWrapper
|
|
||||||
import info.nightscout.androidaps.interfaces.IobCobCalculator
|
import info.nightscout.androidaps.interfaces.IobCobCalculator
|
||||||
import info.nightscout.androidaps.interfaces.ProfileFunction
|
import info.nightscout.androidaps.interfaces.ProfileFunction
|
||||||
import info.nightscout.shared.interfaces.ResourceHelper
|
|
||||||
import info.nightscout.interfaces.aps.SMBDefaults
|
|
||||||
import info.nightscout.androidaps.plugins.general.overview.OverviewData
|
import info.nightscout.androidaps.plugins.general.overview.OverviewData
|
||||||
import info.nightscout.androidaps.plugins.general.overview.OverviewMenus
|
import info.nightscout.androidaps.plugins.general.overview.OverviewMenus
|
||||||
import info.nightscout.androidaps.plugins.general.overview.graphExtensions.DataPointWithLabelInterface
|
import info.nightscout.androidaps.plugins.general.overview.graphExtensions.DataPointWithLabelInterface
|
||||||
|
@ -27,11 +22,18 @@ import info.nightscout.androidaps.plugins.general.overview.graphExtensions.Scale
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensResult
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensResult
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventIobCalculationProgress
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventIobCalculationProgress
|
||||||
import info.nightscout.androidaps.receivers.DataWorkerStorage
|
import info.nightscout.androidaps.receivers.DataWorkerStorage
|
||||||
import info.nightscout.shared.utils.DateUtil
|
|
||||||
import info.nightscout.androidaps.utils.DecimalFormatter
|
import info.nightscout.androidaps.utils.DecimalFormatter
|
||||||
|
import info.nightscout.core.iob.combine
|
||||||
|
import info.nightscout.core.iob.copy
|
||||||
|
import info.nightscout.database.impl.AppRepository
|
||||||
|
import info.nightscout.database.impl.ValueWrapper
|
||||||
|
import info.nightscout.interfaces.aps.SMBDefaults
|
||||||
|
import info.nightscout.interfaces.iob.IobTotal
|
||||||
import info.nightscout.rx.bus.RxBus
|
import info.nightscout.rx.bus.RxBus
|
||||||
import info.nightscout.rx.logging.AAPSLogger
|
import info.nightscout.rx.logging.AAPSLogger
|
||||||
import info.nightscout.rx.logging.LTag
|
import info.nightscout.rx.logging.LTag
|
||||||
|
import info.nightscout.shared.interfaces.ResourceHelper
|
||||||
|
import info.nightscout.shared.utils.DateUtil
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlin.math.abs
|
import kotlin.math.abs
|
||||||
import kotlin.math.max
|
import kotlin.math.max
|
||||||
|
@ -51,6 +53,7 @@ class PrepareIobAutosensGraphDataWorker(
|
||||||
@Inject lateinit var repository: AppRepository
|
@Inject lateinit var repository: AppRepository
|
||||||
@Inject lateinit var rxBus: RxBus
|
@Inject lateinit var rxBus: RxBus
|
||||||
var ctx: Context
|
var ctx: Context
|
||||||
|
|
||||||
init {
|
init {
|
||||||
(context.applicationContext as HasAndroidInjector).androidInjector().inject(this)
|
(context.applicationContext as HasAndroidInjector).androidInjector().inject(this)
|
||||||
ctx = rh.getThemedCtx(context)
|
ctx = rh.getThemedCtx(context)
|
||||||
|
@ -61,6 +64,37 @@ class PrepareIobAutosensGraphDataWorker(
|
||||||
val overviewData: OverviewData
|
val overviewData: OverviewData
|
||||||
)
|
)
|
||||||
|
|
||||||
|
class IobTotalDataPoint(time: Long) : IobTotal(time), DataPointWithLabelInterface {
|
||||||
|
|
||||||
|
constructor(i: IobTotal) : this(i.time) {
|
||||||
|
iob = i.iob
|
||||||
|
activity = i.activity
|
||||||
|
bolussnooze = i.bolussnooze
|
||||||
|
basaliob = i.basaliob
|
||||||
|
netbasalinsulin = i.netbasalinsulin
|
||||||
|
hightempinsulin = i.hightempinsulin
|
||||||
|
lastBolusTime = i.lastBolusTime
|
||||||
|
iobWithZeroTemp = i.iobWithZeroTemp?.copy()
|
||||||
|
netInsulin = i.netInsulin
|
||||||
|
extendedBolusInsulin = i.extendedBolusInsulin
|
||||||
|
}
|
||||||
|
|
||||||
|
private var color = 0
|
||||||
|
override fun getX(): Double = time.toDouble()
|
||||||
|
override fun getY(): Double = iob
|
||||||
|
override fun setY(y: Double) {}
|
||||||
|
override val label = ""
|
||||||
|
override val duration = 0L
|
||||||
|
override val shape = PointsWithLabelGraphSeries.Shape.IOB_PREDICTION
|
||||||
|
override val size = 0.5f
|
||||||
|
|
||||||
|
override fun color(context: Context?): Int = color
|
||||||
|
fun setColor(color: Int): IobTotalDataPoint {
|
||||||
|
this.color = color
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun doWork(): Result {
|
override fun doWork(): Result {
|
||||||
val data = dataWorkerStorage.pickupObject(inputData.getLong(DataWorkerStorage.STORE_KEY, -1)) as PrepareIobAutosensData?
|
val data = dataWorkerStorage.pickupObject(inputData.getLong(DataWorkerStorage.STORE_KEY, -1)) as PrepareIobAutosensData?
|
||||||
?: return Result.failure(workDataOf("Error" to "missing input data"))
|
?: return Result.failure(workDataOf("Error" to "missing input data"))
|
||||||
|
@ -209,7 +243,7 @@ class PrepareIobAutosensGraphDataWorker(
|
||||||
val iobPrediction: MutableList<DataPointWithLabelInterface> = ArrayList()
|
val iobPrediction: MutableList<DataPointWithLabelInterface> = ArrayList()
|
||||||
val iobPredictionArray = data.iobCobCalculator.calculateIobArrayForSMB(lastAutosensResult, SMBDefaults.exercise_mode, SMBDefaults.half_basal_exercise_target, isTempTarget)
|
val iobPredictionArray = data.iobCobCalculator.calculateIobArrayForSMB(lastAutosensResult, SMBDefaults.exercise_mode, SMBDefaults.half_basal_exercise_target, isTempTarget)
|
||||||
for (i in iobPredictionArray) {
|
for (i in iobPredictionArray) {
|
||||||
iobPrediction.add(i.setColor(rh.gac( ctx, R.attr.iobPredASColor)))
|
iobPrediction.add(IobTotalDataPoint(i).setColor(rh.gac(ctx, R.attr.iobPredASColor)))
|
||||||
data.overviewData.maxIobValueFound = max(data.overviewData.maxIobValueFound, abs(i.iob))
|
data.overviewData.maxIobValueFound = max(data.overviewData.maxIobValueFound, abs(i.iob))
|
||||||
}
|
}
|
||||||
data.overviewData.iobPredictions1Series = PointsWithLabelGraphSeries(Array(iobPrediction.size) { i -> iobPrediction[i] })
|
data.overviewData.iobPredictions1Series = PointsWithLabelGraphSeries(Array(iobPrediction.size) { i -> iobPrediction[i] })
|
||||||
|
|
|
@ -4,7 +4,6 @@ import android.content.Context
|
||||||
import dagger.android.AndroidInjector
|
import dagger.android.AndroidInjector
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.androidaps.TestBase
|
import info.nightscout.androidaps.TestBase
|
||||||
import info.nightscout.androidaps.data.IobTotal
|
|
||||||
import info.nightscout.androidaps.interfaces.ActivePlugin
|
import info.nightscout.androidaps.interfaces.ActivePlugin
|
||||||
import info.nightscout.androidaps.interfaces.CommandQueue
|
import info.nightscout.androidaps.interfaces.CommandQueue
|
||||||
import info.nightscout.androidaps.interfaces.Constraints
|
import info.nightscout.androidaps.interfaces.Constraints
|
||||||
|
@ -16,6 +15,7 @@ import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensDataStore
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatusProvider
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatusProvider
|
||||||
import info.nightscout.interfaces.GlucoseUnit
|
import info.nightscout.interfaces.GlucoseUnit
|
||||||
import info.nightscout.interfaces.constraints.Constraint
|
import info.nightscout.interfaces.constraints.Constraint
|
||||||
|
import info.nightscout.interfaces.iob.IobTotal
|
||||||
import info.nightscout.interfaces.pump.defs.PumpDescription
|
import info.nightscout.interfaces.pump.defs.PumpDescription
|
||||||
import info.nightscout.plugins.pump.virtual.VirtualPumpPlugin
|
import info.nightscout.plugins.pump.virtual.VirtualPumpPlugin
|
||||||
import info.nightscout.rx.bus.RxBus
|
import info.nightscout.rx.bus.RxBus
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package info.nightscout.automation.triggers
|
package info.nightscout.automation.triggers
|
||||||
|
|
||||||
import com.google.common.base.Optional
|
import com.google.common.base.Optional
|
||||||
import info.nightscout.androidaps.data.IobTotal
|
|
||||||
import info.nightscout.automation.R
|
import info.nightscout.automation.R
|
||||||
import info.nightscout.automation.elements.Comparator
|
import info.nightscout.automation.elements.Comparator
|
||||||
|
import info.nightscout.interfaces.iob.IobTotal
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
import org.junit.Assert
|
import org.junit.Assert
|
||||||
import org.junit.Before
|
import org.junit.Before
|
||||||
|
|
|
@ -1,143 +0,0 @@
|
||||||
package info.nightscout.androidaps.data
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import info.nightscout.androidaps.plugins.general.overview.graphExtensions.DataPointWithLabelInterface
|
|
||||||
import info.nightscout.androidaps.plugins.general.overview.graphExtensions.PointsWithLabelGraphSeries
|
|
||||||
import info.nightscout.shared.utils.DateUtil
|
|
||||||
import info.nightscout.interfaces.utils.Round
|
|
||||||
import org.json.JSONException
|
|
||||||
import org.json.JSONObject
|
|
||||||
|
|
||||||
@Suppress("SpellCheckingInspection")
|
|
||||||
class IobTotal(val time: Long) : DataPointWithLabelInterface {
|
|
||||||
|
|
||||||
var iob = 0.0
|
|
||||||
var activity = 0.0
|
|
||||||
var bolussnooze = 0.0
|
|
||||||
var basaliob = 0.0
|
|
||||||
var netbasalinsulin = 0.0
|
|
||||||
var hightempinsulin = 0.0
|
|
||||||
|
|
||||||
// oref1
|
|
||||||
var lastBolusTime: Long = 0
|
|
||||||
var iobWithZeroTemp: IobTotal? = null
|
|
||||||
var netInsulin = 0.0 // for calculations from temp basals only
|
|
||||||
var extendedBolusInsulin = 0.0 // total insulin for extended bolus
|
|
||||||
fun copy(): IobTotal {
|
|
||||||
val i = IobTotal(time)
|
|
||||||
i.iob = iob
|
|
||||||
i.activity = activity
|
|
||||||
i.bolussnooze = bolussnooze
|
|
||||||
i.basaliob = basaliob
|
|
||||||
i.netbasalinsulin = netbasalinsulin
|
|
||||||
i.hightempinsulin = hightempinsulin
|
|
||||||
i.lastBolusTime = lastBolusTime
|
|
||||||
i.iobWithZeroTemp = iobWithZeroTemp?.copy()
|
|
||||||
i.netInsulin = netInsulin
|
|
||||||
i.extendedBolusInsulin = extendedBolusInsulin
|
|
||||||
return i
|
|
||||||
}
|
|
||||||
|
|
||||||
operator fun plus(other: IobTotal): IobTotal {
|
|
||||||
iob += other.iob
|
|
||||||
activity += other.activity
|
|
||||||
bolussnooze += other.bolussnooze
|
|
||||||
basaliob += other.basaliob
|
|
||||||
netbasalinsulin += other.netbasalinsulin
|
|
||||||
hightempinsulin += other.hightempinsulin
|
|
||||||
netInsulin += other.netInsulin
|
|
||||||
extendedBolusInsulin += other.extendedBolusInsulin
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
fun round(): IobTotal {
|
|
||||||
iob = Round.roundTo(iob, 0.001)
|
|
||||||
activity = Round.roundTo(activity, 0.0001)
|
|
||||||
bolussnooze = Round.roundTo(bolussnooze, 0.0001)
|
|
||||||
basaliob = Round.roundTo(basaliob, 0.001)
|
|
||||||
netbasalinsulin = Round.roundTo(netbasalinsulin, 0.001)
|
|
||||||
hightempinsulin = Round.roundTo(hightempinsulin, 0.001)
|
|
||||||
netInsulin = Round.roundTo(netInsulin, 0.001)
|
|
||||||
extendedBolusInsulin = Round.roundTo(extendedBolusInsulin, 0.001)
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
fun json(dateUtil: DateUtil): JSONObject {
|
|
||||||
val json = JSONObject()
|
|
||||||
try {
|
|
||||||
json.put("iob", iob)
|
|
||||||
json.put("basaliob", basaliob)
|
|
||||||
json.put("activity", activity)
|
|
||||||
json.put("time", dateUtil.toISOString(time))
|
|
||||||
} catch (ignored: JSONException) {
|
|
||||||
}
|
|
||||||
return json
|
|
||||||
}
|
|
||||||
|
|
||||||
fun determineBasalJson(dateUtil: DateUtil): JSONObject {
|
|
||||||
val json = JSONObject()
|
|
||||||
try {
|
|
||||||
json.put("iob", iob)
|
|
||||||
json.put("basaliob", basaliob)
|
|
||||||
json.put("bolussnooze", bolussnooze)
|
|
||||||
json.put("activity", activity)
|
|
||||||
json.put("lastBolusTime", lastBolusTime)
|
|
||||||
json.put("time", dateUtil.toISOString(time))
|
|
||||||
/*
|
|
||||||
|
|
||||||
This is requested by SMB determine_basal but by based on Scott's info
|
|
||||||
it's MDT specific safety check only
|
|
||||||
It's causing rounding issues in determine_basal
|
|
||||||
|
|
||||||
JSONObject lastTemp = new JSONObject();
|
|
||||||
lastTemp.put("date", lastTempDate);
|
|
||||||
lastTemp.put("rate", lastTempRate);
|
|
||||||
lastTemp.put("duration", lastTempDuration);
|
|
||||||
json.put("lastTemp", lastTemp);
|
|
||||||
*/
|
|
||||||
if (iobWithZeroTemp != null) {
|
|
||||||
val iwzt = iobWithZeroTemp!!.determineBasalJson(dateUtil)
|
|
||||||
json.put("iobWithZeroTemp", iwzt)
|
|
||||||
}
|
|
||||||
} catch (ignored: JSONException) {
|
|
||||||
}
|
|
||||||
return json
|
|
||||||
}
|
|
||||||
|
|
||||||
// DataPoint interface
|
|
||||||
private var color = 0
|
|
||||||
override fun getX(): Double = time.toDouble()
|
|
||||||
override fun getY(): Double = iob
|
|
||||||
override fun setY(y: Double) {}
|
|
||||||
override val label = ""
|
|
||||||
override val duration = 0L
|
|
||||||
override val shape = PointsWithLabelGraphSeries.Shape.IOB_PREDICTION
|
|
||||||
override val size = 0.5f
|
|
||||||
|
|
||||||
override fun color(context: Context?): Int {
|
|
||||||
return color
|
|
||||||
}
|
|
||||||
|
|
||||||
fun setColor(color: Int): IobTotal {
|
|
||||||
this.color = color
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
|
|
||||||
fun combine(bolusIOB: IobTotal, basalIob: IobTotal): IobTotal {
|
|
||||||
val result = IobTotal(bolusIOB.time)
|
|
||||||
result.iob = bolusIOB.iob + basalIob.basaliob
|
|
||||||
result.activity = bolusIOB.activity + basalIob.activity
|
|
||||||
result.bolussnooze = bolusIOB.bolussnooze
|
|
||||||
result.basaliob = bolusIOB.basaliob + basalIob.basaliob
|
|
||||||
result.netbasalinsulin = bolusIOB.netbasalinsulin + basalIob.netbasalinsulin
|
|
||||||
result.hightempinsulin = basalIob.hightempinsulin + bolusIOB.hightempinsulin
|
|
||||||
result.netInsulin = basalIob.netInsulin + bolusIOB.netInsulin
|
|
||||||
result.extendedBolusInsulin = basalIob.extendedBolusInsulin + bolusIOB.extendedBolusInsulin
|
|
||||||
result.lastBolusTime = bolusIOB.lastBolusTime
|
|
||||||
result.iobWithZeroTemp = basalIob.iobWithZeroTemp
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,6 +1,5 @@
|
||||||
package info.nightscout.androidaps.extensions
|
package info.nightscout.androidaps.extensions
|
||||||
|
|
||||||
import info.nightscout.androidaps.data.IobTotal
|
|
||||||
import info.nightscout.androidaps.interfaces.Insulin
|
import info.nightscout.androidaps.interfaces.Insulin
|
||||||
import info.nightscout.androidaps.interfaces.Profile
|
import info.nightscout.androidaps.interfaces.Profile
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensResult
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensResult
|
||||||
|
@ -9,6 +8,7 @@ import info.nightscout.database.entities.Bolus
|
||||||
import info.nightscout.database.entities.ExtendedBolus
|
import info.nightscout.database.entities.ExtendedBolus
|
||||||
import info.nightscout.database.entities.TemporaryBasal
|
import info.nightscout.database.entities.TemporaryBasal
|
||||||
import info.nightscout.database.entities.interfaces.end
|
import info.nightscout.database.entities.interfaces.end
|
||||||
|
import info.nightscout.interfaces.iob.IobTotal
|
||||||
import info.nightscout.shared.utils.DateUtil
|
import info.nightscout.shared.utils.DateUtil
|
||||||
import info.nightscout.shared.utils.T
|
import info.nightscout.shared.utils.T
|
||||||
import kotlin.math.ceil
|
import kotlin.math.ceil
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package info.nightscout.androidaps.extensions
|
package info.nightscout.androidaps.extensions
|
||||||
|
|
||||||
import info.nightscout.androidaps.data.IobTotal
|
|
||||||
import info.nightscout.androidaps.interfaces.Insulin
|
import info.nightscout.androidaps.interfaces.Insulin
|
||||||
import info.nightscout.androidaps.interfaces.Profile
|
import info.nightscout.androidaps.interfaces.Profile
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensResult
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensResult
|
||||||
|
@ -9,6 +8,7 @@ import info.nightscout.androidaps.utils.DecimalFormatter.to2Decimal
|
||||||
import info.nightscout.database.entities.Bolus
|
import info.nightscout.database.entities.Bolus
|
||||||
import info.nightscout.database.entities.TemporaryBasal
|
import info.nightscout.database.entities.TemporaryBasal
|
||||||
import info.nightscout.database.entities.interfaces.end
|
import info.nightscout.database.entities.interfaces.end
|
||||||
|
import info.nightscout.interfaces.iob.IobTotal
|
||||||
import info.nightscout.shared.utils.DateUtil
|
import info.nightscout.shared.utils.DateUtil
|
||||||
import info.nightscout.shared.utils.T
|
import info.nightscout.shared.utils.T
|
||||||
import kotlin.math.ceil
|
import kotlin.math.ceil
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package info.nightscout.androidaps.interfaces
|
package info.nightscout.androidaps.interfaces
|
||||||
|
|
||||||
import info.nightscout.androidaps.data.IobTotal
|
|
||||||
import info.nightscout.androidaps.plugins.aps.loop.APSResult
|
import info.nightscout.androidaps.plugins.aps.loop.APSResult
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus
|
||||||
|
import info.nightscout.interfaces.iob.IobTotal
|
||||||
import info.nightscout.interfaces.iob.MealData
|
import info.nightscout.interfaces.iob.MealData
|
||||||
|
|
||||||
interface DetermineBasalAdapterInterface {
|
interface DetermineBasalAdapterInterface {
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package info.nightscout.androidaps.interfaces
|
package info.nightscout.androidaps.interfaces
|
||||||
|
|
||||||
import info.nightscout.androidaps.data.IobTotal
|
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensDataStore
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensDataStore
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensResult
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensResult
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.BasalData
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.BasalData
|
||||||
|
@ -8,6 +7,7 @@ import info.nightscout.androidaps.plugins.iob.iobCobCalculator.CobInfo
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.data.AutosensData
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.data.AutosensData
|
||||||
import info.nightscout.database.entities.ExtendedBolus
|
import info.nightscout.database.entities.ExtendedBolus
|
||||||
import info.nightscout.database.entities.TemporaryBasal
|
import info.nightscout.database.entities.TemporaryBasal
|
||||||
|
import info.nightscout.interfaces.iob.IobTotal
|
||||||
import info.nightscout.interfaces.iob.MealData
|
import info.nightscout.interfaces.iob.MealData
|
||||||
import org.json.JSONArray
|
import org.json.JSONArray
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@ package info.nightscout.androidaps.plugins.aps.loop
|
||||||
|
|
||||||
import android.text.Spanned
|
import android.text.Spanned
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.androidaps.data.IobTotal
|
|
||||||
import info.nightscout.androidaps.extensions.convertedToAbsolute
|
import info.nightscout.androidaps.extensions.convertedToAbsolute
|
||||||
import info.nightscout.androidaps.extensions.convertedToPercent
|
import info.nightscout.androidaps.extensions.convertedToPercent
|
||||||
import info.nightscout.androidaps.interfaces.ActivePlugin
|
import info.nightscout.androidaps.interfaces.ActivePlugin
|
||||||
|
@ -13,6 +12,7 @@ import info.nightscout.androidaps.utils.DecimalFormatter
|
||||||
import info.nightscout.core.main.R
|
import info.nightscout.core.main.R
|
||||||
import info.nightscout.database.entities.GlucoseValue
|
import info.nightscout.database.entities.GlucoseValue
|
||||||
import info.nightscout.interfaces.constraints.Constraint
|
import info.nightscout.interfaces.constraints.Constraint
|
||||||
|
import info.nightscout.interfaces.iob.IobTotal
|
||||||
import info.nightscout.interfaces.pump.defs.PumpDescription
|
import info.nightscout.interfaces.pump.defs.PumpDescription
|
||||||
import info.nightscout.interfaces.utils.HtmlHelper.fromHtml
|
import info.nightscout.interfaces.utils.HtmlHelper.fromHtml
|
||||||
import info.nightscout.rx.logging.AAPSLogger
|
import info.nightscout.rx.logging.AAPSLogger
|
||||||
|
|
|
@ -7,9 +7,6 @@ import androidx.annotation.DrawableRes
|
||||||
import com.jjoe64.graphview.series.BarGraphSeries
|
import com.jjoe64.graphview.series.BarGraphSeries
|
||||||
import com.jjoe64.graphview.series.DataPoint
|
import com.jjoe64.graphview.series.DataPoint
|
||||||
import com.jjoe64.graphview.series.LineGraphSeries
|
import com.jjoe64.graphview.series.LineGraphSeries
|
||||||
import info.nightscout.androidaps.data.IobTotal
|
|
||||||
import info.nightscout.database.impl.AppRepository
|
|
||||||
import info.nightscout.database.impl.ValueWrapper
|
|
||||||
import info.nightscout.androidaps.extensions.convertedToPercent
|
import info.nightscout.androidaps.extensions.convertedToPercent
|
||||||
import info.nightscout.androidaps.extensions.isInProgress
|
import info.nightscout.androidaps.extensions.isInProgress
|
||||||
import info.nightscout.androidaps.extensions.toStringFull
|
import info.nightscout.androidaps.extensions.toStringFull
|
||||||
|
@ -27,9 +24,13 @@ import info.nightscout.androidaps.plugins.general.overview.graphExtensions.Scale
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.CobInfo
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.CobInfo
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.data.AutosensData
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.data.AutosensData
|
||||||
import info.nightscout.androidaps.utils.DefaultValueHelper
|
import info.nightscout.androidaps.utils.DefaultValueHelper
|
||||||
|
import info.nightscout.core.iob.round
|
||||||
import info.nightscout.core.main.R
|
import info.nightscout.core.main.R
|
||||||
import info.nightscout.database.entities.GlucoseValue
|
import info.nightscout.database.entities.GlucoseValue
|
||||||
import info.nightscout.database.entities.TemporaryTarget
|
import info.nightscout.database.entities.TemporaryTarget
|
||||||
|
import info.nightscout.database.impl.AppRepository
|
||||||
|
import info.nightscout.database.impl.ValueWrapper
|
||||||
|
import info.nightscout.interfaces.iob.IobTotal
|
||||||
import info.nightscout.rx.logging.AAPSLogger
|
import info.nightscout.rx.logging.AAPSLogger
|
||||||
import info.nightscout.shared.interfaces.ResourceHelper
|
import info.nightscout.shared.interfaces.ResourceHelper
|
||||||
import info.nightscout.shared.sharedPreferences.SP
|
import info.nightscout.shared.sharedPreferences.SP
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
package info.nightscout.androidaps.plugins.general.overview.graphExtensions
|
package info.nightscout.androidaps.plugins.general.overview.graphExtensions
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import info.nightscout.interfaces.Constants
|
|
||||||
import info.nightscout.core.main.R
|
|
||||||
import info.nightscout.androidaps.data.InMemoryGlucoseValue
|
|
||||||
import info.nightscout.interfaces.GlucoseUnit
|
|
||||||
import info.nightscout.androidaps.interfaces.ProfileFunction
|
import info.nightscout.androidaps.interfaces.ProfileFunction
|
||||||
|
import info.nightscout.core.main.R
|
||||||
|
import info.nightscout.interfaces.Constants
|
||||||
|
import info.nightscout.interfaces.GlucoseUnit
|
||||||
|
import info.nightscout.interfaces.iob.InMemoryGlucoseValue
|
||||||
import info.nightscout.shared.interfaces.ResourceHelper
|
import info.nightscout.shared.interfaces.ResourceHelper
|
||||||
|
|
||||||
class InMemoryGlucoseValueDataPoint(
|
class InMemoryGlucoseValueDataPoint(
|
||||||
|
|
|
@ -3,11 +3,11 @@ package info.nightscout.androidaps.plugins.iob.iobCobCalculator
|
||||||
import androidx.collection.LongSparseArray
|
import androidx.collection.LongSparseArray
|
||||||
import androidx.collection.size
|
import androidx.collection.size
|
||||||
import info.nightscout.androidaps.annotations.OpenForTesting
|
import info.nightscout.androidaps.annotations.OpenForTesting
|
||||||
import info.nightscout.androidaps.data.InMemoryGlucoseValue
|
|
||||||
import info.nightscout.database.impl.AppRepository
|
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.data.AutosensData
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.data.AutosensData
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventBucketedDataCreated
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventBucketedDataCreated
|
||||||
import info.nightscout.database.entities.GlucoseValue
|
import info.nightscout.database.entities.GlucoseValue
|
||||||
|
import info.nightscout.database.impl.AppRepository
|
||||||
|
import info.nightscout.interfaces.iob.InMemoryGlucoseValue
|
||||||
import info.nightscout.rx.bus.RxBus
|
import info.nightscout.rx.bus.RxBus
|
||||||
import info.nightscout.rx.logging.AAPSLogger
|
import info.nightscout.rx.logging.AAPSLogger
|
||||||
import info.nightscout.rx.logging.LTag
|
import info.nightscout.rx.logging.LTag
|
||||||
|
|
|
@ -0,0 +1,103 @@
|
||||||
|
package info.nightscout.core.iob
|
||||||
|
|
||||||
|
import info.nightscout.interfaces.iob.IobTotal
|
||||||
|
import info.nightscout.interfaces.utils.Round
|
||||||
|
import info.nightscout.shared.utils.DateUtil
|
||||||
|
import org.json.JSONException
|
||||||
|
import org.json.JSONObject
|
||||||
|
|
||||||
|
fun IobTotal.copy(): IobTotal {
|
||||||
|
val i = IobTotal(time)
|
||||||
|
i.iob = iob
|
||||||
|
i.activity = activity
|
||||||
|
i.bolussnooze = bolussnooze
|
||||||
|
i.basaliob = basaliob
|
||||||
|
i.netbasalinsulin = netbasalinsulin
|
||||||
|
i.hightempinsulin = hightempinsulin
|
||||||
|
i.lastBolusTime = lastBolusTime
|
||||||
|
i.iobWithZeroTemp = iobWithZeroTemp?.copy()
|
||||||
|
i.netInsulin = netInsulin
|
||||||
|
i.extendedBolusInsulin = extendedBolusInsulin
|
||||||
|
return i
|
||||||
|
}
|
||||||
|
|
||||||
|
operator fun IobTotal.plus(other: IobTotal): IobTotal {
|
||||||
|
iob += other.iob
|
||||||
|
activity += other.activity
|
||||||
|
bolussnooze += other.bolussnooze
|
||||||
|
basaliob += other.basaliob
|
||||||
|
netbasalinsulin += other.netbasalinsulin
|
||||||
|
hightempinsulin += other.hightempinsulin
|
||||||
|
netInsulin += other.netInsulin
|
||||||
|
extendedBolusInsulin += other.extendedBolusInsulin
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
fun IobTotal.round(): IobTotal {
|
||||||
|
iob = Round.roundTo(iob, 0.001)
|
||||||
|
activity = Round.roundTo(activity, 0.0001)
|
||||||
|
bolussnooze = Round.roundTo(bolussnooze, 0.0001)
|
||||||
|
basaliob = Round.roundTo(basaliob, 0.001)
|
||||||
|
netbasalinsulin = Round.roundTo(netbasalinsulin, 0.001)
|
||||||
|
hightempinsulin = Round.roundTo(hightempinsulin, 0.001)
|
||||||
|
netInsulin = Round.roundTo(netInsulin, 0.001)
|
||||||
|
extendedBolusInsulin = Round.roundTo(extendedBolusInsulin, 0.001)
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
fun IobTotal.json(dateUtil: DateUtil): JSONObject {
|
||||||
|
val json = JSONObject()
|
||||||
|
try {
|
||||||
|
json.put("iob", iob)
|
||||||
|
json.put("basaliob", basaliob)
|
||||||
|
json.put("activity", activity)
|
||||||
|
json.put("time", dateUtil.toISOString(time))
|
||||||
|
} catch (ignored: JSONException) {
|
||||||
|
}
|
||||||
|
return json
|
||||||
|
}
|
||||||
|
|
||||||
|
fun IobTotal.determineBasalJson(dateUtil: DateUtil): JSONObject {
|
||||||
|
val json = JSONObject()
|
||||||
|
try {
|
||||||
|
json.put("iob", iob)
|
||||||
|
json.put("basaliob", basaliob)
|
||||||
|
json.put("bolussnooze", bolussnooze)
|
||||||
|
json.put("activity", activity)
|
||||||
|
json.put("lastBolusTime", lastBolusTime)
|
||||||
|
json.put("time", dateUtil.toISOString(time))
|
||||||
|
/*
|
||||||
|
|
||||||
|
This is requested by SMB determine_basal but by based on Scott's info
|
||||||
|
it's MDT specific safety check only
|
||||||
|
It's causing rounding issues in determine_basal
|
||||||
|
|
||||||
|
JSONObject lastTemp = new JSONObject();
|
||||||
|
lastTemp.put("date", lastTempDate);
|
||||||
|
lastTemp.put("rate", lastTempRate);
|
||||||
|
lastTemp.put("duration", lastTempDuration);
|
||||||
|
json.put("lastTemp", lastTemp);
|
||||||
|
*/
|
||||||
|
if (iobWithZeroTemp != null) {
|
||||||
|
val iwzt = iobWithZeroTemp!!.determineBasalJson(dateUtil)
|
||||||
|
json.put("iobWithZeroTemp", iwzt)
|
||||||
|
}
|
||||||
|
} catch (ignored: JSONException) {
|
||||||
|
}
|
||||||
|
return json
|
||||||
|
}
|
||||||
|
|
||||||
|
fun IobTotal.Companion.combine(bolusIOB: IobTotal, basalIob: IobTotal): IobTotal {
|
||||||
|
val result = IobTotal(bolusIOB.time)
|
||||||
|
result.iob = bolusIOB.iob + basalIob.basaliob
|
||||||
|
result.activity = bolusIOB.activity + basalIob.activity
|
||||||
|
result.bolussnooze = bolusIOB.bolussnooze
|
||||||
|
result.basaliob = bolusIOB.basaliob + basalIob.basaliob
|
||||||
|
result.netbasalinsulin = bolusIOB.netbasalinsulin + basalIob.netbasalinsulin
|
||||||
|
result.hightempinsulin = basalIob.hightempinsulin + bolusIOB.hightempinsulin
|
||||||
|
result.netInsulin = basalIob.netInsulin + bolusIOB.netInsulin
|
||||||
|
result.extendedBolusInsulin = basalIob.extendedBolusInsulin + bolusIOB.extendedBolusInsulin
|
||||||
|
result.lastBolusTime = bolusIOB.lastBolusTime
|
||||||
|
result.iobWithZeroTemp = basalIob.iobWithZeroTemp
|
||||||
|
return result
|
||||||
|
}
|
|
@ -2,6 +2,7 @@ package info.nightscout.androidaps.data
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import info.nightscout.androidaps.TestBase
|
import info.nightscout.androidaps.TestBase
|
||||||
|
import info.nightscout.interfaces.iob.IobTotal
|
||||||
import info.nightscout.shared.utils.DateUtil
|
import info.nightscout.shared.utils.DateUtil
|
||||||
import org.junit.Assert
|
import org.junit.Assert
|
||||||
import org.junit.Before
|
import org.junit.Before
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package info.nightscout.androidaps.data
|
package info.nightscout.interfaces.iob
|
||||||
|
|
||||||
import info.nightscout.database.entities.GlucoseValue
|
import info.nightscout.database.entities.GlucoseValue
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
package info.nightscout.interfaces.iob
|
||||||
|
|
||||||
|
@Suppress("SpellCheckingInspection")
|
||||||
|
open class IobTotal(val time: Long) {
|
||||||
|
|
||||||
|
var iob = 0.0
|
||||||
|
var activity = 0.0
|
||||||
|
var bolussnooze = 0.0
|
||||||
|
var basaliob = 0.0
|
||||||
|
var netbasalinsulin = 0.0
|
||||||
|
var hightempinsulin = 0.0
|
||||||
|
|
||||||
|
// oref1
|
||||||
|
var lastBolusTime: Long = 0
|
||||||
|
var iobWithZeroTemp: IobTotal? = null
|
||||||
|
var netInsulin = 0.0 // for calculations from temp basals only
|
||||||
|
var extendedBolusInsulin = 0.0 // total insulin for extended bolus
|
||||||
|
companion object
|
||||||
|
}
|
|
@ -1,14 +1,13 @@
|
||||||
package info.nightscout.plugins.general.autotune
|
package info.nightscout.plugins.general.autotune
|
||||||
|
|
||||||
import info.nightscout.androidaps.data.IobTotal
|
|
||||||
import info.nightscout.androidaps.data.LocalInsulin
|
import info.nightscout.androidaps.data.LocalInsulin
|
||||||
import info.nightscout.database.impl.AppRepository
|
|
||||||
import info.nightscout.androidaps.extensions.durationInMinutes
|
import info.nightscout.androidaps.extensions.durationInMinutes
|
||||||
import info.nightscout.androidaps.extensions.iobCalc
|
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
|
||||||
import info.nightscout.androidaps.interfaces.ProfileFunction
|
import info.nightscout.androidaps.interfaces.ProfileFunction
|
||||||
|
import info.nightscout.core.iob.round
|
||||||
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.ExtendedBolus
|
import info.nightscout.database.entities.ExtendedBolus
|
||||||
|
@ -16,7 +15,9 @@ import info.nightscout.database.entities.GlucoseValue
|
||||||
import info.nightscout.database.entities.TemporaryBasal
|
import info.nightscout.database.entities.TemporaryBasal
|
||||||
import info.nightscout.database.entities.TherapyEvent
|
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.interfaces.Constants
|
import info.nightscout.interfaces.Constants
|
||||||
|
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
|
||||||
|
|
|
@ -30,6 +30,7 @@ import info.nightscout.androidaps.receivers.DataWorkerStorage
|
||||||
import info.nightscout.androidaps.utils.DecimalFormatter
|
import info.nightscout.androidaps.utils.DecimalFormatter
|
||||||
import info.nightscout.androidaps.utils.textValidator.ValidatingEditTextPreference
|
import info.nightscout.androidaps.utils.textValidator.ValidatingEditTextPreference
|
||||||
import info.nightscout.core.fabric.FabricPrivacy
|
import info.nightscout.core.fabric.FabricPrivacy
|
||||||
|
import info.nightscout.core.iob.round
|
||||||
import info.nightscout.database.entities.OfflineEvent
|
import info.nightscout.database.entities.OfflineEvent
|
||||||
import info.nightscout.database.entities.TemporaryTarget
|
import info.nightscout.database.entities.TemporaryTarget
|
||||||
import info.nightscout.database.entities.UserEntry.Action
|
import info.nightscout.database.entities.UserEntry.Action
|
||||||
|
|
|
@ -12,6 +12,7 @@ import info.nightscout.androidaps.interfaces.Profile
|
||||||
import info.nightscout.androidaps.interfaces.ProfileFunction
|
import info.nightscout.androidaps.interfaces.ProfileFunction
|
||||||
import info.nightscout.androidaps.utils.DecimalFormatter
|
import info.nightscout.androidaps.utils.DecimalFormatter
|
||||||
import info.nightscout.core.fabric.FabricPrivacy
|
import info.nightscout.core.fabric.FabricPrivacy
|
||||||
|
import info.nightscout.core.iob.round
|
||||||
import info.nightscout.interfaces.plugin.PluginBase
|
import info.nightscout.interfaces.plugin.PluginBase
|
||||||
import info.nightscout.interfaces.plugin.PluginDescription
|
import info.nightscout.interfaces.plugin.PluginDescription
|
||||||
import info.nightscout.interfaces.plugin.PluginType
|
import info.nightscout.interfaces.plugin.PluginType
|
||||||
|
|
|
@ -6,6 +6,7 @@ import info.nightscout.androidaps.interfaces.Loop
|
||||||
import info.nightscout.androidaps.interfaces.ProfileFunction
|
import info.nightscout.androidaps.interfaces.ProfileFunction
|
||||||
import info.nightscout.androidaps.interfaces.Pump
|
import info.nightscout.androidaps.interfaces.Pump
|
||||||
import info.nightscout.androidaps.receivers.ReceiverStatusStore
|
import info.nightscout.androidaps.receivers.ReceiverStatusStore
|
||||||
|
import info.nightscout.core.iob.json
|
||||||
import info.nightscout.database.entities.DeviceStatus
|
import info.nightscout.database.entities.DeviceStatus
|
||||||
import info.nightscout.plugins.configBuilder.RunningConfiguration
|
import info.nightscout.plugins.configBuilder.RunningConfiguration
|
||||||
import info.nightscout.shared.utils.DateUtil
|
import info.nightscout.shared.utils.DateUtil
|
||||||
|
|
|
@ -2,11 +2,9 @@ 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.IobTotal
|
|
||||||
import info.nightscout.androidaps.data.LocalInsulin
|
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.impl.AppRepository
|
|
||||||
import info.nightscout.androidaps.extensions.shiftBlock
|
import info.nightscout.androidaps.extensions.shiftBlock
|
||||||
import info.nightscout.androidaps.interfaces.ProfileFunction
|
import info.nightscout.androidaps.interfaces.ProfileFunction
|
||||||
import info.nightscout.database.entities.Bolus
|
import info.nightscout.database.entities.Bolus
|
||||||
|
@ -14,7 +12,9 @@ import info.nightscout.database.entities.Carbs
|
||||||
import info.nightscout.database.entities.GlucoseValue
|
import info.nightscout.database.entities.GlucoseValue
|
||||||
import info.nightscout.database.entities.data.Block
|
import info.nightscout.database.entities.data.Block
|
||||||
import info.nightscout.database.entities.data.TargetBlock
|
import info.nightscout.database.entities.data.TargetBlock
|
||||||
|
import info.nightscout.database.impl.AppRepository
|
||||||
import info.nightscout.interfaces.GlucoseUnit
|
import info.nightscout.interfaces.GlucoseUnit
|
||||||
|
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
|
||||||
|
|
|
@ -5,7 +5,6 @@ import dagger.android.AndroidInjector
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.androidaps.TestBaseWithProfile
|
import info.nightscout.androidaps.TestBaseWithProfile
|
||||||
import info.nightscout.androidaps.TestPumpPlugin
|
import info.nightscout.androidaps.TestPumpPlugin
|
||||||
import info.nightscout.androidaps.data.IobTotal
|
|
||||||
import info.nightscout.androidaps.data.PumpEnactResultImpl
|
import info.nightscout.androidaps.data.PumpEnactResultImpl
|
||||||
import info.nightscout.androidaps.interfaces.ActivePlugin
|
import info.nightscout.androidaps.interfaces.ActivePlugin
|
||||||
import info.nightscout.androidaps.interfaces.CommandQueue
|
import info.nightscout.androidaps.interfaces.CommandQueue
|
||||||
|
@ -26,6 +25,7 @@ import info.nightscout.database.impl.transactions.Transaction
|
||||||
import info.nightscout.interfaces.Constants
|
import info.nightscout.interfaces.Constants
|
||||||
import info.nightscout.interfaces.GlucoseUnit
|
import info.nightscout.interfaces.GlucoseUnit
|
||||||
import info.nightscout.interfaces.constraints.Constraint
|
import info.nightscout.interfaces.constraints.Constraint
|
||||||
|
import info.nightscout.interfaces.iob.IobTotal
|
||||||
import info.nightscout.interfaces.plugin.PluginType
|
import info.nightscout.interfaces.plugin.PluginType
|
||||||
import info.nightscout.interfaces.pump.defs.PumpDescription
|
import info.nightscout.interfaces.pump.defs.PumpDescription
|
||||||
import info.nightscout.interfaces.pump.defs.PumpType
|
import info.nightscout.interfaces.pump.defs.PumpType
|
||||||
|
|
|
@ -15,11 +15,6 @@ import androidx.lifecycle.Lifecycle
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import dagger.android.support.DaggerFragment
|
import dagger.android.support.DaggerFragment
|
||||||
import info.nightscout.androidaps.data.IobTotal
|
|
||||||
import info.nightscout.database.impl.AppRepository
|
|
||||||
import info.nightscout.database.impl.ValueWrapper
|
|
||||||
import info.nightscout.database.impl.transactions.InvalidateExtendedBolusTransaction
|
|
||||||
import info.nightscout.database.impl.transactions.InvalidateTemporaryBasalTransaction
|
|
||||||
import info.nightscout.androidaps.extensions.iobCalc
|
import info.nightscout.androidaps.extensions.iobCalc
|
||||||
import info.nightscout.androidaps.extensions.toStringFull
|
import info.nightscout.androidaps.extensions.toStringFull
|
||||||
import info.nightscout.androidaps.extensions.toTemporaryBasal
|
import info.nightscout.androidaps.extensions.toTemporaryBasal
|
||||||
|
@ -36,6 +31,11 @@ import info.nightscout.database.entities.UserEntry.Action
|
||||||
import info.nightscout.database.entities.UserEntry.Sources
|
import info.nightscout.database.entities.UserEntry.Sources
|
||||||
import info.nightscout.database.entities.ValueWithUnit
|
import info.nightscout.database.entities.ValueWithUnit
|
||||||
import info.nightscout.database.entities.interfaces.end
|
import info.nightscout.database.entities.interfaces.end
|
||||||
|
import info.nightscout.database.impl.AppRepository
|
||||||
|
import info.nightscout.database.impl.ValueWrapper
|
||||||
|
import info.nightscout.database.impl.transactions.InvalidateExtendedBolusTransaction
|
||||||
|
import info.nightscout.database.impl.transactions.InvalidateTemporaryBasalTransaction
|
||||||
|
import info.nightscout.interfaces.iob.IobTotal
|
||||||
import info.nightscout.rx.AapsSchedulers
|
import info.nightscout.rx.AapsSchedulers
|
||||||
import info.nightscout.rx.bus.RxBus
|
import info.nightscout.rx.bus.RxBus
|
||||||
import info.nightscout.rx.events.EventTempBasalChange
|
import info.nightscout.rx.events.EventTempBasalChange
|
||||||
|
|
Loading…
Reference in a new issue