Exception on NaN

This commit is contained in:
Milos Kozak 2022-06-25 13:51:44 +02:00
parent d71cc391fe
commit 991f2c95b7
19 changed files with 90 additions and 140 deletions

View file

@ -207,8 +207,8 @@ class OverviewData @Inject constructor(
* IOB, COB * IOB, COB
*/ */
fun bolusIob(iobCobCalculator: IobCobCalculator): IobTotal = iobCobCalculator.calculateIobFromBolus().round(fabricPrivacy) fun bolusIob(iobCobCalculator: IobCobCalculator): IobTotal = iobCobCalculator.calculateIobFromBolus().round()
fun basalIob(iobCobCalculator: IobCobCalculator): IobTotal = iobCobCalculator.calculateIobFromTempBasalsIncludingConvertedExtended().round(fabricPrivacy) fun basalIob(iobCobCalculator: IobCobCalculator): IobTotal = iobCobCalculator.calculateIobFromTempBasalsIncludingConvertedExtended().round()
fun cobInfo(iobCobCalculator: IobCobCalculator): CobInfo = iobCobCalculator.getCobInfo(true, "Overview COB") fun cobInfo(iobCobCalculator: IobCobCalculator): CobInfo = iobCobCalculator.getCobInfo(true, "Overview COB")
val lastCarbsTime: Long val lastCarbsTime: Long

View file

@ -6,11 +6,7 @@ import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
import info.nightscout.androidaps.events.EventPumpStatusChanged import info.nightscout.androidaps.events.EventPumpStatusChanged
import info.nightscout.androidaps.extensions.* import info.nightscout.androidaps.extensions.*
import info.nightscout.androidaps.interfaces.Config import info.nightscout.androidaps.interfaces.*
import info.nightscout.androidaps.interfaces.Overview
import info.nightscout.androidaps.interfaces.PluginBase
import info.nightscout.androidaps.interfaces.PluginDescription
import info.nightscout.androidaps.interfaces.PluginType
import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.plugins.bus.RxBus
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification
@ -21,7 +17,6 @@ import info.nightscout.androidaps.plugins.general.overview.graphExtensions.Scale
import info.nightscout.androidaps.plugins.general.overview.notifications.NotificationStore import info.nightscout.androidaps.plugins.general.overview.notifications.NotificationStore
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventIobCalculationProgress import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventIobCalculationProgress
import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.interfaces.ResourceHelper
import info.nightscout.androidaps.utils.rx.AapsSchedulers import info.nightscout.androidaps.utils.rx.AapsSchedulers
import info.nightscout.shared.logging.AAPSLogger import info.nightscout.shared.logging.AAPSLogger
import info.nightscout.shared.sharedPreferences.SP import info.nightscout.shared.sharedPreferences.SP
@ -175,46 +170,4 @@ class OverviewPlugin @Inject constructor(
.storeDouble(R.string.key_statuslights_bat_critical, sp, rh) .storeDouble(R.string.key_statuslights_bat_critical, sp, rh)
.storeInt(R.string.key_boluswizard_percentage, sp, rh) .storeInt(R.string.key_boluswizard_percentage, sp, rh)
} }
/*
@Volatile
var runningRefresh = false
override fun refreshLoop(from: String) {
if (runningRefresh) return
runningRefresh = true
overviewBus.send(EventUpdateOverviewNotification(from))
loadIobCobResults(from)
overviewBus.send(EventUpdateOverviewProfile(from))
overviewBus.send(EventUpdateOverviewBg(from))
overviewBus.send(EventUpdateOverviewTime(from))
overviewBus.send(EventUpdateOverviewTemporaryBasal(from))
overviewBus.send(EventUpdateOverviewExtendedBolus(from))
overviewBus.send(EventUpdateOverviewTemporaryTarget(from))
loadAsData(from)
overviewData.preparePredictions(from)
overviewData.prepareBasalData(from)
overviewData.prepareTemporaryTargetData(from)
overviewData.prepareTreatmentsData(from)
overviewData.prepareIobAutosensData(from)
overviewBus.send(EventUpdateOverviewGraph(from))
overviewBus.send(EventUpdateOverviewIobCob(from))
aapsLogger.debug(LTag.UI, "refreshLoop finished")
runningRefresh = false
}
@Suppress("SameParameterValue")
private fun loadAll(from: String) {
loadBg(from)
loadProfile(from)
loadTemporaryTarget(from)
loadIobCobResults(from)
loadAsData(from)
overviewData.prepareBasalData(from)
overviewData.prepareTemporaryTargetData(from)
overviewData.prepareTreatmentsData(from)
// prepareIobAutosensData(from)
// preparePredictions(from)
overviewBus.send(EventUpdateOverviewGraph(from))
aapsLogger.debug(LTag.UI, "loadAll finished")
}
*/
} }

View file

@ -8,12 +8,11 @@ import info.nightscout.androidaps.R
import info.nightscout.androidaps.events.* import info.nightscout.androidaps.events.*
import info.nightscout.androidaps.extensions.toStringShort import info.nightscout.androidaps.extensions.toStringShort
import info.nightscout.androidaps.interfaces.* import info.nightscout.androidaps.interfaces.*
import info.nightscout.shared.logging.AAPSLogger
import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.plugins.bus.RxBus
import info.nightscout.androidaps.utils.DecimalFormatter import info.nightscout.androidaps.utils.DecimalFormatter
import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.interfaces.ResourceHelper
import info.nightscout.androidaps.utils.rx.AapsSchedulers import info.nightscout.androidaps.utils.rx.AapsSchedulers
import info.nightscout.shared.logging.AAPSLogger
import info.nightscout.shared.sharedPreferences.SP import info.nightscout.shared.sharedPreferences.SP
import io.reactivex.rxjava3.disposables.CompositeDisposable import io.reactivex.rxjava3.disposables.CompositeDisposable
import io.reactivex.rxjava3.kotlin.plusAssign import io.reactivex.rxjava3.kotlin.plusAssign
@ -123,8 +122,8 @@ class StatusLinePlugin @Inject constructor(
status += activeTemp.toStringShort() + " " status += activeTemp.toStringShort() + " "
} }
//IOB //IOB
val bolusIob = iobCobCalculator.calculateIobFromBolus().round(fabricPrivacy) val bolusIob = iobCobCalculator.calculateIobFromBolus().round()
val basalIob = iobCobCalculator.calculateIobFromTempBasalsIncludingConvertedExtended().round(fabricPrivacy) val basalIob = iobCobCalculator.calculateIobFromTempBasalsIncludingConvertedExtended().round()
status += DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U" status += DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U"
if (sp.getBoolean(R.string.key_xdripstatus_detailediob, true)) { if (sp.getBoolean(R.string.key_xdripstatus_detailediob, true)) {
status += ("(" status += ("("

View file

@ -8,6 +8,7 @@ import info.nightscout.androidaps.interfaces.ProfileFunction
import info.nightscout.shared.logging.AAPSLogger import info.nightscout.shared.logging.AAPSLogger
import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.plugins.bus.RxBus
import info.nightscout.androidaps.interfaces.ResourceHelper import info.nightscout.androidaps.interfaces.ResourceHelper
import info.nightscout.androidaps.utils.HardLimits
import org.json.JSONObject import org.json.JSONObject
import javax.inject.Inject import javax.inject.Inject
import javax.inject.Singleton import javax.inject.Singleton
@ -19,8 +20,9 @@ class InsulinLyumjevPlugin @Inject constructor(
profileFunction: ProfileFunction, profileFunction: ProfileFunction,
rxBus: RxBus, rxBus: RxBus,
aapsLogger: AAPSLogger, aapsLogger: AAPSLogger,
config: Config config: Config,
) : InsulinOrefBasePlugin(injector, rh, profileFunction, rxBus, aapsLogger, config) { hardLimits: HardLimits
) : InsulinOrefBasePlugin(injector, rh, profileFunction, rxBus, aapsLogger, config, hardLimits) {
override val id get(): Insulin.InsulinType = Insulin.InsulinType.OREF_LYUMJEV override val id get(): Insulin.InsulinType = Insulin.InsulinType.OREF_LYUMJEV
override val friendlyName get(): String = rh.gs(R.string.lyumjev) override val friendlyName get(): String = rh.gs(R.string.lyumjev)

View file

@ -6,12 +6,12 @@ import info.nightscout.androidaps.data.Iob
import info.nightscout.androidaps.database.embedments.InsulinConfiguration import info.nightscout.androidaps.database.embedments.InsulinConfiguration
import info.nightscout.androidaps.database.entities.Bolus import info.nightscout.androidaps.database.entities.Bolus
import info.nightscout.androidaps.interfaces.* import info.nightscout.androidaps.interfaces.*
import info.nightscout.shared.logging.AAPSLogger
import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.plugins.bus.RxBus
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification import info.nightscout.androidaps.plugins.general.overview.notifications.Notification
import info.nightscout.androidaps.utils.HardLimits
import info.nightscout.androidaps.utils.T import info.nightscout.androidaps.utils.T
import info.nightscout.androidaps.interfaces.ResourceHelper import info.nightscout.shared.logging.AAPSLogger
import kotlin.math.exp import kotlin.math.exp
import kotlin.math.pow import kotlin.math.pow
@ -27,7 +27,8 @@ abstract class InsulinOrefBasePlugin(
val profileFunction: ProfileFunction, val profileFunction: ProfileFunction,
val rxBus: RxBus, val rxBus: RxBus,
aapsLogger: AAPSLogger, aapsLogger: AAPSLogger,
config: Config config: Config,
val hardLimits: HardLimits
) : PluginBase( ) : PluginBase(
PluginDescription() PluginDescription()
.mainType(PluginType.INSULIN) .mainType(PluginType.INSULIN)
@ -43,18 +44,18 @@ abstract class InsulinOrefBasePlugin(
override val dia override val dia
get(): Double { get(): Double {
val dia = userDefinedDia val dia = userDefinedDia
return if (dia >= MIN_DIA) { return if (dia >= hardLimits.minDia()) {
dia dia
} else { } else {
sendShortDiaNotification(dia) sendShortDiaNotification(dia)
MIN_DIA hardLimits.minDia()
} }
} }
open fun sendShortDiaNotification(dia: Double) { open fun sendShortDiaNotification(dia: Double) {
if (System.currentTimeMillis() - lastWarned > 60 * 1000) { if (System.currentTimeMillis() - lastWarned > 60 * 1000) {
lastWarned = System.currentTimeMillis() lastWarned = System.currentTimeMillis()
val notification = Notification(Notification.SHORT_DIA, String.format(notificationPattern, dia, MIN_DIA), Notification.URGENT) val notification = Notification(Notification.SHORT_DIA, String.format(notificationPattern, dia, hardLimits.minDia()), Notification.URGENT)
rxBus.send(EventNewNotification(notification)) rxBus.send(EventNewNotification(notification))
} }
} }
@ -65,12 +66,13 @@ abstract class InsulinOrefBasePlugin(
open val userDefinedDia: Double open val userDefinedDia: Double
get() { get() {
val profile = profileFunction.getProfile() val profile = profileFunction.getProfile()
return profile?.dia ?: MIN_DIA return profile?.dia ?: hardLimits.minDia()
} }
override fun iobCalcForTreatment(bolus: Bolus, time: Long, dia: Double): Iob { override fun iobCalcForTreatment(bolus: Bolus, time: Long, dia: Double): Iob {
assert(dia != 0.0)
assert(peak != 0)
val result = Iob() val result = Iob()
val peak = peak
if (bolus.amount != 0.0) { if (bolus.amount != 0.0) {
val bolusTime = bolus.timestamp val bolusTime = bolus.timestamp
val t = (time - bolusTime) / 1000.0 / 60.0 val t = (time - bolusTime) / 1000.0 / 60.0
@ -80,9 +82,9 @@ abstract class InsulinOrefBasePlugin(
if (t < td) { if (t < td) {
val tau = tp * (1 - tp / td) / (1 - 2 * tp / td) val tau = tp * (1 - tp / td) / (1 - 2 * tp / td)
val a = 2 * tau / td val a = 2 * tau / td
val S = 1 / (1 - a + (1 + a) * exp(-td / tau)) val s = 1 / (1 - a + (1 + a) * exp(-td / tau))
result.activityContrib = bolus.amount * (S / tau.pow(2.0)) * t * (1 - t / td) * exp(-t / tau) result.activityContrib = bolus.amount * (s / tau.pow(2.0)) * t * (1 - t / td) * exp(-t / tau)
result.iobContrib = bolus.amount * (1 - S * (1 - a) * ((t.pow(2.0) / (tau * td * (1 - a)) - t / tau - 1) * Math.exp(-t / tau) + 1)) result.iobContrib = bolus.amount * (1 - s * (1 - a) * ((t.pow(2.0) / (tau * td * (1 - a)) - t / tau - 1) * exp(-t / tau) + 1))
} }
} }
return result return result
@ -95,17 +97,12 @@ abstract class InsulinOrefBasePlugin(
get(): String { get(): String {
var comment = commentStandardText() var comment = commentStandardText()
val userDia = userDefinedDia val userDia = userDefinedDia
if (userDia < MIN_DIA) { if (userDia < hardLimits.minDia()) {
comment += "\n" + rh.gs(R.string.dia_too_short, userDia, MIN_DIA) comment += "\n" + rh.gs(R.string.dia_too_short, userDia, hardLimits.minDia())
} }
return comment return comment
} }
override abstract val peak: Int abstract override val peak: Int
abstract fun commentStandardText(): String abstract fun commentStandardText(): String
companion object {
const val MIN_DIA = 5.0
}
} }

View file

@ -10,6 +10,7 @@ import info.nightscout.androidaps.interfaces.ProfileFunction
import info.nightscout.shared.logging.AAPSLogger import info.nightscout.shared.logging.AAPSLogger
import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.plugins.bus.RxBus
import info.nightscout.androidaps.interfaces.ResourceHelper import info.nightscout.androidaps.interfaces.ResourceHelper
import info.nightscout.androidaps.utils.HardLimits
import info.nightscout.shared.sharedPreferences.SP import info.nightscout.shared.sharedPreferences.SP
import org.json.JSONObject import org.json.JSONObject
import javax.inject.Inject import javax.inject.Inject
@ -26,8 +27,9 @@ class InsulinOrefFreePeakPlugin @Inject constructor(
profileFunction: ProfileFunction, profileFunction: ProfileFunction,
rxBus: RxBus, rxBus: RxBus,
aapsLogger: AAPSLogger, aapsLogger: AAPSLogger,
config: Config config: Config,
) : InsulinOrefBasePlugin(injector, rh, profileFunction, rxBus, aapsLogger, config) { hardLimits: HardLimits
) : InsulinOrefBasePlugin(injector, rh, profileFunction, rxBus, aapsLogger, config, hardLimits) {
override val id get(): Insulin.InsulinType = Insulin.InsulinType.OREF_FREE_PEAK override val id get(): Insulin.InsulinType = Insulin.InsulinType.OREF_FREE_PEAK

View file

@ -8,6 +8,7 @@ import info.nightscout.androidaps.interfaces.ProfileFunction
import info.nightscout.shared.logging.AAPSLogger import info.nightscout.shared.logging.AAPSLogger
import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.plugins.bus.RxBus
import info.nightscout.androidaps.interfaces.ResourceHelper import info.nightscout.androidaps.interfaces.ResourceHelper
import info.nightscout.androidaps.utils.HardLimits
import org.json.JSONObject import org.json.JSONObject
import javax.inject.Inject import javax.inject.Inject
import javax.inject.Singleton import javax.inject.Singleton
@ -22,8 +23,9 @@ class InsulinOrefRapidActingPlugin @Inject constructor(
profileFunction: ProfileFunction, profileFunction: ProfileFunction,
rxBus: RxBus, rxBus: RxBus,
aapsLogger: AAPSLogger, aapsLogger: AAPSLogger,
config: Config config: Config,
) : InsulinOrefBasePlugin(injector, rh, profileFunction, rxBus, aapsLogger, config) { hardLimits: HardLimits
) : InsulinOrefBasePlugin(injector, rh, profileFunction, rxBus, aapsLogger, config, hardLimits) {
override val id get(): Insulin.InsulinType = Insulin.InsulinType.OREF_RAPID_ACTING override val id get(): Insulin.InsulinType = Insulin.InsulinType.OREF_RAPID_ACTING
override val friendlyName get(): String = rh.gs(R.string.rapid_acting_oref) override val friendlyName get(): String = rh.gs(R.string.rapid_acting_oref)

View file

@ -8,6 +8,7 @@ import info.nightscout.androidaps.interfaces.ProfileFunction
import info.nightscout.shared.logging.AAPSLogger import info.nightscout.shared.logging.AAPSLogger
import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.plugins.bus.RxBus
import info.nightscout.androidaps.interfaces.ResourceHelper import info.nightscout.androidaps.interfaces.ResourceHelper
import info.nightscout.androidaps.utils.HardLimits
import org.json.JSONObject import org.json.JSONObject
import javax.inject.Inject import javax.inject.Inject
import javax.inject.Singleton import javax.inject.Singleton
@ -22,8 +23,9 @@ class InsulinOrefUltraRapidActingPlugin @Inject constructor(
profileFunction: ProfileFunction, profileFunction: ProfileFunction,
rxBus: RxBus, rxBus: RxBus,
aapsLogger: AAPSLogger, aapsLogger: AAPSLogger,
config: Config config: Config,
) : InsulinOrefBasePlugin(injector, rh, profileFunction, rxBus, aapsLogger, config) { hardLimits: HardLimits
) : InsulinOrefBasePlugin(injector, rh, profileFunction, rxBus, aapsLogger, config, hardLimits) {
override val id get(): Insulin.InsulinType = Insulin.InsulinType.OREF_ULTRA_RAPID_ACTING override val id get(): Insulin.InsulinType = Insulin.InsulinType.OREF_ULTRA_RAPID_ACTING
override val friendlyName get(): String = rh.gs(R.string.ultrarapid_oref) override val friendlyName get(): String = rh.gs(R.string.ultrarapid_oref)

View file

@ -481,6 +481,7 @@ class IobCobCalculatorPlugin @Inject constructor(
val profile = profileFunction.getProfile() ?: return total val profile = profileFunction.getProfile() ?: return total
val dia = profile.dia val dia = profile.dia
val divisor = sp.getDouble(R.string.key_openapsama_bolussnooze_dia_divisor, 2.0) val divisor = sp.getDouble(R.string.key_openapsama_bolussnooze_dia_divisor, 2.0)
assert(divisor > 0)
val boluses = repository.getBolusesDataFromTime(toTime - range(), true).blockingGet() val boluses = repository.getBolusesDataFromTime(toTime - range(), true).blockingGet()

View file

@ -6,9 +6,10 @@ import info.nightscout.androidaps.R
import info.nightscout.androidaps.interfaces.Config import info.nightscout.androidaps.interfaces.Config
import info.nightscout.androidaps.interfaces.Insulin import info.nightscout.androidaps.interfaces.Insulin
import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.interfaces.ProfileFunction
import info.nightscout.shared.logging.AAPSLogger
import info.nightscout.androidaps.plugins.bus.RxBus
import info.nightscout.androidaps.interfaces.ResourceHelper import info.nightscout.androidaps.interfaces.ResourceHelper
import info.nightscout.androidaps.plugins.bus.RxBus
import info.nightscout.androidaps.utils.HardLimits
import info.nightscout.shared.logging.AAPSLogger
import org.junit.Assert.assertEquals import org.junit.Assert.assertEquals
import org.junit.Before import org.junit.Before
import org.junit.Rule import org.junit.Rule
@ -31,6 +32,7 @@ class InsulinLyumjevPluginTest {
@Mock lateinit var profileFunction: ProfileFunction @Mock lateinit var profileFunction: ProfileFunction
@Mock lateinit var aapsLogger: AAPSLogger @Mock lateinit var aapsLogger: AAPSLogger
@Mock lateinit var config: Config @Mock lateinit var config: Config
@Mock lateinit var hardLimits: HardLimits
private var injector: HasAndroidInjector = HasAndroidInjector { private var injector: HasAndroidInjector = HasAndroidInjector {
AndroidInjector { AndroidInjector {
@ -39,7 +41,7 @@ class InsulinLyumjevPluginTest {
@Before @Before
fun setup() { fun setup() {
sut = InsulinLyumjevPlugin(injector, rh, profileFunction, rxBus, aapsLogger, config) sut = InsulinLyumjevPlugin(injector, rh, profileFunction, rxBus, aapsLogger, config, hardLimits)
} }
@Test @Test

View file

@ -9,17 +9,17 @@ import info.nightscout.androidaps.interfaces.ActivePlugin
import info.nightscout.androidaps.interfaces.Config import info.nightscout.androidaps.interfaces.Config
import info.nightscout.androidaps.interfaces.Insulin import info.nightscout.androidaps.interfaces.Insulin
import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.interfaces.ProfileFunction
import info.nightscout.shared.logging.AAPSLogger
import info.nightscout.androidaps.plugins.bus.RxBus
import info.nightscout.androidaps.plugins.insulin.InsulinOrefBasePlugin.Companion.MIN_DIA
import info.nightscout.androidaps.utils.DefaultValueHelper
import info.nightscout.androidaps.interfaces.ResourceHelper import info.nightscout.androidaps.interfaces.ResourceHelper
import info.nightscout.androidaps.plugins.bus.RxBus
import info.nightscout.androidaps.utils.HardLimits
import info.nightscout.shared.logging.AAPSLogger
import org.json.JSONObject import org.json.JSONObject
import org.junit.Assert import org.junit.Assert
import org.junit.Before import org.junit.Before
import org.junit.Rule import org.junit.Rule
import org.junit.Test import org.junit.Test
import org.mockito.Mock import org.mockito.Mock
import org.mockito.Mockito.`when`
import org.mockito.junit.MockitoJUnit import org.mockito.junit.MockitoJUnit
import org.mockito.junit.MockitoRule import org.mockito.junit.MockitoRule
@ -35,10 +35,9 @@ class InsulinOrefBasePluginTest {
profileFunction: ProfileFunction, profileFunction: ProfileFunction,
rxBus: RxBus, rxBus: RxBus,
aapsLogger: AAPSLogger, aapsLogger: AAPSLogger,
config: Config config: Config,
) : InsulinOrefBasePlugin( hardLimits: HardLimits
injector, rh, profileFunction, rxBus, aapsLogger, config ) : InsulinOrefBasePlugin(injector, rh, profileFunction, rxBus, aapsLogger, config, hardLimits) {
) {
override fun sendShortDiaNotification(dia: Double) { override fun sendShortDiaNotification(dia: Double) {
shortDiaNotificationSend = true shortDiaNotificationSend = true
@ -62,13 +61,13 @@ class InsulinOrefBasePluginTest {
private lateinit var sut: InsulinBaseTest private lateinit var sut: InsulinBaseTest
@Mock lateinit var defaultValueHelper: DefaultValueHelper
@Mock lateinit var rh: ResourceHelper @Mock lateinit var rh: ResourceHelper
@Mock lateinit var profileFunction: ProfileFunction @Mock lateinit var profileFunction: ProfileFunction
@Mock lateinit var rxBus: RxBus @Mock lateinit var rxBus: RxBus
@Mock lateinit var aapsLogger: AAPSLogger @Mock lateinit var aapsLogger: AAPSLogger
@Mock lateinit var activePlugin: ActivePlugin @Mock lateinit var activePlugin: ActivePlugin
@Mock lateinit var config: Config @Mock lateinit var config: Config
@Mock lateinit var hardLimits: HardLimits
private var injector: HasAndroidInjector = HasAndroidInjector { private var injector: HasAndroidInjector = HasAndroidInjector {
AndroidInjector { AndroidInjector {
@ -77,30 +76,23 @@ class InsulinOrefBasePluginTest {
@Before @Before
fun setUp() { fun setUp() {
sut = InsulinBaseTest(injector, rh, profileFunction, rxBus, aapsLogger, config) sut = InsulinBaseTest(injector, rh, profileFunction, rxBus, aapsLogger, config, hardLimits)
`when`(hardLimits.minDia()).thenReturn(5.0)
} }
@Test @Test
fun testGetDia() { fun testGetDia() {
Assert.assertEquals(MIN_DIA, sut.dia, 0.0) Assert.assertEquals(5.0, sut.dia, 0.0)
testUserDefinedDia = MIN_DIA + 1 testUserDefinedDia = 5.0 + 1
Assert.assertEquals(MIN_DIA + 1, sut.dia, 0.0) Assert.assertEquals(5.0 + 1, sut.dia, 0.0)
testUserDefinedDia = MIN_DIA - 1 testUserDefinedDia = 5.0 - 1
Assert.assertEquals(MIN_DIA, sut.dia, 0.0) Assert.assertEquals(5.0, sut.dia, 0.0)
Assert.assertTrue(shortDiaNotificationSend) Assert.assertTrue(shortDiaNotificationSend)
} }
@Test
fun minDiaTes() {
Assert.assertEquals(5.0, MIN_DIA, 0.0001)
}
@Test @Test
fun testIobCalcForTreatment() { fun testIobCalcForTreatment() {
val treatment = Bolus(timestamp = 0, amount = 10.0, type = Bolus.Type.NORMAL) val treatment = Bolus(timestamp = 0, amount = 10.0, type = Bolus.Type.NORMAL)
val expected = Iob()
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 testPeak = 30
testUserDefinedDia = 4.0 testUserDefinedDia = 4.0
val time = System.currentTimeMillis() val time = System.currentTimeMillis()

View file

@ -7,8 +7,9 @@ import info.nightscout.androidaps.TestBase
import info.nightscout.androidaps.interfaces.Config import info.nightscout.androidaps.interfaces.Config
import info.nightscout.androidaps.interfaces.Insulin import info.nightscout.androidaps.interfaces.Insulin
import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.interfaces.ProfileFunction
import info.nightscout.androidaps.plugins.bus.RxBus
import info.nightscout.androidaps.interfaces.ResourceHelper import info.nightscout.androidaps.interfaces.ResourceHelper
import info.nightscout.androidaps.plugins.bus.RxBus
import info.nightscout.androidaps.utils.HardLimits
import info.nightscout.shared.sharedPreferences.SP import info.nightscout.shared.sharedPreferences.SP
import org.junit.Assert.assertEquals import org.junit.Assert.assertEquals
import org.junit.Before import org.junit.Before
@ -31,6 +32,7 @@ class InsulinOrefFreePeakPluginTest : TestBase() {
@Mock lateinit var rxBus: RxBus @Mock lateinit var rxBus: RxBus
@Mock lateinit var profileFunction: ProfileFunction @Mock lateinit var profileFunction: ProfileFunction
@Mock lateinit var config: Config @Mock lateinit var config: Config
@Mock lateinit var hardLimits: HardLimits
private var injector: HasAndroidInjector = HasAndroidInjector { private var injector: HasAndroidInjector = HasAndroidInjector {
AndroidInjector { AndroidInjector {
@ -39,7 +41,7 @@ class InsulinOrefFreePeakPluginTest : TestBase() {
@Before @Before
fun setup() { fun setup() {
sut = InsulinOrefFreePeakPlugin( injector, sp, rh, profileFunction, rxBus, aapsLogger, config) sut = InsulinOrefFreePeakPlugin(injector, sp, rh, profileFunction, rxBus, aapsLogger, config, hardLimits)
} }
@Test @Test

View file

@ -6,9 +6,10 @@ import info.nightscout.androidaps.R
import info.nightscout.androidaps.interfaces.Config import info.nightscout.androidaps.interfaces.Config
import info.nightscout.androidaps.interfaces.Insulin import info.nightscout.androidaps.interfaces.Insulin
import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.interfaces.ProfileFunction
import info.nightscout.shared.logging.AAPSLogger
import info.nightscout.androidaps.plugins.bus.RxBus
import info.nightscout.androidaps.interfaces.ResourceHelper import info.nightscout.androidaps.interfaces.ResourceHelper
import info.nightscout.androidaps.plugins.bus.RxBus
import info.nightscout.androidaps.utils.HardLimits
import info.nightscout.shared.logging.AAPSLogger
import org.junit.Assert.assertEquals import org.junit.Assert.assertEquals
import org.junit.Before import org.junit.Before
import org.junit.Rule import org.junit.Rule
@ -31,6 +32,7 @@ class InsulinOrefRapidActingPluginTest {
@Mock lateinit var profileFunction: ProfileFunction @Mock lateinit var profileFunction: ProfileFunction
@Mock lateinit var aapsLogger: AAPSLogger @Mock lateinit var aapsLogger: AAPSLogger
@Mock lateinit var config: Config @Mock lateinit var config: Config
@Mock lateinit var hardLimits: HardLimits
private var injector: HasAndroidInjector = HasAndroidInjector { private var injector: HasAndroidInjector = HasAndroidInjector {
AndroidInjector { AndroidInjector {
@ -39,7 +41,7 @@ class InsulinOrefRapidActingPluginTest {
@Before @Before
fun setup() { fun setup() {
sut = InsulinOrefRapidActingPlugin(injector, rh, profileFunction, rxBus, aapsLogger, config) sut = InsulinOrefRapidActingPlugin(injector, rh, profileFunction, rxBus, aapsLogger, config, hardLimits)
} }
@Test @Test

View file

@ -6,9 +6,10 @@ import info.nightscout.androidaps.R
import info.nightscout.androidaps.interfaces.Config import info.nightscout.androidaps.interfaces.Config
import info.nightscout.androidaps.interfaces.Insulin import info.nightscout.androidaps.interfaces.Insulin
import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.interfaces.ProfileFunction
import info.nightscout.shared.logging.AAPSLogger
import info.nightscout.androidaps.plugins.bus.RxBus
import info.nightscout.androidaps.interfaces.ResourceHelper import info.nightscout.androidaps.interfaces.ResourceHelper
import info.nightscout.androidaps.plugins.bus.RxBus
import info.nightscout.androidaps.utils.HardLimits
import info.nightscout.shared.logging.AAPSLogger
import org.junit.Assert.assertEquals import org.junit.Assert.assertEquals
import org.junit.Before import org.junit.Before
import org.junit.Rule import org.junit.Rule
@ -31,6 +32,7 @@ class InsulinOrefUltraRapidActingPluginTest {
@Mock lateinit var profileFunction: ProfileFunction @Mock lateinit var profileFunction: ProfileFunction
@Mock lateinit var aapsLogger: AAPSLogger @Mock lateinit var aapsLogger: AAPSLogger
@Mock lateinit var config: Config @Mock lateinit var config: Config
@Mock lateinit var hardLimits: HardLimits
private var injector: HasAndroidInjector = HasAndroidInjector { private var injector: HasAndroidInjector = HasAndroidInjector {
AndroidInjector { AndroidInjector {
@ -39,7 +41,7 @@ class InsulinOrefUltraRapidActingPluginTest {
@Before @Before
fun setup() { fun setup() {
sut = InsulinOrefUltraRapidActingPlugin(injector, rh, profileFunction, rxBus, aapsLogger, config) sut = InsulinOrefUltraRapidActingPlugin(injector, rh, profileFunction, rxBus, aapsLogger, config, hardLimits)
} }
@Test @Test

View file

@ -10,7 +10,7 @@ import org.json.JSONException
import org.json.JSONObject import org.json.JSONObject
@Suppress("SpellCheckingInspection") @Suppress("SpellCheckingInspection")
class IobTotal(val time: Long) : DataPointWithLabelInterface { class IobTotal(val time: Long) : DataPointWithLabelInterface {
var iob = 0.0 var iob = 0.0
var activity = 0.0 var activity = 0.0
@ -51,15 +51,15 @@ class IobTotal(val time: Long) : DataPointWithLabelInterface {
return this return this
} }
fun round(fabricPrivacy: FabricPrivacy? = null): IobTotal { fun round(): IobTotal {
iob = Round.roundTo(iob, 0.001, fabricPrivacy) iob = Round.roundTo(iob, 0.001)
activity = Round.roundTo(activity, 0.0001, fabricPrivacy) activity = Round.roundTo(activity, 0.0001)
bolussnooze = Round.roundTo(bolussnooze, 0.0001, fabricPrivacy) bolussnooze = Round.roundTo(bolussnooze, 0.0001)
basaliob = Round.roundTo(basaliob, 0.001, fabricPrivacy) basaliob = Round.roundTo(basaliob, 0.001)
netbasalinsulin = Round.roundTo(netbasalinsulin, 0.001, fabricPrivacy) netbasalinsulin = Round.roundTo(netbasalinsulin, 0.001)
hightempinsulin = Round.roundTo(hightempinsulin, 0.001, fabricPrivacy) hightempinsulin = Round.roundTo(hightempinsulin, 0.001)
netInsulin = Round.roundTo(netInsulin, 0.001, fabricPrivacy) netInsulin = Round.roundTo(netInsulin, 0.001)
extendedBolusInsulin = Round.roundTo(extendedBolusInsulin, 0.001, fabricPrivacy) extendedBolusInsulin = Round.roundTo(extendedBolusInsulin, 0.001)
return this return this
} }

View file

@ -2,6 +2,7 @@ package info.nightscout.androidaps.utils
import android.os.Bundle import android.os.Bundle
import java.math.BigDecimal import java.math.BigDecimal
import java.security.InvalidParameterException
import kotlin.math.abs import kotlin.math.abs
import kotlin.math.ceil import kotlin.math.ceil
import kotlin.math.floor import kotlin.math.floor
@ -12,16 +13,10 @@ import kotlin.math.roundToLong
*/ */
object Round { object Round {
fun roundTo(x: Double, step: Double, fabricPrivacy: FabricPrivacy? = null): Double = try { fun roundTo(x: Double, step: Double): Double {
if (x == 0.0) 0.0 if (x.isNaN()) throw InvalidParameterException("Parameter is NaN")
return if (x == 0.0) 0.0
else BigDecimal.valueOf((x / step).roundToLong()).multiply(BigDecimal.valueOf(step)).toDouble() else BigDecimal.valueOf((x / step).roundToLong()).multiply(BigDecimal.valueOf(step)).toDouble()
} catch (e: Exception) {
fabricPrivacy?.logCustom("Error_roundTo", Bundle().apply {
putDouble("x", x)
putDouble("step", step)
putString("stacktrace", e.stackTraceToString())
})
0.0
} }
fun floorTo(x: Double, step: Double): Double = fun floorTo(x: Double, step: Double): Double =

View file

@ -354,8 +354,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
insulin = constraintChecker.applyExtendedBolusConstraints(new Constraint<>(insulin)).value(); insulin = constraintChecker.applyExtendedBolusConstraints(new Constraint<>(insulin)).value();
// needs to be rounded // needs to be rounded
int durationInHalfHours = Math.max(durationInMinutes / 30, 1); int durationInHalfHours = Math.max(durationInMinutes / 30, 1);
insulin = Round.INSTANCE.roundTo(insulin, getPumpDescription().getExtendedBolusStep(), insulin = Round.INSTANCE.roundTo(insulin, getPumpDescription().getExtendedBolusStep());
null);
PumpEnactResult result = new PumpEnactResult(getInjector()); PumpEnactResult result = new PumpEnactResult(getInjector());
if (danaPump.isExtendedInProgress() && Math.abs(danaPump.getExtendedBolusAmount() - insulin) < pumpDescription.getExtendedBolusStep()) { if (danaPump.isExtendedInProgress() && Math.abs(danaPump.getExtendedBolusAmount() - insulin) < pumpDescription.getExtendedBolusStep()) {

View file

@ -267,8 +267,7 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump
insulin = constraintChecker.applyExtendedBolusConstraints(new Constraint<>(insulin)).value(); insulin = constraintChecker.applyExtendedBolusConstraints(new Constraint<>(insulin)).value();
// needs to be rounded // needs to be rounded
int durationInHalfHours = Math.max(durationInMinutes / 30, 1); int durationInHalfHours = Math.max(durationInMinutes / 30, 1);
insulin = Round.INSTANCE.roundTo(insulin, getPumpDescription().getExtendedBolusStep(), insulin = Round.INSTANCE.roundTo(insulin, getPumpDescription().getExtendedBolusStep());
null);
PumpEnactResult result = new PumpEnactResult(getInjector()); PumpEnactResult result = new PumpEnactResult(getInjector());
if (danaPump.isExtendedInProgress() && Math.abs(danaPump.getExtendedBolusAmount() - insulin) < getPumpDescription().getExtendedBolusStep()) { if (danaPump.isExtendedInProgress() && Math.abs(danaPump.getExtendedBolusAmount() - insulin) < getPumpDescription().getExtendedBolusStep()) {

View file

@ -288,8 +288,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
double extendedRateToSet = absoluteRate - getBaseBasalRate(); double extendedRateToSet = absoluteRate - getBaseBasalRate();
extendedRateToSet = constraintChecker.applyBasalConstraints(new Constraint<>(extendedRateToSet), profile).value(); extendedRateToSet = constraintChecker.applyBasalConstraints(new Constraint<>(extendedRateToSet), profile).value();
// needs to be rounded to 0.1 // needs to be rounded to 0.1
extendedRateToSet = Round.INSTANCE.roundTo(extendedRateToSet, extendedRateToSet = Round.INSTANCE.roundTo(extendedRateToSet, pumpDescription.getExtendedBolusStep() * 2); // *2 because of half hours
pumpDescription.getExtendedBolusStep() * 2, null); // *2 because of half hours
// What is current rate of extended bolusing in u/h? // What is current rate of extended bolusing in u/h?
aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: Extended bolus in progress: " + (danaPump.isExtendedInProgress()) + " rate: " + danaPump.getExtendedBolusAbsoluteRate() + "U/h duration remaining: " + danaPump.getExtendedBolusRemainingMinutes() + "min"); aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: Extended bolus in progress: " + (danaPump.isExtendedInProgress()) + " rate: " + danaPump.getExtendedBolusAbsoluteRate() + "U/h duration remaining: " + danaPump.getExtendedBolusRemainingMinutes() + "min");