Treatment cleanup
This commit is contained in:
parent
699413dd6f
commit
46793abbfc
19 changed files with 28 additions and 105 deletions
|
@ -19,8 +19,7 @@ class WizardElement(carbs: Carbs)
|
|||
val fake = Bolus(
|
||||
amount = 0.0001,
|
||||
timestamp = carbs.timestamp,
|
||||
type = Bolus.Type.NORMAL,
|
||||
isBasalInsulin = false
|
||||
type = Bolus.Type.NORMAL
|
||||
)
|
||||
bolus = BolusElement(fake) // fake insulin record
|
||||
}
|
||||
|
|
|
@ -25,8 +25,7 @@ class ActivityGraph : GraphView {
|
|||
val bolus = Bolus(
|
||||
timestamp = 0,
|
||||
amount = 1.0,
|
||||
type = Bolus.Type.NORMAL,
|
||||
isBasalInsulin = false
|
||||
type = Bolus.Type.NORMAL
|
||||
)
|
||||
val activityArray: MutableList<DataPoint> = ArrayList()
|
||||
val iobArray: MutableList<DataPoint> = ArrayList()
|
||||
|
|
|
@ -4,7 +4,6 @@ import dagger.android.AndroidInjector
|
|||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.androidaps.data.Profile
|
||||
import info.nightscout.androidaps.db.ProfileSwitch
|
||||
import info.nightscout.androidaps.db.Treatment
|
||||
import info.nightscout.androidaps.interfaces.ActivePluginProvider
|
||||
import info.nightscout.androidaps.interfaces.ConfigInterface
|
||||
import info.nightscout.androidaps.interfaces.ProfileFunction
|
||||
|
@ -52,12 +51,6 @@ open class TestBaseWithProfile : TestBase() {
|
|||
it.resourceHelper = resourceHelper
|
||||
it.dateUtil = dateUtil
|
||||
}
|
||||
if (it is Treatment) {
|
||||
it.activePlugin = activePluginProvider
|
||||
it.profileFunction = profileFunction
|
||||
it.defaultValueHelper = defaultValueHelper
|
||||
it.resourceHelper = resourceHelper
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,13 +4,13 @@ import dagger.android.AndroidInjector
|
|||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.androidaps.Constants
|
||||
import info.nightscout.androidaps.data.Iob
|
||||
import info.nightscout.androidaps.database.entities.Bolus
|
||||
import info.nightscout.androidaps.interfaces.ActivePluginProvider
|
||||
import info.nightscout.androidaps.interfaces.InsulinInterface
|
||||
import info.nightscout.androidaps.interfaces.ProfileFunction
|
||||
import info.nightscout.androidaps.logging.AAPSLogger
|
||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||
import info.nightscout.androidaps.interfaces.ProfileFunction
|
||||
import info.nightscout.androidaps.plugins.insulin.InsulinOrefBasePlugin.Companion.MIN_DIA
|
||||
import info.nightscout.androidaps.db.Treatment
|
||||
import info.nightscout.androidaps.interfaces.InsulinInterface
|
||||
import info.nightscout.androidaps.utils.DefaultValueHelper
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
import org.json.JSONObject
|
||||
|
@ -69,12 +69,6 @@ class InsulinOrefBasePluginTest {
|
|||
|
||||
private var injector: HasAndroidInjector = HasAndroidInjector {
|
||||
AndroidInjector {
|
||||
if (it is Treatment) {
|
||||
it.defaultValueHelper = defaultValueHelper
|
||||
it.resourceHelper = resourceHelper
|
||||
it.profileFunction = profileFunction
|
||||
it.activePlugin = activePlugin
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -100,31 +94,32 @@ class InsulinOrefBasePluginTest {
|
|||
|
||||
@Test
|
||||
fun testIobCalcForTreatment() {
|
||||
val treatment = Treatment(injector) //TODO: this should be a separate sut. I'd prefer a separate class.
|
||||
val treatment = Bolus(timestamp = 0, amount = 10.0, type = Bolus.Type.NORMAL)
|
||||
val expected = Iob()
|
||||
Assert.assertEquals(expected, sut.iobCalcForTreatment(treatment, 0, 0.0))
|
||||
Assert.assertEquals(expected.iobContrib, sut.iobCalcForTreatment(treatment, 0, 0.0).iobContrib, 0.001)
|
||||
Assert.assertEquals(expected.activityContrib, sut.iobCalcForTreatment(treatment, 0, 0.0).activityContrib, 0.001)
|
||||
testPeak = 30
|
||||
testUserDefinedDia = 4.0
|
||||
val time = System.currentTimeMillis()
|
||||
// check directly after bolus
|
||||
treatment.date = time
|
||||
treatment.insulin = 10.0
|
||||
treatment.timestamp = time
|
||||
treatment.amount = 10.0
|
||||
Assert.assertEquals(10.0, sut.iobCalcForTreatment(treatment, time, Constants.defaultDIA).iobContrib, 0.1)
|
||||
// check after 1 hour
|
||||
treatment.date = time - 1 * 60 * 60 * 1000 // 1 hour
|
||||
treatment.insulin = 10.0
|
||||
treatment.timestamp = time - 1 * 60 * 60 * 1000 // 1 hour
|
||||
treatment.amount = 10.0
|
||||
Assert.assertEquals(3.92, sut.iobCalcForTreatment(treatment, time, Constants.defaultDIA).iobContrib, 0.1)
|
||||
// check after 2 hour
|
||||
treatment.date = time - 2 * 60 * 60 * 1000 // 1 hour
|
||||
treatment.insulin = 10.0
|
||||
treatment.timestamp = time - 2 * 60 * 60 * 1000 // 2 hours
|
||||
treatment.amount = 10.0
|
||||
Assert.assertEquals(0.77, sut.iobCalcForTreatment(treatment, time, Constants.defaultDIA).iobContrib, 0.1)
|
||||
// check after 3 hour
|
||||
treatment.date = time - 3 * 60 * 60 * 1000 // 1 hour
|
||||
treatment.insulin = 10.0
|
||||
treatment.timestamp = time - 3 * 60 * 60 * 1000 // 3 hours
|
||||
treatment.amount = 10.0
|
||||
Assert.assertEquals(0.10, sut.iobCalcForTreatment(treatment, time, Constants.defaultDIA).iobContrib, 0.1)
|
||||
// check after dia
|
||||
treatment.date = time - 4 * 60 * 60 * 1000
|
||||
treatment.insulin = 10.0
|
||||
treatment.timestamp = time - 4 * 60 * 60 * 1000 // 4 hours
|
||||
treatment.amount = 10.0
|
||||
Assert.assertEquals(0.0, sut.iobCalcForTreatment(treatment, time, Constants.defaultDIA).iobContrib, 0.1)
|
||||
}
|
||||
}
|
|
@ -119,8 +119,7 @@ class CommandQueueTest : TestBaseWithProfile() {
|
|||
Bolus(
|
||||
timestamp = Calendar.getInstance().also { it.set(2000, 0, 1) }.timeInMillis,
|
||||
type = Bolus.Type.NORMAL,
|
||||
amount = 0.0,
|
||||
isBasalInsulin = false
|
||||
amount = 0.0
|
||||
)
|
||||
)
|
||||
`when`(profileFunction.getProfile()).thenReturn(validProfile)
|
||||
|
|
|
@ -5,7 +5,6 @@ import dagger.android.HasAndroidInjector
|
|||
import info.nightscout.androidaps.data.Profile
|
||||
import info.nightscout.androidaps.database.AppRepository
|
||||
import info.nightscout.androidaps.db.ProfileSwitch
|
||||
import info.nightscout.androidaps.db.Treatment
|
||||
import info.nightscout.androidaps.interfaces.ActivePluginProvider
|
||||
import info.nightscout.androidaps.interfaces.ConfigInterface
|
||||
import info.nightscout.androidaps.interfaces.ProfileFunction
|
||||
|
@ -54,12 +53,6 @@ open class TestBaseWithProfile : TestBase() {
|
|||
it.resourceHelper = resourceHelper
|
||||
it.dateUtil = dateUtil
|
||||
}
|
||||
if (it is Treatment) {
|
||||
it.activePlugin = activePluginProvider
|
||||
it.profileFunction = profileFunction
|
||||
it.defaultValueHelper = defaultValueHelper
|
||||
it.resourceHelper = resourceHelper
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -34,8 +34,7 @@ class TriggerBolusAgoTest : TriggerTestBase() {
|
|||
Bolus(
|
||||
timestamp = now,
|
||||
amount = 0.0,
|
||||
type = Bolus.Type.NORMAL,
|
||||
isBasalInsulin = false
|
||||
type = Bolus.Type.NORMAL
|
||||
)
|
||||
) // Set last bolus time to now
|
||||
`when`(dateUtil._now()).thenReturn(now + 10 * 60 * 1000) // set current time to now + 10 min
|
||||
|
@ -64,8 +63,7 @@ class TriggerBolusAgoTest : TriggerTestBase() {
|
|||
Bolus(
|
||||
timestamp = 0L,
|
||||
amount = 0.0,
|
||||
type = Bolus.Type.NORMAL,
|
||||
isBasalInsulin = false
|
||||
type = Bolus.Type.NORMAL
|
||||
)
|
||||
) // Set last bolus time to 0
|
||||
t = TriggerBolusAgo(injector).comparator(Comparator.Compare.IS_NOT_AVAILABLE)
|
||||
|
|
|
@ -106,8 +106,7 @@ class DetailedBolusInfo {
|
|||
Bolus(
|
||||
timestamp = bolusTimestamp ?: timestamp,
|
||||
amount = insulin,
|
||||
type = bolusType.toDBbBolusType(),
|
||||
isBasalInsulin = false
|
||||
type = bolusType.toDBbBolusType()
|
||||
)
|
||||
else null
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@ import info.nightscout.androidaps.utils.DefaultValueHelper;
|
|||
import info.nightscout.androidaps.utils.JsonHelper;
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper;
|
||||
|
||||
@Deprecated
|
||||
@DatabaseTable(tableName = Treatment.TABLE_TREATMENTS)
|
||||
public class Treatment implements DataPointWithLabelInterface, DbObjectBase {
|
||||
@Inject public DefaultValueHelper defaultValueHelper;
|
||||
|
|
|
@ -31,8 +31,7 @@ class PumpSyncImplementation @Inject constructor(
|
|||
temporaryId = temporaryId,
|
||||
pumpType = pumpType.toDbPumpType(),
|
||||
pumpSerial = pumpSerial
|
||||
),
|
||||
isBasalInsulin = false
|
||||
)
|
||||
)
|
||||
repository.runTransactionForResult(InsertPumpBolusWithTempIdTransaction(bolus))
|
||||
.doOnError { aapsLogger.error(LTag.DATABASE, "Error while saving carbs", it) }
|
||||
|
@ -53,8 +52,7 @@ class PumpSyncImplementation @Inject constructor(
|
|||
pumpId = pumpId,
|
||||
pumpType = pumpType.toDbPumpType(),
|
||||
pumpSerial = pumpSerial
|
||||
),
|
||||
isBasalInsulin = false
|
||||
)
|
||||
)
|
||||
repository.runTransactionForResult(SyncPumpBolusWithTempIdTransaction(bolus, type?.toDBbBolusType()))
|
||||
.doOnError { aapsLogger.error(LTag.DATABASE, "Error while saving carbs", it) }
|
||||
|
@ -74,8 +72,7 @@ class PumpSyncImplementation @Inject constructor(
|
|||
pumpId = pumpId,
|
||||
pumpType = pumpType.toDbPumpType(),
|
||||
pumpSerial = pumpSerial
|
||||
),
|
||||
isBasalInsulin = false
|
||||
)
|
||||
)
|
||||
repository.runTransactionForResult(SyncPumpBolusTransaction(bolus, type?.toDBbBolusType()))
|
||||
.doOnError { aapsLogger.error(LTag.DATABASE, "Error while saving carbs", it) }
|
||||
|
|
|
@ -57,8 +57,7 @@ fun bolusFromJson(jsonObject: JSONObject): Bolus? {
|
|||
timestamp = timestamp,
|
||||
amount = amount,
|
||||
type = type,
|
||||
isValid = isValid,
|
||||
isBasalInsulin = false
|
||||
isValid = isValid
|
||||
).also {
|
||||
it.interfaceIDs.nightscoutId = id
|
||||
it.interfaceIDs.pumpId = pumpId
|
||||
|
|
|
@ -4,7 +4,6 @@ import dagger.android.AndroidInjector
|
|||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.androidaps.data.Profile
|
||||
import info.nightscout.androidaps.db.ProfileSwitch
|
||||
import info.nightscout.androidaps.db.Treatment
|
||||
import info.nightscout.androidaps.interfaces.ActivePluginProvider
|
||||
import info.nightscout.androidaps.interfaces.ConfigInterface
|
||||
import info.nightscout.androidaps.interfaces.ProfileFunction
|
||||
|
@ -52,12 +51,6 @@ open class TestBaseWithProfile : TestBase() {
|
|||
it.resourceHelper = resourceHelper
|
||||
it.dateUtil = dateUtil
|
||||
}
|
||||
if (it is Treatment) {
|
||||
it.activePlugin = activePluginProvider
|
||||
it.profileFunction = profileFunction
|
||||
it.defaultValueHelper = defaultValueHelper
|
||||
it.resourceHelper = resourceHelper
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@ import dagger.android.AndroidInjector
|
|||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.androidaps.data.Profile
|
||||
import info.nightscout.androidaps.db.ProfileSwitch
|
||||
import info.nightscout.androidaps.db.Treatment
|
||||
import info.nightscout.androidaps.interfaces.ActivePluginProvider
|
||||
import info.nightscout.androidaps.interfaces.ConfigInterface
|
||||
import info.nightscout.androidaps.interfaces.ProfileFunction
|
||||
|
@ -52,12 +51,6 @@ open class TestBaseWithProfile : TestBase() {
|
|||
it.resourceHelper = resourceHelper
|
||||
it.dateUtil = dateUtil
|
||||
}
|
||||
if (it is Treatment) {
|
||||
it.activePlugin = activePluginProvider
|
||||
it.profileFunction = profileFunction
|
||||
it.defaultValueHelper = defaultValueHelper
|
||||
it.resourceHelper = resourceHelper
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@ import dagger.android.AndroidInjector
|
|||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.androidaps.data.Profile
|
||||
import info.nightscout.androidaps.db.ProfileSwitch
|
||||
import info.nightscout.androidaps.db.Treatment
|
||||
import info.nightscout.androidaps.interfaces.ActivePluginProvider
|
||||
import info.nightscout.androidaps.interfaces.ConfigInterface
|
||||
import info.nightscout.androidaps.interfaces.ProfileFunction
|
||||
|
@ -52,12 +51,6 @@ open class TestBaseWithProfile : TestBase() {
|
|||
it.resourceHelper = resourceHelper
|
||||
it.dateUtil = dateUtil
|
||||
}
|
||||
if (it is Treatment) {
|
||||
it.activePlugin = activePluginProvider
|
||||
it.profileFunction = profileFunction
|
||||
it.defaultValueHelper = defaultValueHelper
|
||||
it.resourceHelper = resourceHelper
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@ import dagger.android.AndroidInjector
|
|||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.androidaps.data.Profile
|
||||
import info.nightscout.androidaps.db.ProfileSwitch
|
||||
import info.nightscout.androidaps.db.Treatment
|
||||
import info.nightscout.androidaps.interfaces.ActivePluginProvider
|
||||
import info.nightscout.androidaps.interfaces.ConfigInterface
|
||||
import info.nightscout.androidaps.interfaces.ProfileFunction
|
||||
|
@ -52,12 +51,6 @@ open class TestBaseWithProfile : TestBase() {
|
|||
it.resourceHelper = resourceHelper
|
||||
it.dateUtil = dateUtil
|
||||
}
|
||||
if (it is Treatment) {
|
||||
it.activePlugin = activePluginProvider
|
||||
it.profileFunction = profileFunction
|
||||
it.defaultValueHelper = defaultValueHelper
|
||||
it.resourceHelper = resourceHelper
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@ import dagger.android.AndroidInjector
|
|||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.androidaps.danars.DanaRSPlugin
|
||||
import info.nightscout.androidaps.danars.DanaRSTestBase
|
||||
import info.nightscout.androidaps.db.Treatment
|
||||
import info.nightscout.androidaps.interfaces.ActivePluginProvider
|
||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||
import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress
|
||||
|
@ -32,12 +31,6 @@ class DanaRSPacketNotifyDeliveryCompleteTest : DanaRSTestBase() {
|
|||
it.resourceHelper = resourceHelper
|
||||
it.danaPump = danaPump
|
||||
}
|
||||
if (it is Treatment) {
|
||||
it.defaultValueHelper = defaultValueHelper
|
||||
it.resourceHelper = resourceHelper
|
||||
it.profileFunction = profileFunction
|
||||
it.activePlugin = activePlugin
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@ import dagger.android.AndroidInjector
|
|||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.androidaps.danars.DanaRSPlugin
|
||||
import info.nightscout.androidaps.danars.DanaRSTestBase
|
||||
import info.nightscout.androidaps.db.Treatment
|
||||
import info.nightscout.androidaps.interfaces.ActivePluginProvider
|
||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||
import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress
|
||||
|
@ -31,12 +30,6 @@ class DanaRsPacketBolusSetStepBolusStopTest : DanaRSTestBase() {
|
|||
it.resourceHelper = resourceHelper
|
||||
it.danaPump = danaPump
|
||||
}
|
||||
if (it is Treatment) {
|
||||
it.defaultValueHelper = defaultValueHelper
|
||||
it.resourceHelper = resourceHelper
|
||||
it.profileFunction = profileFunction
|
||||
it.activePlugin = activePlugin
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@ import dagger.android.AndroidInjector
|
|||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.androidaps.danars.DanaRSPlugin
|
||||
import info.nightscout.androidaps.danars.DanaRSTestBase
|
||||
import info.nightscout.androidaps.db.Treatment
|
||||
import info.nightscout.androidaps.interfaces.ActivePluginProvider
|
||||
import info.nightscout.androidaps.interfaces.CommandQueueProvider
|
||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||
|
@ -42,12 +41,6 @@ class DanaRsPacketNotifyDeliveryRateDisplayTest : DanaRSTestBase() {
|
|||
it.resourceHelper = resourceHelper
|
||||
it.danaPump = danaPump
|
||||
}
|
||||
if (it is Treatment) {
|
||||
it.defaultValueHelper = defaultValueHelper
|
||||
it.resourceHelper = resourceHelper
|
||||
it.profileFunction = profileFunction
|
||||
it.activePlugin = activePlugin
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ data class Bolus(
|
|||
override var utcOffset: Long = TimeZone.getDefault().getOffset(timestamp).toLong(),
|
||||
var amount: Double,
|
||||
var type: Type,
|
||||
var isBasalInsulin: Boolean,
|
||||
var isBasalInsulin: Boolean = false,
|
||||
@Embedded
|
||||
var insulinConfiguration: InsulinConfiguration? = null
|
||||
) : TraceableDBEntry, DBEntryWithTime {
|
||||
|
|
Loading…
Reference in a new issue