Merge pull request #1010

Fix user entry units convertion
This commit is contained in:
Milos Kozak 2021-11-30 21:33:06 +01:00 committed by GitHub
commit 21818546e7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 39 additions and 18 deletions

View file

@ -161,12 +161,17 @@ class DexcomPlugin @Inject constructor(
ValueWithUnit.TherapyEventType(it.type)) ValueWithUnit.TherapyEventType(it.type))
aapsLogger.debug(LTag.DATABASE, "Inserted sensor insertion $it") aapsLogger.debug(LTag.DATABASE, "Inserted sensor insertion $it")
} }
result.calibrationsInserted.forEach { result.calibrationsInserted.forEach { calibration ->
uel.log(Action.CAREPORTAL, calibration.glucose?.let { glucosevalue ->
Sources.Dexcom, uel.log(
ValueWithUnit.Timestamp(it.timestamp), Action.CALIBRATION,
ValueWithUnit.TherapyEventType(it.type)) Sources.Dexcom,
aapsLogger.debug(LTag.DATABASE, "Inserted calibration $it") ValueWithUnit.Timestamp(calibration.timestamp),
ValueWithUnit.TherapyEventType(calibration.type),
ValueWithUnit.fromGlucoseUnit(glucosevalue, calibration.glucoseUnit.toString)
)
}
aapsLogger.debug(LTag.DATABASE, "Inserted calibration $calibration")
} }
} }
} catch (e: Exception) { } catch (e: Exception) {

View file

@ -10,6 +10,8 @@ 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.entities.TherapyEvent
import info.nightscout.androidaps.database.entities.UserEntry
import info.nightscout.androidaps.database.entities.ValueWithUnit
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
@ -17,6 +19,7 @@ import info.nightscout.androidaps.interfaces.PluginDescription
import info.nightscout.androidaps.interfaces.PluginType import info.nightscout.androidaps.interfaces.PluginType
import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.logging.UserEntryLogger
import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.T import info.nightscout.androidaps.utils.T
@ -37,6 +40,7 @@ class GlunovoPlugin @Inject constructor(
private val repository: AppRepository, private val repository: AppRepository,
private val xDripBroadcast: XDripBroadcast, private val xDripBroadcast: XDripBroadcast,
private val dateUtil: DateUtil, private val dateUtil: DateUtil,
private val uel: UserEntryLogger,
private val fabricPrivacy: FabricPrivacy private val fabricPrivacy: FabricPrivacy
) : PluginBase( ) : PluginBase(
PluginDescription() PluginDescription()
@ -146,6 +150,18 @@ class GlunovoPlugin @Inject constructor(
xDripBroadcast.send(it) xDripBroadcast.send(it)
aapsLogger.debug(LTag.DATABASE, "Inserted bg $it") aapsLogger.debug(LTag.DATABASE, "Inserted bg $it")
} }
savedValues.calibrationsInserted.forEach { calibration ->
calibration.glucose?.let { glucosevalue ->
uel.log(
UserEntry.Action.CALIBRATION,
UserEntry.Sources.Dexcom,
ValueWithUnit.Timestamp(calibration.timestamp),
ValueWithUnit.TherapyEventType(calibration.type),
ValueWithUnit.fromGlucoseUnit(glucosevalue, calibration.glucoseUnit.toString)
)
}
aapsLogger.debug(LTag.DATABASE, "Inserted calibration $calibration")
}
} }
} }
} }

View file

@ -71,7 +71,7 @@ class ActionCarePortalEvent(injector: HasAndroidInjector) : Action(injector) {
if (glucoseStatus != null) { if (glucoseStatus != null) {
therapyEvent.glucose = glucoseStatus.glucose therapyEvent.glucose = glucoseStatus.glucose
therapyEvent.glucoseType = TherapyEvent.MeterType.SENSOR therapyEvent.glucoseType = TherapyEvent.MeterType.SENSOR
valuesWithUnit.add(ValueWithUnit.fromGlucoseUnit(glucoseStatus.glucose, profileFunction.getUnits().asText)) valuesWithUnit.add(ValueWithUnit.Mgdl(glucoseStatus.glucose))
valuesWithUnit.add(ValueWithUnit.TherapyEventMeterType(TherapyEvent.MeterType.SENSOR)) valuesWithUnit.add(ValueWithUnit.TherapyEventMeterType(TherapyEvent.MeterType.SENSOR))
} }
} else { } else {

View file

@ -63,8 +63,8 @@ class ActionStartTempTarget(injector: HasAndroidInjector) : Action(injector) {
result.updated.forEach { aapsLogger.debug(LTag.DATABASE, "Updated temp target $it") } result.updated.forEach { aapsLogger.debug(LTag.DATABASE, "Updated temp target $it") }
uel.log(UserEntry.Action.TT, Sources.Automation, title, uel.log(UserEntry.Action.TT, Sources.Automation, title,
ValueWithUnit.TherapyEventTTReason(TemporaryTarget.Reason.AUTOMATION), ValueWithUnit.TherapyEventTTReason(TemporaryTarget.Reason.AUTOMATION),
ValueWithUnit.fromGlucoseUnit(tt().lowTarget, value.units.asText), ValueWithUnit.Mgdl(tt().lowTarget),
ValueWithUnit.fromGlucoseUnit(tt().highTarget, value.units.asText).takeIf { tt().lowTarget != tt().highTarget }, ValueWithUnit.Mgdl(tt().highTarget).takeIf { tt().lowTarget != tt().highTarget },
ValueWithUnit.Minute(TimeUnit.MILLISECONDS.toMinutes(tt().duration).toInt())) ValueWithUnit.Minute(TimeUnit.MILLISECONDS.toMinutes(tt().duration).toInt()))
callback.result(PumpEnactResult(injector).success(true).comment(R.string.ok))?.run() callback.result(PumpEnactResult(injector).success(true).comment(R.string.ok))?.run()
}, { }, {

View file

@ -131,13 +131,13 @@ class UserEntryPresentationHelper @Inject constructor(
is ValueWithUnit.Timestamp -> dateUtil.dateAndTimeAndSecondsString(valueWithUnit.value) is ValueWithUnit.Timestamp -> dateUtil.dateAndTimeAndSecondsString(valueWithUnit.value)
is ValueWithUnit.Mgdl -> { is ValueWithUnit.Mgdl -> {
if (profileFunction.getUnits() == GlucoseUnit.MGDL) DecimalFormatter.to0Decimal(valueWithUnit.value) + translator.translate(valueWithUnit) if (profileFunction.getUnits() == GlucoseUnit.MGDL) DecimalFormatter.to0Decimal(valueWithUnit.value) + rh.gs(R.string.mgdl)
else DecimalFormatter.to1Decimal(valueWithUnit.value * Constants.MGDL_TO_MMOLL) + translator.translate(valueWithUnit) else DecimalFormatter.to1Decimal(valueWithUnit.value * Constants.MGDL_TO_MMOLL) + rh.gs(R.string.mmol)
} }
is ValueWithUnit.Mmoll -> { is ValueWithUnit.Mmoll -> {
if (profileFunction.getUnits() == GlucoseUnit.MMOL) DecimalFormatter.to1Decimal(valueWithUnit.value) + translator.translate(valueWithUnit) if (profileFunction.getUnits() == GlucoseUnit.MMOL) DecimalFormatter.to1Decimal(valueWithUnit.value) + rh.gs(R.string.mmol)
else DecimalFormatter.to0Decimal(valueWithUnit.value * Constants.MMOLL_TO_MGDL) + translator.translate(valueWithUnit) else DecimalFormatter.to0Decimal(valueWithUnit.value * Constants.MMOLL_TO_MGDL) + rh.gs(R.string.mgdl)
} }
ValueWithUnit.UNKNOWN -> "" ValueWithUnit.UNKNOWN -> ""
@ -205,10 +205,10 @@ class UserEntryPresentationHelper @Inject constructor(
is ValueWithUnit.Timestamp -> timestamp = dateUtil.dateAndTimeAndSecondsString(valueWithUnit.value) is ValueWithUnit.Timestamp -> timestamp = dateUtil.dateAndTimeAndSecondsString(valueWithUnit.value)
is ValueWithUnit.Mgdl -> is ValueWithUnit.Mgdl ->
bg = Profile.toUnitsString(valueWithUnit.value, valueWithUnit.value * Constants.MMOLL_TO_MGDL, profileFunction.getUnits()) bg = Profile.toUnitsString(valueWithUnit.value, valueWithUnit.value * Constants.MGDL_TO_MMOLL, profileFunction.getUnits())
is ValueWithUnit.Mmoll -> is ValueWithUnit.Mmoll ->
bg = Profile.toUnitsString(valueWithUnit.value, valueWithUnit.value * Constants.MMOLL_TO_MGDL, profileFunction.getUnits()) bg = Profile.toUnitsString(valueWithUnit.value * Constants.MMOLL_TO_MGDL, valueWithUnit.value , profileFunction.getUnits())
ValueWithUnit.UNKNOWN -> Unit ValueWithUnit.UNKNOWN -> Unit
} }

View file

@ -66,9 +66,9 @@ data class TherapyEvent(
previous.interfaceIDs.nightscoutId == null && previous.interfaceIDs.nightscoutId == null &&
interfaceIDs.nightscoutId != null interfaceIDs.nightscoutId != null
enum class GlucoseUnit { enum class GlucoseUnit (val toString: String) {
MGDL, MGDL (ValueWithUnit.MGDL),
MMOL; MMOL (ValueWithUnit.MMOL);
companion object companion object
} }