improve BgQualityCheckPlugin, fix test

This commit is contained in:
Milos Kozak 2022-12-07 10:43:52 +01:00
parent cd7832a6e1
commit 5d3a3f861a
6 changed files with 21 additions and 6 deletions

View file

@ -42,12 +42,14 @@ import info.nightscout.plugins.source.GlimpPlugin
import info.nightscout.pump.combo.ComboPlugin
import info.nightscout.pump.combo.ruffyscripter.RuffyScripter
import info.nightscout.pump.dana.DanaPump
import info.nightscout.pump.dana.R
import info.nightscout.pump.dana.database.DanaHistoryDatabase
import info.nightscout.shared.sharedPreferences.SP
import org.junit.Assert
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.mockito.Mock
import org.mockito.Mockito
import org.mockito.Mockito.`when`
/**
@ -131,7 +133,10 @@ class ConstraintsCheckerTest : TestBaseWithProfile() {
`when`(rh.gs(info.nightscout.plugins.R.string.objectivenotstarted)).thenReturn("Objective %1\$d not started")
// RS constructor
`when`(sp.getString(R.string.key_danars_name, "")).thenReturn("")
`when`(sp.getString(info.nightscout.pump.dana.R.string.key_danars_address, "")).thenReturn("")
// R
`when`(sp.getString(info.nightscout.pump.dana.R.string.key_danar_bt_name, "")).thenReturn("")
//SafetyPlugin
`when`(activePlugin.activePump).thenReturn(virtualPumpPlugin)

View file

@ -26,6 +26,7 @@ import io.reactivex.rxjava3.kotlin.plusAssign
import javax.inject.Inject
import javax.inject.Singleton
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min
@Singleton
@ -115,9 +116,13 @@ class BgQualityCheckPlugin @Inject constructor(
if (data[data.size - 1].timestamp > now - 45 * 60 * 1000L) return null // data too fresh to detect
if (data[0].timestamp < now - 7 * 60 * 1000L) return null // data is old
var bgmin: Double = lastBg
var bgmax: Double = bgmin
for (bg in data) {
if (bg.timestamp < offset) break
if (abs(lastBg - bg.value) > maxDelta) return false
bgmin = min(bgmin, bg.value)
bgmax = max(bgmax, bg.value)
if (bgmax - bgmin > maxDelta) return false
}
return true
}
@ -142,6 +147,6 @@ class BgQualityCheckPlugin @Inject constructor(
companion object {
const val staleBgCheckPeriodMinutes = 45L
const val staleBgMaxDeltaMgdl = 1.0
const val staleBgMaxDeltaMgdl = 2.0
}
}

View file

@ -42,6 +42,7 @@ class DanaRPluginTest : TestBaseWithProfile() {
@BeforeEach
fun prepareMocks() {
`when`(sp.getString(info.nightscout.pump.dana.R.string.key_danars_address, "")).thenReturn("")
`when`(sp.getString(info.nightscout.pump.dana.R.string.key_danar_bt_name, "")).thenReturn("")
`when`(rh.gs(info.nightscout.core.ui.R.string.pumplimit)).thenReturn("pump limit")
`when`(rh.gs(info.nightscout.core.ui.R.string.itmustbepositivevalue)).thenReturn("it must be positive value")
`when`(rh.gs(info.nightscout.core.ui.R.string.limitingbasalratio)).thenReturn("Limiting max basal rate to %1\$.2f U/h because of %2\$s")

View file

@ -42,6 +42,7 @@ class DanaRKoreanPluginTest : TestBaseWithProfile() {
@BeforeEach
fun prepareMocks() {
`when`(sp.getString(info.nightscout.pump.dana.R.string.key_danars_address, "")).thenReturn("")
`when`(sp.getString(info.nightscout.pump.dana.R.string.key_danar_bt_name, "")).thenReturn("")
`when`(rh.gs(info.nightscout.core.ui.R.string.pumplimit)).thenReturn("pump limit")
`when`(rh.gs(info.nightscout.core.ui.R.string.itmustbepositivevalue)).thenReturn("it must be positive value")
`when`(rh.gs(info.nightscout.core.ui.R.string.limitingbasalratio)).thenReturn("Limiting max basal rate to %1\$.2f U/h because of %2\$s")

View file

@ -44,15 +44,17 @@ class DanaRv2PluginTest : TestBaseWithProfile() {
@BeforeEach
fun prepareMocks() {
`when`(sp.getString(info.nightscout.pump.dana.R.string.key_danars_address, ""))
.thenReturn("")
`when`(sp.getString(info.nightscout.pump.dana.R.string.key_danar_bt_name, "")).thenReturn("")
`when`(sp.getString(info.nightscout.pump.dana.R.string.key_danars_address, "")).thenReturn("")
`when`(rh.gs(info.nightscout.core.ui.R.string.pumplimit)).thenReturn("pump limit")
`when`(rh.gs(info.nightscout.core.ui.R.string.itmustbepositivevalue)).thenReturn("it must be positive value")
`when`(rh.gs(info.nightscout.core.ui.R.string.limitingbasalratio)).thenReturn("Limiting max basal rate to %1\$.2f U/h because of %2\$s")
`when`(rh.gs(info.nightscout.core.ui.R.string.limitingpercentrate)).thenReturn("Limiting max percent rate to %1\$d%% because of %2\$s")
danaPump = DanaPump(aapsLogger, sp, dateUtil, profileInstantiator)
danaRv2Plugin = DanaRv2Plugin(injector, aapsLogger, aapsSchedulers, rxBus, context, rh, constraintChecker, activePluginProvider, sp, commandQueue, danaPump, detailedBolusInfoStorage,
temporaryBasalStorage, dateUtil, fabricPrivacy, pumpSync, uiInteraction, danaHistoryDatabase)
danaRv2Plugin = DanaRv2Plugin(
injector, aapsLogger, aapsSchedulers, rxBus, context, rh, constraintChecker, activePluginProvider, sp, commandQueue, danaPump, detailedBolusInfoStorage,
temporaryBasalStorage, dateUtil, fabricPrivacy, pumpSync, uiInteraction, danaHistoryDatabase
)
}
@Test

View file

@ -57,6 +57,7 @@ class DanaRSPluginTest : DanaRSTestBase() {
@BeforeEach
fun prepareMocks() {
Mockito.`when`(sp.getString(info.nightscout.pump.dana.R.string.key_danars_name, "")).thenReturn("")
Mockito.`when`(sp.getString(info.nightscout.pump.dana.R.string.key_danars_address, "")).thenReturn("")
Mockito.`when`(rh.gs(eq(info.nightscout.core.ui.R.string.limitingbasalratio), anyObject(), anyObject())).thenReturn("limitingbasalratio")
Mockito.`when`(rh.gs(eq(info.nightscout.core.ui.R.string.limitingpercentrate), anyObject(), anyObject())).thenReturn("limitingpercentrate")