Glunovo process calibrations
This commit is contained in:
parent
bb7632aa80
commit
774beb2cb3
1 changed files with 21 additions and 9 deletions
|
@ -9,6 +9,7 @@ import info.nightscout.androidaps.Constants
|
||||||
import info.nightscout.androidaps.R
|
import info.nightscout.androidaps.R
|
||||||
import info.nightscout.androidaps.database.AppRepository
|
import info.nightscout.androidaps.database.AppRepository
|
||||||
import info.nightscout.androidaps.database.entities.GlucoseValue
|
import info.nightscout.androidaps.database.entities.GlucoseValue
|
||||||
|
import info.nightscout.androidaps.database.entities.TherapyEvent
|
||||||
import info.nightscout.androidaps.database.transactions.CgmSourceTransaction
|
import info.nightscout.androidaps.database.transactions.CgmSourceTransaction
|
||||||
import info.nightscout.androidaps.interfaces.BgSource
|
import info.nightscout.androidaps.interfaces.BgSource
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase
|
import info.nightscout.androidaps.interfaces.PluginBase
|
||||||
|
@ -86,11 +87,13 @@ class GlunovoPlugin @Inject constructor(
|
||||||
|
|
||||||
context.contentResolver.query(contentUri, null, null, null, null)?.let { cr ->
|
context.contentResolver.query(contentUri, null, null, null, null)?.let { cr ->
|
||||||
val glucoseValues = mutableListOf<CgmSourceTransaction.TransactionGlucoseValue>()
|
val glucoseValues = mutableListOf<CgmSourceTransaction.TransactionGlucoseValue>()
|
||||||
|
val calibrations = mutableListOf<CgmSourceTransaction.Calibration>()
|
||||||
cr.moveToFirst()
|
cr.moveToFirst()
|
||||||
|
|
||||||
while (!cr.isAfterLast) {
|
while (!cr.isAfterLast) {
|
||||||
val timestamp = cr.getLong(0)
|
val timestamp = cr.getLong(0)
|
||||||
val value = cr.getDouble(1) //value in mmol/l...
|
val value = cr.getDouble(1) //value in mmol/l...
|
||||||
|
val curr = cr.getDouble(2)
|
||||||
if (timestamp > dateUtil.now() || timestamp == 0L) {
|
if (timestamp > dateUtil.now() || timestamp == 0L) {
|
||||||
aapsLogger.error(LTag.BGSOURCE, "Error in received data date/time $timestamp")
|
aapsLogger.error(LTag.BGSOURCE, "Error in received data date/time $timestamp")
|
||||||
cr.moveToNext()
|
cr.moveToNext()
|
||||||
|
@ -109,21 +112,30 @@ class GlunovoPlugin @Inject constructor(
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
glucoseValues += CgmSourceTransaction.TransactionGlucoseValue(
|
if (curr != 0.0)
|
||||||
timestamp = timestamp,
|
glucoseValues += CgmSourceTransaction.TransactionGlucoseValue(
|
||||||
value = value * Constants.MMOLL_TO_MGDL,
|
timestamp = timestamp,
|
||||||
raw = 0.0,
|
value = value * Constants.MMOLL_TO_MGDL,
|
||||||
noise = null,
|
raw = 0.0,
|
||||||
trendArrow = GlucoseValue.TrendArrow.NONE,
|
noise = null,
|
||||||
sourceSensor = GlucoseValue.SourceSensor.GLUNOVO_NATIVE
|
trendArrow = GlucoseValue.TrendArrow.NONE,
|
||||||
)
|
sourceSensor = GlucoseValue.SourceSensor.GLUNOVO_NATIVE
|
||||||
|
)
|
||||||
|
else
|
||||||
|
calibrations.add(
|
||||||
|
CgmSourceTransaction.Calibration(
|
||||||
|
timestamp = timestamp,
|
||||||
|
value = value,
|
||||||
|
glucoseUnit = TherapyEvent.GlucoseUnit.MMOL
|
||||||
|
)
|
||||||
|
)
|
||||||
sp.putLong(R.string.key_last_processed_glunovo_timestamp, timestamp)
|
sp.putLong(R.string.key_last_processed_glunovo_timestamp, timestamp)
|
||||||
cr.moveToNext()
|
cr.moveToNext()
|
||||||
}
|
}
|
||||||
cr.close()
|
cr.close()
|
||||||
|
|
||||||
if (glucoseValues.isNotEmpty())
|
if (glucoseValues.isNotEmpty())
|
||||||
repository.runTransactionForResult(CgmSourceTransaction(glucoseValues, emptyList(), null))
|
repository.runTransactionForResult(CgmSourceTransaction(glucoseValues, calibrations, null))
|
||||||
.doOnError {
|
.doOnError {
|
||||||
aapsLogger.error(LTag.DATABASE, "Error while saving values from Glunovo App", it)
|
aapsLogger.error(LTag.DATABASE, "Error while saving values from Glunovo App", it)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue