From 90e2c8f65fb4392fbfd155b5d7761d9da5c1a7d4 Mon Sep 17 00:00:00 2001 From: Philoul Date: Mon, 29 Nov 2021 21:59:08 +0100 Subject: [PATCH 1/5] Fix Unit convertion mmol->mgdl and mgdl->mmol for csv file --- .../androidaps/utils/userEntry/UserEntryPresentationHelper.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/info/nightscout/androidaps/utils/userEntry/UserEntryPresentationHelper.kt b/core/src/main/java/info/nightscout/androidaps/utils/userEntry/UserEntryPresentationHelper.kt index 615a0be902..e58e9c2cad 100644 --- a/core/src/main/java/info/nightscout/androidaps/utils/userEntry/UserEntryPresentationHelper.kt +++ b/core/src/main/java/info/nightscout/androidaps/utils/userEntry/UserEntryPresentationHelper.kt @@ -205,10 +205,10 @@ class UserEntryPresentationHelper @Inject constructor( is ValueWithUnit.Timestamp -> timestamp = dateUtil.dateAndTimeAndSecondsString(valueWithUnit.value) 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 -> - 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 } From f6ecf8a5dff60cf1f6cca365c92b754e687d9289 Mon Sep 17 00:00:00 2001 From: Philoul Date: Mon, 29 Nov 2021 22:14:03 +0100 Subject: [PATCH 2/5] Fix Units mmol in Automation (internal unit in AAPS is mgdl) --- .../general/automation/actions/ActionCarePortalEvent.kt | 2 +- .../general/automation/actions/ActionStartTempTarget.kt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionCarePortalEvent.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionCarePortalEvent.kt index 5e3f3669eb..7a1b698e47 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionCarePortalEvent.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionCarePortalEvent.kt @@ -71,7 +71,7 @@ class ActionCarePortalEvent(injector: HasAndroidInjector) : Action(injector) { if (glucoseStatus != null) { therapyEvent.glucose = glucoseStatus.glucose 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)) } } else { diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStartTempTarget.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStartTempTarget.kt index 61a9d25952..62d620b3ae 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStartTempTarget.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStartTempTarget.kt @@ -63,8 +63,8 @@ class ActionStartTempTarget(injector: HasAndroidInjector) : Action(injector) { result.updated.forEach { aapsLogger.debug(LTag.DATABASE, "Updated temp target $it") } uel.log(UserEntry.Action.TT, Sources.Automation, title, ValueWithUnit.TherapyEventTTReason(TemporaryTarget.Reason.AUTOMATION), - ValueWithUnit.fromGlucoseUnit(tt().lowTarget, value.units.asText), - ValueWithUnit.fromGlucoseUnit(tt().highTarget, value.units.asText).takeIf { tt().lowTarget != tt().highTarget }, + ValueWithUnit.Mgdl(tt().lowTarget), + ValueWithUnit.Mgdl(tt().highTarget).takeIf { tt().lowTarget != tt().highTarget }, ValueWithUnit.Minute(TimeUnit.MILLISECONDS.toMinutes(tt().duration).toInt())) callback.result(PumpEnactResult(injector).success(true).comment(R.string.ok))?.run() }, { From 8fe0266bcb2fa707f44729c811022c55c49db5eb Mon Sep 17 00:00:00 2001 From: Philoul Date: Mon, 29 Nov 2021 22:25:18 +0100 Subject: [PATCH 3/5] Fix Units in presentation string --- .../utils/userEntry/UserEntryPresentationHelper.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/info/nightscout/androidaps/utils/userEntry/UserEntryPresentationHelper.kt b/core/src/main/java/info/nightscout/androidaps/utils/userEntry/UserEntryPresentationHelper.kt index e58e9c2cad..0b1ac8a3a4 100644 --- a/core/src/main/java/info/nightscout/androidaps/utils/userEntry/UserEntryPresentationHelper.kt +++ b/core/src/main/java/info/nightscout/androidaps/utils/userEntry/UserEntryPresentationHelper.kt @@ -131,13 +131,13 @@ class UserEntryPresentationHelper @Inject constructor( is ValueWithUnit.Timestamp -> dateUtil.dateAndTimeAndSecondsString(valueWithUnit.value) is ValueWithUnit.Mgdl -> { - if (profileFunction.getUnits() == GlucoseUnit.MGDL) DecimalFormatter.to0Decimal(valueWithUnit.value) + translator.translate(valueWithUnit) - else DecimalFormatter.to1Decimal(valueWithUnit.value * Constants.MGDL_TO_MMOLL) + 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) + rh.gs(R.string.mmol) } is ValueWithUnit.Mmoll -> { - if (profileFunction.getUnits() == GlucoseUnit.MMOL) DecimalFormatter.to1Decimal(valueWithUnit.value) + translator.translate(valueWithUnit) - else DecimalFormatter.to0Decimal(valueWithUnit.value * Constants.MMOLL_TO_MGDL) + 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) + rh.gs(R.string.mgdl) } ValueWithUnit.UNKNOWN -> "" From 009d428e89edc60710c324079a726c4401b86c0a Mon Sep 17 00:00:00 2001 From: Philoul Date: Mon, 29 Nov 2021 22:56:18 +0100 Subject: [PATCH 4/5] Add glucose value for calibration (DexcomPlugin and GlunovoPlugin) => To review --- .../androidaps/plugins/source/DexcomPlugin.kt | 17 +++++++++++------ .../androidaps/plugins/source/GlunovoPlugin.kt | 16 ++++++++++++++++ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/source/DexcomPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/source/DexcomPlugin.kt index 2f4f7d935e..abc783856b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/source/DexcomPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/source/DexcomPlugin.kt @@ -161,12 +161,17 @@ class DexcomPlugin @Inject constructor( ValueWithUnit.TherapyEventType(it.type)) aapsLogger.debug(LTag.DATABASE, "Inserted sensor insertion $it") } - result.calibrationsInserted.forEach { - uel.log(Action.CAREPORTAL, - Sources.Dexcom, - ValueWithUnit.Timestamp(it.timestamp), - ValueWithUnit.TherapyEventType(it.type)) - aapsLogger.debug(LTag.DATABASE, "Inserted calibration $it") + result.calibrationsInserted.forEach { calibration -> + calibration.glucose?.let { glucosevalue -> + uel.log( + Action.CAREPORTAL, + Sources.Dexcom, + ValueWithUnit.Timestamp(calibration.timestamp), + ValueWithUnit.TherapyEventType(calibration.type), + ValueWithUnit.fromGlucoseUnit(glucosevalue, calibration.glucoseUnit.toString()) + ) + } + aapsLogger.debug(LTag.DATABASE, "Inserted calibration $calibration") } } } catch (e: Exception) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/source/GlunovoPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/source/GlunovoPlugin.kt index 97c07f815a..e7d52cd536 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/source/GlunovoPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/source/GlunovoPlugin.kt @@ -10,6 +10,8 @@ import info.nightscout.androidaps.R import info.nightscout.androidaps.database.AppRepository import info.nightscout.androidaps.database.entities.GlucoseValue 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.interfaces.BgSource 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.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag +import info.nightscout.androidaps.logging.UserEntryLogger import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.T @@ -37,6 +40,7 @@ class GlunovoPlugin @Inject constructor( private val repository: AppRepository, private val xDripBroadcast: XDripBroadcast, private val dateUtil: DateUtil, + private val uel: UserEntryLogger, private val fabricPrivacy: FabricPrivacy ) : PluginBase( PluginDescription() @@ -146,6 +150,18 @@ class GlunovoPlugin @Inject constructor( xDripBroadcast.send(it) aapsLogger.debug(LTag.DATABASE, "Inserted bg $it") } + savedValues.calibrationsInserted.forEach { calibration -> + calibration.glucose?.let { glucosevalue -> + uel.log( + UserEntry.Action.CAREPORTAL, + UserEntry.Sources.Dexcom, + ValueWithUnit.Timestamp(calibration.timestamp), + ValueWithUnit.TherapyEventType(calibration.type), + ValueWithUnit.fromGlucoseUnit(glucosevalue, calibration.glucoseUnit.toString()) + ) + } + aapsLogger.debug(LTag.DATABASE, "Inserted calibration $calibration") + } } } } From 98ef5768be329338000951b2cef57dbcbd86acf8 Mon Sep 17 00:00:00 2001 From: Philoul Date: Tue, 30 Nov 2021 20:24:54 +0100 Subject: [PATCH 5/5] Fix Calibration value in uel.log --- .../nightscout/androidaps/plugins/source/DexcomPlugin.kt | 4 ++-- .../nightscout/androidaps/plugins/source/GlunovoPlugin.kt | 4 ++-- .../nightscout/androidaps/database/entities/TherapyEvent.kt | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/source/DexcomPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/source/DexcomPlugin.kt index abc783856b..0d8d6893f9 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/source/DexcomPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/source/DexcomPlugin.kt @@ -164,11 +164,11 @@ class DexcomPlugin @Inject constructor( result.calibrationsInserted.forEach { calibration -> calibration.glucose?.let { glucosevalue -> uel.log( - Action.CAREPORTAL, + Action.CALIBRATION, Sources.Dexcom, ValueWithUnit.Timestamp(calibration.timestamp), ValueWithUnit.TherapyEventType(calibration.type), - ValueWithUnit.fromGlucoseUnit(glucosevalue, calibration.glucoseUnit.toString()) + ValueWithUnit.fromGlucoseUnit(glucosevalue, calibration.glucoseUnit.toString) ) } aapsLogger.debug(LTag.DATABASE, "Inserted calibration $calibration") diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/source/GlunovoPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/source/GlunovoPlugin.kt index e7d52cd536..1dca40f24c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/source/GlunovoPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/source/GlunovoPlugin.kt @@ -153,11 +153,11 @@ class GlunovoPlugin @Inject constructor( savedValues.calibrationsInserted.forEach { calibration -> calibration.glucose?.let { glucosevalue -> uel.log( - UserEntry.Action.CAREPORTAL, + UserEntry.Action.CALIBRATION, UserEntry.Sources.Dexcom, ValueWithUnit.Timestamp(calibration.timestamp), ValueWithUnit.TherapyEventType(calibration.type), - ValueWithUnit.fromGlucoseUnit(glucosevalue, calibration.glucoseUnit.toString()) + ValueWithUnit.fromGlucoseUnit(glucosevalue, calibration.glucoseUnit.toString) ) } aapsLogger.debug(LTag.DATABASE, "Inserted calibration $calibration") diff --git a/database/src/main/java/info/nightscout/androidaps/database/entities/TherapyEvent.kt b/database/src/main/java/info/nightscout/androidaps/database/entities/TherapyEvent.kt index f2421908ad..bea32f40d7 100644 --- a/database/src/main/java/info/nightscout/androidaps/database/entities/TherapyEvent.kt +++ b/database/src/main/java/info/nightscout/androidaps/database/entities/TherapyEvent.kt @@ -66,9 +66,9 @@ data class TherapyEvent( previous.interfaceIDs.nightscoutId == null && interfaceIDs.nightscoutId != null - enum class GlucoseUnit { - MGDL, - MMOL; + enum class GlucoseUnit (val toString: String) { + MGDL (ValueWithUnit.MGDL), + MMOL (ValueWithUnit.MMOL); companion object }