Merge branch 'dev' into ns15

This commit is contained in:
Milos Kozak 2023-02-13 12:18:03 +01:00
commit 437c15774c
6 changed files with 98 additions and 79 deletions

View file

@ -23,10 +23,14 @@ class InMemoryGlucoseValue constructor(
* if true value is not corresponding to received value,
* but it was recalculated to fill gap between BGs
*/
var filledGap: Boolean = false
var filledGap: Boolean = false,
/**
* Taken from GlucoseValue
*/
var sourceSensor: GlucoseValue.SourceSensor
) {
constructor(gv: GlucoseValue) : this(gv.timestamp, gv.value, gv.trendArrow)
constructor(gv: GlucoseValue) : this(timestamp = gv.timestamp, value = gv.value, trendArrow = gv.trendArrow, sourceSensor = gv.sourceSensor)
/**
* Provide smoothed value if available,

View file

@ -1,14 +1,10 @@
package info.nightscout.database.entities
import androidx.room.Embedded
import androidx.room.Entity
import androidx.room.ForeignKey
import androidx.room.Index
import androidx.room.PrimaryKey
import androidx.room.*
import info.nightscout.database.entities.embedments.InterfaceIDs
import info.nightscout.database.entities.interfaces.DBEntryWithTime
import info.nightscout.database.entities.interfaces.TraceableDBEntry
import java.util.TimeZone
import java.util.*
@Entity(
tableName = TABLE_GLUCOSE_VALUES,
@ -97,6 +93,7 @@ data class GlucoseValue(
DEXCOM_G6_NATIVE_XDRIP("G6 Native"),
DEXCOM_G5_NATIVE_XDRIP("G5 Native"),
DEXCOM_G6_G5_NATIVE_XDRIP("G6 Native / G5 Native"),
LIBRE_1_OTHER("Other App"),
LIBRE_1_NET("Network libre"),
LIBRE_1_BLUE("BlueReader"),
LIBRE_1_PL("Transmiter PL"),
@ -104,7 +101,9 @@ data class GlucoseValue(
LIBRE_1_TOMATO("Tomato"),
LIBRE_1_RF("Rfduino"),
LIBRE_1_LIMITTER("LimiTTer"),
GLIMP("Glimp"),
LIBRE_1_BUBBLE("Bubble"),
LIBRE_1_ATOM("Bubble"),
LIBRE_1_GLIMP("Glimp"),
LIBRE_2_NATIVE("Libre2"),
POCTECH_NATIVE("Poctech"),
GLUNOVO_NATIVE("Glunovo"),
@ -122,9 +121,26 @@ data class GlucoseValue(
ZT_PREDICTION("ZTPrediction"),
;
fun isLibre(): Boolean = arrayListOf(
LIBRE_1_OTHER,
LIBRE_1_NET,
LIBRE_1_BLUE,
LIBRE_1_PL,
LIBRE_1_BLUCON,
LIBRE_1_TOMATO,
LIBRE_1_RF,
LIBRE_1_LIMITTER,
LIBRE_1_BUBBLE,
LIBRE_1_ATOM,
LIBRE_1_GLIMP,
LIBRE_2_NATIVE,
UNKNOWN // Better check for FLAT on unknown sources too
).any { it.text == text }
companion object {
fun fromString(source: String?) = values().firstOrNull { it.text == source } ?: UNKNOWN
}
}
}

View file

@ -11,7 +11,6 @@ import info.nightscout.interfaces.plugin.ActivePlugin
import info.nightscout.interfaces.plugin.PluginBase
import info.nightscout.interfaces.plugin.PluginDescription
import info.nightscout.interfaces.plugin.PluginType
import info.nightscout.interfaces.source.DexcomBoyda
import info.nightscout.plugins.constraints.R
import info.nightscout.rx.AapsSchedulers
import info.nightscout.rx.bus.RxBus
@ -78,6 +77,7 @@ class BgQualityCheckPlugin @Inject constructor(
fun processBgData() {
val readings = iobCobCalculator.ads.getBgReadingsDataTableCopy()
val lastBg = iobCobCalculator.ads.lastBg()
for (i in readings.indices)
// Deltas are calculated from last ~50 min. Detect RED state only on this interval
if (i < min(readings.size - 2, 10))
@ -87,7 +87,7 @@ class BgQualityCheckPlugin @Inject constructor(
message = rh.gs(R.string.bg_too_close, dateUtil.dateAndTimeAndSecondsString(readings[i].timestamp), dateUtil.dateAndTimeAndSecondsString(readings[i + 1].timestamp))
return
}
if (activePlugin.activeBgSource !is DexcomBoyda && isBgFlatForInterval(staleBgCheckPeriodMinutes, staleBgMaxDeltaMgdl) == true) {
if (lastBg?.sourceSensor?.isLibre() == true && isBgFlatForInterval(staleBgCheckPeriodMinutes, staleBgMaxDeltaMgdl) == true) {
state = BgQualityCheck.State.FLAT
message = rh.gs(R.string.a11y_bg_quality_flat)
} else if (iobCobCalculator.ads.lastUsed5minCalculation == true) {

View file

@ -11,8 +11,6 @@ import info.nightscout.interfaces.constraints.Constraint
import info.nightscout.interfaces.iob.InMemoryGlucoseValue
import info.nightscout.interfaces.iob.IobCobCalculator
import info.nightscout.interfaces.plugin.ActivePlugin
import info.nightscout.interfaces.source.BgSource
import info.nightscout.interfaces.source.DexcomBoyda
import info.nightscout.plugins.constraints.R
import info.nightscout.rx.bus.RxBus
import info.nightscout.shared.interfaces.ResourceHelper
@ -77,10 +75,10 @@ class BgQualityCheckPluginTest : TestBase() {
Assertions.assertEquals(R.drawable.ic_baseline_warning_24_yellow, plugin.icon())
val superData: MutableList<GlucoseValue> = ArrayList()
superData.add(GlucoseValue(raw = 0.0, noise = 0.0, value = 100.0, timestamp = T.mins(20).msecs(), sourceSensor = GlucoseValue.SourceSensor.UNKNOWN, trendArrow = GlucoseValue.TrendArrow.FLAT))
superData.add(GlucoseValue(raw = 0.0, noise = 0.0, value = 100.0, timestamp = T.mins(15).msecs(), sourceSensor = GlucoseValue.SourceSensor.UNKNOWN, trendArrow = GlucoseValue.TrendArrow.FLAT))
superData.add(GlucoseValue(raw = 0.0, noise = 0.0, value = 100.0, timestamp = T.mins(10).msecs(), sourceSensor = GlucoseValue.SourceSensor.UNKNOWN, trendArrow = GlucoseValue.TrendArrow.FLAT))
superData.add(GlucoseValue(raw = 0.0, noise = 0.0, value = 100.0, timestamp = T.mins(5).msecs(), sourceSensor = GlucoseValue.SourceSensor.UNKNOWN, trendArrow = GlucoseValue.TrendArrow.FLAT))
superData.add(GlucoseValue(raw = 0.0, noise = 0.0, value = 100.0, timestamp = T.mins(20).msecs(), sourceSensor = GlucoseValue.SourceSensor.LIBRE_1_OTHER, trendArrow = GlucoseValue.TrendArrow.FLAT))
superData.add(GlucoseValue(raw = 0.0, noise = 0.0, value = 100.0, timestamp = T.mins(15).msecs(), sourceSensor = GlucoseValue.SourceSensor.LIBRE_1_OTHER, trendArrow = GlucoseValue.TrendArrow.FLAT))
superData.add(GlucoseValue(raw = 0.0, noise = 0.0, value = 100.0, timestamp = T.mins(10).msecs(), sourceSensor = GlucoseValue.SourceSensor.LIBRE_1_OTHER, trendArrow = GlucoseValue.TrendArrow.FLAT))
superData.add(GlucoseValue(raw = 0.0, noise = 0.0, value = 100.0, timestamp = T.mins(5).msecs(), sourceSensor = GlucoseValue.SourceSensor.LIBRE_1_OTHER, trendArrow = GlucoseValue.TrendArrow.FLAT))
`when`(autosensDataStore.getBgReadingsDataTableCopy()).thenReturn(superData)
`when`(autosensDataStore.lastUsed5minCalculation).thenReturn(true)
@ -97,7 +95,7 @@ class BgQualityCheckPluginTest : TestBase() {
noise = 0.0,
value = 100.0,
timestamp = T.mins(20).msecs(),
sourceSensor = GlucoseValue.SourceSensor.UNKNOWN,
sourceSensor = GlucoseValue.SourceSensor.LIBRE_1_OTHER,
trendArrow = GlucoseValue.TrendArrow.FLAT
)
)
@ -107,7 +105,7 @@ class BgQualityCheckPluginTest : TestBase() {
noise = 0.0,
value = 100.0,
timestamp = T.mins(20).msecs() + 1,
sourceSensor = GlucoseValue.SourceSensor.UNKNOWN,
sourceSensor = GlucoseValue.SourceSensor.LIBRE_1_OTHER,
trendArrow = GlucoseValue.TrendArrow.FLAT
)
)
@ -117,7 +115,7 @@ class BgQualityCheckPluginTest : TestBase() {
noise = 0.0,
value = 100.0,
timestamp = T.mins(10).msecs(),
sourceSensor = GlucoseValue.SourceSensor.UNKNOWN,
sourceSensor = GlucoseValue.SourceSensor.LIBRE_1_OTHER,
trendArrow = GlucoseValue.TrendArrow.FLAT
)
)
@ -127,7 +125,7 @@ class BgQualityCheckPluginTest : TestBase() {
noise = 0.0,
value = 100.0,
timestamp = T.mins(15).msecs(),
sourceSensor = GlucoseValue.SourceSensor.UNKNOWN,
sourceSensor = GlucoseValue.SourceSensor.LIBRE_1_OTHER,
trendArrow = GlucoseValue.TrendArrow.FLAT
)
)
@ -137,7 +135,7 @@ class BgQualityCheckPluginTest : TestBase() {
noise = 0.0,
value = 100.0,
timestamp = T.mins(5).msecs(),
sourceSensor = GlucoseValue.SourceSensor.UNKNOWN,
sourceSensor = GlucoseValue.SourceSensor.LIBRE_1_OTHER,
trendArrow = GlucoseValue.TrendArrow.FLAT
)
)
@ -155,7 +153,7 @@ class BgQualityCheckPluginTest : TestBase() {
noise = 0.0,
value = 100.0,
timestamp = T.mins(20).msecs(),
sourceSensor = GlucoseValue.SourceSensor.UNKNOWN,
sourceSensor = GlucoseValue.SourceSensor.LIBRE_1_OTHER,
trendArrow = GlucoseValue.TrendArrow.FLAT
)
)
@ -165,7 +163,7 @@ class BgQualityCheckPluginTest : TestBase() {
noise = 0.0,
value = 100.0,
timestamp = T.mins(20).msecs(),
sourceSensor = GlucoseValue.SourceSensor.UNKNOWN,
sourceSensor = GlucoseValue.SourceSensor.LIBRE_1_OTHER,
trendArrow = GlucoseValue.TrendArrow.FLAT
)
)
@ -175,7 +173,7 @@ class BgQualityCheckPluginTest : TestBase() {
noise = 0.0,
value = 100.0,
timestamp = T.mins(10).msecs(),
sourceSensor = GlucoseValue.SourceSensor.UNKNOWN,
sourceSensor = GlucoseValue.SourceSensor.LIBRE_1_OTHER,
trendArrow = GlucoseValue.TrendArrow.FLAT
)
)
@ -185,7 +183,7 @@ class BgQualityCheckPluginTest : TestBase() {
noise = 0.0,
value = 100.0,
timestamp = T.mins(15).msecs(),
sourceSensor = GlucoseValue.SourceSensor.UNKNOWN,
sourceSensor = GlucoseValue.SourceSensor.LIBRE_1_OTHER,
trendArrow = GlucoseValue.TrendArrow.FLAT
)
)
@ -195,7 +193,7 @@ class BgQualityCheckPluginTest : TestBase() {
noise = 0.0,
value = 100.0,
timestamp = T.mins(5).msecs(),
sourceSensor = GlucoseValue.SourceSensor.UNKNOWN,
sourceSensor = GlucoseValue.SourceSensor.LIBRE_1_OTHER,
trendArrow = GlucoseValue.TrendArrow.FLAT
)
)
@ -205,60 +203,59 @@ class BgQualityCheckPluginTest : TestBase() {
plugin.processBgData()
Assertions.assertEquals(BgQualityCheck.State.DOUBLED, plugin.state)
// Flat data
// Flat data Libre
val flatData: MutableList<GlucoseValue> = ArrayList()
flatData.add(GlucoseValue(raw = 0.0, noise = 0.0, value = 100.0, timestamp = now + T.mins(0).msecs(), sourceSensor = GlucoseValue.SourceSensor.UNKNOWN, trendArrow = GlucoseValue.TrendArrow
.FLAT))
flatData.add(GlucoseValue(raw = 0.0, noise = 0.0, value = 100.0, timestamp = now + T.mins(-5).msecs(), sourceSensor = GlucoseValue.SourceSensor.UNKNOWN, trendArrow = GlucoseValue.TrendArrow.FLAT))
flatData.add(GlucoseValue(raw = 0.0, noise = 0.0, value = 101.0, timestamp = now + T.mins(-10).msecs(), sourceSensor = GlucoseValue.SourceSensor.UNKNOWN, trendArrow = GlucoseValue.TrendArrow.FLAT))
flatData.add(GlucoseValue(raw = 0.0, noise = 0.0, value = 100.0, timestamp = now + T.mins(-15).msecs(), sourceSensor = GlucoseValue.SourceSensor.UNKNOWN, trendArrow = GlucoseValue.TrendArrow.FLAT))
flatData.add(GlucoseValue(raw = 0.0, noise = 0.0, value = 100.0, timestamp = now + T.mins(-20).msecs(), sourceSensor = GlucoseValue.SourceSensor.UNKNOWN, trendArrow = GlucoseValue.TrendArrow.FLAT))
flatData.add(GlucoseValue(raw = 0.0, noise = 0.0, value = 100.0, timestamp = now + T.mins(-25).msecs(), sourceSensor = GlucoseValue.SourceSensor.UNKNOWN, trendArrow = GlucoseValue.TrendArrow.FLAT))
flatData.add(GlucoseValue(raw = 0.0, noise = 0.0, value = 99.0, timestamp = now + T.mins(-30).msecs(), sourceSensor = GlucoseValue.SourceSensor.UNKNOWN, trendArrow = GlucoseValue.TrendArrow.FLAT))
flatData.add(GlucoseValue(raw = 0.0, noise = 0.0, value = 100.0, timestamp = now + T.mins(-35).msecs(), sourceSensor = GlucoseValue.SourceSensor.UNKNOWN, trendArrow = GlucoseValue.TrendArrow.FLAT))
flatData.add(GlucoseValue(raw = 0.0, noise = 0.0, value = 100.0, timestamp = now + T.mins(-40).msecs(), sourceSensor = GlucoseValue.SourceSensor.UNKNOWN, trendArrow = GlucoseValue.TrendArrow.FLAT))
flatData.add(GlucoseValue(raw = 0.0, noise = 0.0, value = 100.0, timestamp = now + T.mins(-45).msecs(), sourceSensor = GlucoseValue.SourceSensor.UNKNOWN, trendArrow = GlucoseValue.TrendArrow.FLAT))
flatData.add(GlucoseValue(raw = 0.0, noise = 0.0, value = 100.0, timestamp = now + T.mins(0).msecs(), sourceSensor = GlucoseValue.SourceSensor.LIBRE_1_OTHER, trendArrow = GlucoseValue.TrendArrow.FLAT))
flatData.add(GlucoseValue(raw = 0.0, noise = 0.0, value = 100.0, timestamp = now + T.mins(-5).msecs(), sourceSensor = GlucoseValue.SourceSensor.LIBRE_1_OTHER, trendArrow = GlucoseValue.TrendArrow.FLAT))
flatData.add(GlucoseValue(raw = 0.0, noise = 0.0, value = 101.0, timestamp = now + T.mins(-10).msecs(), sourceSensor = GlucoseValue.SourceSensor.LIBRE_1_OTHER, trendArrow = GlucoseValue.TrendArrow.FLAT))
flatData.add(GlucoseValue(raw = 0.0, noise = 0.0, value = 100.0, timestamp = now + T.mins(-15).msecs(), sourceSensor = GlucoseValue.SourceSensor.LIBRE_1_OTHER, trendArrow = GlucoseValue.TrendArrow.FLAT))
flatData.add(GlucoseValue(raw = 0.0, noise = 0.0, value = 100.0, timestamp = now + T.mins(-20).msecs(), sourceSensor = GlucoseValue.SourceSensor.LIBRE_1_OTHER, trendArrow = GlucoseValue.TrendArrow.FLAT))
flatData.add(GlucoseValue(raw = 0.0, noise = 0.0, value = 100.0, timestamp = now + T.mins(-25).msecs(), sourceSensor = GlucoseValue.SourceSensor.LIBRE_1_OTHER, trendArrow = GlucoseValue.TrendArrow.FLAT))
flatData.add(GlucoseValue(raw = 0.0, noise = 0.0, value = 99.0, timestamp = now + T.mins(-30).msecs(), sourceSensor = GlucoseValue.SourceSensor.LIBRE_1_OTHER, trendArrow = GlucoseValue.TrendArrow.FLAT))
flatData.add(GlucoseValue(raw = 0.0, noise = 0.0, value = 100.0, timestamp = now + T.mins(-35).msecs(), sourceSensor = GlucoseValue.SourceSensor.LIBRE_1_OTHER, trendArrow = GlucoseValue.TrendArrow.FLAT))
flatData.add(GlucoseValue(raw = 0.0, noise = 0.0, value = 100.0, timestamp = now + T.mins(-40).msecs(), sourceSensor = GlucoseValue.SourceSensor.LIBRE_1_OTHER, trendArrow = GlucoseValue.TrendArrow.FLAT))
flatData.add(GlucoseValue(raw = 0.0, noise = 0.0, value = 100.0, timestamp = now + T.mins(-45).msecs(), sourceSensor = GlucoseValue.SourceSensor.LIBRE_1_OTHER, trendArrow = GlucoseValue.TrendArrow.FLAT))
`when`(autosensDataStore.getBgReadingsDataTableCopy()).thenReturn(flatData)
`when`(iobCobCalculator.ads.lastBg()).thenReturn(InMemoryGlucoseValue(flatData[0]))
// Test non-dexcom plugin on flat data
class OtherPlugin : BgSource {
override fun shouldUploadToNs(glucoseValue: GlucoseValue): Boolean = true
}
`when`(activePlugin.activeBgSource).thenReturn(OtherPlugin())
plugin.processBgData()
Assertions.assertEquals(BgQualityCheck.State.FLAT, plugin.state)
Assertions.assertEquals(R.drawable.ic_baseline_trending_flat_24, plugin.icon())
// Test dexcom plugin on flat data
class DexcomPlugin : BgSource, DexcomBoyda {
// Flat data Libre
val flatDataDexcom: MutableList<GlucoseValue> = ArrayList()
flatDataDexcom.add(GlucoseValue(raw = 0.0, noise = 0.0, value = 100.0, timestamp = now + T.mins(0).msecs(), sourceSensor = GlucoseValue.SourceSensor.DEXCOM_G6_NATIVE, trendArrow = GlucoseValue.TrendArrow.FLAT))
flatDataDexcom.add(GlucoseValue(raw = 0.0, noise = 0.0, value = 100.0, timestamp = now + T.mins(-5).msecs(), sourceSensor = GlucoseValue.SourceSensor.DEXCOM_G6_NATIVE, trendArrow = GlucoseValue.TrendArrow.FLAT))
flatDataDexcom.add(GlucoseValue(raw = 0.0, noise = 0.0, value = 101.0, timestamp = now + T.mins(-10).msecs(), sourceSensor = GlucoseValue.SourceSensor.DEXCOM_G6_NATIVE, trendArrow = GlucoseValue.TrendArrow.FLAT))
flatDataDexcom.add(GlucoseValue(raw = 0.0, noise = 0.0, value = 100.0, timestamp = now + T.mins(-15).msecs(), sourceSensor = GlucoseValue.SourceSensor.DEXCOM_G6_NATIVE, trendArrow = GlucoseValue.TrendArrow.FLAT))
flatDataDexcom.add(GlucoseValue(raw = 0.0, noise = 0.0, value = 100.0, timestamp = now + T.mins(-20).msecs(), sourceSensor = GlucoseValue.SourceSensor.DEXCOM_G6_NATIVE, trendArrow = GlucoseValue.TrendArrow.FLAT))
flatDataDexcom.add(GlucoseValue(raw = 0.0, noise = 0.0, value = 100.0, timestamp = now + T.mins(-25).msecs(), sourceSensor = GlucoseValue.SourceSensor.DEXCOM_G6_NATIVE, trendArrow = GlucoseValue.TrendArrow.FLAT))
flatDataDexcom.add(GlucoseValue(raw = 0.0, noise = 0.0, value = 99.0, timestamp = now + T.mins(-30).msecs(), sourceSensor = GlucoseValue.SourceSensor.DEXCOM_G6_NATIVE, trendArrow = GlucoseValue.TrendArrow.FLAT))
flatDataDexcom.add(GlucoseValue(raw = 0.0, noise = 0.0, value = 100.0, timestamp = now + T.mins(-35).msecs(), sourceSensor = GlucoseValue.SourceSensor.DEXCOM_G6_NATIVE, trendArrow = GlucoseValue.TrendArrow.FLAT))
flatDataDexcom.add(GlucoseValue(raw = 0.0, noise = 0.0, value = 100.0, timestamp = now + T.mins(-40).msecs(), sourceSensor = GlucoseValue.SourceSensor.DEXCOM_G6_NATIVE, trendArrow = GlucoseValue.TrendArrow.FLAT))
flatDataDexcom.add(GlucoseValue(raw = 0.0, noise = 0.0, value = 100.0, timestamp = now + T.mins(-45).msecs(), sourceSensor = GlucoseValue.SourceSensor.DEXCOM_G6_NATIVE, trendArrow = GlucoseValue.TrendArrow.FLAT))
`when`(autosensDataStore.getBgReadingsDataTableCopy()).thenReturn(flatDataDexcom)
`when`(iobCobCalculator.ads.lastBg()).thenReturn(InMemoryGlucoseValue(flatDataDexcom[0]))
override fun shouldUploadToNs(glucoseValue: GlucoseValue): Boolean = true
override fun isEnabled(): Boolean = false
override fun requestPermissionIfNeeded() {}
override fun findDexcomPackageName(): String? = null
}
`when`(activePlugin.activeBgSource).thenReturn(DexcomPlugin())
plugin.processBgData()
Assertions.assertNotEquals(BgQualityCheck.State.FLAT, plugin.state)
Assertions.assertNotEquals(R.drawable.ic_baseline_trending_flat_24, plugin.icon())
// not enough data
val incompleteData: MutableList<GlucoseValue> = ArrayList()
incompleteData.add(GlucoseValue(raw = 0.0, noise = 0.0, value = 100.0, timestamp = now + T.mins(0).msecs(), sourceSensor = GlucoseValue.SourceSensor.UNKNOWN, trendArrow = GlucoseValue.TrendArrow.FLAT))
incompleteData.add(GlucoseValue(raw = 0.0, noise = 0.0, value = 100.0, timestamp = now + T.mins(-5).msecs(), sourceSensor = GlucoseValue.SourceSensor.UNKNOWN, trendArrow = GlucoseValue.TrendArrow.FLAT))
incompleteData.add(GlucoseValue(raw = 0.0, noise = 0.0, value = 100.0, timestamp = now + T.mins(0).msecs(), sourceSensor = GlucoseValue.SourceSensor.LIBRE_1_OTHER, trendArrow = GlucoseValue.TrendArrow.FLAT))
incompleteData.add(GlucoseValue(raw = 0.0, noise = 0.0, value = 100.0, timestamp = now + T.mins(-5).msecs(), sourceSensor = GlucoseValue.SourceSensor.LIBRE_1_OTHER, trendArrow = GlucoseValue.TrendArrow.FLAT))
`when`(autosensDataStore.getBgReadingsDataTableCopy()).thenReturn(incompleteData)
`when`(iobCobCalculator.ads.lastBg()).thenReturn(InMemoryGlucoseValue(incompleteData[0]))
`when`(activePlugin.activeBgSource).thenReturn(OtherPlugin())
plugin.processBgData()// must be more than 5 values
Assertions.assertNotEquals(BgQualityCheck.State.FLAT, plugin.state)
flatData.add(GlucoseValue(raw = 0.0, noise = 0.0, value = 101.0, timestamp = now + T.mins(-10).msecs(), sourceSensor = GlucoseValue.SourceSensor.UNKNOWN, trendArrow = GlucoseValue.TrendArrow.FLAT))
flatData.add(GlucoseValue(raw = 0.0, noise = 0.0, value = 100.0, timestamp = now + T.mins(-15).msecs(), sourceSensor = GlucoseValue.SourceSensor.UNKNOWN, trendArrow = GlucoseValue.TrendArrow.FLAT))
flatData.add(GlucoseValue(raw = 0.0, noise = 0.0, value = 100.0, timestamp = now + T.mins(-20).msecs(), sourceSensor = GlucoseValue.SourceSensor.UNKNOWN, trendArrow = GlucoseValue.TrendArrow.FLAT))
flatData.add(GlucoseValue(raw = 0.0, noise = 0.0, value = 100.0, timestamp = now + T.mins(-25).msecs(), sourceSensor = GlucoseValue.SourceSensor.UNKNOWN, trendArrow = GlucoseValue.TrendArrow.FLAT))
flatData.add(GlucoseValue(raw = 0.0, noise = 0.0, value = 99.0, timestamp = now + T.mins(-30).msecs(), sourceSensor = GlucoseValue.SourceSensor.UNKNOWN, trendArrow = GlucoseValue.TrendArrow.FLAT))
flatData.add(GlucoseValue(raw = 0.0, noise = 0.0, value = 100.0, timestamp = now + T.mins(-35).msecs(), sourceSensor = GlucoseValue.SourceSensor.UNKNOWN, trendArrow = GlucoseValue.TrendArrow.FLAT))
flatData.add(GlucoseValue(raw = 0.0, noise = 0.0, value = 100.0, timestamp = now + T.mins(-40).msecs(), sourceSensor = GlucoseValue.SourceSensor.UNKNOWN, trendArrow = GlucoseValue.TrendArrow.FLAT))
flatData.add(GlucoseValue(raw = 0.0, noise = 0.0, value = 101.0, timestamp = now + T.mins(-10).msecs(), sourceSensor = GlucoseValue.SourceSensor.LIBRE_1_OTHER, trendArrow = GlucoseValue.TrendArrow.FLAT))
flatData.add(GlucoseValue(raw = 0.0, noise = 0.0, value = 100.0, timestamp = now + T.mins(-15).msecs(), sourceSensor = GlucoseValue.SourceSensor.LIBRE_1_OTHER, trendArrow = GlucoseValue.TrendArrow.FLAT))
flatData.add(GlucoseValue(raw = 0.0, noise = 0.0, value = 100.0, timestamp = now + T.mins(-20).msecs(), sourceSensor = GlucoseValue.SourceSensor.LIBRE_1_OTHER, trendArrow = GlucoseValue.TrendArrow.FLAT))
flatData.add(GlucoseValue(raw = 0.0, noise = 0.0, value = 100.0, timestamp = now + T.mins(-25).msecs(), sourceSensor = GlucoseValue.SourceSensor.LIBRE_1_OTHER, trendArrow = GlucoseValue.TrendArrow.FLAT))
flatData.add(GlucoseValue(raw = 0.0, noise = 0.0, value = 99.0, timestamp = now + T.mins(-30).msecs(), sourceSensor = GlucoseValue.SourceSensor.LIBRE_1_OTHER, trendArrow = GlucoseValue.TrendArrow.FLAT))
flatData.add(GlucoseValue(raw = 0.0, noise = 0.0, value = 100.0, timestamp = now + T.mins(-35).msecs(), sourceSensor = GlucoseValue.SourceSensor.LIBRE_1_OTHER, trendArrow = GlucoseValue.TrendArrow.FLAT))
flatData.add(GlucoseValue(raw = 0.0, noise = 0.0, value = 100.0, timestamp = now + T.mins(-40).msecs(), sourceSensor = GlucoseValue.SourceSensor.LIBRE_1_OTHER, trendArrow = GlucoseValue.TrendArrow.FLAT))
plugin.processBgData() // must be at least 45 min old
Assertions.assertNotEquals(BgQualityCheck.State.FLAT, plugin.state)
}

View file

@ -225,6 +225,7 @@ class AutosensDataStoreObject : AutosensDataStore {
bucketedData = null
return
}
val lastBg = bgReadings[0]
val newBucketedData = ArrayList<InMemoryGlucoseValue>()
var currentTime = bgReadings[0].timestamp
val adjustedTime = adjustToReferenceTime(currentTime)
@ -245,7 +246,7 @@ class AutosensDataStoreObject : AutosensDataStore {
val timeDiffToOlder = currentTime - older.timestamp
val filledGap = timeDiffToOlder > T.mins(5).msecs() || timeDiffToNew > T.mins(5).msecs()
val currentBg = newer.value - timeDiffToNew.toDouble() / (newer.timestamp - older.timestamp) * bgDelta
val newBgReading = InMemoryGlucoseValue(currentTime, currentBg.roundToLong().toDouble(), filledGap = filledGap)
val newBgReading = InMemoryGlucoseValue(currentTime, currentBg.roundToLong().toDouble(), filledGap = filledGap, sourceSensor = lastBg.sourceSensor)
newBucketedData.add(newBgReading)
//log.debug("BG: " + newBgReading.value + " (" + new Date(newBgReading.date).toLocaleString() + ") Prev: " + older.value + " (" + new Date(older.date).toLocaleString() + ") Newer: " + newer.value + " (" + new Date(newer.date).toLocaleString() + ")");
}
@ -259,6 +260,7 @@ class AutosensDataStoreObject : AutosensDataStore {
bucketedData = null
return
}
val lastBg = bgReadings[0]
val bData: MutableList<InMemoryGlucoseValue> = ArrayList()
bData.add(InMemoryGlucoseValue(bgReadings[0]))
aapsLogger.debug(LTag.AUTOSENS) { "Adding. bgTime: ${dateUtil.toISOString(bgReadings[0].timestamp)} lastBgTime: none-first-value ${bgReadings[0]}" }
@ -271,33 +273,33 @@ class AutosensDataStoreObject : AutosensDataStore {
when {
abs(elapsedMinutes) > 8 -> {
// interpolate missing data points
var lastBg = bgReadings[i - 1].value
var lastBgValue = bgReadings[i - 1].value
elapsedMinutes = abs(elapsedMinutes)
//console.error(elapsed_minutes);
var nextBgTime: Long
while (elapsedMinutes > 5) {
nextBgTime = lastBgTime - 5 * 60 * 1000
j++
val gapDelta = bgReadings[i].value - lastBg
val gapDelta = bgReadings[i].value - lastBgValue
//console.error(gapDelta, lastBg, elapsed_minutes);
val nextBg = lastBg + 5.0 / elapsedMinutes * gapDelta
val newBgReading = InMemoryGlucoseValue(nextBgTime, nextBg.roundToLong().toDouble(), filledGap = true)
val nextBg = lastBgValue + 5.0 / elapsedMinutes * gapDelta
val newBgReading = InMemoryGlucoseValue(nextBgTime, nextBg.roundToLong().toDouble(), filledGap = true, sourceSensor = lastBg.sourceSensor)
//console.error("Interpolated", bData[j]);
bData.add(newBgReading)
aapsLogger.debug(LTag.AUTOSENS) { "Adding. bgTime: ${dateUtil.toISOString(bgTime)} lastBgTime: ${dateUtil.toISOString(lastBgTime)} $newBgReading" }
elapsedMinutes -= 5
lastBg = nextBg
lastBgValue = nextBg
lastBgTime = nextBgTime
}
j++
val newBgReading = InMemoryGlucoseValue(bgTime, bgReadings[i].value)
val newBgReading = InMemoryGlucoseValue(bgTime, bgReadings[i].value, sourceSensor = lastBg.sourceSensor)
bData.add(newBgReading)
aapsLogger.debug(LTag.AUTOSENS) { "Adding. bgTime: ${dateUtil.toISOString(bgTime)} lastBgTime: ${dateUtil.toISOString(lastBgTime)} $newBgReading" }
}
abs(elapsedMinutes) > 2 -> {
j++
val newBgReading = InMemoryGlucoseValue(bgTime, bgReadings[i].value)
val newBgReading = InMemoryGlucoseValue(bgTime, bgReadings[i].value, sourceSensor = lastBg.sourceSensor)
bData.add(newBgReading)
aapsLogger.debug(LTag.AUTOSENS) { "Adding. bgTime: ${dateUtil.toISOString(bgTime)} lastBgTime: ${dateUtil.toISOString(lastBgTime)} $newBgReading" }
}

View file

@ -62,7 +62,7 @@ class GlimpPlugin @Inject constructor(
raw = inputData.getDouble("mySGV", 0.0),
noise = null,
trendArrow = GlucoseValue.TrendArrow.fromString(inputData.getString("myTrend")),
sourceSensor = GlucoseValue.SourceSensor.GLIMP
sourceSensor = GlucoseValue.SourceSensor.LIBRE_1_GLIMP
)
repository.runTransactionForResult(CgmSourceTransaction(glucoseValues, emptyList(), null))
.doOnError {
@ -80,6 +80,6 @@ class GlimpPlugin @Inject constructor(
}
override fun shouldUploadToNs(glucoseValue: GlucoseValue): Boolean =
glucoseValue.sourceSensor == GlucoseValue.SourceSensor.GLIMP && sp.getBoolean(info.nightscout.core.utils.R.string.key_do_ns_upload, false)
glucoseValue.sourceSensor == GlucoseValue.SourceSensor.LIBRE_1_GLIMP && sp.getBoolean(info.nightscout.core.utils.R.string.key_do_ns_upload, false)
}