fix receiving dexcom calibrations

This commit is contained in:
Milos Kozak 2021-05-21 15:49:42 +02:00
parent 7fe75cf425
commit af3df53f10
2 changed files with 12 additions and 10 deletions

View file

@ -8,7 +8,6 @@ import androidx.work.Worker
import androidx.work.WorkerParameters
import androidx.work.workDataOf
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.interfaces.Config
import info.nightscout.androidaps.R
import info.nightscout.androidaps.activities.RequestDexcomPermissionActivity
import info.nightscout.androidaps.database.AppRepository
@ -18,10 +17,8 @@ import info.nightscout.androidaps.database.entities.UserEntry.Action
import info.nightscout.androidaps.database.entities.UserEntry.Sources
import info.nightscout.androidaps.database.entities.ValueWithUnit
import info.nightscout.androidaps.database.transactions.CgmSourceTransaction
import info.nightscout.androidaps.interfaces.BgSource
import info.nightscout.androidaps.interfaces.PluginBase
import info.nightscout.androidaps.interfaces.PluginDescription
import info.nightscout.androidaps.interfaces.PluginType
import info.nightscout.androidaps.extensions.fromConstant
import info.nightscout.androidaps.interfaces.*
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.logging.UserEntryLogger
@ -126,11 +123,12 @@ class DexcomPlugin @Inject constructor(
meters.getBundle(i.toString())?.let {
val timestamp = it.getLong("timestamp") * 1000
val now = dateUtil.now()
val value = it.getInt("meterValue").toDouble()
if (timestamp > now - T.months(1).msecs() && timestamp < now) {
calibrations.add(CgmSourceTransaction.Calibration(
timestamp = it.getLong("timestamp") * 1000,
value = it.getInt("meterValue").toDouble(),
glucoseUnit = TherapyEvent.GlucoseUnit.MGDL
value = value,
glucoseUnit = TherapyEvent.GlucoseUnit.fromConstant(Profile.unit(value))
))
}
}

View file

@ -165,16 +165,20 @@ interface Profile {
if (units == GlucoseUnit.MGDL) (if (valueInMgdl > 0) "+" else "") + to0Decimal(valueInMgdl)
else (if (valueInMmol > 0) "+" else "") + to1Decimal(valueInMmol)
fun isMgdl(anyBg: Double) = anyBg >= 39
fun isMmol(anyBg: Double) = anyBg < 39
fun unit(anyBg: Double) = if (isMgdl(anyBg)) GlucoseUnit.MGDL else GlucoseUnit.MMOL
fun toCurrentUnits(profileFunction: ProfileFunction, anyBg: Double): Double =
if (anyBg < 32) fromMmolToUnits(anyBg, profileFunction.getUnits())
if (isMmol(anyBg)) fromMmolToUnits(anyBg, profileFunction.getUnits())
else fromMgdlToUnits(anyBg, profileFunction.getUnits())
fun toCurrentUnits(units: GlucoseUnit, anyBg: Double): Double =
if (anyBg < 32) fromMmolToUnits(anyBg, units)
if (isMmol(anyBg)) fromMmolToUnits(anyBg, units)
else fromMgdlToUnits(anyBg, units)
fun toCurrentUnitsString(profileFunction: ProfileFunction, anyBg: Double): String =
if (anyBg < 32) toUnitsString(anyBg * Constants.MMOLL_TO_MGDL, anyBg, profileFunction.getUnits())
if (isMmol(anyBg)) toUnitsString(anyBg * Constants.MMOLL_TO_MGDL, anyBg, profileFunction.getUnits())
else toUnitsString(anyBg, anyBg * Constants.MGDL_TO_MMOLL, profileFunction.getUnits())
fun toMgdl(value: Double, units: GlucoseUnit): Double =