G6 calibration workaround

This commit is contained in:
Milos Kozak 2022-01-24 22:32:03 +01:00
parent 890cae381b
commit 1aa4f7452c

View file

@ -30,6 +30,7 @@ import info.nightscout.shared.logging.LTag
import info.nightscout.shared.sharedPreferences.SP import info.nightscout.shared.sharedPreferences.SP
import javax.inject.Inject import javax.inject.Inject
import javax.inject.Singleton import javax.inject.Singleton
import kotlin.math.abs
@Singleton @Singleton
class DexcomPlugin @Inject constructor( class DexcomPlugin @Inject constructor(
@ -143,6 +144,18 @@ class DexcomPlugin @Inject constructor(
sourceSensor = sourceSensor sourceSensor = sourceSensor
) )
} }
// G6 calibration bug workaround (2 additional GVs are created within 1 second from previous record)
if (sourceSensor == GlucoseValue.SourceSensor.DEXCOM_G6_NATIVE) {
glucoseValues.sortBy { it.timestamp }
for (i in glucoseValues.indices) {
if (i < glucoseValues.size - 1) {
if (abs(glucoseValues[i].timestamp - glucoseValues[i + 1].timestamp) < 1000) {
aapsLogger.debug(LTag.DATABASE, "Excluding bg ${glucoseValues[i + 1]}")
glucoseValues.removeAt(i + 1)
}
}
}
}
val sensorStartTime = if (sp.getBoolean(R.string.key_dexcom_lognssensorchange, false) && bundle.containsKey("sensorInsertionTime")) { val sensorStartTime = if (sp.getBoolean(R.string.key_dexcom_lognssensorchange, false) && bundle.containsKey("sensorInsertionTime")) {
bundle.getLong("sensorInsertionTime", 0) * 1000 bundle.getLong("sensorInsertionTime", 0) * 1000
} else { } else {