UI: fix display bg when there is less than 3 BGs available
This commit is contained in:
parent
0a34c77ce8
commit
50818c2d4c
4 changed files with 104 additions and 6 deletions
|
@ -47,6 +47,15 @@ interface OverviewData {
|
||||||
* BG
|
* BG
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get newest glucose value from bucketed data.
|
||||||
|
* If there are less than 3 glucose values, bucketed data is not created.
|
||||||
|
* In this case take newest [GlucoseValue] from db and convert it to [InMemoryGlucoseValue]
|
||||||
|
*
|
||||||
|
* Intended for display on screen only
|
||||||
|
*
|
||||||
|
* @return newest glucose value
|
||||||
|
*/
|
||||||
fun lastBg(autosensDataStore: AutosensDataStore): InMemoryGlucoseValue?
|
fun lastBg(autosensDataStore: AutosensDataStore): InMemoryGlucoseValue?
|
||||||
fun isLow(autosensDataStore: AutosensDataStore): Boolean
|
fun isLow(autosensDataStore: AutosensDataStore): Boolean
|
||||||
fun isHigh(autosensDataStore: AutosensDataStore): Boolean
|
fun isHigh(autosensDataStore: AutosensDataStore): Boolean
|
||||||
|
|
|
@ -138,11 +138,11 @@ class OverviewDataImpl @Inject constructor(
|
||||||
*/
|
*/
|
||||||
|
|
||||||
override fun lastBg(autosensDataStore: AutosensDataStore): InMemoryGlucoseValue? =
|
override fun lastBg(autosensDataStore: AutosensDataStore): InMemoryGlucoseValue? =
|
||||||
autosensDataStore.bucketedData?.let { if (it.size > 0) it[0] else null }
|
autosensDataStore.bucketedData?.firstOrNull()
|
||||||
// repository.getLastGlucoseValueWrapped().blockingGet().let { gvWrapped ->
|
?: repository.getLastGlucoseValueWrapped().blockingGet().let { gvWrapped ->
|
||||||
// if (gvWrapped is ValueWrapper.Existing) gvWrapped.value
|
if (gvWrapped is ValueWrapper.Existing) InMemoryGlucoseValue(gvWrapped.value)
|
||||||
// else null
|
else null
|
||||||
// }
|
}
|
||||||
|
|
||||||
override fun isLow(autosensDataStore: AutosensDataStore): Boolean =
|
override fun isLow(autosensDataStore: AutosensDataStore): Boolean =
|
||||||
lastBg(autosensDataStore)?.let { lastBg ->
|
lastBg(autosensDataStore)?.let { lastBg ->
|
||||||
|
|
|
@ -0,0 +1,90 @@
|
||||||
|
package info.nightscout.implementation.overview
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.TestBase
|
||||||
|
import info.nightscout.database.ValueWrapper
|
||||||
|
import info.nightscout.database.entities.GlucoseValue
|
||||||
|
import info.nightscout.database.impl.AppRepository
|
||||||
|
import info.nightscout.interfaces.GlucoseUnit
|
||||||
|
import info.nightscout.interfaces.aps.AutosensDataStore
|
||||||
|
import info.nightscout.interfaces.iob.InMemoryGlucoseValue
|
||||||
|
import info.nightscout.interfaces.plugin.ActivePlugin
|
||||||
|
import info.nightscout.interfaces.profile.DefaultValueHelper
|
||||||
|
import info.nightscout.interfaces.profile.ProfileFunction
|
||||||
|
import info.nightscout.shared.interfaces.ResourceHelper
|
||||||
|
import info.nightscout.shared.sharedPreferences.SP
|
||||||
|
import info.nightscout.shared.utils.DateUtil
|
||||||
|
import info.nightscout.shared.utils.T
|
||||||
|
import io.reactivex.rxjava3.core.Single
|
||||||
|
import org.junit.jupiter.api.Assertions
|
||||||
|
import org.junit.jupiter.api.BeforeEach
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
import org.mockito.Mock
|
||||||
|
import org.mockito.Mockito
|
||||||
|
|
||||||
|
class OverviewDataImplTest : TestBase() {
|
||||||
|
|
||||||
|
@Mock lateinit var rh: ResourceHelper
|
||||||
|
@Mock lateinit var dateUtil: DateUtil
|
||||||
|
@Mock lateinit var sp: SP
|
||||||
|
@Mock lateinit var activePlugin: ActivePlugin
|
||||||
|
@Mock lateinit var defaultValueHelper: DefaultValueHelper
|
||||||
|
@Mock lateinit var profileFunction: ProfileFunction
|
||||||
|
@Mock lateinit var repository: AppRepository
|
||||||
|
@Mock lateinit var autosensDataStore: AutosensDataStore
|
||||||
|
|
||||||
|
private lateinit var sut: OverviewDataImpl
|
||||||
|
private val time = 1000000L
|
||||||
|
|
||||||
|
private val glucoseValue =
|
||||||
|
GlucoseValue(raw = 200.0, noise = 0.0, value = 200.0, timestamp = time, sourceSensor = GlucoseValue.SourceSensor.UNKNOWN, trendArrow = GlucoseValue.TrendArrow.FLAT)
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
fun setup() {
|
||||||
|
sut = OverviewDataImpl(aapsLogger, rh, dateUtil, sp, activePlugin, defaultValueHelper, profileFunction, repository)
|
||||||
|
Mockito.`when`(defaultValueHelper.determineLowLine()).thenReturn(80.0)
|
||||||
|
Mockito.`when`(defaultValueHelper.determineHighLine()).thenReturn(180.0)
|
||||||
|
Mockito.`when`(profileFunction.getUnits()).thenReturn(GlucoseUnit.MGDL)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun lastBg() {
|
||||||
|
val bucketedData: MutableList<InMemoryGlucoseValue> = mutableListOf()
|
||||||
|
bucketedData.add(InMemoryGlucoseValue(time, 70.0, sourceSensor = GlucoseValue.SourceSensor.UNKNOWN))
|
||||||
|
// no data
|
||||||
|
Mockito.`when`(autosensDataStore.bucketedData).thenReturn(null)
|
||||||
|
Mockito.`when`(repository.getLastGlucoseValueWrapped()).thenReturn(Single.just(ValueWrapper.Absent()))
|
||||||
|
Assertions.assertNull(sut.lastBg(autosensDataStore))
|
||||||
|
Assertions.assertFalse(sut.isLow(autosensDataStore))
|
||||||
|
Assertions.assertFalse(sut.isHigh(autosensDataStore))
|
||||||
|
|
||||||
|
// no bucketed but in db
|
||||||
|
Mockito.`when`(autosensDataStore.bucketedData).thenReturn(null)
|
||||||
|
Mockito.`when`(repository.getLastGlucoseValueWrapped()).thenReturn(Single.just(ValueWrapper.Existing(glucoseValue)))
|
||||||
|
Assertions.assertEquals(200.0, sut.lastBg(autosensDataStore)?.value)
|
||||||
|
Assertions.assertFalse(sut.isLow(autosensDataStore))
|
||||||
|
Assertions.assertTrue(sut.isHigh(autosensDataStore))
|
||||||
|
|
||||||
|
// in bucketed
|
||||||
|
Mockito.`when`(autosensDataStore.bucketedData).thenReturn(bucketedData)
|
||||||
|
Mockito.`when`(repository.getLastGlucoseValueWrapped()).thenReturn(Single.just(ValueWrapper.Existing(glucoseValue)))
|
||||||
|
Assertions.assertEquals(70.0, sut.lastBg(autosensDataStore)?.value)
|
||||||
|
Assertions.assertTrue(sut.isLow(autosensDataStore))
|
||||||
|
Assertions.assertFalse(sut.isHigh(autosensDataStore))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun isActualBg() {
|
||||||
|
// no bucketed but in db
|
||||||
|
Mockito.`when`(autosensDataStore.bucketedData).thenReturn(null)
|
||||||
|
Mockito.`when`(repository.getLastGlucoseValueWrapped()).thenReturn(Single.just(ValueWrapper.Existing(glucoseValue)))
|
||||||
|
Mockito.`when`(dateUtil.now()).thenReturn(time + T.mins(1).msecs())
|
||||||
|
Assertions.assertTrue(sut.isActualBg(autosensDataStore))
|
||||||
|
Mockito.`when`(dateUtil.now()).thenReturn(time + T.mins(9).msecs() + 1)
|
||||||
|
Assertions.assertFalse(sut.isActualBg(autosensDataStore))
|
||||||
|
|
||||||
|
// no data
|
||||||
|
Mockito.`when`(autosensDataStore.bucketedData).thenReturn(null)
|
||||||
|
Mockito.`when`(repository.getLastGlucoseValueWrapped()).thenReturn(Single.just(ValueWrapper.Absent()))
|
||||||
|
Assertions.assertFalse(sut.isActualBg(autosensDataStore))
|
||||||
|
}
|
||||||
|
}
|
|
@ -43,7 +43,6 @@ class LoadBgDataWorker(
|
||||||
bgReadings = repository
|
bgReadings = repository
|
||||||
.compatGetBgReadingsDataFromTime(start, to + T.mins(2).msecs(), false)
|
.compatGetBgReadingsDataFromTime(start, to + T.mins(2).msecs(), false)
|
||||||
.blockingGet()
|
.blockingGet()
|
||||||
.filter { it.value >= 39 }
|
|
||||||
aapsLogger.debug(LTag.AUTOSENS) { "BG data loaded. Size: ${bgReadings.size} Start date: ${dateUtil.dateAndTimeString(start)} End date: ${dateUtil.dateAndTimeString(to)}" }
|
aapsLogger.debug(LTag.AUTOSENS) { "BG data loaded. Size: ${bgReadings.size} Start date: ${dateUtil.dateAndTimeString(start)} End date: ${dateUtil.dateAndTimeString(to)}" }
|
||||||
createBucketedData(aapsLogger, dateUtil)
|
createBucketedData(aapsLogger, dateUtil)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue