Merge branch 'meallink' into meallink_ValueWithUnit

This commit is contained in:
Philoul 2021-04-01 23:02:52 +02:00
commit 16959d4de9
21 changed files with 47 additions and 105 deletions

View file

@ -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
}

View file

@ -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()

View file

@ -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
}
}
}

View file

@ -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)
}
}

View file

@ -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)

View file

@ -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
}
}
}

View file

@ -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)

View file

@ -106,8 +106,7 @@ class DetailedBolusInfo {
Bolus(
timestamp = bolusTimestamp ?: timestamp,
amount = insulin,
type = bolusType.toDBbBolusType(),
isBasalInsulin = false
type = bolusType.toDBbBolusType()
)
else null

View file

@ -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;

View file

@ -12,6 +12,9 @@ import info.nightscout.androidaps.utils.TimeChangeType
import org.json.JSONObject
/**
* This interface defines the communication from AAPS-core to pump drivers.
* Pump drivers communicate data changes back to AAPS-core using {@link info.nightscout.androidaps.interfaces.PumpSync}.
*
* Created by mike on 04.06.2016.
*/
interface PumpInterface {

View file

@ -3,6 +3,22 @@ package info.nightscout.androidaps.interfaces
import info.nightscout.androidaps.data.DetailedBolusInfo
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType
/**
* This interface allows pump drivers to push data changes (creation and update of treatments) back to AAPS-core.
*
* Intended use cases for handling bolus treatments:
*
* - for pumps that have a reliable history that can be read and which therefore issue a bolus on the pump,
* read the history back and add new bolus entries on the pump, the method [syncBolusWithPumpId]
* are used to inform AAPS-core of a new bolus.
* [VirtualPumpPlugin](info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin) is a pump driver that
* takes this approach.
* - for pumps that don't support history or take rather long to complete a bolus, the methods
* [addBolusWithTempId] and [syncBolusWithTempId] provide a mechanism to notify AAPS-core of a started
* bolus, so AAPS-core can operate under the assumption the bolus will be delivered and effect IOB until delivery
* completed. Upon completion, the pump driver will call the second method to turn a temporary bolus into a finished
* bolus.
*/
interface PumpSync {
/**
* Create bolus with temporary id

View file

@ -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) }

View file

@ -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

View file

@ -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
}
}
}

View file

@ -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
}
}
}

View file

@ -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
}
}
}

View file

@ -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
}
}
}

View file

@ -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
}
}
}

View file

@ -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
}
}
}

View file

@ -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
}
}
}

View file

@ -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 {