Merge pull request #451 from Philoul/meallink_ValueWithUnit

Meallink ValueWithUnit Refactor
This commit is contained in:
Milos Kozak 2021-04-05 22:42:50 +02:00 committed by GitHub
commit b04da525c1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
120 changed files with 4491 additions and 786 deletions

View file

@ -2,6 +2,22 @@
<code_scheme name="Project" version="173"> <code_scheme name="Project" version="173">
<option name="AUTODETECT_INDENTS" value="false" /> <option name="AUTODETECT_INDENTS" value="false" />
<JetCodeStyleSettings> <JetCodeStyleSettings>
<option name="PACKAGES_TO_USE_STAR_IMPORTS">
<value>
<package name="java.util" alias="false" withSubpackages="false" />
<package name="kotlinx.android.synthetic" alias="false" withSubpackages="true" />
<package name="io.ktor" alias="false" withSubpackages="true" />
</value>
</option>
<option name="PACKAGES_IMPORT_LAYOUT">
<value>
<package name="" alias="false" withSubpackages="true" />
<package name="java" alias="false" withSubpackages="true" />
<package name="javax" alias="false" withSubpackages="true" />
<package name="kotlin" alias="false" withSubpackages="true" />
<package name="" alias="true" withSubpackages="true" />
</value>
</option>
<option name="ALIGN_IN_COLUMNS_CASE_BRANCH" value="true" /> <option name="ALIGN_IN_COLUMNS_CASE_BRANCH" value="true" />
<option name="NAME_COUNT_TO_USE_STAR_IMPORT" value="6" /> <option name="NAME_COUNT_TO_USE_STAR_IMPORT" value="6" />
<option name="NAME_COUNT_TO_USE_STAR_IMPORT_FOR_MEMBERS" value="6" /> <option name="NAME_COUNT_TO_USE_STAR_IMPORT_FOR_MEMBERS" value="6" />

View file

@ -2,7 +2,8 @@ package info.nightscout.androidaps.activities
import android.os.Bundle import android.os.Bundle
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
import info.nightscout.androidaps.database.entities.UserEntry.* import info.nightscout.androidaps.database.entities.UserEntry.Action
import info.nightscout.androidaps.database.entities.UserEntry.Sources
import info.nightscout.androidaps.databinding.ActivityStatsBinding import info.nightscout.androidaps.databinding.ActivityStatsBinding
import info.nightscout.androidaps.logging.UserEntryLogger import info.nightscout.androidaps.logging.UserEntryLogger
import info.nightscout.androidaps.utils.ActivityMonitor import info.nightscout.androidaps.utils.ActivityMonitor
@ -32,7 +33,7 @@ class StatsActivity : NoSplashAppCompatActivity() {
binding.ok.setOnClickListener { finish() } binding.ok.setOnClickListener { finish() }
binding.reset.setOnClickListener { binding.reset.setOnClickListener {
OKDialog.showConfirmation(this, resourceHelper.gs(R.string.doyouwantresetstats)) { OKDialog.showConfirmation(this, resourceHelper.gs(R.string.doyouwantresetstats)) {
uel.log(Action.STAT_RESET) uel.log(Action.STAT_RESET, Sources.Stats)
activityMonitor.reset() activityMonitor.reset()
recreate() recreate()
} }

View file

@ -9,7 +9,9 @@ import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.Constants import info.nightscout.androidaps.Constants
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
import info.nightscout.androidaps.data.Profile import info.nightscout.androidaps.data.Profile
import info.nightscout.androidaps.database.entities.UserEntry.* import info.nightscout.androidaps.database.entities.ValueWithUnit
import info.nightscout.androidaps.database.entities.UserEntry.Action
import info.nightscout.androidaps.database.entities.UserEntry.Sources
import info.nightscout.androidaps.databinding.DialogCalibrationBinding import info.nightscout.androidaps.databinding.DialogCalibrationBinding
import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.interfaces.ProfileFunction
import info.nightscout.androidaps.logging.UserEntryLogger import info.nightscout.androidaps.logging.UserEntryLogger
@ -79,7 +81,7 @@ class CalibrationDialog : DialogFragmentWithDate() {
if (bg > 0) { if (bg > 0) {
activity?.let { activity -> activity?.let { activity ->
OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.overview_calibration), HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions)), { OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.overview_calibration), HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions)), {
uel.log(Action.CALIBRATION, ValueWithUnit(bg, units)) uel.log(Action.CALIBRATION, Sources.CalibrationDialog, ValueWithUnit.fromGlucoseUnit(bg, units))
xdripCalibrations.sendIntent(bg) xdripCalibrations.sendIntent(bg)
}) })
} }

View file

@ -14,10 +14,10 @@ import info.nightscout.androidaps.activities.ErrorHelperActivity
import info.nightscout.androidaps.data.DetailedBolusInfo import info.nightscout.androidaps.data.DetailedBolusInfo
import info.nightscout.androidaps.data.Profile import info.nightscout.androidaps.data.Profile
import info.nightscout.androidaps.database.AppRepository import info.nightscout.androidaps.database.AppRepository
import info.nightscout.androidaps.database.entities.ValueWithUnit
import info.nightscout.androidaps.database.entities.TemporaryTarget import info.nightscout.androidaps.database.entities.TemporaryTarget
import info.nightscout.androidaps.database.entities.UserEntry.Action import info.nightscout.androidaps.database.entities.UserEntry.Action
import info.nightscout.androidaps.database.entities.UserEntry.Units import info.nightscout.androidaps.database.entities.UserEntry.Sources
import info.nightscout.androidaps.database.entities.UserEntry.ValueWithUnit
import info.nightscout.androidaps.database.transactions.InsertTemporaryTargetAndCancelCurrentTransaction import info.nightscout.androidaps.database.transactions.InsertTemporaryTargetAndCancelCurrentTransaction
import info.nightscout.androidaps.databinding.DialogCarbsBinding import info.nightscout.androidaps.databinding.DialogCarbsBinding
import info.nightscout.androidaps.interfaces.Constraint import info.nightscout.androidaps.interfaces.Constraint
@ -224,7 +224,10 @@ class CarbsDialog : DialogFragmentWithDate() {
OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.carbs), HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions)), { OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.carbs), HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions)), {
when { when {
activitySelected -> { activitySelected -> {
uel.log(Action.TT, ValueWithUnit(TemporaryTarget.Reason.ACTIVITY.text, Units.TherapyEvent), ValueWithUnit(activityTT, units), ValueWithUnit(activityTTDuration, Units.M)) uel.log(Action.TT, Sources.CarbDialog,
ValueWithUnit.TherapyEventTTReason(TemporaryTarget.Reason.ACTIVITY),
ValueWithUnit.fromGlucoseUnit(activityTT, units) ,
ValueWithUnit.Minute(activityTTDuration))
disposable += repository.runTransactionForResult(InsertTemporaryTargetAndCancelCurrentTransaction( disposable += repository.runTransactionForResult(InsertTemporaryTargetAndCancelCurrentTransaction(
timestamp = System.currentTimeMillis(), timestamp = System.currentTimeMillis(),
duration = TimeUnit.MINUTES.toMillis(activityTTDuration.toLong()), duration = TimeUnit.MINUTES.toMillis(activityTTDuration.toLong()),
@ -240,7 +243,10 @@ class CarbsDialog : DialogFragmentWithDate() {
} }
eatingSoonSelected -> { eatingSoonSelected -> {
uel.log(Action.TT, ValueWithUnit(TemporaryTarget.Reason.EATING_SOON.text, Units.TherapyEvent), ValueWithUnit(eatingSoonTT, units), ValueWithUnit(eatingSoonTTDuration, Units.M)) uel.log(Action.TT, Sources.CarbDialog,
ValueWithUnit.TherapyEventTTReason(TemporaryTarget.Reason.EATING_SOON),
ValueWithUnit.fromGlucoseUnit(eatingSoonTT, units) ,
ValueWithUnit.Minute(eatingSoonTTDuration))
disposable += repository.runTransactionForResult(InsertTemporaryTargetAndCancelCurrentTransaction( disposable += repository.runTransactionForResult(InsertTemporaryTargetAndCancelCurrentTransaction(
timestamp = System.currentTimeMillis(), timestamp = System.currentTimeMillis(),
duration = TimeUnit.MINUTES.toMillis(eatingSoonTTDuration.toLong()), duration = TimeUnit.MINUTES.toMillis(eatingSoonTTDuration.toLong()),
@ -256,7 +262,10 @@ class CarbsDialog : DialogFragmentWithDate() {
} }
hypoSelected -> { hypoSelected -> {
uel.log(Action.TT, ValueWithUnit(TemporaryTarget.Reason.HYPOGLYCEMIA.text, Units.TherapyEvent), ValueWithUnit(hypoTT, units), ValueWithUnit(hypoTTDuration, Units.M)) uel.log(Action.TT, Sources.CarbDialog,
ValueWithUnit.TherapyEventTTReason(TemporaryTarget.Reason.HYPOGLYCEMIA),
ValueWithUnit.fromGlucoseUnit(hypoTT, units) ,
ValueWithUnit.Minute(hypoTTDuration))
disposable += repository.runTransactionForResult(InsertTemporaryTargetAndCancelCurrentTransaction( disposable += repository.runTransactionForResult(InsertTemporaryTargetAndCancelCurrentTransaction(
timestamp = System.currentTimeMillis(), timestamp = System.currentTimeMillis(),
duration = TimeUnit.MINUTES.toMillis(hypoTTDuration.toLong()), duration = TimeUnit.MINUTES.toMillis(hypoTTDuration.toLong()),
@ -279,19 +288,17 @@ class CarbsDialog : DialogFragmentWithDate() {
detailedBolusInfo.notes = notes detailedBolusInfo.notes = notes
detailedBolusInfo.carbsDuration = T.hours(duration.toLong()).msecs() detailedBolusInfo.carbsDuration = T.hours(duration.toLong()).msecs()
detailedBolusInfo.carbsTimestamp = time detailedBolusInfo.carbsTimestamp = time
uel.log(Action.CARBS, detailedBolusInfo.notes, uel.log(if (duration == 0) Action.CARBS else Action.EXTENDED_CARBS, Sources.CarbDialog,
ValueWithUnit(detailedBolusInfo.timestamp, Units.Timestamp), notes,
ValueWithUnit(detailedBolusInfo.carbs, Units.G), ValueWithUnit.Timestamp(eventTime).takeIf { eventTimeChanged },
ValueWithUnit(detailedBolusInfo.carbTime, Units.M, detailedBolusInfo.carbTime != 0), ValueWithUnit.Gram(carbsAfterConstraints),
ValueWithUnit(T.msecs(detailedBolusInfo.carbsDuration).hours(), Units.H, detailedBolusInfo.carbsDuration != 0L) ValueWithUnit.Minute(timeOffset).takeIf { timeOffset != 0 },
) ValueWithUnit.Hour(duration).takeIf { duration != 0 })
commandQueue.bolus(detailedBolusInfo, object : Callback() { commandQueue.bolus(detailedBolusInfo, object : Callback() {
override fun run() { override fun run() {
if (!result.success) { if (!result.success) {
ErrorHelperActivity.runAlarm(ctx, result.comment, resourceHelper.gs(R.string.treatmentdeliveryerror), R.raw.boluserror) ErrorHelperActivity.runAlarm(ctx, result.comment, resourceHelper.gs(R.string.treatmentdeliveryerror), R.raw.boluserror)
} else }
uel.log(Action.BOLUS, notes, ValueWithUnit(carbsAfterConstraints, Units.G))
} }
}) })
} }

View file

@ -14,10 +14,10 @@ import info.nightscout.androidaps.Constants
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
import info.nightscout.androidaps.data.Profile import info.nightscout.androidaps.data.Profile
import info.nightscout.androidaps.database.AppRepository import info.nightscout.androidaps.database.AppRepository
import info.nightscout.androidaps.database.entities.ValueWithUnit
import info.nightscout.androidaps.database.entities.TherapyEvent import info.nightscout.androidaps.database.entities.TherapyEvent
import info.nightscout.androidaps.database.entities.UserEntry.Action import info.nightscout.androidaps.database.entities.UserEntry.Action
import info.nightscout.androidaps.database.entities.UserEntry.Units import info.nightscout.androidaps.database.entities.UserEntry.Sources
import info.nightscout.androidaps.database.entities.UserEntry.ValueWithUnit
import info.nightscout.androidaps.database.transactions.InsertIfNewByTimestampTherapyEventTransaction import info.nightscout.androidaps.database.transactions.InsertIfNewByTimestampTherapyEventTransaction
import info.nightscout.androidaps.databinding.DialogCareBinding import info.nightscout.androidaps.databinding.DialogCareBinding
import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.interfaces.ProfileFunction
@ -60,7 +60,8 @@ class CareDialog : DialogFragmentWithDate() {
} }
private var options: EventType = EventType.BGCHECK private var options: EventType = EventType.BGCHECK
private var valuesWithUnit = mutableListOf<ValueWithUnit>() //private var valuesWithUnit = mutableListOf<XXXValueWithUnit?>()
private var valuesWithUnit = mutableListOf<ValueWithUnit?>()
@StringRes @StringRes
private var event: Int = R.string.none private var event: Int = R.string.none
@ -198,17 +199,17 @@ class CareDialog : DialogFragmentWithDate() {
binding.sensor.isChecked -> TherapyEvent.MeterType.SENSOR binding.sensor.isChecked -> TherapyEvent.MeterType.SENSOR
else -> TherapyEvent.MeterType.MANUAL else -> TherapyEvent.MeterType.MANUAL
} }
actions.add(resourceHelper.gs(R.string.careportal_newnstreatment_glucosetype) + ": " + translator.translate(meterType.text)) actions.add(resourceHelper.gs(R.string.careportal_newnstreatment_glucosetype) + ": " + translator.translate(meterType))
actions.add(resourceHelper.gs(R.string.treatments_wizard_bg_label) + ": " + Profile.toCurrentUnitsString(profileFunction, binding.bg.value) + " " + resourceHelper.gs(unitResId)) actions.add(resourceHelper.gs(R.string.treatments_wizard_bg_label) + ": " + Profile.toCurrentUnitsString(profileFunction, binding.bg.value) + " " + resourceHelper.gs(unitResId))
therapyEvent.glucoseType = meterType therapyEvent.glucoseType = meterType
therapyEvent.glucose = binding.bg.value therapyEvent.glucose = binding.bg.value
valuesWithUnit.add(ValueWithUnit(binding.bg.value.toDouble(), profileFunction.getUnits())) valuesWithUnit.add(ValueWithUnit.fromGlucoseUnit(binding.bg.value.toDouble(), profileFunction.getUnits()))
valuesWithUnit.add(ValueWithUnit(meterType.text, Units.TherapyEvent)) valuesWithUnit.add(ValueWithUnit.TherapyEventMeterType(meterType))
} }
if (options == EventType.NOTE || options == EventType.EXERCISE) { if (options == EventType.NOTE || options == EventType.EXERCISE) {
actions.add(resourceHelper.gs(R.string.careportal_newnstreatment_duration_label) + ": " + resourceHelper.gs(R.string.format_mins, binding.duration.value.toInt())) actions.add(resourceHelper.gs(R.string.careportal_newnstreatment_duration_label) + ": " + resourceHelper.gs(R.string.format_mins, binding.duration.value.toInt()))
therapyEvent.duration = T.mins(binding.duration.value.toLong()).msecs() therapyEvent.duration = T.mins(binding.duration.value.toLong()).msecs()
valuesWithUnit.add(ValueWithUnit(binding.duration.value.toInt(), Units.M, !binding.duration.value.equals(0.0))) valuesWithUnit.add(ValueWithUnit.Minute(binding.duration.value.toInt()).takeIf { !binding.duration.value.equals(0.0) } )
} }
val notes = binding.notesLayout.notes.text.toString() val notes = binding.notesLayout.notes.text.toString()
if (notes.isNotEmpty()) { if (notes.isNotEmpty()) {
@ -220,6 +221,16 @@ class CareDialog : DialogFragmentWithDate() {
therapyEvent.enteredBy = enteredBy therapyEvent.enteredBy = enteredBy
var source = when (options) {
EventType.BGCHECK -> Sources.BgCheck
EventType.SENSOR_INSERT -> Sources.SensorInsert
EventType.BATTERY_CHANGE -> Sources.BatteryChange
EventType.NOTE -> Sources.Note
EventType.EXERCISE -> Sources.Exercise
EventType.QUESTION -> Sources.Question
EventType.ANNOUNCEMENT -> Sources.Announcement
}
activity?.let { activity -> activity?.let { activity ->
OKDialog.showConfirmation(activity, resourceHelper.gs(event), HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions)), { OKDialog.showConfirmation(activity, resourceHelper.gs(event), HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions)), {
disposable += repository.runTransactionForResult(InsertIfNewByTimestampTherapyEventTransaction(therapyEvent)) disposable += repository.runTransactionForResult(InsertIfNewByTimestampTherapyEventTransaction(therapyEvent))
@ -227,9 +238,9 @@ class CareDialog : DialogFragmentWithDate() {
{ result -> result.inserted.forEach { aapsLogger.debug(LTag.DATABASE, "Inserted therapy event $it") } }, { result -> result.inserted.forEach { aapsLogger.debug(LTag.DATABASE, "Inserted therapy event $it") } },
{ aapsLogger.error(LTag.DATABASE, "Error while saving therapy event", it) } { aapsLogger.error(LTag.DATABASE, "Error while saving therapy event", it) }
) )
valuesWithUnit.add(0, ValueWithUnit(eventTime, Units.Timestamp, eventTimeChanged)) valuesWithUnit.add(0, ValueWithUnit.Timestamp(eventTime).takeIf { eventTimeChanged })
valuesWithUnit.add(1, ValueWithUnit(therapyEvent.type.text, Units.TherapyEvent)) valuesWithUnit.add(1, ValueWithUnit.TherapyEventType(therapyEvent.type))
uel.log(Action.CAREPORTAL, notes, valuesWithUnit) uel.log(Action.CAREPORTAL, source, notes, valuesWithUnit)
}, null) }, null)
} }
return true return true

View file

@ -8,7 +8,9 @@ import android.view.ViewGroup
import com.google.common.base.Joiner import com.google.common.base.Joiner
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
import info.nightscout.androidaps.activities.ErrorHelperActivity import info.nightscout.androidaps.activities.ErrorHelperActivity
import info.nightscout.androidaps.database.entities.UserEntry.* import info.nightscout.androidaps.database.entities.ValueWithUnit
import info.nightscout.androidaps.database.entities.UserEntry.Action
import info.nightscout.androidaps.database.entities.UserEntry.Sources
import info.nightscout.androidaps.databinding.DialogExtendedbolusBinding import info.nightscout.androidaps.databinding.DialogExtendedbolusBinding
import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.interfaces.ActivePluginProvider
import info.nightscout.androidaps.interfaces.CommandQueueProvider import info.nightscout.androidaps.interfaces.CommandQueueProvider
@ -88,7 +90,9 @@ class ExtendedBolusDialog : DialogFragmentWithDate() {
activity?.let { activity -> activity?.let { activity ->
OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.extended_bolus), HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions)), { OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.extended_bolus), HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions)), {
uel.log(Action.EXTENDED_BOLUS, ValueWithUnit(insulinAfterConstraint, Units.U), ValueWithUnit(durationInMinutes, Units.M)) uel.log(Action.EXTENDED_BOLUS, Sources.ExtendedBolusDialog,
ValueWithUnit.Insulin(insulinAfterConstraint),
ValueWithUnit.Minute(durationInMinutes))
commandQueue.extendedBolus(insulinAfterConstraint, durationInMinutes, object : Callback() { commandQueue.extendedBolus(insulinAfterConstraint, durationInMinutes, object : Callback() {
override fun run() { override fun run() {
if (!result.success) { if (!result.success) {

View file

@ -10,10 +10,10 @@ import info.nightscout.androidaps.R
import info.nightscout.androidaps.activities.ErrorHelperActivity import info.nightscout.androidaps.activities.ErrorHelperActivity
import info.nightscout.androidaps.data.DetailedBolusInfo import info.nightscout.androidaps.data.DetailedBolusInfo
import info.nightscout.androidaps.database.AppRepository import info.nightscout.androidaps.database.AppRepository
import info.nightscout.androidaps.database.entities.ValueWithUnit
import info.nightscout.androidaps.database.entities.TherapyEvent import info.nightscout.androidaps.database.entities.TherapyEvent
import info.nightscout.androidaps.database.entities.UserEntry.Action import info.nightscout.androidaps.database.entities.UserEntry.Action
import info.nightscout.androidaps.database.entities.UserEntry.Units import info.nightscout.androidaps.database.entities.UserEntry.Sources
import info.nightscout.androidaps.database.entities.UserEntry.ValueWithUnit
import info.nightscout.androidaps.database.transactions.InsertIfNewByTimestampTherapyEventTransaction import info.nightscout.androidaps.database.transactions.InsertIfNewByTimestampTherapyEventTransaction
import info.nightscout.androidaps.databinding.DialogFillBinding import info.nightscout.androidaps.databinding.DialogFillBinding
import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.interfaces.ActivePluginProvider
@ -123,7 +123,7 @@ class FillDialog : DialogFragmentWithDate() {
val insulinChange = binding.fillCartridgeChange.isChecked val insulinChange = binding.fillCartridgeChange.isChecked
if (insulinChange) if (insulinChange)
actions.add(resourceHelper.gs(R.string.record_insulin_cartridge_change).formatColor(resourceHelper, R.color.actionsConfirm)) actions.add(resourceHelper.gs(R.string.record_insulin_cartridge_change).formatColor(resourceHelper, R.color.actionsConfirm))
val notes = binding.notesLayout.notes.text.toString() val notes: String = binding.notesLayout.notes.text.toString()
if (notes.isNotEmpty()) if (notes.isNotEmpty())
actions.add(resourceHelper.gs(R.string.notes_label) + ": " + notes) actions.add(resourceHelper.gs(R.string.notes_label) + ": " + notes)
eventTime -= eventTime % 1000 eventTime -= eventTime % 1000
@ -135,11 +135,16 @@ class FillDialog : DialogFragmentWithDate() {
activity?.let { activity -> activity?.let { activity ->
OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.primefill), HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions)), { OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.primefill), HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions)), {
if (insulinAfterConstraints > 0) { if (insulinAfterConstraints > 0) {
uel.log(Action.PRIME_BOLUS, notes, ValueWithUnit(insulinAfterConstraints, Units.U, insulinAfterConstraints != 0.0)) uel.log(Action.PRIME_BOLUS, Sources.FillDialog,
notes,
ValueWithUnit.Insulin(insulinAfterConstraints).takeIf { insulinAfterConstraints != 0.0 })
requestPrimeBolus(insulinAfterConstraints, notes) requestPrimeBolus(insulinAfterConstraints, notes)
} }
if (siteChange) { if (siteChange) {
uel.log(Action.CAREPORTAL, notes, ValueWithUnit(TherapyEvent.Type.CANNULA_CHANGE.text, Units.TherapyEvent)) uel.log(Action.SITE_CHANGE, Sources.FillDialog,
notes,
ValueWithUnit.Timestamp(eventTime).takeIf { eventTimeChanged },
ValueWithUnit.TherapyEventType(TherapyEvent.Type.CANNULA_CHANGE))
disposable += repository.runTransactionForResult(InsertIfNewByTimestampTherapyEventTransaction( disposable += repository.runTransactionForResult(InsertIfNewByTimestampTherapyEventTransaction(
timestamp = eventTime, timestamp = eventTime,
type = TherapyEvent.Type.CANNULA_CHANGE, type = TherapyEvent.Type.CANNULA_CHANGE,
@ -152,7 +157,10 @@ class FillDialog : DialogFragmentWithDate() {
} }
if (insulinChange) { if (insulinChange) {
// add a second for case of both checked // add a second for case of both checked
uel.log(Action.CAREPORTAL, notes, ValueWithUnit(TherapyEvent.Type.INSULIN_CHANGE.text, Units.TherapyEvent)) uel.log(Action.RESERVOIR_CHANGE, Sources.FillDialog,
notes,
ValueWithUnit.Timestamp(eventTime).takeIf { eventTimeChanged },
ValueWithUnit.TherapyEventType(TherapyEvent.Type.INSULIN_CHANGE))
disposable += repository.runTransactionForResult(InsertIfNewByTimestampTherapyEventTransaction( disposable += repository.runTransactionForResult(InsertIfNewByTimestampTherapyEventTransaction(
timestamp = eventTime + 1000, timestamp = eventTime + 1000,
type = TherapyEvent.Type.INSULIN_CHANGE, type = TherapyEvent.Type.INSULIN_CHANGE,

View file

@ -15,10 +15,10 @@ import info.nightscout.androidaps.activities.ErrorHelperActivity
import info.nightscout.androidaps.data.DetailedBolusInfo import info.nightscout.androidaps.data.DetailedBolusInfo
import info.nightscout.androidaps.data.Profile import info.nightscout.androidaps.data.Profile
import info.nightscout.androidaps.database.AppRepository import info.nightscout.androidaps.database.AppRepository
import info.nightscout.androidaps.database.entities.ValueWithUnit
import info.nightscout.androidaps.database.entities.TemporaryTarget import info.nightscout.androidaps.database.entities.TemporaryTarget
import info.nightscout.androidaps.database.entities.UserEntry.Action import info.nightscout.androidaps.database.entities.UserEntry.Action
import info.nightscout.androidaps.database.entities.UserEntry.Units import info.nightscout.androidaps.database.entities.UserEntry.Sources
import info.nightscout.androidaps.database.entities.UserEntry.ValueWithUnit
import info.nightscout.androidaps.database.transactions.InsertTemporaryTargetAndCancelCurrentTransaction import info.nightscout.androidaps.database.transactions.InsertTemporaryTargetAndCancelCurrentTransaction
import info.nightscout.androidaps.databinding.DialogInsulinBinding import info.nightscout.androidaps.databinding.DialogInsulinBinding
import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.interfaces.ActivePluginProvider
@ -189,7 +189,11 @@ class InsulinDialog : DialogFragmentWithDate() {
activity?.let { activity -> activity?.let { activity ->
OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.bolus), HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions)), { OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.bolus), HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions)), {
if (eatingSoonChecked) { if (eatingSoonChecked) {
uel.log(Action.TT, notes, ValueWithUnit(TemporaryTarget.Reason.EATING_SOON.text, Units.TherapyEvent), ValueWithUnit(eatingSoonTT, units), ValueWithUnit(eatingSoonTTDuration, Units.M)) uel.log(Action.TT, Sources.InsulinDialog,
notes,
ValueWithUnit.TherapyEventTTReason(TemporaryTarget.Reason.EATING_SOON),
ValueWithUnit.fromGlucoseUnit(eatingSoonTT, units),
ValueWithUnit.Minute(eatingSoonTTDuration))
disposable += repository.runTransactionForResult(InsertTemporaryTargetAndCancelCurrentTransaction( disposable += repository.runTransactionForResult(InsertTemporaryTargetAndCancelCurrentTransaction(
timestamp = System.currentTimeMillis(), timestamp = System.currentTimeMillis(),
duration = TimeUnit.MINUTES.toMillis(eatingSoonTTDuration.toLong()), duration = TimeUnit.MINUTES.toMillis(eatingSoonTTDuration.toLong()),
@ -210,12 +214,12 @@ class InsulinDialog : DialogFragmentWithDate() {
detailedBolusInfo.context = context detailedBolusInfo.context = context
detailedBolusInfo.notes = notes detailedBolusInfo.notes = notes
detailedBolusInfo.timestamp = time detailedBolusInfo.timestamp = time
uel.log(Action.BOLUS_RECORD, notes,
ValueWithUnit(detailedBolusInfo.timestamp, Units.Timestamp),
ValueWithUnit(detailedBolusInfo.insulin, Units.U),
ValueWithUnit(timeOffset, Units.M, timeOffset != 0)
)
if (recordOnlyChecked) { if (recordOnlyChecked) {
uel.log(Action.BOLUS, Sources.InsulinDialog,
notes,
ValueWithUnit.StringResource(R.string.record),
ValueWithUnit.Insulin(insulinAfterConstraints),
ValueWithUnit.Minute(timeOffset).takeIf { timeOffset!= 0 })
disposable += repository.runTransactionForResult(detailedBolusInfo.insertBolusTransaction()) disposable += repository.runTransactionForResult(detailedBolusInfo.insertBolusTransaction())
.subscribe( .subscribe(
{ result -> result.inserted.forEach { aapsLogger.debug(LTag.DATABASE, "Inserted bolus $it") } }, { result -> result.inserted.forEach { aapsLogger.debug(LTag.DATABASE, "Inserted bolus $it") } },
@ -227,7 +231,9 @@ class InsulinDialog : DialogFragmentWithDate() {
if (!result.success) { if (!result.success) {
ErrorHelperActivity.runAlarm(ctx, result.comment, resourceHelper.gs(R.string.treatmentdeliveryerror), info.nightscout.androidaps.dana.R.raw.boluserror) ErrorHelperActivity.runAlarm(ctx, result.comment, resourceHelper.gs(R.string.treatmentdeliveryerror), info.nightscout.androidaps.dana.R.raw.boluserror)
} else } else
uel.log(Action.BOLUS, notes, ValueWithUnit(insulinAfterConstraints, Units.U)) uel.log(Action.BOLUS, Sources.InsulinDialog,
notes,
ValueWithUnit.Insulin(insulinAfterConstraints))
} }
}) })

View file

@ -12,7 +12,9 @@ import androidx.fragment.app.FragmentManager
import dagger.android.support.DaggerDialogFragment import dagger.android.support.DaggerDialogFragment
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
import info.nightscout.androidaps.activities.ErrorHelperActivity import info.nightscout.androidaps.activities.ErrorHelperActivity
import info.nightscout.androidaps.database.entities.UserEntry.* import info.nightscout.androidaps.database.entities.ValueWithUnit
import info.nightscout.androidaps.database.entities.UserEntry.Action
import info.nightscout.androidaps.database.entities.UserEntry.Sources
import info.nightscout.androidaps.databinding.DialogLoopBinding import info.nightscout.androidaps.databinding.DialogLoopBinding
import info.nightscout.androidaps.events.EventPreferenceChange import info.nightscout.androidaps.events.EventPreferenceChange
import info.nightscout.androidaps.events.EventRefreshOverview import info.nightscout.androidaps.events.EventRefreshOverview
@ -239,28 +241,28 @@ class LoopDialog : DaggerDialogFragment() {
val profile = profileFunction.getProfile() ?: return true val profile = profileFunction.getProfile() ?: return true
when (v.id) { when (v.id) {
R.id.overview_closeloop -> { R.id.overview_closeloop -> {
uel.log(Action.CLOSED_LOOP_MODE) uel.log(Action.CLOSED_LOOP_MODE, Sources.LoopDialog)
sp.putString(R.string.key_aps_mode, "closed") sp.putString(R.string.key_aps_mode, "closed")
rxBus.send(EventPreferenceChange(resourceHelper.gs(R.string.closedloop))) rxBus.send(EventPreferenceChange(resourceHelper.gs(R.string.closedloop)))
return true return true
} }
R.id.overview_lgsloop -> { R.id.overview_lgsloop -> {
uel.log(Action.LGS_LOOP_MODE) uel.log(Action.LGS_LOOP_MODE, Sources.LoopDialog)
sp.putString(R.string.key_aps_mode, "lgs") sp.putString(R.string.key_aps_mode, "lgs")
rxBus.send(EventPreferenceChange(resourceHelper.gs(R.string.lowglucosesuspend))) rxBus.send(EventPreferenceChange(resourceHelper.gs(R.string.lowglucosesuspend)))
return true return true
} }
R.id.overview_openloop -> { R.id.overview_openloop -> {
uel.log(Action.OPEN_LOOP_MODE) uel.log(Action.OPEN_LOOP_MODE, Sources.LoopDialog)
sp.putString(R.string.key_aps_mode, "open") sp.putString(R.string.key_aps_mode, "open")
rxBus.send(EventPreferenceChange(resourceHelper.gs(R.string.lowglucosesuspend))) rxBus.send(EventPreferenceChange(resourceHelper.gs(R.string.lowglucosesuspend)))
return true return true
} }
R.id.overview_disable -> { R.id.overview_disable -> {
uel.log(Action.LOOP_DISABLED) uel.log(Action.LOOP_DISABLED, Sources.LoopDialog)
loopPlugin.setPluginEnabled(PluginType.LOOP, false) loopPlugin.setPluginEnabled(PluginType.LOOP, false)
loopPlugin.setFragmentVisible(PluginType.LOOP, false) loopPlugin.setFragmentVisible(PluginType.LOOP, false)
configBuilderPlugin.storeSettings("DisablingLoop") configBuilderPlugin.storeSettings("DisablingLoop")
@ -277,7 +279,7 @@ class LoopDialog : DaggerDialogFragment() {
} }
R.id.overview_enable -> { R.id.overview_enable -> {
uel.log(Action.LOOP_ENABLED) uel.log(Action.LOOP_ENABLED, Sources.LoopDialog)
loopPlugin.setPluginEnabled(PluginType.LOOP, true) loopPlugin.setPluginEnabled(PluginType.LOOP, true)
loopPlugin.setFragmentVisible(PluginType.LOOP, true) loopPlugin.setFragmentVisible(PluginType.LOOP, true)
configBuilderPlugin.storeSettings("EnablingLoop") configBuilderPlugin.storeSettings("EnablingLoop")
@ -287,7 +289,7 @@ class LoopDialog : DaggerDialogFragment() {
} }
R.id.overview_resume, R.id.overview_reconnect -> { R.id.overview_resume, R.id.overview_reconnect -> {
uel.log(if (v.id==R.id.overview_resume) Action.RESUME else Action.RECONNECT ) uel.log(if (v.id==R.id.overview_resume) Action.RESUME else Action.RECONNECT, Sources.LoopDialog)
loopPlugin.suspendTo(0L) loopPlugin.suspendTo(0L)
rxBus.send(EventRefreshOverview("suspendmenu")) rxBus.send(EventRefreshOverview("suspendmenu"))
commandQueue.cancelTempBasal(true, object : Callback() { commandQueue.cancelTempBasal(true, object : Callback() {
@ -303,49 +305,49 @@ class LoopDialog : DaggerDialogFragment() {
} }
R.id.overview_suspend_1h -> { R.id.overview_suspend_1h -> {
uel.log(Action.SUSPEND, ValueWithUnit(1, Units.H)) uel.log(Action.SUSPEND, Sources.LoopDialog, ValueWithUnit.Hour(1))
loopPlugin.suspendLoop(60) loopPlugin.suspendLoop(60)
rxBus.send(EventRefreshOverview("suspendmenu")) rxBus.send(EventRefreshOverview("suspendmenu"))
return true return true
} }
R.id.overview_suspend_2h -> { R.id.overview_suspend_2h -> {
uel.log(Action.SUSPEND, ValueWithUnit(2, Units.H)) uel.log(Action.SUSPEND, Sources.LoopDialog, ValueWithUnit.Hour(2))
loopPlugin.suspendLoop(120) loopPlugin.suspendLoop(120)
rxBus.send(EventRefreshOverview("suspendmenu")) rxBus.send(EventRefreshOverview("suspendmenu"))
return true return true
} }
R.id.overview_suspend_3h -> { R.id.overview_suspend_3h -> {
uel.log(Action.SUSPEND, ValueWithUnit(3, Units.H)) uel.log(Action.SUSPEND, Sources.LoopDialog, ValueWithUnit.Hour(3))
loopPlugin.suspendLoop(180) loopPlugin.suspendLoop(180)
rxBus.send(EventRefreshOverview("suspendmenu")) rxBus.send(EventRefreshOverview("suspendmenu"))
return true return true
} }
R.id.overview_suspend_10h -> { R.id.overview_suspend_10h -> {
uel.log(Action.SUSPEND, ValueWithUnit(10, Units.H)) uel.log(Action.SUSPEND, Sources.LoopDialog, ValueWithUnit.Hour(10))
loopPlugin.suspendLoop(600) loopPlugin.suspendLoop(600)
rxBus.send(EventRefreshOverview("suspendmenu")) rxBus.send(EventRefreshOverview("suspendmenu"))
return true return true
} }
R.id.overview_disconnect_15m -> { R.id.overview_disconnect_15m -> {
uel.log(Action.DISCONNECT, ValueWithUnit(15, Units.M)) uel.log(Action.DISCONNECT, Sources.LoopDialog, ValueWithUnit.Minute(15))
loopPlugin.disconnectPump(15, profile) loopPlugin.disconnectPump(15, profile)
rxBus.send(EventRefreshOverview("suspendmenu")) rxBus.send(EventRefreshOverview("suspendmenu"))
return true return true
} }
R.id.overview_disconnect_30m -> { R.id.overview_disconnect_30m -> {
uel.log(Action.DISCONNECT, ValueWithUnit(30, Units.M)) uel.log(Action.DISCONNECT, Sources.LoopDialog, ValueWithUnit.Minute(30))
loopPlugin.disconnectPump(30, profile) loopPlugin.disconnectPump(30, profile)
rxBus.send(EventRefreshOverview("suspendmenu")) rxBus.send(EventRefreshOverview("suspendmenu"))
return true return true
} }
R.id.overview_disconnect_1h -> { R.id.overview_disconnect_1h -> {
uel.log(Action.DISCONNECT, ValueWithUnit(1, Units.H)) uel.log(Action.DISCONNECT, Sources.LoopDialog, ValueWithUnit.Hour(1))
loopPlugin.disconnectPump(60, profile) loopPlugin.disconnectPump(60, profile)
sp.putBoolean(R.string.key_objectiveusedisconnect, true) sp.putBoolean(R.string.key_objectiveusedisconnect, true)
rxBus.send(EventRefreshOverview("suspendmenu")) rxBus.send(EventRefreshOverview("suspendmenu"))
@ -353,14 +355,14 @@ class LoopDialog : DaggerDialogFragment() {
} }
R.id.overview_disconnect_2h -> { R.id.overview_disconnect_2h -> {
uel.log(Action.DISCONNECT, ValueWithUnit(2, Units.H)) uel.log(Action.DISCONNECT, Sources.LoopDialog, ValueWithUnit.Hour(2))
loopPlugin.disconnectPump(120, profile) loopPlugin.disconnectPump(120, profile)
rxBus.send(EventRefreshOverview("suspendmenu")) rxBus.send(EventRefreshOverview("suspendmenu"))
return true return true
} }
R.id.overview_disconnect_3h -> { R.id.overview_disconnect_3h -> {
uel.log(Action.DISCONNECT, ValueWithUnit(3, Units.H)) uel.log(Action.DISCONNECT, Sources.LoopDialog, ValueWithUnit.Hour(3))
loopPlugin.disconnectPump(180, profile) loopPlugin.disconnectPump(180, profile)
rxBus.send(EventRefreshOverview("suspendmenu")) rxBus.send(EventRefreshOverview("suspendmenu"))
return true return true

View file

@ -8,7 +8,9 @@ import android.widget.ArrayAdapter
import com.google.common.base.Joiner import com.google.common.base.Joiner
import info.nightscout.androidaps.Constants import info.nightscout.androidaps.Constants
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
import info.nightscout.androidaps.database.entities.UserEntry.* import info.nightscout.androidaps.database.entities.ValueWithUnit
import info.nightscout.androidaps.database.entities.UserEntry.Action
import info.nightscout.androidaps.database.entities.UserEntry.Sources
import info.nightscout.androidaps.databinding.DialogProfileswitchBinding import info.nightscout.androidaps.databinding.DialogProfileswitchBinding
import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.interfaces.ActivePluginProvider
import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.interfaces.ProfileFunction
@ -125,7 +127,14 @@ class ProfileSwitchDialog : DialogFragmentWithDate() {
activity?.let { activity -> activity?.let { activity ->
OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.careportal_profileswitch), HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions)), { OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.careportal_profileswitch), HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions)), {
uel.log(Action.PROFILE_SWITCH, notes, ValueWithUnit(eventTime, Units.Timestamp, eventTimeChanged), ValueWithUnit(profile, Units.None), ValueWithUnit(percent, Units.Percent), ValueWithUnit(timeShift, Units.H, timeShift != 0), ValueWithUnit(duration, Units.M, duration != 0)) uel.log(Action.PROFILE_SWITCH,
Sources.ProfileSwitchDialog,
notes,
ValueWithUnit.Timestamp(eventTime).takeIf { eventTimeChanged },
ValueWithUnit.SimpleString(profile),
ValueWithUnit.Percent(percent),
ValueWithUnit.Hour(timeShift).takeIf { timeShift != 0 },
ValueWithUnit.Minute(duration).takeIf { duration != 0 })
treatmentsPlugin.doProfileSwitch(profileStore, profile, duration, percent, timeShift, eventTime) treatmentsPlugin.doProfileSwitch(profileStore, profile, duration, percent, timeShift, eventTime)
}) })
} }

View file

@ -8,7 +8,9 @@ import android.view.ViewGroup
import com.google.common.base.Joiner import com.google.common.base.Joiner
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
import info.nightscout.androidaps.activities.ErrorHelperActivity import info.nightscout.androidaps.activities.ErrorHelperActivity
import info.nightscout.androidaps.database.entities.UserEntry.* import info.nightscout.androidaps.database.entities.ValueWithUnit
import info.nightscout.androidaps.database.entities.UserEntry.Action
import info.nightscout.androidaps.database.entities.UserEntry.Sources
import info.nightscout.androidaps.databinding.DialogTempbasalBinding import info.nightscout.androidaps.databinding.DialogTempbasalBinding
import info.nightscout.androidaps.interfaces.* import info.nightscout.androidaps.interfaces.*
import info.nightscout.androidaps.logging.UserEntryLogger import info.nightscout.androidaps.logging.UserEntryLogger
@ -122,10 +124,14 @@ class TempBasalDialog : DialogFragmentWithDate() {
} }
} }
if (isPercentPump) { if (isPercentPump) {
uel.log(Action.TEMP_BASAL, ValueWithUnit(percent, Units.Percent), ValueWithUnit(durationInMinutes, Units.M)) uel.log(Action.TEMP_BASAL, Sources.TempBasalDialog,
ValueWithUnit.Percent(percent),
ValueWithUnit.Minute(durationInMinutes))
commandQueue.tempBasalPercent(percent, durationInMinutes, true, profile, PumpSync.TemporaryBasalType.NORMAL, callback) commandQueue.tempBasalPercent(percent, durationInMinutes, true, profile, PumpSync.TemporaryBasalType.NORMAL, callback)
} else { } else {
uel.log(Action.TEMP_BASAL, ValueWithUnit(absolute, Units.U), ValueWithUnit(durationInMinutes, Units.M)) uel.log(Action.TEMP_BASAL, Sources.TempBasalDialog,
ValueWithUnit.Insulin(absolute),
ValueWithUnit.Minute(durationInMinutes))
commandQueue.tempBasalAbsolute(absolute, durationInMinutes, true, profile, PumpSync.TemporaryBasalType.NORMAL, callback) commandQueue.tempBasalAbsolute(absolute, durationInMinutes, true, profile, PumpSync.TemporaryBasalType.NORMAL, callback)
} }
}) })

View file

@ -12,8 +12,10 @@ import info.nightscout.androidaps.R
import info.nightscout.androidaps.data.Profile import info.nightscout.androidaps.data.Profile
import info.nightscout.androidaps.database.AppRepository import info.nightscout.androidaps.database.AppRepository
import info.nightscout.androidaps.database.ValueWrapper import info.nightscout.androidaps.database.ValueWrapper
import info.nightscout.androidaps.database.entities.ValueWithUnit
import info.nightscout.androidaps.database.entities.TemporaryTarget import info.nightscout.androidaps.database.entities.TemporaryTarget
import info.nightscout.androidaps.database.entities.UserEntry.* import info.nightscout.androidaps.database.entities.UserEntry.Action
import info.nightscout.androidaps.database.entities.UserEntry.Sources
import info.nightscout.androidaps.database.transactions.CancelCurrentTemporaryTargetIfAnyTransaction import info.nightscout.androidaps.database.transactions.CancelCurrentTemporaryTargetIfAnyTransaction
import info.nightscout.androidaps.database.transactions.InsertTemporaryTargetAndCancelCurrentTransaction import info.nightscout.androidaps.database.transactions.InsertTemporaryTargetAndCancelCurrentTransaction
import info.nightscout.androidaps.databinding.DialogTemptargetBinding import info.nightscout.androidaps.databinding.DialogTemptargetBinding
@ -178,12 +180,12 @@ class TempTargetDialog : DialogFragmentWithDate() {
activity?.let { activity -> activity?.let { activity ->
OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.careportal_temporarytarget), HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions)), { OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.careportal_temporarytarget), HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions)), {
val units = profileFunction.getUnits() val units = profileFunction.getUnits()
when (reason) { when(reason) {
resourceHelper.gs(R.string.eatingsoon) -> uel.log(Action.TT, ValueWithUnit(eventTime, Units.Timestamp, eventTimeChanged), ValueWithUnit(TemporaryTarget.Reason.EATING_SOON.text, Units.TherapyEvent), ValueWithUnit(target, units), ValueWithUnit(duration, Units.M)) resourceHelper.gs(R.string.eatingsoon) -> uel.log(Action.TT, Sources.TTDialog, ValueWithUnit.Timestamp(eventTime).takeIf { eventTimeChanged }, ValueWithUnit.TherapyEventTTReason(TemporaryTarget.Reason.EATING_SOON), ValueWithUnit.fromGlucoseUnit(target, units), ValueWithUnit.Minute(duration))
resourceHelper.gs(R.string.activity) -> uel.log(Action.TT, ValueWithUnit(eventTime, Units.Timestamp, eventTimeChanged), ValueWithUnit(TemporaryTarget.Reason.ACTIVITY.text, Units.TherapyEvent), ValueWithUnit(target, units), ValueWithUnit(duration, Units.M)) resourceHelper.gs(R.string.activity) -> uel.log(Action.TT, Sources.TTDialog, ValueWithUnit.Timestamp(eventTime).takeIf { eventTimeChanged }, ValueWithUnit.TherapyEventTTReason(TemporaryTarget.Reason.ACTIVITY), ValueWithUnit.fromGlucoseUnit(target, units), ValueWithUnit.Minute(duration))
resourceHelper.gs(R.string.hypo) -> uel.log(Action.TT, ValueWithUnit(eventTime, Units.Timestamp, eventTimeChanged), ValueWithUnit(TemporaryTarget.Reason.HYPOGLYCEMIA.text, Units.TherapyEvent), ValueWithUnit(target, units), ValueWithUnit(duration, Units.M)) resourceHelper.gs(R.string.hypo) -> uel.log(Action.TT, Sources.TTDialog, ValueWithUnit.Timestamp(eventTime).takeIf { eventTimeChanged }, ValueWithUnit.TherapyEventTTReason(TemporaryTarget.Reason.HYPOGLYCEMIA), ValueWithUnit.fromGlucoseUnit(target, units), ValueWithUnit.Minute(duration))
resourceHelper.gs(R.string.manual) -> uel.log(Action.TT, ValueWithUnit(eventTime, Units.Timestamp, eventTimeChanged), ValueWithUnit(TemporaryTarget.Reason.CUSTOM.text, Units.TherapyEvent), ValueWithUnit(target, units), ValueWithUnit(duration, Units.M)) resourceHelper.gs(R.string.manual) -> uel.log(Action.TT, Sources.TTDialog, ValueWithUnit.Timestamp(eventTime).takeIf { eventTimeChanged }, ValueWithUnit.TherapyEventTTReason(TemporaryTarget.Reason.CUSTOM), ValueWithUnit.fromGlucoseUnit(target, units), ValueWithUnit.Minute(duration))
resourceHelper.gs(R.string.stoptemptarget) -> uel.log(Action.CANCEL_TT, ValueWithUnit(eventTime, Units.Timestamp, eventTimeChanged)) resourceHelper.gs(R.string.stoptemptarget) -> uel.log(Action.CANCEL_TT, Sources.TTDialog, ValueWithUnit.Timestamp(eventTime).takeIf { eventTimeChanged })
} }
if (target == 0.0 || duration == 0) { if (target == 0.0 || duration == 0) {
disposable += repository.runTransactionForResult(CancelCurrentTemporaryTargetIfAnyTransaction(eventTime)) disposable += repository.runTransactionForResult(CancelCurrentTemporaryTargetIfAnyTransaction(eventTime))
@ -200,7 +202,7 @@ class TempTargetDialog : DialogFragmentWithDate() {
resourceHelper.gs(R.string.eatingsoon) -> TemporaryTarget.Reason.EATING_SOON resourceHelper.gs(R.string.eatingsoon) -> TemporaryTarget.Reason.EATING_SOON
resourceHelper.gs(R.string.activity) -> TemporaryTarget.Reason.ACTIVITY resourceHelper.gs(R.string.activity) -> TemporaryTarget.Reason.ACTIVITY
resourceHelper.gs(R.string.hypo) -> TemporaryTarget.Reason.HYPOGLYCEMIA resourceHelper.gs(R.string.hypo) -> TemporaryTarget.Reason.HYPOGLYCEMIA
else -> TemporaryTarget.Reason.CUSTOM else -> TemporaryTarget.Reason.CUSTOM
}, },
lowTarget = Profile.toMgdl(target, profileFunction.getUnits()), lowTarget = Profile.toMgdl(target, profileFunction.getUnits()),
highTarget = Profile.toMgdl(target, profileFunction.getUnits()) highTarget = Profile.toMgdl(target, profileFunction.getUnits())

View file

@ -13,9 +13,9 @@ import info.nightscout.androidaps.R
import info.nightscout.androidaps.activities.ErrorHelperActivity import info.nightscout.androidaps.activities.ErrorHelperActivity
import info.nightscout.androidaps.data.DetailedBolusInfo import info.nightscout.androidaps.data.DetailedBolusInfo
import info.nightscout.androidaps.database.AppRepository import info.nightscout.androidaps.database.AppRepository
import info.nightscout.androidaps.database.entities.ValueWithUnit
import info.nightscout.androidaps.database.entities.UserEntry.Action import info.nightscout.androidaps.database.entities.UserEntry.Action
import info.nightscout.androidaps.database.entities.UserEntry.Units import info.nightscout.androidaps.database.entities.UserEntry.Sources
import info.nightscout.androidaps.database.entities.UserEntry.ValueWithUnit
import info.nightscout.androidaps.databinding.DialogTreatmentBinding import info.nightscout.androidaps.databinding.DialogTreatmentBinding
import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.interfaces.ActivePluginProvider
import info.nightscout.androidaps.interfaces.CommandQueueProvider import info.nightscout.androidaps.interfaces.CommandQueueProvider
@ -139,18 +139,23 @@ class TreatmentDialog : DialogFragmentWithDate() {
if (insulinAfterConstraints > 0 || carbsAfterConstraints > 0) { if (insulinAfterConstraints > 0 || carbsAfterConstraints > 0) {
activity?.let { activity -> activity?.let { activity ->
OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.overview_treatment_label), HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions)), { OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.overview_treatment_label), HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions)), {
val action = when {
insulinAfterConstraints.equals(0.0) -> Action.CARBS
carbsAfterConstraints.equals(0) -> Action.BOLUS
else -> Action.TREATMENT
}
val detailedBolusInfo = DetailedBolusInfo() val detailedBolusInfo = DetailedBolusInfo()
if (insulinAfterConstraints == 0.0) detailedBolusInfo.eventType = DetailedBolusInfo.EventType.CARBS_CORRECTION if (insulinAfterConstraints == 0.0) detailedBolusInfo.eventType = DetailedBolusInfo.EventType.CARBS_CORRECTION
if (carbsAfterConstraints == 0) detailedBolusInfo.eventType = DetailedBolusInfo.EventType.CORRECTION_BOLUS if (carbsAfterConstraints == 0) detailedBolusInfo.eventType = DetailedBolusInfo.EventType.CORRECTION_BOLUS
detailedBolusInfo.insulin = insulinAfterConstraints detailedBolusInfo.insulin = insulinAfterConstraints
detailedBolusInfo.carbs = carbsAfterConstraints.toDouble() detailedBolusInfo.carbs = carbsAfterConstraints.toDouble()
detailedBolusInfo.context = context detailedBolusInfo.context = context
uel.log(Action.TREATMENT,
ValueWithUnit(detailedBolusInfo.timestamp, Units.Timestamp),
ValueWithUnit(insulin, Units.U, insulin != 0.0),
ValueWithUnit(carbs, Units.G, carbs != 0)
)
if (recordOnlyChecked) { if (recordOnlyChecked) {
uel.log(action, Sources.TreatmentDialog,
ValueWithUnit.Timestamp(detailedBolusInfo.timestamp).takeIf { eventTimeChanged },
ValueWithUnit.StringResource(R.string.record).takeIf { insulinAfterConstraints != 0.0 },
ValueWithUnit.Insulin(insulinAfterConstraints).takeIf { insulinAfterConstraints != 0.0 },
ValueWithUnit.Gram(carbsAfterConstraints).takeIf { carbsAfterConstraints != 0 })
if (detailedBolusInfo.insulin > 0) if (detailedBolusInfo.insulin > 0)
disposable += repository.runTransactionForResult(detailedBolusInfo.insertBolusTransaction()) disposable += repository.runTransactionForResult(detailedBolusInfo.insertBolusTransaction())
.subscribe( .subscribe(
@ -164,13 +169,20 @@ class TreatmentDialog : DialogFragmentWithDate() {
{ aapsLogger.error(LTag.DATABASE, "Error while saving carbs", it) } { aapsLogger.error(LTag.DATABASE, "Error while saving carbs", it) }
) )
} else { } else {
commandQueue.bolus(detailedBolusInfo, object : Callback() { if (detailedBolusInfo.insulin > 0)
override fun run() { commandQueue.bolus(detailedBolusInfo, object : Callback() {
if (!result.success) { override fun run() {
ErrorHelperActivity.runAlarm(ctx, result.comment, resourceHelper.gs(R.string.treatmentdeliveryerror), info.nightscout.androidaps.dana.R.raw.boluserror) if (!result.success) {
ErrorHelperActivity.runAlarm(ctx, result.comment, resourceHelper.gs(R.string.treatmentdeliveryerror), info.nightscout.androidaps.dana.R.raw.boluserror)
} else
uel.log(action, Sources.TreatmentDialog,
ValueWithUnit.Insulin(insulinAfterConstraints),
ValueWithUnit.Gram(carbsAfterConstraints).takeIf { carbsAfterConstraints != 0 })
} }
} })
}) else
uel.log(action, Sources.TreatmentDialog,
ValueWithUnit.Gram(carbsAfterConstraints).takeIf { carbs != 0 })
} }
}) })
} }

View file

@ -17,6 +17,9 @@ import info.nightscout.androidaps.data.Profile
import info.nightscout.androidaps.data.PumpEnactResult import info.nightscout.androidaps.data.PumpEnactResult
import info.nightscout.androidaps.database.AppRepository import info.nightscout.androidaps.database.AppRepository
import info.nightscout.androidaps.database.entities.TherapyEvent import info.nightscout.androidaps.database.entities.TherapyEvent
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.InsertIfNewByTimestampTherapyEventTransaction import info.nightscout.androidaps.database.transactions.InsertIfNewByTimestampTherapyEventTransaction
import info.nightscout.androidaps.database.transactions.InsertTherapyEventAnnouncementTransaction import info.nightscout.androidaps.database.transactions.InsertTherapyEventAnnouncementTransaction
import info.nightscout.androidaps.events.EventAcceptOpenLoopChange import info.nightscout.androidaps.events.EventAcceptOpenLoopChange
@ -27,6 +30,7 @@ import info.nightscout.androidaps.interfaces.*
import info.nightscout.androidaps.interfaces.LoopInterface.LastRun import info.nightscout.androidaps.interfaces.LoopInterface.LastRun
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.plugins.aps.loop.events.EventLoopSetLastRunGui import info.nightscout.androidaps.plugins.aps.loop.events.EventLoopSetLastRunGui
import info.nightscout.androidaps.plugins.aps.loop.events.EventLoopUpdateGui import info.nightscout.androidaps.plugins.aps.loop.events.EventLoopUpdateGui
import info.nightscout.androidaps.plugins.aps.loop.events.EventNewOpenLoopNotification import info.nightscout.androidaps.plugins.aps.loop.events.EventNewOpenLoopNotification
@ -78,6 +82,7 @@ open class LoopPlugin @Inject constructor(
private val receiverStatusStore: ReceiverStatusStore, private val receiverStatusStore: ReceiverStatusStore,
private val fabricPrivacy: FabricPrivacy, private val fabricPrivacy: FabricPrivacy,
private val dateUtil: DateUtil, private val dateUtil: DateUtil,
private val uel: UserEntryLogger,
private val repository: AppRepository, private val repository: AppRepository,
private val runningConfiguration: RunningConfiguration private val runningConfiguration: RunningConfiguration
) : PluginBase(PluginDescription() ) : PluginBase(PluginDescription()
@ -546,6 +551,7 @@ open class LoopPlugin @Inject constructor(
if (request.percent == 100 && request.duration == 0) { if (request.percent == 100 && request.duration == 0) {
if (activeTemp != null) { if (activeTemp != null) {
aapsLogger.debug(LTag.APS, "applyAPSRequest: cancelTempBasal()") aapsLogger.debug(LTag.APS, "applyAPSRequest: cancelTempBasal()")
uel.log(Action.CANCEL_TEMP_BASAL, Sources.Loop)
commandQueue.cancelTempBasal(false, callback) commandQueue.cancelTempBasal(false, callback)
} else { } else {
aapsLogger.debug(LTag.APS, "applyAPSRequest: Basal set correctly") aapsLogger.debug(LTag.APS, "applyAPSRequest: Basal set correctly")
@ -559,12 +565,16 @@ open class LoopPlugin @Inject constructor(
.comment(R.string.let_temp_basal_run))?.run() .comment(R.string.let_temp_basal_run))?.run()
} else { } else {
aapsLogger.debug(LTag.APS, "applyAPSRequest: tempBasalPercent()") aapsLogger.debug(LTag.APS, "applyAPSRequest: tempBasalPercent()")
uel.log(Action.TEMP_BASAL, Sources.Loop,
ValueWithUnit.Percent(request.percent),
ValueWithUnit.Minute(request.duration))
commandQueue.tempBasalPercent(request.percent, request.duration, false, profile, PumpSync.TemporaryBasalType.NORMAL, callback) commandQueue.tempBasalPercent(request.percent, request.duration, false, profile, PumpSync.TemporaryBasalType.NORMAL, callback)
} }
} else { } else {
if (request.rate == 0.0 && request.duration == 0 || abs(request.rate - pump.baseBasalRate) < pump.pumpDescription.basalStep) { if (request.rate == 0.0 && request.duration == 0 || abs(request.rate - pump.baseBasalRate) < pump.pumpDescription.basalStep) {
if (activeTemp != null) { if (activeTemp != null) {
aapsLogger.debug(LTag.APS, "applyAPSRequest: cancelTempBasal()") aapsLogger.debug(LTag.APS, "applyAPSRequest: cancelTempBasal()")
uel.log(Action.CANCEL_TEMP_BASAL, Sources.Loop)
commandQueue.cancelTempBasal(false, callback) commandQueue.cancelTempBasal(false, callback)
} else { } else {
aapsLogger.debug(LTag.APS, "applyAPSRequest: Basal set correctly") aapsLogger.debug(LTag.APS, "applyAPSRequest: Basal set correctly")
@ -578,6 +588,9 @@ open class LoopPlugin @Inject constructor(
.comment(R.string.let_temp_basal_run))?.run() .comment(R.string.let_temp_basal_run))?.run()
} else { } else {
aapsLogger.debug(LTag.APS, "applyAPSRequest: setTempBasalAbsolute()") aapsLogger.debug(LTag.APS, "applyAPSRequest: setTempBasalAbsolute()")
uel.log(Action.TEMP_BASAL, Sources.Loop,
ValueWithUnit.UnitPerHour(request.rate),
ValueWithUnit.Minute(request.duration))
commandQueue.tempBasalAbsolute(request.rate, request.duration, false, profile, PumpSync.TemporaryBasalType.NORMAL, callback) commandQueue.tempBasalAbsolute(request.rate, request.duration, false, profile, PumpSync.TemporaryBasalType.NORMAL, callback)
} }
} }
@ -616,6 +629,8 @@ open class LoopPlugin @Inject constructor(
detailedBolusInfo.bolusType = DetailedBolusInfo.BolusType.SMB detailedBolusInfo.bolusType = DetailedBolusInfo.BolusType.SMB
detailedBolusInfo.deliverAtTheLatest = request.deliverAt detailedBolusInfo.deliverAtTheLatest = request.deliverAt
aapsLogger.debug(LTag.APS, "applyAPSRequest: bolus()") aapsLogger.debug(LTag.APS, "applyAPSRequest: bolus()")
if (request.smb > 0.0)
uel.log(Action.SMB, Sources.Loop, ValueWithUnit.Insulin(detailedBolusInfo.insulin))
commandQueue.bolus(detailedBolusInfo, callback) commandQueue.bolus(detailedBolusInfo, callback)
} }

View file

@ -3,7 +3,8 @@ package info.nightscout.androidaps.plugins.configBuilder
import androidx.fragment.app.FragmentActivity import androidx.fragment.app.FragmentActivity
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
import info.nightscout.androidaps.database.entities.UserEntry.* import info.nightscout.androidaps.database.entities.UserEntry.Action
import info.nightscout.androidaps.database.entities.UserEntry.Sources
import info.nightscout.androidaps.events.EventAppInitialized import info.nightscout.androidaps.events.EventAppInitialized
import info.nightscout.androidaps.events.EventConfigBuilderChange import info.nightscout.androidaps.events.EventConfigBuilderChange
import info.nightscout.androidaps.events.EventRebuildTabs import info.nightscout.androidaps.events.EventRebuildTabs
@ -143,7 +144,7 @@ class ConfigBuilderPlugin @Inject constructor(
OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.allow_hardware_pump_text), Runnable { OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.allow_hardware_pump_text), Runnable {
performPluginSwitch(changedPlugin, newState, type) performPluginSwitch(changedPlugin, newState, type)
sp.putBoolean("allow_hardware_pump", true) sp.putBoolean("allow_hardware_pump", true)
uel.log(Action.HW_PUMP_ALLOWED) uel.log(Action.HW_PUMP_ALLOWED, Sources.ConfigBuilder)
aapsLogger.debug(LTag.PUMP, "First time HW pump allowed!") aapsLogger.debug(LTag.PUMP, "First time HW pump allowed!")
}, Runnable { }, Runnable {
rxBus.send(EventConfigBuilderUpdateGui()) rxBus.send(EventConfigBuilderUpdateGui())

View file

@ -17,7 +17,9 @@ import androidx.recyclerview.widget.LinearSmoothScroller
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import dagger.android.support.DaggerFragment import dagger.android.support.DaggerFragment
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
import info.nightscout.androidaps.database.entities.UserEntry.* 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.databinding.ObjectivesFragmentBinding import info.nightscout.androidaps.databinding.ObjectivesFragmentBinding
import info.nightscout.androidaps.databinding.ObjectivesItemBinding import info.nightscout.androidaps.databinding.ObjectivesItemBinding
import info.nightscout.androidaps.dialogs.NtpProgressDialog import info.nightscout.androidaps.dialogs.NtpProgressDialog
@ -308,7 +310,8 @@ class ObjectivesFragment : DaggerFragment() {
holder.binding.unstart.setOnClickListener { holder.binding.unstart.setOnClickListener {
activity?.let { activity -> activity?.let { activity ->
OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.objectives), resourceHelper.gs(R.string.doyouwantresetstart), Runnable { OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.objectives), resourceHelper.gs(R.string.doyouwantresetstart), Runnable {
uel.log(Action.OBJECTIVE_UNSTARTED, ValueWithUnit(position + 1, Units.None)) uel.log(Action.OBJECTIVE_UNSTARTED, Sources.Objectives,
ValueWithUnit.SimpleInt(position + 1))
objective.startedOn = 0 objective.startedOn = 0
scrollToCurrentObjective() scrollToCurrentObjective()
rxBus.send(EventObjectivesUpdateGui()) rxBus.send(EventObjectivesUpdateGui())

View file

@ -7,7 +7,8 @@ import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.BuildConfig import info.nightscout.androidaps.BuildConfig
import info.nightscout.androidaps.Config import info.nightscout.androidaps.Config
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
import info.nightscout.androidaps.database.entities.UserEntry.* import info.nightscout.androidaps.database.entities.UserEntry.Action
import info.nightscout.androidaps.database.entities.UserEntry.Sources
import info.nightscout.androidaps.interfaces.* import info.nightscout.androidaps.interfaces.*
import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.UserEntryLogger import info.nightscout.androidaps.logging.UserEntryLogger
@ -143,7 +144,7 @@ class ObjectivesPlugin @Inject constructor(
sp.putLong("Objectives_" + "auto" + "_accomplished", DateUtil.now()) sp.putLong("Objectives_" + "auto" + "_accomplished", DateUtil.now())
setupObjectives() setupObjectives()
OKDialog.show(activity, resourceHelper.gs(R.string.objectives), resourceHelper.gs(R.string.codeaccepted)) OKDialog.show(activity, resourceHelper.gs(R.string.objectives), resourceHelper.gs(R.string.codeaccepted))
uel.log(Action.OBJECTIVES_SKIPPED) uel.log(Action.OBJECTIVES_SKIPPED, Sources.Objectives)
} else { } else {
OKDialog.show(activity, resourceHelper.gs(R.string.objectives), resourceHelper.gs(R.string.codeinvalid)) OKDialog.show(activity, resourceHelper.gs(R.string.objectives), resourceHelper.gs(R.string.codeinvalid))
} }

View file

@ -16,7 +16,8 @@ import info.nightscout.androidaps.Constants
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
import info.nightscout.androidaps.activities.ErrorHelperActivity import info.nightscout.androidaps.activities.ErrorHelperActivity
import info.nightscout.androidaps.activities.TDDStatsActivity import info.nightscout.androidaps.activities.TDDStatsActivity
import info.nightscout.androidaps.database.entities.UserEntry.* import info.nightscout.androidaps.database.entities.UserEntry.Action
import info.nightscout.androidaps.database.entities.UserEntry.Sources
import info.nightscout.androidaps.dialogs.* import info.nightscout.androidaps.dialogs.*
import info.nightscout.androidaps.events.* import info.nightscout.androidaps.events.*
import info.nightscout.androidaps.historyBrowser.HistoryBrowseActivity import info.nightscout.androidaps.historyBrowser.HistoryBrowseActivity
@ -155,7 +156,7 @@ class ActionsFragment : DaggerFragment() {
} }
extendedBolusCancel?.setOnClickListener { extendedBolusCancel?.setOnClickListener {
if (activePlugin.activeTreatments.isInHistoryExtendedBolusInProgress) { if (activePlugin.activeTreatments.isInHistoryExtendedBolusInProgress) {
uel.log(Action.CANCEL_EXTENDED_BOLUS) uel.log(Action.CANCEL_EXTENDED_BOLUS, Sources.Actions)
commandQueue.cancelExtended(object : Callback() { commandQueue.cancelExtended(object : Callback() {
override fun run() { override fun run() {
if (!result.success) { if (!result.success) {
@ -170,7 +171,7 @@ class ActionsFragment : DaggerFragment() {
} }
cancelTempBasal?.setOnClickListener { cancelTempBasal?.setOnClickListener {
if (activePlugin.activeTreatments.isTempBasalInProgress) { if (activePlugin.activeTreatments.isTempBasalInProgress) {
uel.log(Action.CANCEL_TEMP_BASAL) uel.log(Action.CANCEL_TEMP_BASAL, Sources.Actions)
commandQueue.cancelTempBasal(true, object : Callback() { commandQueue.cancelTempBasal(true, object : Callback() {
override fun run() { override fun run() {
if (!result.success) { if (!result.success) {

View file

@ -17,6 +17,8 @@ import info.nightscout.androidaps.R
import info.nightscout.androidaps.database.AppRepository import info.nightscout.androidaps.database.AppRepository
import info.nightscout.androidaps.database.entities.Food import info.nightscout.androidaps.database.entities.Food
import info.nightscout.androidaps.database.entities.UserEntry.Action 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.InvalidateFoodTransaction import info.nightscout.androidaps.database.transactions.InvalidateFoodTransaction
import info.nightscout.androidaps.databinding.FoodFragmentBinding import info.nightscout.androidaps.databinding.FoodFragmentBinding
import info.nightscout.androidaps.databinding.FoodItemBinding import info.nightscout.androidaps.databinding.FoodItemBinding
@ -74,7 +76,8 @@ class FoodFragment : DaggerFragment() {
binding.refreshFromNightscout.setOnClickListener { binding.refreshFromNightscout.setOnClickListener {
context?.let { context -> context?.let { context ->
OKDialog.showConfirmation(context, resourceHelper.gs(R.string.refresheventsfromnightscout) + " ?", { OKDialog.showConfirmation(context, resourceHelper.gs(R.string.refresheventsfromnightscout) + " ?", {
uel.log(Action.FOOD_FROM_NS) uel.log(Action.FOOD, Sources.Food,
ValueWithUnit.StringResource(R.string.refresheventsfromnightscout))
disposable += Completable.fromAction { repository.deleteAllFoods() } disposable += Completable.fromAction { repository.deleteAllFoods() }
.subscribeOn(aapsSchedulers.io) .subscribeOn(aapsSchedulers.io)
.observeOn(aapsSchedulers.main) .observeOn(aapsSchedulers.main)
@ -250,7 +253,7 @@ class FoodFragment : DaggerFragment() {
val food = v.tag as Food val food = v.tag as Food
activity?.let { activity -> activity?.let { activity ->
OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.removerecord) + "\n" + food.name, { OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.removerecord) + "\n" + food.name, {
uel.log(Action.FOOD_REMOVED, food.name) uel.log(Action.FOOD_REMOVED, Sources.Food, food.name)
disposable += repository.runTransactionForResult(InvalidateFoodTransaction(food.id)) disposable += repository.runTransactionForResult(InvalidateFoodTransaction(food.id))
.subscribe( .subscribe(
{ aapsLogger.error(LTag.DATABASE, "Invalidated food $it") }, { aapsLogger.error(LTag.DATABASE, "Invalidated food $it") },

View file

@ -16,7 +16,8 @@ import info.nightscout.androidaps.R
import info.nightscout.androidaps.activities.DaggerAppCompatActivityWithResult import info.nightscout.androidaps.activities.DaggerAppCompatActivityWithResult
import info.nightscout.androidaps.activities.PreferencesActivity import info.nightscout.androidaps.activities.PreferencesActivity
import info.nightscout.androidaps.database.entities.UserEntry import info.nightscout.androidaps.database.entities.UserEntry
import info.nightscout.androidaps.database.entities.UserEntry.* import info.nightscout.androidaps.database.entities.UserEntry.Action
import info.nightscout.androidaps.database.entities.UserEntry.Sources
import info.nightscout.androidaps.events.EventAppExit import info.nightscout.androidaps.events.EventAppExit
import info.nightscout.androidaps.interfaces.ConfigInterface import info.nightscout.androidaps.interfaces.ConfigInterface
import info.nightscout.androidaps.interfaces.ImportExportPrefsInterface import info.nightscout.androidaps.interfaces.ImportExportPrefsInterface
@ -348,7 +349,7 @@ class ImportExportPrefs @Inject constructor(
private fun restartAppAfterImport(context: Context) { private fun restartAppAfterImport(context: Context) {
sp.putBoolean(R.string.key_setupwizard_processed, true) sp.putBoolean(R.string.key_setupwizard_processed, true)
OKDialog.show(context, resourceHelper.gs(R.string.setting_imported), resourceHelper.gs(R.string.restartingapp)) { OKDialog.show(context, resourceHelper.gs(R.string.setting_imported), resourceHelper.gs(R.string.restartingapp)) {
uel.log(Action.IMPORT_SETTINGS) uel.log(Action.IMPORT_SETTINGS, Sources.Maintenance)
log.debug(LTag.CORE, "Exiting") log.debug(LTag.CORE, "Exiting")
rxBus.send(EventAppExit()) rxBus.send(EventAppExit())
if (context is AppCompatActivity) { if (context is AppCompatActivity) {

View file

@ -9,6 +9,7 @@ import dagger.android.support.DaggerFragment
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.UserEntry.Action import info.nightscout.androidaps.database.entities.UserEntry.Action
import info.nightscout.androidaps.database.entities.UserEntry.Sources
import info.nightscout.androidaps.databinding.MaintenanceFragmentBinding import info.nightscout.androidaps.databinding.MaintenanceFragmentBinding
import info.nightscout.androidaps.events.EventNewBG import info.nightscout.androidaps.events.EventNewBG
import info.nightscout.androidaps.interfaces.DataSyncSelector import info.nightscout.androidaps.interfaces.DataSyncSelector
@ -56,13 +57,12 @@ class MaintenanceFragment : DaggerFragment() {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
binding.logSend.setOnClickListener { maintenancePlugin.sendLogs() } binding.logSend.setOnClickListener { maintenancePlugin.sendLogs() }
binding.logDelete.setOnClickListener { binding.logDelete.setOnClickListener {
uel.log(Action.DELETE_LOGS) uel.log(Action.DELETE_LOGS, Sources.Maintenance)
maintenancePlugin.deleteLogs() maintenancePlugin.deleteLogs()
} }
binding.navResetdb.setOnClickListener { binding.navResetdb.setOnClickListener {
activity?.let { activity -> activity?.let { activity ->
OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.maintenance), resourceHelper.gs(R.string.reset_db_confirm), Runnable { OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.maintenance), resourceHelper.gs(R.string.reset_db_confirm), Runnable {
uel.log(Action.RESET_DATABASES)
compositeDisposable.add( compositeDisposable.add(
fromAction { fromAction {
databaseHelper.resetDatabases() databaseHelper.resetDatabases()
@ -76,18 +76,19 @@ class MaintenanceFragment : DaggerFragment() {
onComplete = { rxBus.send(EventNewBG(null)) } onComplete = { rxBus.send(EventNewBG(null)) }
) )
) )
uel.log(Action.RESET_DATABASES, Sources.Maintenance)
}) })
} }
} }
binding.navExport.setOnClickListener { binding.navExport.setOnClickListener {
uel.log(Action.EXPORT_SETTINGS) uel.log(Action.EXPORT_SETTINGS, Sources.Maintenance)
// start activity for checking permissions... // start activity for checking permissions...
importExportPrefs.verifyStoragePermissions(this) { importExportPrefs.verifyStoragePermissions(this) {
importExportPrefs.exportSharedPreferences(this) importExportPrefs.exportSharedPreferences(this)
} }
} }
binding.navImport.setOnClickListener { binding.navImport.setOnClickListener {
uel.log(Action.IMPORT_SETTINGS) uel.log(Action.IMPORT_SETTINGS, Sources.Maintenance)
// start activity for checking permissions... // start activity for checking permissions...
importExportPrefs.verifyStoragePermissions(this) { importExportPrefs.verifyStoragePermissions(this) {
importExportPrefs.importSharedPreferences(this) importExportPrefs.importSharedPreferences(this)
@ -97,7 +98,7 @@ class MaintenanceFragment : DaggerFragment() {
binding.exportCsv.setOnClickListener { binding.exportCsv.setOnClickListener {
activity?.let { activity -> activity?.let { activity ->
OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.ue_export_to_csv) + "?") { OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.ue_export_to_csv) + "?") {
uel.log(Action.EXPORT_CSV) uel.log(Action.EXPORT_CSV, Sources.Maintenance)
importExportPrefs.exportUserEntriesCsv(activity, repository.getAllUserEntries()) importExportPrefs.exportUserEntriesCsv(activity, repository.getAllUserEntries())
} }
} }

View file

@ -1,16 +1,17 @@
package info.nightscout.androidaps.plugins.general.nsclient package info.nightscout.androidaps.plugins.general.nsclient
import android.content.Context import android.content.Context
import androidx.work.Data
import androidx.work.Worker import androidx.work.Worker
import androidx.work.WorkerParameters import androidx.work.WorkerParameters
import androidx.work.workDataOf import androidx.work.workDataOf
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
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.ValueWithUnit
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.UserEntry.Action
import info.nightscout.androidaps.database.entities.UserEntry.ValueWithUnit import info.nightscout.androidaps.database.entities.UserEntry.Sources
import info.nightscout.androidaps.database.transactions.SyncNsBolusTransaction import info.nightscout.androidaps.database.transactions.SyncNsBolusTransaction
import info.nightscout.androidaps.database.transactions.SyncNsCarbsTransaction import info.nightscout.androidaps.database.transactions.SyncNsCarbsTransaction
import info.nightscout.androidaps.database.transactions.SyncNsTemporaryTargetTransaction import info.nightscout.androidaps.database.transactions.SyncNsTemporaryTargetTransaction
@ -33,6 +34,7 @@ import info.nightscout.androidaps.utils.extensions.carbsFromJson
import info.nightscout.androidaps.utils.extensions.temporaryTargetFromJson import info.nightscout.androidaps.utils.extensions.temporaryTargetFromJson
import info.nightscout.androidaps.utils.extensions.therapyEventFromJson import info.nightscout.androidaps.utils.extensions.therapyEventFromJson
import info.nightscout.androidaps.utils.sharedPreferences.SP import info.nightscout.androidaps.utils.sharedPreferences.SP
import java.util.concurrent.TimeUnit
import javax.inject.Inject import javax.inject.Inject
class NSClientAddUpdateWorker( class NSClientAddUpdateWorker(
@ -88,15 +90,15 @@ class NSClientAddUpdateWorker(
.blockingGet() .blockingGet()
.also { result -> .also { result ->
result.inserted.forEach { result.inserted.forEach {
uel.log(UserEntry.Action.CAREPORTAL_FROM_NS, uel.log(Action.CAREPORTAL, Sources.NSClient,
ValueWithUnit(it.timestamp, UserEntry.Units.Timestamp, true), ValueWithUnit.Timestamp(it.timestamp),
ValueWithUnit(it.amount, UserEntry.Units.U) ValueWithUnit.Insulin(it.amount)
) )
} }
result.invalidated.forEach { result.invalidated.forEach {
uel.log(UserEntry.Action.CAREPORTAL_DELETED_FROM_NS, uel.log(Action.CAREPORTAL_REMOVED, Sources.NSClient,
ValueWithUnit(it.timestamp, UserEntry.Units.Timestamp, true), ValueWithUnit.Timestamp(it.timestamp),
ValueWithUnit(it.amount, UserEntry.Units.U) ValueWithUnit.Insulin(it.amount)
) )
} }
} }
@ -112,15 +114,15 @@ class NSClientAddUpdateWorker(
.blockingGet() .blockingGet()
.also { result -> .also { result ->
result.inserted.forEach { result.inserted.forEach {
uel.log(UserEntry.Action.CAREPORTAL_FROM_NS, uel.log(Action.CAREPORTAL, Sources.NSClient,
ValueWithUnit(it.timestamp, UserEntry.Units.Timestamp, true), ValueWithUnit.Timestamp(it.timestamp),
ValueWithUnit(it.amount, UserEntry.Units.G) ValueWithUnit.Gram(it.amount.toInt())
) )
} }
result.invalidated.forEach { result.invalidated.forEach {
uel.log(UserEntry.Action.CAREPORTAL_DELETED_FROM_NS, uel.log(Action.CAREPORTAL, Sources.NSClient,
ValueWithUnit(it.timestamp, UserEntry.Units.Timestamp, true), ValueWithUnit.Timestamp(it.timestamp),
ValueWithUnit(it.amount, UserEntry.Units.G) ValueWithUnit.Gram(it.amount.toInt())
) )
} }
} }
@ -137,28 +139,28 @@ class NSClientAddUpdateWorker(
} }
.blockingGet() .blockingGet()
.also { result -> .also { result ->
result.inserted.forEach { result.inserted.forEach { tt ->
uel.log(UserEntry.Action.TT_FROM_NS, uel.log(Action.TT, Sources.NSClient,
ValueWithUnit(it.reason.text, UserEntry.Units.TherapyEvent), ValueWithUnit.TherapyEventTTReason(tt.reason),
ValueWithUnit(it.lowTarget, UserEntry.Units.Mg_Dl, true), ValueWithUnit.fromGlucoseUnit(tt.lowTarget, Constants.MGDL),
ValueWithUnit(it.highTarget, UserEntry.Units.Mg_Dl, it.lowTarget != it.highTarget), ValueWithUnit.fromGlucoseUnit(tt.highTarget, Constants.MGDL).takeIf { tt.lowTarget != tt.highTarget },
ValueWithUnit(it.duration.toInt() / 60000, UserEntry.Units.M, true) ValueWithUnit.Minute(TimeUnit.MILLISECONDS.toMinutes(tt.duration).toInt())
) )
} }
result.invalidated.forEach { result.invalidated.forEach { tt ->
uel.log(UserEntry.Action.TT_DELETED_FROM_NS, uel.log(Action.TT_REMOVED, Sources.NSClient,
ValueWithUnit(it.reason.text, UserEntry.Units.TherapyEvent), ValueWithUnit.TherapyEventTTReason(tt.reason),
ValueWithUnit(it.lowTarget, UserEntry.Units.Mg_Dl, true), ValueWithUnit.Mgdl(tt.lowTarget),
ValueWithUnit(it.highTarget, UserEntry.Units.Mg_Dl, it.lowTarget != it.highTarget), ValueWithUnit.Mgdl(tt.highTarget).takeIf { tt.lowTarget != tt.highTarget },
ValueWithUnit(it.duration.toInt() / 60000, UserEntry.Units.M, true) ValueWithUnit.Minute(TimeUnit.MILLISECONDS.toMinutes(tt.duration).toInt())
) )
} }
result.ended.forEach { result.ended.forEach { tt ->
uel.log(UserEntry.Action.TT_CANCELED_FROM_NS, uel.log(Action.CANCEL_TT, Sources.NSClient,
ValueWithUnit(it.reason.text, UserEntry.Units.TherapyEvent), ValueWithUnit.TherapyEventTTReason(tt.reason),
ValueWithUnit(it.lowTarget, UserEntry.Units.Mg_Dl, true), ValueWithUnit.Mgdl(tt.lowTarget),
ValueWithUnit(it.highTarget, UserEntry.Units.Mg_Dl, it.lowTarget != it.highTarget), ValueWithUnit.Mgdl(tt.highTarget).takeIf { tt.lowTarget != tt.highTarget },
ValueWithUnit(it.duration.toInt() / 60000, UserEntry.Units.M, true) ValueWithUnit.Minute(TimeUnit.MILLISECONDS.toMinutes(tt.duration).toInt())
) )
} }
} }
@ -182,17 +184,17 @@ class NSClientAddUpdateWorker(
.blockingGet() .blockingGet()
.also { result -> .also { result ->
result.inserted.forEach { result.inserted.forEach {
uel.log(UserEntry.Action.CAREPORTAL_FROM_NS, uel.log(Action.CAREPORTAL, Sources.NSClient,
it.note ?: "", it.note ?: "",
ValueWithUnit(it.timestamp, UserEntry.Units.Timestamp, true), ValueWithUnit.Timestamp(it.timestamp),
ValueWithUnit(it.type.text, UserEntry.Units.TherapyEvent) ValueWithUnit.TherapyEventType(it.type)
) )
} }
result.invalidated.forEach { result.invalidated.forEach {
uel.log(UserEntry.Action.CAREPORTAL_DELETED_FROM_NS, uel.log(Action.CAREPORTAL_REMOVED, Sources.NSClient,
it.note ?: "", it.note ?: "",
ValueWithUnit(it.timestamp, UserEntry.Units.Timestamp, true), ValueWithUnit.Timestamp(it.timestamp),
ValueWithUnit(it.type.text, UserEntry.Units.TherapyEvent) ValueWithUnit.TherapyEventType(it.type)
) )
} }
} }

View file

@ -8,7 +8,8 @@ import android.view.ViewGroup
import android.widget.ScrollView import android.widget.ScrollView
import dagger.android.support.DaggerFragment import dagger.android.support.DaggerFragment
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
import info.nightscout.androidaps.database.entities.UserEntry import info.nightscout.androidaps.database.entities.UserEntry.Action
import info.nightscout.androidaps.database.entities.UserEntry.Sources
import info.nightscout.androidaps.databinding.NsClientFragmentBinding import info.nightscout.androidaps.databinding.NsClientFragmentBinding
import info.nightscout.androidaps.interfaces.DataSyncSelector import info.nightscout.androidaps.interfaces.DataSyncSelector
import info.nightscout.androidaps.interfaces.UploadQueueAdminInterface import info.nightscout.androidaps.interfaces.UploadQueueAdminInterface
@ -61,7 +62,7 @@ class NSClientFragment : DaggerFragment() {
binding.paused.isChecked = nsClientPlugin.paused binding.paused.isChecked = nsClientPlugin.paused
binding.paused.setOnCheckedChangeListener { _, isChecked -> binding.paused.setOnCheckedChangeListener { _, isChecked ->
uel.log(if (isChecked) UserEntry.Action.NS_PAUSED else UserEntry.Action.NS_RESUME) uel.log(if (isChecked) Action.NS_PAUSED else Action.NS_RESUME, Sources.NSClient)
nsClientPlugin.pause(isChecked) nsClientPlugin.pause(isChecked)
updateGui() updateGui()
} }
@ -74,7 +75,7 @@ class NSClientFragment : DaggerFragment() {
binding.clearQueue.setOnClickListener { binding.clearQueue.setOnClickListener {
context?.let { context -> context?.let { context ->
OKDialog.showConfirmation(context, resourceHelper.gs(R.string.nsclientinternal), resourceHelper.gs(R.string.clearqueueconfirm), Runnable { OKDialog.showConfirmation(context, resourceHelper.gs(R.string.nsclientinternal), resourceHelper.gs(R.string.clearqueueconfirm), Runnable {
uel.log(UserEntry.Action.NS_QUEUE_CLEARED) uel.log(Action.NS_QUEUE_CLEARED, Sources.NSClient)
uploadQueue.clearQueue() uploadQueue.clearQueue()
updateGui() updateGui()
}) })

View file

@ -7,8 +7,9 @@ import androidx.work.workDataOf
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
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.UserEntry import info.nightscout.androidaps.database.entities.ValueWithUnit
import info.nightscout.androidaps.database.entities.UserEntry.ValueWithUnit import info.nightscout.androidaps.database.entities.UserEntry.Action
import info.nightscout.androidaps.database.entities.UserEntry.Sources
import info.nightscout.androidaps.database.transactions.SyncNsBolusTransaction import info.nightscout.androidaps.database.transactions.SyncNsBolusTransaction
import info.nightscout.androidaps.database.transactions.SyncNsCarbsTransaction import info.nightscout.androidaps.database.transactions.SyncNsCarbsTransaction
import info.nightscout.androidaps.database.transactions.SyncNsTemporaryTargetTransaction import info.nightscout.androidaps.database.transactions.SyncNsTemporaryTargetTransaction
@ -27,6 +28,7 @@ import info.nightscout.androidaps.utils.extensions.carbsFromNsIdForInvalidating
import info.nightscout.androidaps.utils.extensions.temporaryTargetFromNsIdForInvalidating import info.nightscout.androidaps.utils.extensions.temporaryTargetFromNsIdForInvalidating
import info.nightscout.androidaps.utils.extensions.therapyEventFromNsIdForInvalidating import info.nightscout.androidaps.utils.extensions.therapyEventFromNsIdForInvalidating
import info.nightscout.androidaps.utils.sharedPreferences.SP import info.nightscout.androidaps.utils.sharedPreferences.SP
import java.util.concurrent.TimeUnit
import javax.inject.Inject import javax.inject.Inject
// This will not be needed fpr NS v3 // This will not be needed fpr NS v3
@ -69,13 +71,13 @@ class NSClientRemoveWorker(
} }
.blockingGet() .blockingGet()
.also { result -> .also { result ->
result.invalidated.forEach { result.invalidated.forEach { tt ->
uel.log( uel.log(
UserEntry.Action.TT_DELETED_FROM_NS, Action.TT_REMOVED, Sources.NSClient,
ValueWithUnit(it.reason.text, UserEntry.Units.TherapyEvent), ValueWithUnit.TherapyEventTTReason(tt.reason),
ValueWithUnit(it.lowTarget, UserEntry.Units.Mg_Dl, true), ValueWithUnit.Mgdl(tt.lowTarget),
ValueWithUnit(it.highTarget, UserEntry.Units.Mg_Dl, it.lowTarget != it.highTarget), ValueWithUnit.Mgdl(tt.highTarget).takeIf { tt.lowTarget != tt.highTarget },
ValueWithUnit(it.duration.toInt() / 60000, UserEntry.Units.M, it.duration != 0L) ValueWithUnit.Minute(TimeUnit.MILLISECONDS.toMinutes(tt.duration).toInt()).takeIf { tt.duration != 0L }
) )
} }
} }
@ -90,10 +92,10 @@ class NSClientRemoveWorker(
.blockingGet() .blockingGet()
.also { result -> .also { result ->
result.invalidated.forEach { result.invalidated.forEach {
uel.log( uel.log(Action.CAREPORTAL_REMOVED, Sources.NSClient,
UserEntry.Action.CAREPORTAL_DELETED_FROM_NS, (it.note ?: ""), (it.note ?: ""),
ValueWithUnit(it.timestamp, UserEntry.Units.Timestamp, true), ValueWithUnit.Timestamp(it.timestamp),
ValueWithUnit(it.type.text, UserEntry.Units.TherapyEvent)) ValueWithUnit.TherapyEventType(it.type))
} }
} }
@ -107,10 +109,9 @@ class NSClientRemoveWorker(
.blockingGet() .blockingGet()
.also { result -> .also { result ->
result.invalidated.forEach { result.invalidated.forEach {
uel.log( uel.log(Action.CAREPORTAL_REMOVED, Sources.NSClient,
UserEntry.Action.CAREPORTAL_DELETED_FROM_NS, ValueWithUnit.Timestamp(it.timestamp),
ValueWithUnit(it.timestamp, UserEntry.Units.Timestamp, true), ValueWithUnit.Insulin(it.amount))
ValueWithUnit(it.amount, UserEntry.Units.U))
} }
} }
@ -124,10 +125,9 @@ class NSClientRemoveWorker(
.blockingGet() .blockingGet()
.also { result -> .also { result ->
result.invalidated.forEach { result.invalidated.forEach {
uel.log( uel.log(Action.CAREPORTAL_REMOVED, Sources.NSClient,
UserEntry.Action.CAREPORTAL_DELETED_FROM_NS, ValueWithUnit.Timestamp(it.timestamp),
ValueWithUnit(it.timestamp, UserEntry.Units.Timestamp, true), ValueWithUnit.Gram(it.amount.toInt()))
ValueWithUnit(it.amount, UserEntry.Units.G))
} }
} }

View file

@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.general.nsclient.data
import android.content.Context import android.content.Context
import info.nightscout.androidaps.Config import info.nightscout.androidaps.Config
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
import info.nightscout.androidaps.database.entities.UserEntry
import info.nightscout.androidaps.database.entities.UserEntry.Action import info.nightscout.androidaps.database.entities.UserEntry.Action
import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.logging.LTag
@ -246,7 +247,7 @@ class NSSettingsStatus @Inject constructor(
getExtendedWarnValue("sage", "urgent")?.let { sp.putDouble(R.string.key_statuslights_sage_critical, it) } getExtendedWarnValue("sage", "urgent")?.let { sp.putDouble(R.string.key_statuslights_sage_critical, it) }
getExtendedWarnValue("bage", "warn")?.let { sp.putDouble(R.string.key_statuslights_bage_warning, it) } getExtendedWarnValue("bage", "warn")?.let { sp.putDouble(R.string.key_statuslights_bage_warning, it) }
getExtendedWarnValue("bage", "urgent")?.let { sp.putDouble(R.string.key_statuslights_bage_critical, it) } getExtendedWarnValue("bage", "urgent")?.let { sp.putDouble(R.string.key_statuslights_bage_critical, it) }
uel.log(Action.NS_SETTINGS_COPIED) uel.log(Action.NS_SETTINGS_COPIED, UserEntry.Sources.NSClient)
} }
if (context != null) OKDialog.showConfirmation(context, resourceHelper.gs(R.string.statuslights), resourceHelper.gs(R.string.copyexistingvalues), action) if (context != null) OKDialog.showConfirmation(context, resourceHelper.gs(R.string.statuslights), resourceHelper.gs(R.string.copyexistingvalues), action)

View file

@ -31,7 +31,8 @@ import info.nightscout.androidaps.data.Profile
import info.nightscout.androidaps.database.AppRepository import info.nightscout.androidaps.database.AppRepository
import info.nightscout.androidaps.database.ValueWrapper import info.nightscout.androidaps.database.ValueWrapper
import info.nightscout.androidaps.database.entities.TemporaryTarget import info.nightscout.androidaps.database.entities.TemporaryTarget
import info.nightscout.androidaps.database.entities.UserEntry.* import info.nightscout.androidaps.database.entities.UserEntry.Action
import info.nightscout.androidaps.database.entities.UserEntry.Sources
import info.nightscout.androidaps.database.interfaces.end import info.nightscout.androidaps.database.interfaces.end
import info.nightscout.androidaps.databinding.OverviewFragmentBinding import info.nightscout.androidaps.databinding.OverviewFragmentBinding
import info.nightscout.androidaps.dialogs.* import info.nightscout.androidaps.dialogs.*
@ -351,7 +352,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
protectionCheck.queryProtection(activity, ProtectionCheck.Protection.BOLUS, UIRunnable { protectionCheck.queryProtection(activity, ProtectionCheck.Protection.BOLUS, UIRunnable {
OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.tempbasal_label), lastRun.constraintsProcessed?.toSpanned() OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.tempbasal_label), lastRun.constraintsProcessed?.toSpanned()
?: "".toSpanned(), { ?: "".toSpanned(), {
uel.log(Action.ACCEPTS_TEMP_BASAL) uel.log(Action.ACCEPTS_TEMP_BASAL, Sources.Overview)
binding.buttonsLayout.acceptTempButton.visibility = View.GONE binding.buttonsLayout.acceptTempButton.visibility = View.GONE
(context?.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager).cancel(Constants.notificationID) (context?.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager).cancel(Constants.notificationID)
rxBus.send(EventWearInitiateAction("cancelChangeRequest")) rxBus.send(EventWearInitiateAction("cancelChangeRequest"))

View file

@ -49,7 +49,7 @@ class TherapyEventDataPoint @Inject constructor(
override fun getLabel(): String? = override fun getLabel(): String? =
if (data.note != null) data.note if (data.note != null) data.note
else translator.translate(data.type.text) else translator.translate(data.type)
override fun getDuration(): Long = end() - start() override fun getDuration(): Long = end() - start()
override fun getShape(): PointsWithLabelGraphSeries.Shape = override fun getShape(): PointsWithLabelGraphSeries.Shape =

View file

@ -17,10 +17,10 @@ import info.nightscout.androidaps.R
import info.nightscout.androidaps.data.DetailedBolusInfo import info.nightscout.androidaps.data.DetailedBolusInfo
import info.nightscout.androidaps.data.Profile import info.nightscout.androidaps.data.Profile
import info.nightscout.androidaps.database.AppRepository import info.nightscout.androidaps.database.AppRepository
import info.nightscout.androidaps.database.entities.ValueWithUnit
import info.nightscout.androidaps.database.entities.TemporaryTarget import info.nightscout.androidaps.database.entities.TemporaryTarget
import info.nightscout.androidaps.database.entities.UserEntry.Action import info.nightscout.androidaps.database.entities.UserEntry.Action
import info.nightscout.androidaps.database.entities.UserEntry.Units import info.nightscout.androidaps.database.entities.UserEntry.Sources
import info.nightscout.androidaps.database.entities.UserEntry.ValueWithUnit
import info.nightscout.androidaps.database.transactions.CancelCurrentTemporaryTargetIfAnyTransaction import info.nightscout.androidaps.database.transactions.CancelCurrentTemporaryTargetIfAnyTransaction
import info.nightscout.androidaps.database.transactions.InsertTemporaryTargetAndCancelCurrentTransaction import info.nightscout.androidaps.database.transactions.InsertTemporaryTargetAndCancelCurrentTransaction
import info.nightscout.androidaps.events.EventPreferenceChange import info.nightscout.androidaps.events.EventPreferenceChange
@ -341,7 +341,7 @@ class SmsCommunicatorPlugin @Inject constructor(
receivedSms.processed = true receivedSms.processed = true
messageToConfirm = AuthRequest(injector, receivedSms, reply, passCode, object : SmsAction() { messageToConfirm = AuthRequest(injector, receivedSms, reply, passCode, object : SmsAction() {
override fun run() { override fun run() {
uel.log(Action.SMS_LOOP_DISABLED) uel.log(Action.LOOP_DISABLED, Sources.SMS)
loopPlugin.setPluginEnabled(PluginType.LOOP, false) loopPlugin.setPluginEnabled(PluginType.LOOP, false)
commandQueue.cancelTempBasal(true, object : Callback() { commandQueue.cancelTempBasal(true, object : Callback() {
override fun run() { override fun run() {
@ -365,7 +365,7 @@ class SmsCommunicatorPlugin @Inject constructor(
receivedSms.processed = true receivedSms.processed = true
messageToConfirm = AuthRequest(injector, receivedSms, reply, passCode, object : SmsAction() { messageToConfirm = AuthRequest(injector, receivedSms, reply, passCode, object : SmsAction() {
override fun run() { override fun run() {
uel.log(Action.SMS_LOOP_ENABLED) uel.log(Action.LOOP_ENABLED, Sources.SMS)
loopPlugin.setPluginEnabled(PluginType.LOOP, true) loopPlugin.setPluginEnabled(PluginType.LOOP, true)
sendSMS(Sms(receivedSms.phoneNumber, resourceHelper.gs(R.string.smscommunicator_loophasbeenenabled))) sendSMS(Sms(receivedSms.phoneNumber, resourceHelper.gs(R.string.smscommunicator_loophasbeenenabled)))
rxBus.send(EventRefreshOverview("SMS_LOOP_START")) rxBus.send(EventRefreshOverview("SMS_LOOP_START"))
@ -392,7 +392,7 @@ class SmsCommunicatorPlugin @Inject constructor(
receivedSms.processed = true receivedSms.processed = true
messageToConfirm = AuthRequest(injector, receivedSms, reply, passCode, object : SmsAction() { messageToConfirm = AuthRequest(injector, receivedSms, reply, passCode, object : SmsAction() {
override fun run() { override fun run() {
uel.log(Action.SMS_LOOP_RESUME) uel.log(Action.RESUME, Sources.SMS)
loopPlugin.suspendTo(0L) loopPlugin.suspendTo(0L)
rxBus.send(EventRefreshOverview("SMS_LOOP_RESUME")) rxBus.send(EventRefreshOverview("SMS_LOOP_RESUME"))
commandQueue.cancelTempBasal(true, object : Callback() { commandQueue.cancelTempBasal(true, object : Callback() {
@ -425,7 +425,7 @@ class SmsCommunicatorPlugin @Inject constructor(
receivedSms.processed = true receivedSms.processed = true
messageToConfirm = AuthRequest(injector, receivedSms, reply, passCode, object : SmsAction(duration) { messageToConfirm = AuthRequest(injector, receivedSms, reply, passCode, object : SmsAction(duration) {
override fun run() { override fun run() {
uel.log(Action.SMS_LOOP_SUSPEND) uel.log(Action.SUSPEND, Sources.SMS)
commandQueue.cancelTempBasal(true, object : Callback() { commandQueue.cancelTempBasal(true, object : Callback() {
override fun run() { override fun run() {
if (result.success) { if (result.success) {
@ -499,7 +499,7 @@ class SmsCommunicatorPlugin @Inject constructor(
receivedSms.processed = true receivedSms.processed = true
messageToConfirm = AuthRequest(injector, receivedSms, reply, passCode, object : SmsAction() { messageToConfirm = AuthRequest(injector, receivedSms, reply, passCode, object : SmsAction() {
override fun run() { override fun run() {
uel.log(Action.SMS_PUMP_CONNECT) uel.log(Action.RECONNECT, Sources.SMS)
commandQueue.cancelTempBasal(true, object : Callback() { commandQueue.cancelTempBasal(true, object : Callback() {
override fun run() { override fun run() {
if (!result.success) { if (!result.success) {
@ -528,7 +528,7 @@ class SmsCommunicatorPlugin @Inject constructor(
receivedSms.processed = true receivedSms.processed = true
messageToConfirm = AuthRequest(injector, receivedSms, reply, passCode, object : SmsAction() { messageToConfirm = AuthRequest(injector, receivedSms, reply, passCode, object : SmsAction() {
override fun run() { override fun run() {
uel.log(Action.SMS_PUMP_DISCONNECT) uel.log(Action.DISCONNECT, Sources.SMS)
val profile = profileFunction.getProfile() val profile = profileFunction.getProfile()
loopPlugin.disconnectPump(duration, profile) loopPlugin.disconnectPump(duration, profile)
rxBus.send(EventRefreshOverview("SMS_PUMP_DISCONNECT")) rxBus.send(EventRefreshOverview("SMS_PUMP_DISCONNECT"))
@ -585,7 +585,8 @@ class SmsCommunicatorPlugin @Inject constructor(
activePlugin.activeTreatments.doProfileSwitch(store, list[pIndex - 1] as String, 0, finalPercentage, 0, DateUtil.now()) activePlugin.activeTreatments.doProfileSwitch(store, list[pIndex - 1] as String, 0, finalPercentage, 0, DateUtil.now())
val replyText = resourceHelper.gs(R.string.profileswitchcreated) val replyText = resourceHelper.gs(R.string.profileswitchcreated)
sendSMS(Sms(receivedSms.phoneNumber, replyText)) sendSMS(Sms(receivedSms.phoneNumber, replyText))
uel.log(Action.SMS_PROFILE, ValueWithUnit(R.string.profileswitchcreated, Units.R_String)) uel.log(Action.PROFILE_SWITCH, Sources.SMS,
ValueWithUnit.StringResource(R.string.profileswitchcreated))
} }
}) })
} }
@ -607,12 +608,14 @@ class SmsCommunicatorPlugin @Inject constructor(
var replyText = resourceHelper.gs(R.string.smscommunicator_tempbasalcanceled) var replyText = resourceHelper.gs(R.string.smscommunicator_tempbasalcanceled)
replyText += "\n" + activePlugin.activePump.shortStatus(true) replyText += "\n" + activePlugin.activePump.shortStatus(true)
sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText)) sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText))
uel.log(Action.SMS_BASAL, activePlugin.activePump.shortStatus(true), ValueWithUnit(R.string.smscommunicator_tempbasalcanceled, Units.R_String)) uel.log(Action.TEMP_BASAL, Sources.SMS, activePlugin.activePump.shortStatus(true),
ValueWithUnit.StringResource(R.string.smscommunicator_tempbasalcanceled))
} else { } else {
var replyText = resourceHelper.gs(R.string.smscommunicator_tempbasalcancelfailed) var replyText = resourceHelper.gs(R.string.smscommunicator_tempbasalcancelfailed)
replyText += "\n" + activePlugin.activePump.shortStatus(true) replyText += "\n" + activePlugin.activePump.shortStatus(true)
sendSMS(Sms(receivedSms.phoneNumber, replyText)) sendSMS(Sms(receivedSms.phoneNumber, replyText))
uel.log(Action.SMS_BASAL, activePlugin.activePump.shortStatus(true), ValueWithUnit(R.string.smscommunicator_tempbasalcancelfailed, Units.R_String)) uel.log(Action.TEMP_BASAL, Sources.SMS, activePlugin.activePump.shortStatus(true),
ValueWithUnit.StringResource(R.string.smscommunicator_tempbasalcancelfailed))
} }
} }
}) })
@ -641,14 +644,19 @@ class SmsCommunicatorPlugin @Inject constructor(
replyText += "\n" + activePlugin.activePump.shortStatus(true) replyText += "\n" + activePlugin.activePump.shortStatus(true)
sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText)) sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText))
if (result.isPercent) if (result.isPercent)
uel.log(Action.SMS_BASAL, activePlugin.activePump.shortStatus(true), ValueWithUnit(R.string.smscommunicator_tempbasalset_percent, 2), ValueWithUnit(result.percent, Units.Percent), ValueWithUnit(result.duration, Units.M)) uel.log(Action.TEMP_BASAL, Sources.SMS,
activePlugin.activePump.shortStatus(true),
ValueWithUnit.StringResource(R.string.smscommunicator_tempbasalset_percent, listOf(ValueWithUnit.Percent(result.percent), ValueWithUnit.Minute(result.duration))) )
else else
uel.log(Action.SMS_BASAL, activePlugin.activePump.shortStatus(true), ValueWithUnit(R.string.smscommunicator_tempbasalset, 2), ValueWithUnit(result.absolute, Units.U_H), ValueWithUnit(result.duration, Units.M)) uel.log(Action.TEMP_BASAL, Sources.SMS,
activePlugin.activePump.shortStatus(true),
ValueWithUnit.StringResource(R.string.smscommunicator_tempbasalset, listOf( ValueWithUnit.UnitPerHour(result.absolute), ValueWithUnit.Minute(result.duration))))
} else { } else {
var replyText = resourceHelper.gs(R.string.smscommunicator_tempbasalfailed) var replyText = resourceHelper.gs(R.string.smscommunicator_tempbasalfailed)
replyText += "\n" + activePlugin.activePump.shortStatus(true) replyText += "\n" + activePlugin.activePump.shortStatus(true)
sendSMS(Sms(receivedSms.phoneNumber, replyText)) sendSMS(Sms(receivedSms.phoneNumber, replyText))
uel.log(Action.SMS_BASAL, activePlugin.activePump.shortStatus(true), ValueWithUnit(R.string.smscommunicator_tempbasalfailed, Units.R_String)) uel.log(Action.TEMP_BASAL, Sources.SMS, activePlugin.activePump.shortStatus(true),
ValueWithUnit.StringResource(R.string.smscommunicator_tempbasalfailed))
} }
} }
}) })
@ -679,14 +687,17 @@ class SmsCommunicatorPlugin @Inject constructor(
replyText += "\n" + activePlugin.activePump.shortStatus(true) replyText += "\n" + activePlugin.activePump.shortStatus(true)
sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText)) sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText))
if (result.isPercent) if (result.isPercent)
uel.log(Action.SMS_BASAL, activePlugin.activePump.shortStatus(true), ValueWithUnit(R.string.smscommunicator_tempbasalset_percent, 2), ValueWithUnit(result.percent, Units.Percent), ValueWithUnit(result.duration, Units.M)) uel.log(Action.TEMP_BASAL, Sources.SMS, activePlugin.activePump.shortStatus(true),
ValueWithUnit.StringResource(R.string.smscommunicator_tempbasalset_percent, listOf(ValueWithUnit.Percent(result.percent), ValueWithUnit.Minute(result.duration))))
else else
uel.log(Action.SMS_BASAL, activePlugin.activePump.shortStatus(true), ValueWithUnit(R.string.smscommunicator_tempbasalset, 2), ValueWithUnit(result.absolute, Units.U_H), ValueWithUnit(result.duration, Units.M)) uel.log(Action.TEMP_BASAL, Sources.SMS, activePlugin.activePump.shortStatus(true),
ValueWithUnit.StringResource(R.string.smscommunicator_tempbasalset, listOf(ValueWithUnit.UnitPerHour(result.absolute), ValueWithUnit.Minute(result.duration))))
} else { } else {
var replyText = resourceHelper.gs(R.string.smscommunicator_tempbasalfailed) var replyText = resourceHelper.gs(R.string.smscommunicator_tempbasalfailed)
replyText += "\n" + activePlugin.activePump.shortStatus(true) replyText += "\n" + activePlugin.activePump.shortStatus(true)
sendSMS(Sms(receivedSms.phoneNumber, replyText)) sendSMS(Sms(receivedSms.phoneNumber, replyText))
uel.log(Action.SMS_BASAL, activePlugin.activePump.shortStatus(true), ValueWithUnit(R.string.smscommunicator_tempbasalfailed, Units.R_String)) uel.log(Action.TEMP_BASAL, Sources.SMS, activePlugin.activePump.shortStatus(true),
ValueWithUnit.StringResource(R.string.smscommunicator_tempbasalfailed))
} }
} }
}) })
@ -713,7 +724,8 @@ class SmsCommunicatorPlugin @Inject constructor(
var replyText = resourceHelper.gs(R.string.smscommunicator_extendedcancelfailed) var replyText = resourceHelper.gs(R.string.smscommunicator_extendedcancelfailed)
replyText += "\n" + activePlugin.activePump.shortStatus(true) replyText += "\n" + activePlugin.activePump.shortStatus(true)
sendSMS(Sms(receivedSms.phoneNumber, replyText)) sendSMS(Sms(receivedSms.phoneNumber, replyText))
uel.log(Action.SMS_EXTENDED_BOLUS, activePlugin.activePump.shortStatus(true), ValueWithUnit(R.string.smscommunicator_extendedcanceled, Units.R_String)) uel.log(Action.EXTENDED_BOLUS, Sources.SMS, activePlugin.activePump.shortStatus(true),
ValueWithUnit.StringResource(R.string.smscommunicator_extendedcanceled))
} }
} }
}) })
@ -740,16 +752,18 @@ class SmsCommunicatorPlugin @Inject constructor(
replyText += "\n" + activePlugin.activePump.shortStatus(true) replyText += "\n" + activePlugin.activePump.shortStatus(true)
sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText)) sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText))
if (config.APS) if (config.APS)
uel.log(Action.SMS_EXTENDED_BOLUS, activePlugin.activePump.shortStatus(true), ValueWithUnit(R.string.smscommunicator_extendedset, 2), ValueWithUnit(aDouble uel.log(Action.EXTENDED_BOLUS, Sources.SMS, activePlugin.activePump.shortStatus(true),
?: 0.0, Units.U), ValueWithUnit(duration, Units.M), ValueWithUnit(R.string.loopsuspended, Units.R_String)) ValueWithUnit.StringResource(R.string.smscommunicator_extendedset, listOf(ValueWithUnit.Insulin(aDouble ?: 0.0), ValueWithUnit.Minute(duration))),
ValueWithUnit.StringResource(R.string.loopsuspended))
else else
uel.log(Action.SMS_EXTENDED_BOLUS, activePlugin.activePump.shortStatus(true), ValueWithUnit(R.string.smscommunicator_extendedset, 2), ValueWithUnit(aDouble uel.log(Action.EXTENDED_BOLUS, Sources.SMS, activePlugin.activePump.shortStatus(true),
?: 0.0, Units.U), ValueWithUnit(duration, Units.M)) ValueWithUnit.StringResource(R.string.smscommunicator_extendedset, listOf( ValueWithUnit.Insulin(aDouble ?: 0.0), ValueWithUnit.Minute(duration))))
} else { } else {
var replyText = resourceHelper.gs(R.string.smscommunicator_extendedfailed) var replyText = resourceHelper.gs(R.string.smscommunicator_extendedfailed)
replyText += "\n" + activePlugin.activePump.shortStatus(true) replyText += "\n" + activePlugin.activePump.shortStatus(true)
sendSMS(Sms(receivedSms.phoneNumber, replyText)) sendSMS(Sms(receivedSms.phoneNumber, replyText))
uel.log(Action.SMS_EXTENDED_BOLUS, activePlugin.activePump.shortStatus(true), ValueWithUnit(R.string.smscommunicator_extendedfailed, Units.R_String)) uel.log(Action.EXTENDED_BOLUS, Sources.SMS, activePlugin.activePump.shortStatus(true),
ValueWithUnit.StringResource(R.string.smscommunicator_extendedfailed))
} }
} }
}) })
@ -821,12 +835,13 @@ class SmsCommunicatorPlugin @Inject constructor(
} }
} }
sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText)) sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText))
uel.log(Action.SMS_BOLUS, replyText) uel.log(Action.BOLUS, Sources.SMS, replyText)
} else { } else {
var replyText = resourceHelper.gs(R.string.smscommunicator_bolusfailed) var replyText = resourceHelper.gs(R.string.smscommunicator_bolusfailed)
replyText += "\n" + activePlugin.activePump.shortStatus(true) replyText += "\n" + activePlugin.activePump.shortStatus(true)
sendSMS(Sms(receivedSms.phoneNumber, replyText)) sendSMS(Sms(receivedSms.phoneNumber, replyText))
uel.log(Action.SMS_BOLUS, activePlugin.activePump.shortStatus(true), ValueWithUnit(R.string.smscommunicator_bolusfailed, Units.R_String)) uel.log(Action.BOLUS, Sources.SMS, activePlugin.activePump.shortStatus(true),
ValueWithUnit.StringResource(R.string.smscommunicator_bolusfailed))
} }
} }
}) })
@ -864,14 +879,14 @@ class SmsCommunicatorPlugin @Inject constructor(
var replyText = String.format(resourceHelper.gs(R.string.smscommunicator_carbsset), anInteger) var replyText = String.format(resourceHelper.gs(R.string.smscommunicator_carbsset), anInteger)
replyText += "\n" + activePlugin.activePump.shortStatus(true) replyText += "\n" + activePlugin.activePump.shortStatus(true)
sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText)) sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText))
uel.log(Action.SMS_CARBS, activePlugin.activePump.shortStatus(true), ValueWithUnit(R.string.smscommunicator_carbsset, 1), ValueWithUnit(anInteger uel.log(Action.CARBS, Sources.SMS, activePlugin.activePump.shortStatus(true),
?: 0, Units.G)) ValueWithUnit.StringResource(R.string.smscommunicator_carbsset, listOf(ValueWithUnit.Gram(anInteger ?: 0))))
} else { } else {
var replyText = resourceHelper.gs(R.string.smscommunicator_carbsfailed, anInteger) var replyText = resourceHelper.gs(R.string.smscommunicator_carbsfailed, anInteger)
replyText += "\n" + activePlugin.activePump.shortStatus(true) replyText += "\n" + activePlugin.activePump.shortStatus(true)
sendSMS(Sms(receivedSms.phoneNumber, replyText)) sendSMS(Sms(receivedSms.phoneNumber, replyText))
uel.log(Action.SMS_CARBS, activePlugin.activePump.shortStatus(true), ValueWithUnit(R.string.smscommunicator_carbsfailed, 1), ValueWithUnit(anInteger uel.log(Action.CARBS, Sources.SMS, activePlugin.activePump.shortStatus(true),
?: 0, Units.G)) ValueWithUnit.StringResource(R.string.smscommunicator_carbsfailed, listOf(ValueWithUnit.Gram(anInteger ?: 0))))
} }
} }
}) })
@ -942,8 +957,9 @@ class SmsCommunicatorPlugin @Inject constructor(
val ttString = if (units == Constants.MMOL) DecimalFormatter.to1Decimal(tt) else DecimalFormatter.to0Decimal(tt) val ttString = if (units == Constants.MMOL) DecimalFormatter.to1Decimal(tt) else DecimalFormatter.to0Decimal(tt)
val replyText = String.format(resourceHelper.gs(R.string.smscommunicator_tt_set), ttString, ttDuration) val replyText = String.format(resourceHelper.gs(R.string.smscommunicator_tt_set), ttString, ttDuration)
sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText)) sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText))
//uel.log(Action.SMS_TT, ValueWithUnit(R.string.smscommunicator_tt_set, 2), ValueWithUnit(tt, units), ValueWithUnit(ttDuration, Units.M)) uel.log(Action.TT, Sources.SMS,
uel.log(Action.SMS_TT, ValueWithUnit(tt, units), ValueWithUnit(ttDuration, Units.M)) ValueWithUnit.fromGlucoseUnit(tt, units),
ValueWithUnit.Minute(ttDuration))
} }
}) })
} else if (isStop) { } else if (isStop) {
@ -960,7 +976,8 @@ class SmsCommunicatorPlugin @Inject constructor(
}) })
val replyText = String.format(resourceHelper.gs(R.string.smscommunicator_tt_canceled)) val replyText = String.format(resourceHelper.gs(R.string.smscommunicator_tt_canceled))
sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText)) sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText))
uel.log(Action.SMS_TT, ValueWithUnit(R.string.smscommunicator_tt_canceled, Units.R_String)) uel.log(Action.CANCEL_TT, Sources.SMS,
ValueWithUnit.StringResource(R.string.smscommunicator_tt_canceled))
} }
}) })
} else } else
@ -979,7 +996,8 @@ class SmsCommunicatorPlugin @Inject constructor(
sp.putBoolean(R.string.key_smscommunicator_remotecommandsallowed, false) sp.putBoolean(R.string.key_smscommunicator_remotecommandsallowed, false)
val replyText = String.format(resourceHelper.gs(R.string.smscommunicator_stoppedsms)) val replyText = String.format(resourceHelper.gs(R.string.smscommunicator_stoppedsms))
sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText)) sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText))
uel.log(Action.SMS_SMS, ValueWithUnit(R.string.smscommunicator_stoppedsms, Units.R_String)) uel.log(Action.STOP_SMS, Sources.SMS,
ValueWithUnit.StringResource(R.string.smscommunicator_stoppedsms))
} }
}) })
} else sendSMS(Sms(receivedSms.phoneNumber, resourceHelper.gs(R.string.wrongformat))) } else sendSMS(Sms(receivedSms.phoneNumber, resourceHelper.gs(R.string.wrongformat)))
@ -998,9 +1016,11 @@ class SmsCommunicatorPlugin @Inject constructor(
if (result) resourceHelper.gs(R.string.smscommunicator_calibrationsent) else resourceHelper.gs(R.string.smscommunicator_calibrationfailed) if (result) resourceHelper.gs(R.string.smscommunicator_calibrationsent) else resourceHelper.gs(R.string.smscommunicator_calibrationfailed)
sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText)) sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText))
if (result) if (result)
uel.log(Action.SMS_CAL, ValueWithUnit(R.string.smscommunicator_calibrationsent, Units.R_String)) uel.log(Action.CALIBRATION, Sources.SMS,
ValueWithUnit.StringResource(R.string.smscommunicator_calibrationsent))
else else
uel.log(Action.SMS_CAL, ValueWithUnit(R.string.smscommunicator_calibrationfailed, Units.R_String)) uel.log(Action.CALIBRATION, Sources.SMS,
ValueWithUnit.StringResource(R.string.smscommunicator_calibrationfailed))
} }
}) })
} else sendSMS(Sms(receivedSms.phoneNumber, resourceHelper.gs(R.string.wrongformat))) } else sendSMS(Sms(receivedSms.phoneNumber, resourceHelper.gs(R.string.wrongformat)))

View file

@ -14,7 +14,8 @@ import com.google.common.primitives.Ints.min
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
import info.nightscout.androidaps.activities.NoSplashAppCompatActivity import info.nightscout.androidaps.activities.NoSplashAppCompatActivity
import info.nightscout.androidaps.database.entities.UserEntry.* import info.nightscout.androidaps.database.entities.UserEntry.Action
import info.nightscout.androidaps.database.entities.UserEntry.Sources
import info.nightscout.androidaps.databinding.ActivitySmscommunicatorOtpBinding import info.nightscout.androidaps.databinding.ActivitySmscommunicatorOtpBinding
import info.nightscout.androidaps.logging.UserEntryLogger import info.nightscout.androidaps.logging.UserEntryLogger
import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.bus.RxBusWrapper
@ -73,7 +74,7 @@ class SmsCommunicatorOtpActivity : NoSplashAppCompatActivity() {
resourceHelper.gs(R.string.smscommunicator_otp_reset_title), resourceHelper.gs(R.string.smscommunicator_otp_reset_title),
resourceHelper.gs(R.string.smscommunicator_otp_reset_prompt), resourceHelper.gs(R.string.smscommunicator_otp_reset_prompt),
Runnable { Runnable {
uel.log(Action.OTP_RESET) uel.log(Action.OTP_RESET, Sources.SMS)
otp.ensureKey(true) otp.ensureKey(true)
updateGui() updateGui()
ToastUtils.Long.infoToast(this, resourceHelper.gs(R.string.smscommunicator_otp_reset_successful)) ToastUtils.Long.infoToast(this, resourceHelper.gs(R.string.smscommunicator_otp_reset_successful))
@ -89,7 +90,7 @@ class SmsCommunicatorOtpActivity : NoSplashAppCompatActivity() {
val clip = ClipData.newPlainText("OTP Secret", otp.provisioningSecret()) val clip = ClipData.newPlainText("OTP Secret", otp.provisioningSecret())
clipboard.primaryClip = clip clipboard.primaryClip = clip
ToastUtils.Long.infoToast(this, resourceHelper.gs(R.string.smscommunicator_otp_export_successful)) ToastUtils.Long.infoToast(this, resourceHelper.gs(R.string.smscommunicator_otp_export_successful))
uel.log(Action.OTP_EXPORT) uel.log(Action.OTP_EXPORT, Sources.SMS)
}) })
true true

View file

@ -16,6 +16,9 @@ import info.nightscout.androidaps.data.Profile
import info.nightscout.androidaps.database.AppRepository import info.nightscout.androidaps.database.AppRepository
import info.nightscout.androidaps.database.ValueWrapper import info.nightscout.androidaps.database.ValueWrapper
import info.nightscout.androidaps.database.entities.TemporaryTarget import info.nightscout.androidaps.database.entities.TemporaryTarget
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.interfaces.end import info.nightscout.androidaps.database.interfaces.end
import info.nightscout.androidaps.database.transactions.CancelCurrentTemporaryTargetIfAnyTransaction import info.nightscout.androidaps.database.transactions.CancelCurrentTemporaryTargetIfAnyTransaction
import info.nightscout.androidaps.database.transactions.InsertTemporaryTargetAndCancelCurrentTransaction import info.nightscout.androidaps.database.transactions.InsertTemporaryTargetAndCancelCurrentTransaction
@ -23,6 +26,7 @@ import info.nightscout.androidaps.db.TDD
import info.nightscout.androidaps.interfaces.* import info.nightscout.androidaps.interfaces.*
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.plugins.aps.loop.LoopPlugin import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin
import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
@ -77,7 +81,8 @@ class ActionStringHandler @Inject constructor(
private val dateUtil: DateUtil, private val dateUtil: DateUtil,
private val config: Config, private val config: Config,
private val databaseHelper: DatabaseHelperInterface, private val databaseHelper: DatabaseHelperInterface,
private val repository: AppRepository private val repository: AppRepository,
private val uel: UserEntryLogger
) { ) {
private val timeout = 65 * 1000 private val timeout = 65 * 1000
@ -564,11 +569,14 @@ class ActionStringHandler @Inject constructor(
return return
} }
//send profile to pump //send profile to pump
uel.log(Action.PROFILE_SWITCH, Sources.Wear,
ValueWithUnit.Percent(percentage),
ValueWithUnit.Hour(timeshift).takeIf { timeshift != 0 })
activePlugin.activeTreatments.doProfileSwitch(0, percentage, timeshift) activePlugin.activeTreatments.doProfileSwitch(0, percentage, timeshift)
} }
private fun generateTempTarget(duration: Int, low: Double, high: Double) { private fun generateTempTarget(duration: Int, low: Double, high: Double) {
if (duration != 0) if (duration != 0) {
disposable += repository.runTransactionForResult(InsertTemporaryTargetAndCancelCurrentTransaction( disposable += repository.runTransactionForResult(InsertTemporaryTargetAndCancelCurrentTransaction(
timestamp = System.currentTimeMillis(), timestamp = System.currentTimeMillis(),
duration = TimeUnit.MINUTES.toMillis(duration.toLong()), duration = TimeUnit.MINUTES.toMillis(duration.toLong()),
@ -581,19 +589,29 @@ class ActionStringHandler @Inject constructor(
}, { }, {
aapsLogger.error(LTag.DATABASE, "Error while saving temporary target", it) aapsLogger.error(LTag.DATABASE, "Error while saving temporary target", it)
}) })
else uel.log(Action.TT, Sources.Wear,
ValueWithUnit.TherapyEventTTReason(TemporaryTarget.Reason.WEAR),
ValueWithUnit.fromGlucoseUnit(low, profileFunction.getUnits()),
ValueWithUnit.fromGlucoseUnit(high, profileFunction.getUnits()).takeIf { low != high },
ValueWithUnit.Minute(duration))
} else {
disposable += repository.runTransactionForResult(CancelCurrentTemporaryTargetIfAnyTransaction(System.currentTimeMillis())) disposable += repository.runTransactionForResult(CancelCurrentTemporaryTargetIfAnyTransaction(System.currentTimeMillis()))
.subscribe({ result -> .subscribe({ result ->
result.updated.forEach { aapsLogger.debug(LTag.DATABASE, "Updated temp target $it") } result.updated.forEach { aapsLogger.debug(LTag.DATABASE, "Updated temp target $it") }
}, { }, {
aapsLogger.error(LTag.DATABASE, "Error while saving temporary target", it) aapsLogger.error(LTag.DATABASE, "Error while saving temporary target", it)
}) })
uel.log(Action.CANCEL_TT, Sources.Wear,
ValueWithUnit.TherapyEventTTReason(TemporaryTarget.Reason.WEAR))
}
} }
private fun doFillBolus(amount: Double) { private fun doFillBolus(amount: Double) {
val detailedBolusInfo = DetailedBolusInfo() val detailedBolusInfo = DetailedBolusInfo()
detailedBolusInfo.insulin = amount detailedBolusInfo.insulin = amount
detailedBolusInfo.bolusType = DetailedBolusInfo.BolusType.PRIMING detailedBolusInfo.bolusType = DetailedBolusInfo.BolusType.PRIMING
uel.log(Action.PRIME_BOLUS, Sources.Wear,
ValueWithUnit.Insulin(amount).takeIf { amount != 0.0 })
commandQueue.bolus(detailedBolusInfo, object : Callback() { commandQueue.bolus(detailedBolusInfo, object : Callback() {
override fun run() { override fun run() {
if (!result.success) { if (!result.success) {
@ -606,6 +624,10 @@ class ActionStringHandler @Inject constructor(
} }
private fun doECarbs(carbs: Int, time: Long, duration: Int) { private fun doECarbs(carbs: Int, time: Long, duration: Int) {
uel.log(if (duration==0) Action.CARBS else Action.EXTENDED_CARBS, Sources.Wear,
ValueWithUnit.Timestamp(time),
ValueWithUnit.Gram(carbs),
ValueWithUnit.Hour(duration).takeIf { duration !=0 })
doBolus(0.0, carbs, time, duration) doBolus(0.0, carbs, time, duration)
} }
@ -617,6 +639,16 @@ class ActionStringHandler @Inject constructor(
detailedBolusInfo.carbsTimestamp = carbsTime detailedBolusInfo.carbsTimestamp = carbsTime
detailedBolusInfo.carbsDuration = T.hours(carbsDuration.toLong()).msecs() detailedBolusInfo.carbsDuration = T.hours(carbsDuration.toLong()).msecs()
if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) { if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) {
val action = when {
amount.equals(0.0) -> Action.CARBS
carbs.equals(0) -> Action.BOLUS
carbsDuration>0 -> Action.EXTENDED_CARBS
else -> Action.TREATMENT
}
uel.log(action, Sources.Wear,
ValueWithUnit.Insulin(amount).takeIf { amount != 0.0 },
ValueWithUnit.Gram(carbs).takeIf { carbs != 0 },
ValueWithUnit.Hour(carbsDuration).takeIf { carbsDuration != 0 })
commandQueue.bolus(detailedBolusInfo, object : Callback() { commandQueue.bolus(detailedBolusInfo, object : Callback() {
override fun run() { override fun run() {
if (!result.success) { if (!result.success) {

View file

@ -12,7 +12,9 @@ import dagger.android.support.DaggerFragment
import info.nightscout.androidaps.Constants import info.nightscout.androidaps.Constants
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
import info.nightscout.androidaps.data.Profile import info.nightscout.androidaps.data.Profile
import info.nightscout.androidaps.database.entities.UserEntry.* 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.databinding.LocalprofileFragmentBinding import info.nightscout.androidaps.databinding.LocalprofileFragmentBinding
import info.nightscout.androidaps.dialogs.ProfileSwitchDialog import info.nightscout.androidaps.dialogs.ProfileSwitchDialog
import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.interfaces.ActivePluginProvider
@ -163,7 +165,7 @@ class LocalProfileFragment : DaggerFragment() {
if (localProfilePlugin.isEdited) { if (localProfilePlugin.isEdited) {
activity?.let { OKDialog.show(it, "", resourceHelper.gs(R.string.saveorresetchangesfirst)) } activity?.let { OKDialog.show(it, "", resourceHelper.gs(R.string.saveorresetchangesfirst)) }
} else { } else {
uel.log(Action.NEW_PROFILE) uel.log(Action.NEW_PROFILE, Sources.LocalProfile)
localProfilePlugin.addNewProfile() localProfilePlugin.addNewProfile()
build() build()
} }
@ -173,7 +175,7 @@ class LocalProfileFragment : DaggerFragment() {
if (localProfilePlugin.isEdited) { if (localProfilePlugin.isEdited) {
activity?.let { OKDialog.show(it, "", resourceHelper.gs(R.string.saveorresetchangesfirst)) } activity?.let { OKDialog.show(it, "", resourceHelper.gs(R.string.saveorresetchangesfirst)) }
} else { } else {
uel.log(Action.CLONE_PROFILE, localProfilePlugin.currentProfile()?.name ?: "") uel.log(Action.CLONE_PROFILE, Sources.LocalProfile, ValueWithUnit.SimpleString(localProfilePlugin.currentProfile()?.name ?: ""))
localProfilePlugin.cloneProfile() localProfilePlugin.cloneProfile()
build() build()
} }
@ -182,7 +184,7 @@ class LocalProfileFragment : DaggerFragment() {
binding.profileRemove.setOnClickListener { binding.profileRemove.setOnClickListener {
activity?.let { activity -> activity?.let { activity ->
OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.deletecurrentprofile), { OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.deletecurrentprofile), {
uel.log(Action.PROFILE_REMOVED, localProfilePlugin.currentProfile()?.name ?: "") uel.log(Action.PROFILE_REMOVED, Sources.LocalProfile, ValueWithUnit.SimpleString(localProfilePlugin.currentProfile()?.name ?: ""))
localProfilePlugin.removeCurrentProfile() localProfilePlugin.removeCurrentProfile()
build() build()
}, null) }, null)
@ -210,6 +212,7 @@ class LocalProfileFragment : DaggerFragment() {
if (!localProfilePlugin.isValidEditState()) { if (!localProfilePlugin.isValidEditState()) {
return@setOnClickListener //Should not happen as saveButton should not be visible if not valid return@setOnClickListener //Should not happen as saveButton should not be visible if not valid
} }
uel.log(Action.STORE_PROFILE, Sources.LocalProfile, ValueWithUnit.SimpleString(localProfilePlugin.currentProfile()?.name ?: ""))
localProfilePlugin.storeSettings(activity) localProfilePlugin.storeSettings(activity)
build() build()
} }

View file

@ -5,7 +5,6 @@ import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.Constants import info.nightscout.androidaps.Constants
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
import info.nightscout.androidaps.data.Profile import info.nightscout.androidaps.data.Profile
import info.nightscout.androidaps.database.entities.UserEntry.*
import info.nightscout.androidaps.events.EventProfileStoreChanged import info.nightscout.androidaps.events.EventProfileStoreChanged
import info.nightscout.androidaps.interfaces.* import info.nightscout.androidaps.interfaces.*
import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.AAPSLogger
@ -116,7 +115,6 @@ class LocalProfilePlugin @Inject constructor(
createAndStoreConvertedProfile() createAndStoreConvertedProfile()
isEdited = false isEdited = false
aapsLogger.debug(LTag.PROFILE, "Storing settings: " + rawProfile?.data.toString()) aapsLogger.debug(LTag.PROFILE, "Storing settings: " + rawProfile?.data.toString())
uel.log(Action.STORE_PROFILE)
rxBus.send(EventProfileStoreChanged()) rxBus.send(EventProfileStoreChanged())
var namesOK = true var namesOK = true
profiles.forEach { profiles.forEach {

View file

@ -8,7 +8,9 @@ import android.widget.AdapterView
import android.widget.ArrayAdapter import android.widget.ArrayAdapter
import dagger.android.support.DaggerFragment import dagger.android.support.DaggerFragment
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
import info.nightscout.androidaps.database.entities.UserEntry.* import info.nightscout.androidaps.database.entities.ValueWithUnit
import info.nightscout.androidaps.database.entities.UserEntry.Action
import info.nightscout.androidaps.database.entities.UserEntry.Sources
import info.nightscout.androidaps.databinding.NsprofileFragmentBinding import info.nightscout.androidaps.databinding.NsprofileFragmentBinding
import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.interfaces.ProfileFunction
import info.nightscout.androidaps.logging.UserEntryLogger import info.nightscout.androidaps.logging.UserEntryLogger
@ -62,7 +64,9 @@ class NSProfileFragment : DaggerFragment() {
activity?.let { activity -> activity?.let { activity ->
OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.nsprofile), OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.nsprofile),
resourceHelper.gs(R.string.activate_profile) + ": " + name + " ?", Runnable { resourceHelper.gs(R.string.activate_profile) + ": " + name + " ?", Runnable {
uel.log(Action.PROFILE_SWITCH, ValueWithUnit(name, Units.None), ValueWithUnit(100.toInt(), Units.Percent)) uel.log(Action.PROFILE_SWITCH, Sources.NSProfile,
ValueWithUnit.SimpleString(name),
ValueWithUnit.Percent(100))
treatmentsPlugin.doProfileSwitch(store, name, 0, 100, 0, DateUtil.now()) treatmentsPlugin.doProfileSwitch(store, name, 0, 100, 0, DateUtil.now())
}) })
} }

View file

@ -10,8 +10,10 @@ import androidx.recyclerview.widget.RecyclerView
import dagger.android.support.DaggerFragment import dagger.android.support.DaggerFragment
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.ValueWithUnit
import info.nightscout.androidaps.database.entities.GlucoseValue import info.nightscout.androidaps.database.entities.GlucoseValue
import info.nightscout.androidaps.database.entities.UserEntry.* import info.nightscout.androidaps.database.entities.UserEntry.Action
import info.nightscout.androidaps.database.entities.UserEntry.Sources
import info.nightscout.androidaps.database.transactions.InvalidateGlucoseValueTransaction import info.nightscout.androidaps.database.transactions.InvalidateGlucoseValueTransaction
import info.nightscout.androidaps.databinding.BgsourceFragmentBinding import info.nightscout.androidaps.databinding.BgsourceFragmentBinding
import info.nightscout.androidaps.databinding.BgsourceItemBinding import info.nightscout.androidaps.databinding.BgsourceItemBinding
@ -129,7 +131,9 @@ class BGSourceFragment : DaggerFragment() {
activity?.let { activity -> activity?.let { activity ->
val text = dateUtil.dateAndTimeString(glucoseValue.timestamp) + "\n" + glucoseValue.valueToUnitsString(profileFunction.getUnits()) val text = dateUtil.dateAndTimeString(glucoseValue.timestamp) + "\n" + glucoseValue.valueToUnitsString(profileFunction.getUnits())
OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.removerecord), text, Runnable { OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.removerecord), text, Runnable {
uel.log(Action.BG_REMOVED, ValueWithUnit(glucoseValue.timestamp, Units.Timestamp)) //uel.log(Action.BG_REMOVED, XXXValueWithUnit.Timestamp(glucoseValue.timestamp))
uel.log(Action.BG_REMOVED, Sources.BG,
ValueWithUnit.Timestamp(glucoseValue.timestamp))
disposable += repository.runTransaction(InvalidateGlucoseValueTransaction(glucoseValue.id)).subscribe() disposable += repository.runTransaction(InvalidateGlucoseValueTransaction(glucoseValue.id)).subscribe()
}) })
} }

View file

@ -13,7 +13,9 @@ import info.nightscout.androidaps.database.AppRepository
import info.nightscout.androidaps.database.entities.Bolus import info.nightscout.androidaps.database.entities.Bolus
import info.nightscout.androidaps.database.entities.BolusCalculatorResult import info.nightscout.androidaps.database.entities.BolusCalculatorResult
import info.nightscout.androidaps.database.entities.Carbs import info.nightscout.androidaps.database.entities.Carbs
import info.nightscout.androidaps.database.entities.UserEntry.* 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.InvalidateBolusCalculatorResultTransaction import info.nightscout.androidaps.database.transactions.InvalidateBolusCalculatorResultTransaction
import info.nightscout.androidaps.database.transactions.InvalidateBolusTransaction import info.nightscout.androidaps.database.transactions.InvalidateBolusTransaction
import info.nightscout.androidaps.database.transactions.InvalidateCarbsTransaction import info.nightscout.androidaps.database.transactions.InvalidateCarbsTransaction
@ -90,7 +92,7 @@ class TreatmentsBolusCarbsFragment : DaggerFragment() {
binding.refreshFromNightscout.setOnClickListener { binding.refreshFromNightscout.setOnClickListener {
activity?.let { activity -> activity?.let { activity ->
OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.refresheventsfromnightscout) + "?") { OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.refresheventsfromnightscout) + "?") {
uel.log(Action.TREATMENTS_NS_REFRESH) uel.log(Action.TREATMENTS_NS_REFRESH, Sources.Treatments)
disposable += disposable +=
Completable.fromAction { Completable.fromAction {
repository.deleteAllBolusCalculatorResults() repository.deleteAllBolusCalculatorResults()
@ -110,7 +112,7 @@ class TreatmentsBolusCarbsFragment : DaggerFragment() {
binding.deleteFutureTreatments.setOnClickListener { binding.deleteFutureTreatments.setOnClickListener {
activity?.let { activity -> activity?.let { activity ->
OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.overview_treatment_label), resourceHelper.gs(R.string.deletefuturetreatments) + "?", Runnable { OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.overview_treatment_label), resourceHelper.gs(R.string.deletefuturetreatments) + "?", Runnable {
uel.log(Action.DELETE_FUTURE_TREATMENTS) uel.log(Action.DELETE_FUTURE_TREATMENTS, Sources.Treatments)
repository repository
.getBolusesDataFromTime(dateUtil._now(), false) .getBolusesDataFromTime(dateUtil._now(), false)
.observeOn(aapsSchedulers.main) .observeOn(aapsSchedulers.main)
@ -333,10 +335,10 @@ class TreatmentsBolusCarbsFragment : DaggerFragment() {
resourceHelper.gs(R.string.date) + ": " + dateUtil.dateAndTimeString(bolus.timestamp) resourceHelper.gs(R.string.date) + ": " + dateUtil.dateAndTimeString(bolus.timestamp)
OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.removerecord), text, Runnable { OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.removerecord), text, Runnable {
uel.log( uel.log(
Action.TREATMENT_REMOVED, Action.TREATMENT_REMOVED, Sources.Treatments,
ValueWithUnit(bolus.timestamp, Units.Timestamp), ValueWithUnit.Timestamp(bolus.timestamp),
ValueWithUnit(bolus.amount, Units.U) ValueWithUnit.Insulin(bolus.amount)
// ValueWithUnit(mealLinkLoaded.carbs.toInt(), Units.G) //XXXValueWithUnit.Gram(mealLinkLoaded.carbs.toInt())
) )
disposable += repository.runTransactionForResult(InvalidateBolusTransaction(bolus.id)) disposable += repository.runTransactionForResult(InvalidateBolusTransaction(bolus.id))
.subscribe( .subscribe(
@ -355,10 +357,9 @@ class TreatmentsBolusCarbsFragment : DaggerFragment() {
resourceHelper.gs(R.string.date) + ": " + dateUtil.dateAndTimeString(carb.timestamp) resourceHelper.gs(R.string.date) + ": " + dateUtil.dateAndTimeString(carb.timestamp)
OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.removerecord), text, Runnable { OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.removerecord), text, Runnable {
uel.log( uel.log(
Action.TREATMENT_REMOVED, Action.TREATMENT_REMOVED, Sources.Treatments,
ValueWithUnit(carb.timestamp, Units.Timestamp), ValueWithUnit.Timestamp(carb.timestamp),
ValueWithUnit(carb.amount, Units.G) ValueWithUnit.Gram(carb.amount.toInt()))
)
disposable += repository.runTransactionForResult(InvalidateCarbsTransaction(carb.id)) disposable += repository.runTransactionForResult(InvalidateCarbsTransaction(carb.id))
.subscribe( .subscribe(
{ result -> result.invalidated.forEach { aapsLogger.debug(LTag.DATABASE, "Invalidated carbs $it") } }, { result -> result.invalidated.forEach { aapsLogger.debug(LTag.DATABASE, "Invalidated carbs $it") } },

View file

@ -10,10 +10,10 @@ import androidx.recyclerview.widget.RecyclerView
import dagger.android.support.DaggerFragment import dagger.android.support.DaggerFragment
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.ValueWithUnit
import info.nightscout.androidaps.database.entities.TherapyEvent import info.nightscout.androidaps.database.entities.TherapyEvent
import info.nightscout.androidaps.database.entities.UserEntry.Action import info.nightscout.androidaps.database.entities.UserEntry.Action
import info.nightscout.androidaps.database.entities.UserEntry.Units import info.nightscout.androidaps.database.entities.UserEntry.Sources
import info.nightscout.androidaps.database.entities.UserEntry.ValueWithUnit
import info.nightscout.androidaps.database.transactions.InvalidateAAPSStartedTherapyEventTransaction import info.nightscout.androidaps.database.transactions.InvalidateAAPSStartedTherapyEventTransaction
import info.nightscout.androidaps.database.transactions.InvalidateTherapyEventTransaction import info.nightscout.androidaps.database.transactions.InvalidateTherapyEventTransaction
import info.nightscout.androidaps.databinding.TreatmentsCareportalFragmentBinding import info.nightscout.androidaps.databinding.TreatmentsCareportalFragmentBinding
@ -77,7 +77,7 @@ class TreatmentsCareportalFragment : DaggerFragment() {
binding.refreshFromNightscout.setOnClickListener { binding.refreshFromNightscout.setOnClickListener {
activity?.let { activity -> activity?.let { activity ->
OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.careportal), resourceHelper.gs(R.string.refresheventsfromnightscout) + " ?", Runnable { OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.careportal), resourceHelper.gs(R.string.refresheventsfromnightscout) + " ?", Runnable {
uel.log(Action.CAREPORTAL_NS_REFRESH) uel.log(Action.CAREPORTAL_NS_REFRESH, Sources.Treatments)
disposable += Completable.fromAction { repository.deleteAllTherapyEventsEntries() } disposable += Completable.fromAction { repository.deleteAllTherapyEventsEntries() }
.subscribeOn(aapsSchedulers.io) .subscribeOn(aapsSchedulers.io)
.observeOn(aapsSchedulers.main) .observeOn(aapsSchedulers.main)
@ -92,7 +92,7 @@ class TreatmentsCareportalFragment : DaggerFragment() {
binding.removeAndroidapsStartedEvents.setOnClickListener { binding.removeAndroidapsStartedEvents.setOnClickListener {
activity?.let { activity -> activity?.let { activity ->
OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.careportal), resourceHelper.gs(R.string.careportal_removestartedevents), Runnable { OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.careportal), resourceHelper.gs(R.string.careportal_removestartedevents), Runnable {
uel.log(Action.RESTART_EVENTS_REMOVED) uel.log(Action.RESTART_EVENTS_REMOVED, Sources.Treatments)
repository.runTransactionForResult(InvalidateAAPSStartedTherapyEventTransaction(resourceHelper.gs(R.string.androidaps_start))) repository.runTransactionForResult(InvalidateAAPSStartedTherapyEventTransaction(resourceHelper.gs(R.string.androidaps_start)))
.subscribe( .subscribe(
{ result -> result.invalidated.forEach { aapsLogger.debug(LTag.DATABASE, "Invalidated therapy event $it") } }, { result -> result.invalidated.forEach { aapsLogger.debug(LTag.DATABASE, "Invalidated therapy event $it") } },
@ -167,7 +167,7 @@ class TreatmentsCareportalFragment : DaggerFragment() {
holder.binding.date.text = dateUtil.dateAndTimeString(therapyEvent.timestamp) holder.binding.date.text = dateUtil.dateAndTimeString(therapyEvent.timestamp)
holder.binding.duration.text = if (therapyEvent.duration == 0L) "" else DateUtil.niceTimeScalar(therapyEvent.duration, resourceHelper) holder.binding.duration.text = if (therapyEvent.duration == 0L) "" else DateUtil.niceTimeScalar(therapyEvent.duration, resourceHelper)
holder.binding.note.text = therapyEvent.note holder.binding.note.text = therapyEvent.note
holder.binding.type.text = translator.translate(therapyEvent.type.text) holder.binding.type.text = translator.translate(therapyEvent.type)
holder.binding.remove.tag = therapyEvent holder.binding.remove.tag = therapyEvent
} }
@ -183,12 +183,14 @@ class TreatmentsCareportalFragment : DaggerFragment() {
binding.remove.setOnClickListener { v: View -> binding.remove.setOnClickListener { v: View ->
val therapyEvent = v.tag as TherapyEvent val therapyEvent = v.tag as TherapyEvent
activity?.let { activity -> activity?.let { activity ->
val text = resourceHelper.gs(R.string.eventtype) + ": " + translator.translate(therapyEvent.type.text) + "\n" + val text = resourceHelper.gs(R.string.eventtype) + ": " + translator.translate(therapyEvent.type) + "\n" +
resourceHelper.gs(R.string.notes_label) + ": " + (therapyEvent.note resourceHelper.gs(R.string.notes_label) + ": " + (therapyEvent.note
?: "") + "\n" + ?: "") + "\n" +
resourceHelper.gs(R.string.date) + ": " + dateUtil.dateAndTimeString(therapyEvent.timestamp) resourceHelper.gs(R.string.date) + ": " + dateUtil.dateAndTimeString(therapyEvent.timestamp)
OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.removerecord), text, Runnable { OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.removerecord), text, Runnable {
uel.log(Action.CAREPORTAL_REMOVED, therapyEvent.note, ValueWithUnit(therapyEvent.timestamp, Units.Timestamp), ValueWithUnit(therapyEvent.type.text, Units.TherapyEvent)) uel.log(Action.CAREPORTAL_REMOVED, Sources.Treatments, therapyEvent.note ,
ValueWithUnit.Timestamp(therapyEvent.timestamp),
ValueWithUnit.TherapyEventType(therapyEvent.type))
disposable += repository.runTransactionForResult(InvalidateTherapyEventTransaction(therapyEvent.id)) disposable += repository.runTransactionForResult(InvalidateTherapyEventTransaction(therapyEvent.id))
.subscribe( .subscribe(
{ result -> result.invalidated.forEach { aapsLogger.debug(LTag.DATABASE, "Invalidated therapy event $it") } }, { result -> result.invalidated.forEach { aapsLogger.debug(LTag.DATABASE, "Invalidated therapy event $it") } },

View file

@ -12,7 +12,8 @@ import androidx.recyclerview.widget.RecyclerView
import dagger.android.support.DaggerFragment import dagger.android.support.DaggerFragment
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
import info.nightscout.androidaps.data.Intervals import info.nightscout.androidaps.data.Intervals
import info.nightscout.androidaps.database.entities.UserEntry.* import info.nightscout.androidaps.database.entities.UserEntry.Action
import info.nightscout.androidaps.database.entities.UserEntry.Sources
import info.nightscout.androidaps.databinding.TreatmentsExtendedbolusFragmentBinding import info.nightscout.androidaps.databinding.TreatmentsExtendedbolusFragmentBinding
import info.nightscout.androidaps.databinding.TreatmentsExtendedbolusItemBinding import info.nightscout.androidaps.databinding.TreatmentsExtendedbolusItemBinding
import info.nightscout.androidaps.db.ExtendedBolus import info.nightscout.androidaps.db.ExtendedBolus
@ -123,7 +124,7 @@ class TreatmentsExtendedBolusesFragment : DaggerFragment() {
${resourceHelper.gs(R.string.extended_bolus)} ${resourceHelper.gs(R.string.extended_bolus)}
${resourceHelper.gs(R.string.date)}: ${dateUtil.dateAndTimeString(extendedBolus.date)} ${resourceHelper.gs(R.string.date)}: ${dateUtil.dateAndTimeString(extendedBolus.date)}
""".trimIndent(), { _: DialogInterface, _: Int -> """.trimIndent(), { _: DialogInterface, _: Int ->
uel.log(Action.EXTENDED_BOLUS_REMOVED) uel.log(Action.EXTENDED_BOLUS_REMOVED, Sources.Treatments)
val id = extendedBolus._id val id = extendedBolus._id
if (NSUpload.isIdValid(id)) nsUpload.removeCareportalEntryFromNS(id) if (NSUpload.isIdValid(id)) nsUpload.removeCareportalEntryFromNS(id)
else uploadQueue.removeByMongoId("dbAdd", id) else uploadQueue.removeByMongoId("dbAdd", id)

View file

@ -9,7 +9,9 @@ import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import dagger.android.support.DaggerFragment import dagger.android.support.DaggerFragment
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
import info.nightscout.androidaps.database.entities.UserEntry.* import info.nightscout.androidaps.database.entities.ValueWithUnit
import info.nightscout.androidaps.database.entities.UserEntry.Action
import info.nightscout.androidaps.database.entities.UserEntry.Sources
import info.nightscout.androidaps.databinding.TreatmentsProfileswitchFragmentBinding import info.nightscout.androidaps.databinding.TreatmentsProfileswitchFragmentBinding
import info.nightscout.androidaps.databinding.TreatmentsProfileswitchItemBinding import info.nightscout.androidaps.databinding.TreatmentsProfileswitchItemBinding
import info.nightscout.androidaps.db.ProfileSwitch import info.nightscout.androidaps.db.ProfileSwitch
@ -71,7 +73,7 @@ class TreatmentsProfileSwitchFragment : DaggerFragment() {
binding.refreshFromNightscout.setOnClickListener { binding.refreshFromNightscout.setOnClickListener {
activity?.let { activity -> activity?.let { activity ->
uel.log(Action.PROFILE_SWITCH_NS_REFRESH) uel.log(Action.PROFILE_SWITCH_NS_REFRESH, Sources.Treatments)
OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.refresheventsfromnightscout) + "?") { OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.refresheventsfromnightscout) + "?") {
databaseHelper.resetProfileSwitch() databaseHelper.resetProfileSwitch()
rxBus.send(EventNSClientRestart()) rxBus.send(EventNSClientRestart())
@ -148,7 +150,8 @@ class TreatmentsProfileSwitchFragment : DaggerFragment() {
OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.removerecord), OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.removerecord),
resourceHelper.gs(R.string.careportal_profileswitch) + ": " + profileSwitch.profileName + resourceHelper.gs(R.string.careportal_profileswitch) + ": " + profileSwitch.profileName +
"\n" + resourceHelper.gs(R.string.date) + ": " + dateUtil.dateAndTimeString(profileSwitch.date), Runnable { "\n" + resourceHelper.gs(R.string.date) + ": " + dateUtil.dateAndTimeString(profileSwitch.date), Runnable {
uel.log(Action.PROFILE_SWITCH_REMOVED, profileSwitch.profileName, ValueWithUnit(profileSwitch.date, Units.Timestamp)) uel.log(Action.PROFILE_SWITCH_REMOVED, Sources.Treatments, profileSwitch.profileName,
ValueWithUnit.Timestamp(profileSwitch.date))
val id = profileSwitch._id val id = profileSwitch._id
if (NSUpload.isIdValid(id)) nsUpload.removeCareportalEntryFromNS(id) if (NSUpload.isIdValid(id)) nsUpload.removeCareportalEntryFromNS(id)
else uploadQueue.removeByMongoId("dbAdd", id) else uploadQueue.removeByMongoId("dbAdd", id)
@ -161,7 +164,10 @@ class TreatmentsProfileSwitchFragment : DaggerFragment() {
val profileSwitch = it.tag as ProfileSwitch val profileSwitch = it.tag as ProfileSwitch
OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.careportal_profileswitch), resourceHelper.gs(R.string.copytolocalprofile) + "\n" + profileSwitch.customizedName + "\n" + dateUtil.dateAndTimeString(profileSwitch.date), Runnable { OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.careportal_profileswitch), resourceHelper.gs(R.string.copytolocalprofile) + "\n" + profileSwitch.customizedName + "\n" + dateUtil.dateAndTimeString(profileSwitch.date), Runnable {
profileSwitch.profileObject?.let { profileSwitch.profileObject?.let {
uel.log(Action.PROFILE_SWITCH_CLONED, ValueWithUnit(profileSwitch.date, Units.Timestamp), ValueWithUnit(profileSwitch.profileName, Units.None)) uel.log(Action.PROFILE_SWITCH_CLONED, Sources.Treatments,
profileSwitch.customizedName + " " + dateUtil.dateAndTimeString(profileSwitch.date).replace(".", "_"),
ValueWithUnit.Timestamp(profileSwitch.date),
ValueWithUnit.SimpleString(profileSwitch.profileName))
val nonCustomized = it.convertToNonCustomizedProfile() val nonCustomized = it.convertToNonCustomizedProfile()
if (nonCustomized.isValid(resourceHelper.gs(R.string.careportal_profileswitch, false))) { if (nonCustomized.isValid(resourceHelper.gs(R.string.careportal_profileswitch, false))) {
localProfilePlugin.addProfile(localProfilePlugin.copyFrom(nonCustomized, profileSwitch.customizedName + " " + dateUtil.dateAndTimeString(profileSwitch.date).replace(".", "_"))) localProfilePlugin.addProfile(localProfilePlugin.copyFrom(nonCustomized, profileSwitch.customizedName + " " + dateUtil.dateAndTimeString(profileSwitch.date).replace(".", "_")))

View file

@ -13,10 +13,10 @@ import dagger.android.support.DaggerFragment
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.ValueWrapper import info.nightscout.androidaps.database.ValueWrapper
import info.nightscout.androidaps.database.entities.ValueWithUnit
import info.nightscout.androidaps.database.entities.TemporaryTarget import info.nightscout.androidaps.database.entities.TemporaryTarget
import info.nightscout.androidaps.database.entities.UserEntry.Action import info.nightscout.androidaps.database.entities.UserEntry.Action
import info.nightscout.androidaps.database.entities.UserEntry.Units import info.nightscout.androidaps.database.entities.UserEntry.Sources
import info.nightscout.androidaps.database.entities.UserEntry.ValueWithUnit
import info.nightscout.androidaps.database.interfaces.end import info.nightscout.androidaps.database.interfaces.end
import info.nightscout.androidaps.database.transactions.InvalidateTemporaryTargetTransaction import info.nightscout.androidaps.database.transactions.InvalidateTemporaryTargetTransaction
import info.nightscout.androidaps.databinding.TreatmentsTemptargetFragmentBinding import info.nightscout.androidaps.databinding.TreatmentsTemptargetFragmentBinding
@ -86,7 +86,7 @@ class TreatmentsTempTargetFragment : DaggerFragment() {
binding.refreshFromNightscout.setOnClickListener { binding.refreshFromNightscout.setOnClickListener {
context?.let { context -> context?.let { context ->
OKDialog.showConfirmation(context, resourceHelper.gs(R.string.refresheventsfromnightscout) + " ?", { OKDialog.showConfirmation(context, resourceHelper.gs(R.string.refresheventsfromnightscout) + " ?", {
uel.log(Action.TT_NS_REFRESH) uel.log(Action.TT_NS_REFRESH, Sources.Treatments)
disposable += Completable.fromAction { repository.deleteAllTempTargetEntries() } disposable += Completable.fromAction { repository.deleteAllTempTargetEntries() }
.subscribeOn(aapsSchedulers.io) .subscribeOn(aapsSchedulers.io)
.observeOn(aapsSchedulers.main) .observeOn(aapsSchedulers.main)
@ -170,7 +170,7 @@ class TreatmentsTempTargetFragment : DaggerFragment() {
holder.binding.duration.text = resourceHelper.gs(R.string.format_mins, T.msecs(tempTarget.duration).mins()) holder.binding.duration.text = resourceHelper.gs(R.string.format_mins, T.msecs(tempTarget.duration).mins())
holder.binding.low.text = tempTarget.lowValueToUnitsToString(units) holder.binding.low.text = tempTarget.lowValueToUnitsToString(units)
holder.binding.high.text = tempTarget.highValueToUnitsToString(units) holder.binding.high.text = tempTarget.highValueToUnitsToString(units)
holder.binding.reason.text = translator.translate(tempTarget.reason.text) holder.binding.reason.text = translator.translate(tempTarget.reason)
holder.binding.date.setTextColor( holder.binding.date.setTextColor(
when { when {
tempTarget.id == currentlyActiveTarget?.id -> resourceHelper.gc(R.color.colorActive) tempTarget.id == currentlyActiveTarget?.id -> resourceHelper.gc(R.color.colorActive)
@ -196,7 +196,12 @@ class TreatmentsTempTargetFragment : DaggerFragment() {
${dateUtil.dateAndTimeString(tempTarget.timestamp)} ${dateUtil.dateAndTimeString(tempTarget.timestamp)}
""".trimIndent(), """.trimIndent(),
{ _: DialogInterface?, _: Int -> { _: DialogInterface?, _: Int ->
uel.log(Action.TT_REMOVED, ValueWithUnit(tempTarget.timestamp, Units.Timestamp), ValueWithUnit(tempTarget.reason.text, Units.TherapyEvent), ValueWithUnit(tempTarget.lowTarget, Units.Mg_Dl), ValueWithUnit(tempTarget.highTarget, Units.Mg_Dl, tempTarget.lowTarget != tempTarget.highTarget), ValueWithUnit(tempTarget.duration.toInt(), Units.M)) uel.log(Action.TT_REMOVED, Sources.Treatments,
ValueWithUnit.Timestamp(tempTarget.timestamp),
ValueWithUnit.TherapyEventTTReason(tempTarget.reason),
ValueWithUnit.Mgdl(tempTarget.lowTarget),
ValueWithUnit.Mgdl(tempTarget.highTarget).takeIf { tempTarget.lowTarget != tempTarget.highTarget },
ValueWithUnit.Minute(TimeUnit.MILLISECONDS.toMinutes(tempTarget.duration).toInt()))
disposable += repository.runTransactionForResult(InvalidateTemporaryTargetTransaction(tempTarget.id)) disposable += repository.runTransactionForResult(InvalidateTemporaryTargetTransaction(tempTarget.id))
.subscribe( .subscribe(
{ aapsLogger.debug(LTag.DATABASE, "Removed temp target $tempTarget") }, { aapsLogger.debug(LTag.DATABASE, "Removed temp target $tempTarget") },

View file

@ -12,7 +12,9 @@ import dagger.android.support.DaggerFragment
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
import info.nightscout.androidaps.data.Intervals import info.nightscout.androidaps.data.Intervals
import info.nightscout.androidaps.data.IobTotal import info.nightscout.androidaps.data.IobTotal
import info.nightscout.androidaps.database.entities.UserEntry.* import info.nightscout.androidaps.database.entities.ValueWithUnit
import info.nightscout.androidaps.database.entities.UserEntry.Action
import info.nightscout.androidaps.database.entities.UserEntry.Sources
import info.nightscout.androidaps.databinding.TreatmentsTempbasalsFragmentBinding import info.nightscout.androidaps.databinding.TreatmentsTempbasalsFragmentBinding
import info.nightscout.androidaps.databinding.TreatmentsTempbasalsItemBinding import info.nightscout.androidaps.databinding.TreatmentsTempbasalsItemBinding
import info.nightscout.androidaps.db.Source import info.nightscout.androidaps.db.Source
@ -164,7 +166,8 @@ class TreatmentsTemporaryBasalsFragment : DaggerFragment() {
${resourceHelper.gs(R.string.date)}: ${dateUtil.dateAndTimeString(tempBasal.date)} ${resourceHelper.gs(R.string.date)}: ${dateUtil.dateAndTimeString(tempBasal.date)}
""".trimIndent(), """.trimIndent(),
{ _: DialogInterface?, _: Int -> { _: DialogInterface?, _: Int ->
uel.log(Action.TT_REMOVED, ValueWithUnit(tempBasal.date, Units.Timestamp)) uel.log(Action.TT_REMOVED, Sources.Treatments,
ValueWithUnit.Timestamp(tempBasal.date))
activePlugin.activeTreatments.removeTempBasal(tempBasal) activePlugin.activeTreatments.removeTempBasal(tempBasal)
}, null) }, null)
} }

View file

@ -7,11 +7,11 @@ import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import dagger.android.support.DaggerFragment import dagger.android.support.DaggerFragment
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.UserEntry import info.nightscout.androidaps.database.entities.UserEntry
import info.nightscout.androidaps.database.entities.UserEntry.* import info.nightscout.androidaps.database.entities.UserEntry.Action
import info.nightscout.androidaps.database.entities.UserEntry.Sources
import info.nightscout.androidaps.databinding.TreatmentsUserEntryFragmentBinding import info.nightscout.androidaps.databinding.TreatmentsUserEntryFragmentBinding
import info.nightscout.androidaps.databinding.TreatmentsUserEntryItemBinding import info.nightscout.androidaps.databinding.TreatmentsUserEntryItemBinding
import info.nightscout.androidaps.events.EventPreferenceChange import info.nightscout.androidaps.events.EventPreferenceChange
@ -19,15 +19,17 @@ import info.nightscout.androidaps.interfaces.ImportExportPrefsInterface
import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.interfaces.ProfileFunction
import info.nightscout.androidaps.logging.UserEntryLogger import info.nightscout.androidaps.logging.UserEntryLogger
import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.treatments.events.EventTreatmentUpdateGui
import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.DecimalFormatter
import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.T
import info.nightscout.androidaps.utils.Translator import info.nightscout.androidaps.utils.Translator
import info.nightscout.androidaps.utils.UserEntryPresentationHelper
import info.nightscout.androidaps.utils.alertDialogs.OKDialog import info.nightscout.androidaps.utils.alertDialogs.OKDialog
import info.nightscout.androidaps.utils.extensions.*
import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.rx.AapsSchedulers import info.nightscout.androidaps.utils.rx.AapsSchedulers
import io.reactivex.disposables.CompositeDisposable import io.reactivex.disposables.CompositeDisposable
import java.util.concurrent.TimeUnit
import javax.inject.Inject import javax.inject.Inject
class TreatmentsUserEntryFragment : DaggerFragment() { class TreatmentsUserEntryFragment : DaggerFragment() {
@ -42,9 +44,13 @@ class TreatmentsUserEntryFragment : DaggerFragment() {
@Inject lateinit var translator: Translator @Inject lateinit var translator: Translator
@Inject lateinit var importExportPrefs: ImportExportPrefsInterface @Inject lateinit var importExportPrefs: ImportExportPrefsInterface
@Inject lateinit var uel: UserEntryLogger @Inject lateinit var uel: UserEntryLogger
@Inject lateinit var userEntryPresentationHelper: UserEntryPresentationHelper
private val disposable = CompositeDisposable() private val disposable = CompositeDisposable()
private val millsToThePastFiltered = T.days(30).msecs()
private val millsToThePastUnFiltered = T.days(3).msecs()
private var _binding: TreatmentsUserEntryFragmentBinding? = null private var _binding: TreatmentsUserEntryFragmentBinding? = null
// This property is only valid between onCreateView and // This property is only valid between onCreateView and
@ -61,20 +67,30 @@ class TreatmentsUserEntryFragment : DaggerFragment() {
binding.ueExportToXml.setOnClickListener { binding.ueExportToXml.setOnClickListener {
activity?.let { activity -> activity?.let { activity ->
OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.ue_export_to_csv) + "?") { OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.ue_export_to_csv) + "?") {
uel.log(Action.EXPORT_CSV) uel.log(Action.EXPORT_CSV, Sources.Treatments)
importExportPrefs.exportUserEntriesCsv(activity, repository.getAllUserEntries()) importExportPrefs.exportUserEntriesCsv(activity, repository.getAllUserEntries())
} }
} }
} }
binding.showLoop.setOnCheckedChangeListener { _, _ ->
rxBus.send(EventTreatmentUpdateGui())
}
} }
fun swapAdapter() { fun swapAdapter() {
disposable.add( repository val now = System.currentTimeMillis()
.getAllUserEntries() if (binding.showLoop.isChecked)
.observeOn(aapsSchedulers.main) disposable.add( repository
.subscribe { list -> binding.recyclerview.swapAdapter(UserEntryAdapter(list), true) } .getUserEntryDataFromTime(now - millsToThePastUnFiltered)
) .observeOn(aapsSchedulers.main)
.subscribe { list -> binding.recyclerview.swapAdapter(UserEntryAdapter(list), true) }
)
else
disposable.add( repository
.getUserEntryFilteredDataFromTime(now - millsToThePastFiltered)
.observeOn(aapsSchedulers.main)
.subscribe { list -> binding.recyclerview.swapAdapter(UserEntryAdapter(list), true) }
)
} }
@Synchronized @Synchronized
@ -86,6 +102,11 @@ class TreatmentsUserEntryFragment : DaggerFragment() {
.toObservable(EventPreferenceChange::class.java) .toObservable(EventPreferenceChange::class.java)
.observeOn(aapsSchedulers.io) .observeOn(aapsSchedulers.io)
.subscribe({ swapAdapter() }, fabricPrivacy::logException)) .subscribe({ swapAdapter() }, fabricPrivacy::logException))
disposable.add(rxBus
.toObservable(EventTreatmentUpdateGui::class.java)
.observeOn(aapsSchedulers.io)
.debounce(1L, TimeUnit.SECONDS)
.subscribe({ swapAdapter() }, fabricPrivacy::logException))
} }
@Synchronized @Synchronized
@ -111,44 +132,13 @@ class TreatmentsUserEntryFragment : DaggerFragment() {
override fun onBindViewHolder(holder: UserEntryViewHolder, position: Int) { override fun onBindViewHolder(holder: UserEntryViewHolder, position: Int) {
val current = entries[position] val current = entries[position]
holder.binding.date.text = dateUtil.dateAndTimeAndSecondsString(current.timestamp) holder.binding.date.text = dateUtil.dateAndTimeAndSecondsString(current.timestamp)
holder.binding.action.text = translator.translate(current.action.name) holder.binding.action.text = userEntryPresentationHelper.actionToColoredString(current.action)
holder.binding.action.setTextColor(resourceHelper.gc(current.action.colorGroup.colorId())) holder.binding.s.text = current.note
if (current.s != "") { holder.binding.s.visibility = if (current.note != "") View.VISIBLE else View.GONE
holder.binding.s.text = current.s holder.binding.iconSource.setImageResource(userEntryPresentationHelper.iconId(current.source))
holder.binding.s.visibility = View.VISIBLE holder.binding.iconSource.visibility = View.VISIBLE
} else holder.binding.values.text = userEntryPresentationHelper.listToPresentationString(current.values)
holder.binding.s.visibility = View.GONE holder.binding.values.visibility = if (holder.binding.values.text != "") View.VISIBLE else View.GONE
var valuesWithUnitString = ""
var rStringParam = 0
val separator = " "
for(v in current.values) {
if (rStringParam >0)
rStringParam--
else
when (v.unit) {
Units.Timestamp -> valuesWithUnitString += dateUtil.dateAndTimeAndSecondsString(v.lValue) + separator
Units.TherapyEvent -> valuesWithUnitString += translator.translate(v.sValue) + separator
Units.R_String -> {
rStringParam = v.lValue.toInt()
when (rStringParam) { //
0 -> valuesWithUnitString += resourceHelper.gs(v.iValue) + separator
1 -> valuesWithUnitString += resourceHelper.gs(v.iValue, current.values[current.values.indexOf(v)+1].value()) + separator
2 -> valuesWithUnitString += resourceHelper.gs(v.iValue, current.values[current.values.indexOf(v)+1].value(), current.values[current.values.indexOf(v)+2].value()) + separator
3 -> valuesWithUnitString += resourceHelper.gs(v.iValue, current.values[current.values.indexOf(v)+1].value(), current.values[current.values.indexOf(v)+2].value(), current.values[current.values.indexOf(v)+3].value()) + separator
4 -> rStringParam = 0
}
}
Units.Mg_Dl -> valuesWithUnitString += if (profileFunction.getUnits()==Constants.MGDL) DecimalFormatter.to0Decimal(v.dValue) + translator.translate(Units.Mg_Dl.name) + separator else DecimalFormatter.to1Decimal(v.dValue/Constants.MMOLL_TO_MGDL) + translator.translate(Units.Mmol_L.name) + separator
Units.Mmol_L -> valuesWithUnitString += if (profileFunction.getUnits()==Constants.MGDL) DecimalFormatter.to0Decimal(v.dValue*Constants.MMOLL_TO_MGDL) + translator.translate(Units.Mg_Dl.name) + separator else DecimalFormatter.to1Decimal(v.dValue) + translator.translate(Units.Mmol_L.name) + separator
Units.U_H, Units.U
-> valuesWithUnitString += DecimalFormatter.to2Decimal(v.dValue) + translator.translate(v.unit.name) + separator
Units.G, Units.M, Units.H, Units.Percent
-> valuesWithUnitString += v.iValue.toString() + translator.translate(v.unit.name) + separator
else -> valuesWithUnitString += if (v.iValue != 0 || v.sValue != "") { v.value().toString() + separator } else ""
}
}
holder.binding.values.text = valuesWithUnitString.trim()
holder.binding.values.visibility = if (current.values.size > 0) View.VISIBLE else View.GONE
} }
inner class UserEntryViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { inner class UserEntryViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
@ -157,6 +147,6 @@ class TreatmentsUserEntryFragment : DaggerFragment() {
} }
override fun getItemCount(): Int = entries.size override fun getItemCount(): Int = entries.size
} }
} }

View file

@ -12,8 +12,10 @@ import info.nightscout.androidaps.data.DetailedBolusInfo
import info.nightscout.androidaps.data.Profile import info.nightscout.androidaps.data.Profile
import info.nightscout.androidaps.database.AppRepository import info.nightscout.androidaps.database.AppRepository
import info.nightscout.androidaps.database.entities.BolusCalculatorResult import info.nightscout.androidaps.database.entities.BolusCalculatorResult
import info.nightscout.androidaps.database.entities.ValueWithUnit
import info.nightscout.androidaps.database.entities.TemporaryTarget import info.nightscout.androidaps.database.entities.TemporaryTarget
import info.nightscout.androidaps.database.entities.UserEntry.* import info.nightscout.androidaps.database.entities.UserEntry.Action
import info.nightscout.androidaps.database.entities.UserEntry.Sources
import info.nightscout.androidaps.database.transactions.InsertOrUpdateBolusCalculatorResultTransaction import info.nightscout.androidaps.database.transactions.InsertOrUpdateBolusCalculatorResultTransaction
import info.nightscout.androidaps.events.EventRefreshOverview import info.nightscout.androidaps.events.EventRefreshOverview
import info.nightscout.androidaps.interfaces.* import info.nightscout.androidaps.interfaces.*
@ -130,6 +132,7 @@ class BolusWizard @Inject constructor(
private var useAlarm = false private var useAlarm = false
var notes: String = "" var notes: String = ""
private var carbTime: Int = 0 private var carbTime: Int = 0
private var quickWizard: Boolean = true
@JvmOverloads @JvmOverloads
fun doCalc(profile: Profile, fun doCalc(profile: Profile,
@ -149,7 +152,8 @@ class BolusWizard @Inject constructor(
useTrend: Boolean, useTrend: Boolean,
useAlarm: Boolean, useAlarm: Boolean,
notes: String = "", notes: String = "",
carbTime: Int = 0 carbTime: Int = 0,
quickWizard: Boolean = false
): BolusWizard { ): BolusWizard {
this.profile = profile this.profile = profile
@ -170,6 +174,7 @@ class BolusWizard @Inject constructor(
this.useAlarm = useAlarm this.useAlarm = useAlarm
this.notes = notes this.notes = notes
this.carbTime = carbTime this.carbTime = carbTime
this.quickWizard = quickWizard
// Insulin from BG // Insulin from BG
sens = Profile.fromMgdlToUnits(profile.isfMgdl, profileFunction.getUnits()) sens = Profile.fromMgdlToUnits(profile.isfMgdl, profileFunction.getUnits())
@ -343,7 +348,10 @@ class BolusWizard @Inject constructor(
carbTime = 0 carbTime = 0
bolusCalculatorResult = createBolusCalculatorResult() bolusCalculatorResult = createBolusCalculatorResult()
notes = this@BolusWizard.notes notes = this@BolusWizard.notes
uel.log(Action.BOLUS_ADVISOR, notes, ValueWithUnit(eventType.toDBbEventType(), Units.TherapyEvent), ValueWithUnit(insulinAfterConstraints, Units.U)) uel.log(Action.BOLUS_ADVISOR, if (quickWizard) Sources.QuickWizard else Sources.WizardDialog,
notes,
ValueWithUnit.TherapyEventType(eventType.toDBbEventType()),
ValueWithUnit.Insulin(insulinAfterConstraints))
if (insulin > 0) { if (insulin > 0) {
commandQueue.bolus(this, object : Callback() { commandQueue.bolus(this, object : Callback() {
override fun run() { override fun run() {
@ -366,7 +374,7 @@ class BolusWizard @Inject constructor(
OKDialog.showConfirmation(ctx, resourceHelper.gs(R.string.boluswizard), confirmMessage, { OKDialog.showConfirmation(ctx, resourceHelper.gs(R.string.boluswizard), confirmMessage, {
if (insulinAfterConstraints > 0 || carbs > 0) { if (insulinAfterConstraints > 0 || carbs > 0) {
if (useSuperBolus) { if (useSuperBolus) {
uel.log(Action.SUPERBOLUS_TBR) uel.log(Action.SUPERBOLUS_TBR, Sources.WizardDialog)
if (loopPlugin.isEnabled(PluginType.LOOP)) { if (loopPlugin.isEnabled(PluginType.LOOP)) {
loopPlugin.superBolusTo(System.currentTimeMillis() + 2 * 60L * 60 * 1000) loopPlugin.superBolusTo(System.currentTimeMillis() + 2 * 60L * 60 * 1000)
rxBus.send(EventRefreshOverview("WizardDialog")) rxBus.send(EventRefreshOverview("WizardDialog"))
@ -381,7 +389,6 @@ class BolusWizard @Inject constructor(
} }
}) })
} else { } else {
commandQueue.tempBasalPercent(0, 120, true, profile, PumpSync.TemporaryBasalType.NORMAL, object : Callback() { commandQueue.tempBasalPercent(0, 120, true, profile, PumpSync.TemporaryBasalType.NORMAL, object : Callback() {
override fun run() { override fun run() {
if (!result.success) { if (!result.success) {
@ -406,13 +413,18 @@ class BolusWizard @Inject constructor(
carbTime = this@BolusWizard.carbTime carbTime = this@BolusWizard.carbTime
bolusCalculatorResult = createBolusCalculatorResult() bolusCalculatorResult = createBolusCalculatorResult()
notes = this@BolusWizard.notes notes = this@BolusWizard.notes
uel.log(Action.BOLUS, notes,
ValueWithUnit(eventType.toDBbEventType(), Units.TherapyEvent),
ValueWithUnit(insulinAfterConstraints, Units.U),
ValueWithUnit(this@BolusWizard.carbs, Units.G, this@BolusWizard.carbs != 0),
ValueWithUnit(carbTime, Units.M, carbTime != 0)
)
if (insulin > 0 || carbs > 0) { if (insulin > 0 || carbs > 0) {
val action = when {
insulinAfterConstraints.equals(0.0) -> Action.CARBS
carbs.equals(0.0) -> Action.BOLUS
else -> Action.TREATMENT
}
uel.log(action, if (quickWizard) Sources.QuickWizard else Sources.WizardDialog,
notes,
ValueWithUnit.TherapyEventType(eventType.toDBbEventType()),
ValueWithUnit.Insulin(insulinAfterConstraints).takeIf { insulinAfterConstraints != 0.0 },
ValueWithUnit.Gram(this@BolusWizard.carbs).takeIf { this@BolusWizard.carbs != 0 },
ValueWithUnit.Minute(carbTime).takeIf { carbTime != 0 })
commandQueue.bolus(this, object : Callback() { commandQueue.bolus(this, object : Callback() {
override fun run() { override fun run() {
if (!result.success) { if (!result.success) {

View file

@ -124,7 +124,7 @@ class QuickWizardEntry @Inject constructor(private val injector: HasAndroidInjec
trend = true trend = true
} }
val percentage = sp.getInt(R.string.key_boluswizard_percentage, 100) val percentage = sp.getInt(R.string.key_boluswizard_percentage, 100)
return BolusWizard(injector).doCalc(profile, profileName, tempTarget, carbs(), cob, bg, 0.0, percentage, true, useCOB() == YES, bolusIOB, basalIOB, superBolus, useTempTarget() == YES, trend, false, "QuickWizard") return BolusWizard(injector).doCalc(profile, profileName, tempTarget, carbs(), cob, bg, 0.0, percentage, true, useCOB() == YES, bolusIOB, basalIOB, superBolus, useTempTarget() == YES, trend, false, buttonText(), quickWizard = true) //tbc, ok if only quickwizard, but if other sources elsewhere use Sources.QuickWiard
} }
fun buttonText(): String = safeGetString(storage, "buttonText", "") fun buttonText(): String = safeGetString(storage, "buttonText", "")

View file

@ -1,18 +1,44 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical" android:orientation="vertical"
tools:context=".plugins.treatments.fragments.TreatmentsUserEntryFragment"> tools:context=".plugins.treatments.fragments.TreatmentsUserEntryFragment">
<info.nightscout.androidaps.utils.ui.SingleClickButton <LinearLayout
android:id="@+id/ue_export_to_xml"
style="?android:attr/buttonStyle"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" android:orientation="horizontal">
android:drawableStart="@drawable/ic_header_export"
android:text="@string/ue_export_to_csv" /> <info.nightscout.androidaps.utils.ui.SingleClickButton
android:id="@+id/ue_export_to_xml"
style="?android:attr/buttonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:drawableStart="@drawable/ic_header_export"
android:text="@string/ue_export_to_csv" />
<CheckBox
android:id="@+id/show_loop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|center_vertical"
android:checked="false"
android:paddingEnd="5dp"
tools:ignore="RtlSymmetry" />
<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_gravity="center_vertical"
android:contentDescription="@string/show_calculation"
app:srcCompat="@drawable/ic_loop_closed_white" />
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerview" android:id="@+id/recyclerview"

View file

@ -1,42 +1,49 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/info_layout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center" android:orientation="horizontal" >
card_view:cardBackgroundColor="?android:colorBackground">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="true"
android:orientation="horizontal">
<TextView <TextView
android:id="@+id/date" android:id="@+id/date"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingStart="5dp" android:paddingStart="10dp"
android:paddingTop="3dp"
android:text="1.1.2021 09:00" android:text="1.1.2021 09:00"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/iconSource"
app:layout_constraintBottom_toBottomOf="@+id/iconSource"
android:textAppearance="?android:attr/textAppearanceSmall" android:textAppearance="?android:attr/textAppearanceSmall"
tools:ignore="HardcodedText,RtlSymmetry" /> tools:ignore="HardcodedText,RtlSymmetry" />
<TextView <TextView
android:id="@+id/action" android:id="@+id/action"
android:layout_width="wrap_content" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingStart="10dp" android:paddingStart="10dp"
android:paddingTop="3dp"
android:text="USER ENTRY" android:text="USER ENTRY"
android:textAppearance="?android:attr/textAppearanceSmall" app:layout_constraintStart_toEndOf="@id/date"
tools:ignore="HardcodedText,RtlSymmetry" /> app:layout_constraintEnd_toStartOf="@+id/iconSource"
app:layout_constraintTop_toTopOf="parent"
android:textAppearance="?android:attr/textAppearanceSmall" />
<ImageView
android:id="@+id/iconSource"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginEnd="8dp"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/action"
app:layout_constraintBottom_toBottomOf="@+id/action"
app:srcCompat="@drawable/ic_cp_bolus_carbs" />
</LinearLayout>
<TextView <TextView
android:id="@+id/values" android:id="@+id/values"
@ -46,6 +53,8 @@
android:paddingStart="20dp" android:paddingStart="20dp"
android:paddingEnd="10dp" android:paddingEnd="10dp"
android:textStyle="bold" android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/action"
android:visibility="gone" android:visibility="gone"
android:text="Values with units" /> android:text="Values with units" />
@ -54,8 +63,12 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingStart="20dp" android:paddingStart="20dp"
android:visibility="gone" android:paddingEnd="10dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/values"
android:textAppearance="?android:attr/textAppearanceSmall" android:textAppearance="?android:attr/textAppearanceSmall"
android:visibility="gone"
android:text="Notes"
tools:ignore="HardcodedText,RtlSymmetry" /> tools:ignore="HardcodedText,RtlSymmetry" />
<View <View
@ -65,8 +78,9 @@
android:layout_marginStart="5dp" android:layout_marginStart="5dp"
android:layout_marginEnd="5dp" android:layout_marginEnd="5dp"
android:layout_marginTop="5dp" android:layout_marginTop="5dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/s"
android:background="@color/list_delimiter" /> android:background="@color/list_delimiter" />
</LinearLayout>
</androidx.cardview.widget.CardView> </androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -142,7 +142,6 @@
<string name="configbuilder_constraints_description">Which constraints are applied?</string> <string name="configbuilder_constraints_description">Which constraints are applied?</string>
<string name="constraints">Constraints</string> <string name="constraints">Constraints</string>
<string name="loop">Loop</string>
<string name="configbuilder_loop">Loop</string> <string name="configbuilder_loop">Loop</string>
<string name="configbuilder_loop_description">Use this to activate AndroidAPS\' loop integration.</string> <string name="configbuilder_loop_description">Use this to activate AndroidAPS\' loop integration.</string>
<string name="loop_aps_label">APS</string> <string name="loop_aps_label">APS</string>
@ -519,7 +518,6 @@
<string name="openapsama_autosens_period_summary">Amount of hours in the past for sensitivity detection (carbs absorption time is excluded)</string> <string name="openapsama_autosens_period_summary">Amount of hours in the past for sensitivity detection (carbs absorption time is excluded)</string>
<string name="key_openapsama_autosens_period" translatable="false">openapsama_autosens_period</string> <string name="key_openapsama_autosens_period" translatable="false">openapsama_autosens_period</string>
<string name="key_nsclient_localbroadcasts" translatable="false">nsclient_localbroadcasts</string> <string name="key_nsclient_localbroadcasts" translatable="false">nsclient_localbroadcasts</string>
<string name="pump">Pump</string>
<string name="openaps">OpenAPS</string> <string name="openaps">OpenAPS</string>
<string name="uploader">Uploader</string> <string name="uploader">Uploader</string>
<string name="configbuilder_sensitivity">Sensitivity detection</string> <string name="configbuilder_sensitivity">Sensitivity detection</string>

View file

@ -20,7 +20,8 @@ import dagger.android.support.DaggerFragment
import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.automation.R
import info.nightscout.androidaps.automation.databinding.AutomationEventItemBinding import info.nightscout.androidaps.automation.databinding.AutomationEventItemBinding
import info.nightscout.androidaps.automation.databinding.AutomationFragmentBinding import info.nightscout.androidaps.automation.databinding.AutomationFragmentBinding
import info.nightscout.androidaps.database.entities.UserEntry.* import info.nightscout.androidaps.database.entities.UserEntry.Action
import info.nightscout.androidaps.database.entities.UserEntry.Sources
import info.nightscout.androidaps.logging.UserEntryLogger import info.nightscout.androidaps.logging.UserEntryLogger
import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.general.automation.dialogs.EditEventDialog import info.nightscout.androidaps.plugins.general.automation.dialogs.EditEventDialog
@ -217,7 +218,7 @@ class AutomationFragment : DaggerFragment(), OnStartDragListener {
holder.binding.iconTrash.setOnClickListener { holder.binding.iconTrash.setOnClickListener {
OKDialog.showConfirmation(requireContext(), resourceHelper.gs(R.string.removerecord) + " " + automationPlugin.at(position).title, OKDialog.showConfirmation(requireContext(), resourceHelper.gs(R.string.removerecord) + " " + automationPlugin.at(position).title,
{ {
uel.log(Action.AUTOMATION_REMOVED, automationPlugin.at(position).title) uel.log(Action.AUTOMATION_REMOVED, Sources.Automation, automationPlugin.at(position).title)
automationPlugin.removeAt(position) automationPlugin.removeAt(position)
notifyItemRemoved(position) notifyItemRemoved(position)
}, { }, {
@ -240,7 +241,7 @@ class AutomationFragment : DaggerFragment(), OnStartDragListener {
activity?.let { activity -> activity?.let { activity ->
OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.removerecord) + " " + automationPlugin.at(position).title, OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.removerecord) + " " + automationPlugin.at(position).title,
Runnable { Runnable {
uel.log(Action.AUTOMATION_REMOVED, automationPlugin.at(position).title) uel.log(Action.AUTOMATION_REMOVED, Sources.Automation, automationPlugin.at(position).title)
automationPlugin.removeAt(position) automationPlugin.removeAt(position)
notifyItemRemoved(position) notifyItemRemoved(position)
rxBus.send(EventAutomationDataChanged()) rxBus.send(EventAutomationDataChanged())

View file

@ -203,6 +203,7 @@ class AutomationPlugin @Inject constructor(
if (event.systemAction || userEventsEnabled) { if (event.systemAction || userEventsEnabled) {
val actions = event.actions val actions = event.actions
for (action in actions) { for (action in actions) {
action.title = event.title
if (action.isValid()) if (action.isValid())
action.doAction(object : Callback() { action.doAction(object : Callback() {
override fun run() { override fun run() {

View file

@ -23,6 +23,8 @@ abstract class Action(val injector: HasAndroidInjector) {
abstract fun isValid(): Boolean abstract fun isValid(): Boolean
@DrawableRes abstract fun icon(): Int @DrawableRes abstract fun icon(): Int
var title = ""
init { init {
injector.androidInjector().inject(this) injector.androidInjector().inject(this)
} }

View file

@ -4,12 +4,15 @@ import androidx.annotation.DrawableRes
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.automation.R
import info.nightscout.androidaps.data.PumpEnactResult import info.nightscout.androidaps.data.PumpEnactResult
import info.nightscout.androidaps.database.entities.UserEntry
import info.nightscout.androidaps.database.entities.UserEntry.Sources
import info.nightscout.androidaps.events.EventRefreshOverview import info.nightscout.androidaps.events.EventRefreshOverview
import info.nightscout.androidaps.interfaces.CommandQueueProvider import info.nightscout.androidaps.interfaces.CommandQueueProvider
import info.nightscout.androidaps.interfaces.ConfigBuilderInterface import info.nightscout.androidaps.interfaces.ConfigBuilderInterface
import info.nightscout.androidaps.interfaces.LoopInterface import info.nightscout.androidaps.interfaces.LoopInterface
import info.nightscout.androidaps.interfaces.PluginBase import info.nightscout.androidaps.interfaces.PluginBase
import info.nightscout.androidaps.interfaces.PluginType import info.nightscout.androidaps.interfaces.PluginType
import info.nightscout.androidaps.logging.UserEntryLogger
import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.queue.Callback import info.nightscout.androidaps.queue.Callback
import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.resources.ResourceHelper
@ -21,6 +24,7 @@ class ActionLoopDisable(injector: HasAndroidInjector) : Action(injector) {
@Inject lateinit var configBuilderPlugin: ConfigBuilderInterface @Inject lateinit var configBuilderPlugin: ConfigBuilderInterface
@Inject lateinit var commandQueue: CommandQueueProvider @Inject lateinit var commandQueue: CommandQueueProvider
@Inject lateinit var rxBus: RxBusWrapper @Inject lateinit var rxBus: RxBusWrapper
@Inject lateinit var uel: UserEntryLogger
override fun friendlyName(): Int = R.string.disableloop override fun friendlyName(): Int = R.string.disableloop
override fun shortDescription(): String = resourceHelper.gs(R.string.disableloop) override fun shortDescription(): String = resourceHelper.gs(R.string.disableloop)
@ -30,6 +34,7 @@ class ActionLoopDisable(injector: HasAndroidInjector) : Action(injector) {
if ((loopPlugin as PluginBase).isEnabled()) { if ((loopPlugin as PluginBase).isEnabled()) {
(loopPlugin as PluginBase).setPluginEnabled(PluginType.LOOP, false) (loopPlugin as PluginBase).setPluginEnabled(PluginType.LOOP, false)
configBuilderPlugin.storeSettings("ActionLoopDisable") configBuilderPlugin.storeSettings("ActionLoopDisable")
uel.log(UserEntry.Action.LOOP_DISABLED, Sources.Automation, title)
commandQueue.cancelTempBasal(true, object : Callback() { commandQueue.cancelTempBasal(true, object : Callback() {
override fun run() { override fun run() {
rxBus.send(EventRefreshOverview("ActionLoopDisable")) rxBus.send(EventRefreshOverview("ActionLoopDisable"))

View file

@ -4,11 +4,14 @@ import androidx.annotation.DrawableRes
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.automation.R
import info.nightscout.androidaps.data.PumpEnactResult import info.nightscout.androidaps.data.PumpEnactResult
import info.nightscout.androidaps.database.entities.UserEntry
import info.nightscout.androidaps.database.entities.UserEntry.Sources
import info.nightscout.androidaps.events.EventRefreshOverview import info.nightscout.androidaps.events.EventRefreshOverview
import info.nightscout.androidaps.interfaces.ConfigBuilderInterface import info.nightscout.androidaps.interfaces.ConfigBuilderInterface
import info.nightscout.androidaps.interfaces.LoopInterface import info.nightscout.androidaps.interfaces.LoopInterface
import info.nightscout.androidaps.interfaces.PluginBase import info.nightscout.androidaps.interfaces.PluginBase
import info.nightscout.androidaps.interfaces.PluginType import info.nightscout.androidaps.interfaces.PluginType
import info.nightscout.androidaps.logging.UserEntryLogger
import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.queue.Callback import info.nightscout.androidaps.queue.Callback
import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.resources.ResourceHelper
@ -20,6 +23,7 @@ class ActionLoopEnable(injector: HasAndroidInjector) : Action(injector) {
@Inject lateinit var loopPlugin: LoopInterface @Inject lateinit var loopPlugin: LoopInterface
@Inject lateinit var configBuilderPlugin: ConfigBuilderInterface @Inject lateinit var configBuilderPlugin: ConfigBuilderInterface
@Inject lateinit var rxBus: RxBusWrapper @Inject lateinit var rxBus: RxBusWrapper
@Inject lateinit var uel: UserEntryLogger
override fun friendlyName(): Int = R.string.enableloop override fun friendlyName(): Int = R.string.enableloop
override fun shortDescription(): String = resourceHelper.gs(R.string.enableloop) override fun shortDescription(): String = resourceHelper.gs(R.string.enableloop)
@ -30,6 +34,7 @@ class ActionLoopEnable(injector: HasAndroidInjector) : Action(injector) {
(loopPlugin as PluginBase).setPluginEnabled(PluginType.LOOP, true) (loopPlugin as PluginBase).setPluginEnabled(PluginType.LOOP, true)
configBuilderPlugin.storeSettings("ActionLoopEnable") configBuilderPlugin.storeSettings("ActionLoopEnable")
rxBus.send(EventRefreshOverview("ActionLoopEnable")) rxBus.send(EventRefreshOverview("ActionLoopEnable"))
uel.log(UserEntry.Action.LOOP_ENABLED, Sources.Automation, title)
callback.result(PumpEnactResult(injector).success(true).comment(R.string.ok))?.run() callback.result(PumpEnactResult(injector).success(true).comment(R.string.ok))?.run()
} else { } else {
callback.result(PumpEnactResult(injector).success(true).comment(R.string.alreadyenabled))?.run() callback.result(PumpEnactResult(injector).success(true).comment(R.string.alreadyenabled))?.run()

View file

@ -4,9 +4,12 @@ import androidx.annotation.DrawableRes
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.automation.R
import info.nightscout.androidaps.data.PumpEnactResult import info.nightscout.androidaps.data.PumpEnactResult
import info.nightscout.androidaps.database.entities.UserEntry
import info.nightscout.androidaps.database.entities.UserEntry.Sources
import info.nightscout.androidaps.events.EventRefreshOverview import info.nightscout.androidaps.events.EventRefreshOverview
import info.nightscout.androidaps.interfaces.ConfigBuilderInterface import info.nightscout.androidaps.interfaces.ConfigBuilderInterface
import info.nightscout.androidaps.interfaces.LoopInterface import info.nightscout.androidaps.interfaces.LoopInterface
import info.nightscout.androidaps.logging.UserEntryLogger
import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.queue.Callback import info.nightscout.androidaps.queue.Callback
import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.resources.ResourceHelper
@ -17,6 +20,7 @@ class ActionLoopResume(injector: HasAndroidInjector) : Action(injector) {
@Inject lateinit var loopPlugin: LoopInterface @Inject lateinit var loopPlugin: LoopInterface
@Inject lateinit var configBuilderPlugin: ConfigBuilderInterface @Inject lateinit var configBuilderPlugin: ConfigBuilderInterface
@Inject lateinit var rxBus: RxBusWrapper @Inject lateinit var rxBus: RxBusWrapper
@Inject lateinit var uel: UserEntryLogger
override fun friendlyName(): Int = R.string.resumeloop override fun friendlyName(): Int = R.string.resumeloop
override fun shortDescription(): String = resourceHelper.gs(R.string.resumeloop) override fun shortDescription(): String = resourceHelper.gs(R.string.resumeloop)
@ -28,6 +32,7 @@ class ActionLoopResume(injector: HasAndroidInjector) : Action(injector) {
configBuilderPlugin.storeSettings("ActionLoopResume") configBuilderPlugin.storeSettings("ActionLoopResume")
loopPlugin.createOfflineEvent(0) loopPlugin.createOfflineEvent(0)
rxBus.send(EventRefreshOverview("ActionLoopResume")) rxBus.send(EventRefreshOverview("ActionLoopResume"))
uel.log(UserEntry.Action.RESUME, Sources.Automation, title)
callback.result(PumpEnactResult(injector).success(true).comment(R.string.ok))?.run() callback.result(PumpEnactResult(injector).success(true).comment(R.string.ok))?.run()
} else { } else {
callback.result(PumpEnactResult(injector).success(true).comment(R.string.notsuspended))?.run() callback.result(PumpEnactResult(injector).success(true).comment(R.string.notsuspended))?.run()

View file

@ -5,8 +5,12 @@ import androidx.annotation.DrawableRes
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.automation.R
import info.nightscout.androidaps.data.PumpEnactResult import info.nightscout.androidaps.data.PumpEnactResult
import info.nightscout.androidaps.database.entities.UserEntry
import info.nightscout.androidaps.database.entities.UserEntry.Sources
import info.nightscout.androidaps.database.entities.ValueWithUnit
import info.nightscout.androidaps.events.EventRefreshOverview import info.nightscout.androidaps.events.EventRefreshOverview
import info.nightscout.androidaps.interfaces.LoopInterface import info.nightscout.androidaps.interfaces.LoopInterface
import info.nightscout.androidaps.logging.UserEntryLogger
import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.general.automation.elements.InputDuration import info.nightscout.androidaps.plugins.general.automation.elements.InputDuration
import info.nightscout.androidaps.plugins.general.automation.elements.LabelWithElement import info.nightscout.androidaps.plugins.general.automation.elements.LabelWithElement
@ -21,6 +25,7 @@ class ActionLoopSuspend(injector: HasAndroidInjector) : Action(injector) {
@Inject lateinit var resourceHelper: ResourceHelper @Inject lateinit var resourceHelper: ResourceHelper
@Inject lateinit var loopPlugin: LoopInterface @Inject lateinit var loopPlugin: LoopInterface
@Inject lateinit var rxBus: RxBusWrapper @Inject lateinit var rxBus: RxBusWrapper
@Inject lateinit var uel: UserEntryLogger
var minutes = InputDuration(30, InputDuration.TimeUnit.MINUTES) var minutes = InputDuration(30, InputDuration.TimeUnit.MINUTES)
@ -32,6 +37,8 @@ class ActionLoopSuspend(injector: HasAndroidInjector) : Action(injector) {
if (!loopPlugin.isSuspended) { if (!loopPlugin.isSuspended) {
loopPlugin.suspendLoop(minutes.getMinutes()) loopPlugin.suspendLoop(minutes.getMinutes())
rxBus.send(EventRefreshOverview("ActionLoopSuspend")) rxBus.send(EventRefreshOverview("ActionLoopSuspend"))
uel.log(UserEntry.Action.SUSPEND, Sources.Automation, title,
ValueWithUnit.StringResource(R.string.suspendloopforXmin, listOf(ValueWithUnit.Minute(minutes.getMinutes()))))
callback.result(PumpEnactResult(injector).success(true).comment(R.string.ok))?.run() callback.result(PumpEnactResult(injector).success(true).comment(R.string.ok))?.run()
} else { } else {
callback.result(PumpEnactResult(injector).success(true).comment(R.string.alreadysuspended))?.run() callback.result(PumpEnactResult(injector).success(true).comment(R.string.alreadysuspended))?.run()

View file

@ -5,9 +5,13 @@ import androidx.annotation.DrawableRes
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.automation.R
import info.nightscout.androidaps.data.PumpEnactResult import info.nightscout.androidaps.data.PumpEnactResult
import info.nightscout.androidaps.database.entities.UserEntry
import info.nightscout.androidaps.database.entities.UserEntry.Sources
import info.nightscout.androidaps.database.entities.ValueWithUnit
import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.interfaces.ActivePluginProvider
import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.interfaces.ProfileFunction
import info.nightscout.androidaps.logging.UserEntryLogger
import info.nightscout.androidaps.plugins.general.automation.elements.InputProfileName import info.nightscout.androidaps.plugins.general.automation.elements.InputProfileName
import info.nightscout.androidaps.plugins.general.automation.elements.LabelWithElement import info.nightscout.androidaps.plugins.general.automation.elements.LabelWithElement
import info.nightscout.androidaps.plugins.general.automation.elements.LayoutBuilder import info.nightscout.androidaps.plugins.general.automation.elements.LayoutBuilder
@ -22,6 +26,7 @@ class ActionProfileSwitch(injector: HasAndroidInjector) : Action(injector) {
@Inject lateinit var resourceHelper: ResourceHelper @Inject lateinit var resourceHelper: ResourceHelper
@Inject lateinit var activePlugin: ActivePluginProvider @Inject lateinit var activePlugin: ActivePluginProvider
@Inject lateinit var profileFunction: ProfileFunction @Inject lateinit var profileFunction: ProfileFunction
@Inject lateinit var uel: UserEntryLogger
var inputProfileName: InputProfileName = InputProfileName(resourceHelper, activePlugin, "") var inputProfileName: InputProfileName = InputProfileName(resourceHelper, activePlugin, "")
@ -53,6 +58,9 @@ class ActionProfileSwitch(injector: HasAndroidInjector) : Action(injector) {
callback.result(PumpEnactResult(injector).success(false).comment(R.string.notexists))?.run() callback.result(PumpEnactResult(injector).success(false).comment(R.string.notexists))?.run()
return return
} }
uel.log(UserEntry.Action.PROFILE_SWITCH, Sources.Automation, title,
ValueWithUnit.SimpleString(inputProfileName.value),
ValueWithUnit.Percent(100))
activePlugin.activeTreatments.doProfileSwitch(profileStore, inputProfileName.value, 0, 100, 0, DateUtil.now()) activePlugin.activeTreatments.doProfileSwitch(profileStore, inputProfileName.value, 0, 100, 0, DateUtil.now())
callback.result(PumpEnactResult(injector).success(true).comment(R.string.ok))?.run() callback.result(PumpEnactResult(injector).success(true).comment(R.string.ok))?.run()
} }

View file

@ -5,7 +5,11 @@ import androidx.annotation.DrawableRes
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.automation.R
import info.nightscout.androidaps.data.PumpEnactResult import info.nightscout.androidaps.data.PumpEnactResult
import info.nightscout.androidaps.database.entities.UserEntry
import info.nightscout.androidaps.database.entities.UserEntry.Sources
import info.nightscout.androidaps.database.entities.ValueWithUnit
import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.interfaces.ActivePluginProvider
import info.nightscout.androidaps.logging.UserEntryLogger
import info.nightscout.androidaps.plugins.general.automation.elements.Comparator import info.nightscout.androidaps.plugins.general.automation.elements.Comparator
import info.nightscout.androidaps.plugins.general.automation.elements.InputDuration import info.nightscout.androidaps.plugins.general.automation.elements.InputDuration
import info.nightscout.androidaps.plugins.general.automation.elements.InputPercent import info.nightscout.androidaps.plugins.general.automation.elements.InputPercent
@ -21,6 +25,7 @@ import javax.inject.Inject
class ActionProfileSwitchPercent(injector: HasAndroidInjector) : Action(injector) { class ActionProfileSwitchPercent(injector: HasAndroidInjector) : Action(injector) {
@Inject lateinit var resourceHelper: ResourceHelper @Inject lateinit var resourceHelper: ResourceHelper
@Inject lateinit var activePlugin: ActivePluginProvider @Inject lateinit var activePlugin: ActivePluginProvider
@Inject lateinit var uel: UserEntryLogger
var pct = InputPercent() var pct = InputPercent()
var duration = InputDuration(30, InputDuration.TimeUnit.MINUTES) var duration = InputDuration(30, InputDuration.TimeUnit.MINUTES)
@ -37,6 +42,8 @@ class ActionProfileSwitchPercent(injector: HasAndroidInjector) : Action(injector
} }
override fun doAction(callback: Callback) { override fun doAction(callback: Callback) {
uel.log(UserEntry.Action.PROFILE_SWITCH, Sources.Automation, title,
ValueWithUnit.StringResource( R.string.startprofile, listOf(ValueWithUnit.Percent(pct.value.toInt()), ValueWithUnit.Minute(duration.value))))
activePlugin.activeTreatments.doProfileSwitch(duration.value, pct.value.toInt(), 0) activePlugin.activeTreatments.doProfileSwitch(duration.value, pct.value.toInt(), 0)
callback.result(PumpEnactResult(injector).success(true).comment(R.string.ok))?.run() callback.result(PumpEnactResult(injector).success(true).comment(R.string.ok))?.run()
} }

View file

@ -9,10 +9,14 @@ import info.nightscout.androidaps.data.Profile
import info.nightscout.androidaps.data.PumpEnactResult import info.nightscout.androidaps.data.PumpEnactResult
import info.nightscout.androidaps.database.AppRepository import info.nightscout.androidaps.database.AppRepository
import info.nightscout.androidaps.database.entities.TemporaryTarget import info.nightscout.androidaps.database.entities.TemporaryTarget
import info.nightscout.androidaps.database.entities.UserEntry
import info.nightscout.androidaps.database.entities.UserEntry.Sources
import info.nightscout.androidaps.database.entities.ValueWithUnit
import info.nightscout.androidaps.database.transactions.InsertTemporaryTargetAndCancelCurrentTransaction import info.nightscout.androidaps.database.transactions.InsertTemporaryTargetAndCancelCurrentTransaction
import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.interfaces.ActivePluginProvider
import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.interfaces.ProfileFunction
import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.logging.UserEntryLogger
import info.nightscout.androidaps.plugins.general.automation.elements.ComparatorExists import info.nightscout.androidaps.plugins.general.automation.elements.ComparatorExists
import info.nightscout.androidaps.plugins.general.automation.elements.InputDuration import info.nightscout.androidaps.plugins.general.automation.elements.InputDuration
import info.nightscout.androidaps.plugins.general.automation.elements.InputTempTarget import info.nightscout.androidaps.plugins.general.automation.elements.InputTempTarget
@ -37,6 +41,7 @@ class ActionStartTempTarget(injector: HasAndroidInjector) : Action(injector) {
@Inject lateinit var activePlugin: ActivePluginProvider @Inject lateinit var activePlugin: ActivePluginProvider
@Inject lateinit var repository: AppRepository @Inject lateinit var repository: AppRepository
@Inject lateinit var profileFunction: ProfileFunction @Inject lateinit var profileFunction: ProfileFunction
@Inject lateinit var uel: UserEntryLogger
private val disposable = CompositeDisposable() private val disposable = CompositeDisposable()
@ -56,6 +61,11 @@ class ActionStartTempTarget(injector: HasAndroidInjector) : Action(injector) {
.subscribe({ result -> .subscribe({ result ->
result.inserted.forEach { aapsLogger.debug(LTag.DATABASE, "Inserted temp target $it") } result.inserted.forEach { aapsLogger.debug(LTag.DATABASE, "Inserted temp target $it") }
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,
ValueWithUnit.TherapyEventTTReason(TemporaryTarget.Reason.AUTOMATION),
ValueWithUnit.fromGlucoseUnit(tt().lowTarget, Constants.MGDL),
ValueWithUnit.fromGlucoseUnit(tt().highTarget, Constants.MGDL).takeIf { tt().lowTarget != tt().highTarget },
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()
}, { }, {
aapsLogger.error(LTag.DATABASE, "Error while saving temporary target", it) aapsLogger.error(LTag.DATABASE, "Error while saving temporary target", it)

View file

@ -4,8 +4,11 @@ import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.automation.R
import info.nightscout.androidaps.data.PumpEnactResult import info.nightscout.androidaps.data.PumpEnactResult
import info.nightscout.androidaps.database.AppRepository import info.nightscout.androidaps.database.AppRepository
import info.nightscout.androidaps.database.entities.UserEntry
import info.nightscout.androidaps.database.entities.UserEntry.Sources
import info.nightscout.androidaps.database.transactions.CancelCurrentTemporaryTargetIfAnyTransaction import info.nightscout.androidaps.database.transactions.CancelCurrentTemporaryTargetIfAnyTransaction
import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.logging.UserEntryLogger
import info.nightscout.androidaps.queue.Callback import info.nightscout.androidaps.queue.Callback
import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.resources.ResourceHelper
@ -18,6 +21,7 @@ class ActionStopTempTarget(injector: HasAndroidInjector) : Action(injector) {
@Inject lateinit var resourceHelper: ResourceHelper @Inject lateinit var resourceHelper: ResourceHelper
@Inject lateinit var repository: AppRepository @Inject lateinit var repository: AppRepository
@Inject lateinit var dateUtil: DateUtil @Inject lateinit var dateUtil: DateUtil
@Inject lateinit var uel: UserEntryLogger
private val disposable = CompositeDisposable() private val disposable = CompositeDisposable()
@ -28,6 +32,7 @@ class ActionStopTempTarget(injector: HasAndroidInjector) : Action(injector) {
override fun doAction(callback: Callback) { override fun doAction(callback: Callback) {
disposable += repository.runTransactionForResult(CancelCurrentTemporaryTargetIfAnyTransaction(dateUtil._now())) disposable += repository.runTransactionForResult(CancelCurrentTemporaryTargetIfAnyTransaction(dateUtil._now()))
.subscribe({ result -> .subscribe({ result ->
uel.log(UserEntry.Action.CANCEL_TT, Sources.Automation, title)
result.updated.forEach { aapsLogger.debug(LTag.DATABASE, "Updated temp target $it") } result.updated.forEach { aapsLogger.debug(LTag.DATABASE, "Updated temp target $it") }
}, { }, {
aapsLogger.error(LTag.DATABASE, "Error while saving temporary target", it) aapsLogger.error(LTag.DATABASE, "Error while saving temporary target", it)

View file

@ -25,7 +25,6 @@
<string name="alreadyset">Already set</string> <string name="alreadyset">Already set</string>
<string name="profilepercentage">Profile percentage</string> <string name="profilepercentage">Profile percentage</string>
<string name="startprofileforever">Start profile %1$d%%</string> <string name="startprofileforever">Start profile %1$d%%</string>
<string name="startprofile">Start profile %1$d%% for %2$d min</string>
<string name="percent_u">Percent [%]:</string> <string name="percent_u">Percent [%]:</string>
<string name="sendsmsactionlabel">Send SMS: %1$s</string> <string name="sendsmsactionlabel">Send SMS: %1$s</string>
<string name="sendsmsactiondescription">Send SMS to all numbers</string> <string name="sendsmsactiondescription">Send SMS to all numbers</string>

View file

@ -1,14 +1,14 @@
package info.nightscout.androidaps; package info.nightscout.androidaps;
import info.nightscout.androidaps.database.entities.ValueWithUnit;
import info.nightscout.androidaps.utils.T; import info.nightscout.androidaps.utils.T;
import info.nightscout.androidaps.database.entities.UserEntry.*;
/** /**
* Created by mike on 07.06.2016. * Created by mike on 07.06.2016.
*/ */
public class Constants { public class Constants {
public static final String MGDL = Units.Mg_Dl.getText(); // This is Nightscout's representation public static final String MGDL = ValueWithUnit.MGDL; // This is Nightscout's representation
public static final String MMOL = Units.Mmol_L.getText(); public static final String MMOL = ValueWithUnit.MMOL;
public static final double MMOLL_TO_MGDL = 18; // 18.0182; public static final double MMOLL_TO_MGDL = 18; // 18.0182;
public static final double MGDL_TO_MMOLL = 1 / MMOLL_TO_MGDL; public static final double MGDL_TO_MMOLL = 1 / MMOLL_TO_MGDL;

View file

@ -11,11 +11,13 @@ import dagger.android.support.DaggerDialogFragment
import info.nightscout.androidaps.activities.ErrorHelperActivity import info.nightscout.androidaps.activities.ErrorHelperActivity
import info.nightscout.androidaps.core.R import info.nightscout.androidaps.core.R
import info.nightscout.androidaps.core.databinding.DialogErrorBinding import info.nightscout.androidaps.core.databinding.DialogErrorBinding
import info.nightscout.androidaps.database.entities.UserEntry.* import info.nightscout.androidaps.database.entities.UserEntry.Action
import info.nightscout.androidaps.database.entities.UserEntry.Sources
import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.UserEntryLogger import info.nightscout.androidaps.logging.UserEntryLogger
import info.nightscout.androidaps.services.AlarmSoundServiceHelper import info.nightscout.androidaps.services.AlarmSoundServiceHelper
import info.nightscout.androidaps.utils.T import info.nightscout.androidaps.utils.T
import org.mozilla.javascript.tools.jsc.Main
import javax.inject.Inject import javax.inject.Inject
class ErrorDialog : DaggerDialogFragment() { class ErrorDialog : DaggerDialogFragment() {
@ -59,15 +61,15 @@ class ErrorDialog : DaggerDialogFragment() {
binding.title.text = title binding.title.text = title
binding.ok.setOnClickListener { binding.ok.setOnClickListener {
uel.log(Action.ERROR_DIALOG_OK) uel.log(Action.ERROR_DIALOG_OK, Sources.Unknown)
dismiss() dismiss()
} }
binding.mute.setOnClickListener { binding.mute.setOnClickListener {
uel.log(Action.ERROR_DIALOG_MUTE) uel.log(Action.ERROR_DIALOG_MUTE, Sources.Unknown)
stopAlarm() stopAlarm()
} }
binding.mute5min.setOnClickListener { binding.mute5min.setOnClickListener {
uel.log(Action.ERROR_DIALOG_MUTE_5MIN) uel.log(Action.ERROR_DIALOG_MUTE_5MIN, Sources.Unknown)
stopAlarm() stopAlarm()
loopHandler.postDelayed(this::startAlarm, T.mins(5).msecs()) loopHandler.postDelayed(this::startAlarm, T.mins(5).msecs())
} }

View file

@ -1,8 +1,9 @@
package info.nightscout.androidaps.logging package info.nightscout.androidaps.logging
import info.nightscout.androidaps.database.AppRepository import info.nightscout.androidaps.database.AppRepository
import info.nightscout.androidaps.database.entities.ValueWithUnit
import info.nightscout.androidaps.database.entities.UserEntry.Action import info.nightscout.androidaps.database.entities.UserEntry.Action
import info.nightscout.androidaps.database.entities.UserEntry.ValueWithUnit import info.nightscout.androidaps.database.entities.UserEntry.Sources
import info.nightscout.androidaps.database.transactions.UserEntryTransaction import info.nightscout.androidaps.database.transactions.UserEntryTransaction
import info.nightscout.androidaps.utils.rx.AapsSchedulers import info.nightscout.androidaps.utils.rx.AapsSchedulers
import io.reactivex.disposables.CompositeDisposable import io.reactivex.disposables.CompositeDisposable
@ -20,66 +21,23 @@ class UserEntryLogger @Inject constructor(
private val compositeDisposable = CompositeDisposable() private val compositeDisposable = CompositeDisposable()
fun log(action: Action, s: String? ="", vararg listvalues: ValueWithUnit) { fun log(action: Action, source: Sources, note: String? ="", vararg listvalues: ValueWithUnit?) = log(action, source, note, listvalues.toList())
val values = mutableListOf<ValueWithUnit>()
for (v in listvalues){
if (v.condition) values.add(v)
}
compositeDisposable += repository.runTransaction(UserEntryTransaction(
action = action,
s = s ?:"",
values = values
))
.subscribeOn(aapsSchedulers.io)
.observeOn(aapsSchedulers.io)
.subscribeBy(
onError = { aapsLogger.debug("ERRORED USER ENTRY: $action $s $values") },
onComplete = { aapsLogger.debug("USER ENTRY: $action $s $values") }
)
}
fun log(action: Action, vararg listValues: ValueWithUnit) { fun log(action: Action, source: Sources, vararg listvalues: ValueWithUnit?) = log(action, source,"", listvalues.toList())
val values = mutableListOf<ValueWithUnit>()
for (v in listValues){
if (v.condition) values.add(v)
}
compositeDisposable += repository.runTransaction(UserEntryTransaction(
action = action,
s = "",
values = values
))
.subscribeOn(aapsSchedulers.io)
.observeOn(aapsSchedulers.io)
.subscribeBy(
onError = { aapsLogger.debug("ERRORED USER ENTRY: $action $values") },
onComplete = { aapsLogger.debug("USER ENTRY: $action $values") }
)
}
fun log(action: Action, s: String? = "") { fun log(action: Action, source: Sources, note: String? ="", listvalues: List<ValueWithUnit?> = listOf()) {
val filteredValues = listvalues.toList().filter { it != null}
compositeDisposable += repository.runTransaction(UserEntryTransaction( compositeDisposable += repository.runTransaction(UserEntryTransaction(
action = action, action = action,
s = s ?:"" source = source,
note = note ?: "",
values = filteredValues
)) ))
.subscribeOn(aapsSchedulers.io) .subscribeOn(aapsSchedulers.io)
.observeOn(aapsSchedulers.io) .observeOn(aapsSchedulers.io)
.subscribeBy( .subscribeBy(
onError = { aapsLogger.debug("ERRORED USER ENTRY: $action") }, onError = { aapsLogger.debug("ERRORED USER ENTRY: $action $source $note $filteredValues") },
onComplete = { aapsLogger.debug("USER ENTRY: $action") } onComplete = { aapsLogger.debug("USER ENTRY: $action $source $note $filteredValues") }
)
}
fun log(action: Action, s: String? = "", values: MutableList<ValueWithUnit>) {
compositeDisposable += repository.runTransaction(UserEntryTransaction(
action = action,
s = s ?:"",
values = values
))
.subscribeOn(aapsSchedulers.io)
.observeOn(aapsSchedulers.io)
.subscribeBy(
onError = { aapsLogger.debug("ERRORED USER ENTRY: $action $s $values") },
onComplete = { aapsLogger.debug("USER ENTRY: $action $s $values") }
) )
} }
} }

View file

@ -3,11 +3,10 @@ package info.nightscout.androidaps.plugins.general.maintenance.formats
import info.nightscout.androidaps.Constants import info.nightscout.androidaps.Constants
import info.nightscout.androidaps.core.R import info.nightscout.androidaps.core.R
import info.nightscout.androidaps.database.entities.UserEntry import info.nightscout.androidaps.database.entities.UserEntry
import info.nightscout.androidaps.database.entities.UserEntry.*
import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.interfaces.ProfileFunction
import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.DecimalFormatter
import info.nightscout.androidaps.utils.Translator import info.nightscout.androidaps.utils.Translator
import info.nightscout.androidaps.utils.UserEntryPresentationHelper
import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.storage.Storage import info.nightscout.androidaps.utils.storage.Storage
import java.io.File import java.io.File
@ -22,6 +21,7 @@ class ClassicPrefsFormat @Inject constructor(
private var dateUtil: DateUtil, private var dateUtil: DateUtil,
private var translator: Translator, private var translator: Translator,
private var profileFunction: ProfileFunction, private var profileFunction: ProfileFunction,
private var userEntryPresentationHelper: UserEntryPresentationHelper,
private var storage: Storage private var storage: Storage
) : PrefsFormat { ) : PrefsFormat {
@ -78,7 +78,7 @@ class ClassicPrefsFormat @Inject constructor(
fun saveCsv(file: File, userEntries: List<UserEntry>) { fun saveCsv(file: File, userEntries: List<UserEntry>) {
try { try {
val contents = UserEntriesToCsv(userEntries) val contents = userEntryPresentationHelper.userEntriesToCsv(userEntries)
storage.putFileContents(file, contents) storage.putFileContents(file, contents)
} catch (e: FileNotFoundException) { } catch (e: FileNotFoundException) {
throw PrefFileNotFoundError(file.absolutePath) throw PrefFileNotFoundError(file.absolutePath)
@ -86,47 +86,4 @@ class ClassicPrefsFormat @Inject constructor(
throw PrefIOError(file.absolutePath) throw PrefIOError(file.absolutePath)
} }
} }
fun UserEntriesToCsv(userEntries: List<UserEntry>): String {
val userEntryHeader = resourceHelper.gs(R.string.ue_csv_header) + "\n"
return userEntryHeader + userEntries.joinToString("\n") { entry ->
if (entry.values.size > 0) {
entry.values.joinToString("\n") { value ->
entry.timestamp.toString() + ";" +
dateUtil.dateAndTimeAndSecondsString(entry.timestamp) + ";" +
dateUtil.timeString(entry.utcOffset) + ";" +
csvString(entry.action) + ";" +
csvString(entry.s) + ";" +
valueWithUnitToCsv(value)
}
} else {
entry.timestamp.toString() + ";" +
dateUtil.dateAndTimeAndSecondsString(entry.timestamp) + ";" +
dateUtil.timeString(entry.utcOffset) + ";" +
csvString(entry.action) + ";" +
csvString(entry.s) + ";;"
}
}
}
fun valueWithUnitToCsv(v: ValueWithUnit): String {
return when (v.unit) {
Units.Timestamp -> dateUtil.dateAndTimeAndSecondsString(v.lValue) + ";" + csvString(R.string.date)
Units.TherapyEvent -> csvString(translator.translate(v.sValue)) + ";"
Units.R_String -> if (v.lValue.toInt() == 0) csvString(v.iValue) + ";" else ";" //If lValue > 0 it's a formated string, so hidden for
Units.Mg_Dl -> if (profileFunction.getUnits()==Constants.MGDL) DecimalFormatter.to0Decimal(v.dValue) + ";" + csvString(Units.Mg_Dl) else DecimalFormatter.to1Decimal(v.dValue/Constants.MMOLL_TO_MGDL) + ";" + csvString(Units.Mmol_L)
Units.Mmol_L -> if (profileFunction.getUnits()==Constants.MGDL) DecimalFormatter.to0Decimal(v.dValue*Constants.MMOLL_TO_MGDL) + ";" + csvString(Units.Mg_Dl) else DecimalFormatter.to1Decimal(v.dValue) + ";" + csvString(Units.Mmol_L)
Units.U_H, Units.U -> DecimalFormatter.to2Decimal(v.dValue) + ";" + csvString(v.unit)
Units.G, Units.M, Units.H, Units.Percent
-> v.iValue.toString() + ";" + csvString(v.unit)
else -> if (v.sValue != "") { csvString(v.sValue) + ";" + csvString(v.unit)}
else if (v.iValue != 0) { v.iValue.toString() + ";" + csvString(v.unit)}
else ";"
}
}
private fun csvString(action: Action): String = "\"" + translator.translate(action.name).replace("\"", "\"\"") + "\""
private fun csvString(unit: Units): String = "\"" + translator.translate(unit.name).replace("\"", "\"\"") + "\""
private fun csvString(id: Int): String = if (id != 0) "\"" + resourceHelper.gs(id).replace("\"", "\"\"") + "\"" else ""
private fun csvString(s: String): String = if (s != "") "\"" + s.replace("\"", "\"\"") + "\"" else ""
} }

View file

@ -158,7 +158,7 @@ public class NSUpload {
/* /*
JSONObject data = new JSONObject(); JSONObject data = new JSONObject();
try { try {
data.put("eventType", detailedBolusInfo.eventType); data.put("eventType", detailedBolusInfo.eventType.getText());
if (detailedBolusInfo.insulin != 0d) data.put("insulin", detailedBolusInfo.insulin); if (detailedBolusInfo.insulin != 0d) data.put("insulin", detailedBolusInfo.insulin);
if (detailedBolusInfo.carbs != 0d) data.put("carbs", (int) detailedBolusInfo.carbs); if (detailedBolusInfo.carbs != 0d) data.put("carbs", (int) detailedBolusInfo.carbs);
data.put("created_at", DateUtil.toISOString(detailedBolusInfo.timestamp)); data.put("created_at", DateUtil.toISOString(detailedBolusInfo.timestamp));

View file

@ -3,7 +3,9 @@ package info.nightscout.androidaps.utils
import info.nightscout.androidaps.core.R import info.nightscout.androidaps.core.R
import info.nightscout.androidaps.database.entities.TemporaryTarget import info.nightscout.androidaps.database.entities.TemporaryTarget
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.UserEntry.Action
import info.nightscout.androidaps.database.entities.UserEntry.Sources
import info.nightscout.androidaps.database.entities.ValueWithUnit
import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.resources.ResourceHelper
import javax.inject.Inject import javax.inject.Inject
import javax.inject.Singleton import javax.inject.Singleton
@ -13,142 +15,252 @@ class Translator @Inject internal constructor(
private val resourceHelper: ResourceHelper private val resourceHelper: ResourceHelper
) { ) {
fun translate(text: String): String = @Deprecated("use type instead of string")
when (text) { fun translate(text: String): String = text
TherapyEvent.Type.FINGER_STICK_BG_VALUE.text -> resourceHelper.gs(R.string.careportal_bgcheck)
TherapyEvent.Type.SNACK_BOLUS.text -> resourceHelper.gs(R.string.careportal_snackbolus)
TherapyEvent.Type.MEAL_BOLUS.text -> resourceHelper.gs(R.string.careportal_mealbolus)
TherapyEvent.Type.CORRECTION_BOLUS.text -> resourceHelper.gs(R.string.careportal_correctionbolus)
TherapyEvent.Type.CARBS_CORRECTION.text -> resourceHelper.gs(R.string.careportal_carbscorrection)
TherapyEvent.Type.BOLUS_WIZARD.text -> resourceHelper.gs(R.string.boluswizard)
TherapyEvent.Type.COMBO_BOLUS.text -> resourceHelper.gs(R.string.careportal_combobolus)
TherapyEvent.Type.ANNOUNCEMENT.text -> resourceHelper.gs(R.string.careportal_announcement)
TherapyEvent.Type.NOTE.text -> resourceHelper.gs(R.string.careportal_note)
TherapyEvent.Type.QUESTION.text -> resourceHelper.gs(R.string.careportal_question)
TherapyEvent.Type.EXERCISE.text -> resourceHelper.gs(R.string.careportal_exercise)
TherapyEvent.Type.CANNULA_CHANGE.text -> resourceHelper.gs(R.string.careportal_pumpsitechange)
TherapyEvent.Type.PUMP_BATTERY_CHANGE.text -> resourceHelper.gs(R.string.careportal_pumpbatterychange)
TherapyEvent.Type.SENSOR_STARTED.text -> resourceHelper.gs(R.string.careportal_cgmsensorstart)
TherapyEvent.Type.SENSOR_STOPPED.text -> resourceHelper.gs(R.string.careportal_cgm_sensor_stop)
TherapyEvent.Type.SENSOR_CHANGE.text -> resourceHelper.gs(R.string.careportal_cgmsensorinsert)
TherapyEvent.Type.INSULIN_CHANGE.text -> resourceHelper.gs(R.string.careportal_insulincartridgechange)
TherapyEvent.Type.DAD_ALERT.text -> resourceHelper.gs(R.string.careportal_dad_alert)
TherapyEvent.Type.TEMPORARY_BASAL_START.text -> resourceHelper.gs(R.string.careportal_tempbasalstart)
TherapyEvent.Type.TEMPORARY_BASAL_END.text -> resourceHelper.gs(R.string.careportal_tempbasalend)
TherapyEvent.Type.PROFILE_SWITCH.text -> resourceHelper.gs(R.string.careportal_profileswitch)
TherapyEvent.Type.TEMPORARY_TARGET.text -> resourceHelper.gs(R.string.careportal_temporarytarget)
TherapyEvent.Type.TEMPORARY_TARGET_CANCEL.text -> resourceHelper.gs(R.string.careportal_temporarytargetcancel)
TherapyEvent.Type.APS_OFFLINE.text -> resourceHelper.gs(R.string.careportal_openapsoffline)
TherapyEvent.Type.NS_MBG.text -> resourceHelper.gs(R.string.careportal_mbg)
TherapyEvent.MeterType.FINGER.text -> resourceHelper.gs(R.string.glucosetype_finger)
TherapyEvent.MeterType.SENSOR.text -> resourceHelper.gs(R.string.glucosetype_sensor)
TherapyEvent.MeterType.MANUAL.text -> resourceHelper.gs(R.string.manual)
TemporaryTarget.Reason.CUSTOM.text -> resourceHelper.gs(R.string.custom) fun translate(action: Action): String = when(action) {
TemporaryTarget.Reason.HYPOGLYCEMIA.text -> resourceHelper.gs(R.string.hypo) Action.BOLUS -> resourceHelper.gs(R.string.uel_bolus)
TemporaryTarget.Reason.EATING_SOON.text -> resourceHelper.gs(R.string.eatingsoon) Action.SMB -> resourceHelper.gs(R.string.smb_shortname)
TemporaryTarget.Reason.ACTIVITY.text -> resourceHelper.gs(R.string.activity) Action.BOLUS_ADVISOR -> resourceHelper.gs(R.string.uel_bolus_advisor)
TemporaryTarget.Reason.AUTOMATION.text -> resourceHelper.gs(R.string.automation) Action.EXTENDED_BOLUS -> resourceHelper.gs(R.string.uel_extended_bolus)
TemporaryTarget.Reason.WEAR.text -> resourceHelper.gs(R.string.wear) Action.SUPERBOLUS_TBR -> resourceHelper.gs(R.string.uel_superbolus_tbr)
Action.CARBS -> resourceHelper.gs(R.string.uel_carbs)
Action.EXTENDED_CARBS -> resourceHelper.gs(R.string.uel_extended_carbs)
Action.TEMP_BASAL -> resourceHelper.gs(R.string.uel_temp_basal)
Action.TT -> resourceHelper.gs(R.string.uel_tt)
Action.NEW_PROFILE -> resourceHelper.gs(R.string.uel_new_profile)
Action.CLONE_PROFILE -> resourceHelper.gs(R.string.uel_clone_profile)
Action.STORE_PROFILE -> resourceHelper.gs(R.string.uel_store_profile)
Action.PROFILE_SWITCH -> resourceHelper.gs(R.string.uel_profile_switch)
Action.PROFILE_SWITCH_CLONED -> resourceHelper.gs(R.string.uel_profile_switch_cloned)
Action.CLOSED_LOOP_MODE -> resourceHelper.gs(R.string.uel_closed_loop_mode)
Action.LGS_LOOP_MODE -> resourceHelper.gs(R.string.uel_lgs_loop_mode)
Action.OPEN_LOOP_MODE -> resourceHelper.gs(R.string.uel_open_loop_mode)
Action.LOOP_DISABLED -> resourceHelper.gs(R.string.uel_loop_disabled)
Action.LOOP_ENABLED -> resourceHelper.gs(R.string.uel_loop_enabled)
Action.RECONNECT -> resourceHelper.gs(R.string.uel_reconnect)
Action.DISCONNECT -> resourceHelper.gs(R.string.uel_disconnect)
Action.RESUME -> resourceHelper.gs(R.string.uel_resume)
Action.SUSPEND -> resourceHelper.gs(R.string.uel_suspend)
Action.HW_PUMP_ALLOWED -> resourceHelper.gs(R.string.uel_hw_pump_allowed)
Action.CLEAR_PAIRING_KEYS -> resourceHelper.gs(R.string.uel_clear_pairing_keys)
Action.ACCEPTS_TEMP_BASAL -> resourceHelper.gs(R.string.uel_accepts_temp_basal)
Action.CANCEL_TEMP_BASAL -> resourceHelper.gs(R.string.uel_cancel_temp_basal)
Action.CANCEL_EXTENDED_BOLUS -> resourceHelper.gs(R.string.uel_cancel_extended_bolus)
Action.CANCEL_TT -> resourceHelper.gs(R.string.uel_cancel_tt)
Action.CAREPORTAL -> resourceHelper.gs(R.string.uel_careportal)
Action.SITE_CHANGE -> resourceHelper.gs(R.string.uel_site_change)
Action.RESERVOIR_CHANGE -> resourceHelper.gs(R.string.uel_reservoir_change)
Action.CALIBRATION -> resourceHelper.gs(R.string.uel_calibration)
Action.PRIME_BOLUS -> resourceHelper.gs(R.string.uel_prime_bolus)
Action.TREATMENT -> resourceHelper.gs(R.string.uel_treatment)
Action.CAREPORTAL_NS_REFRESH -> resourceHelper.gs(R.string.uel_careportal_ns_refresh)
Action.PROFILE_SWITCH_NS_REFRESH -> resourceHelper.gs(R.string.uel_profile_switch_ns_refresh)
Action.TREATMENTS_NS_REFRESH -> resourceHelper.gs(R.string.uel_treatments_ns_refresh)
Action.TT_NS_REFRESH -> resourceHelper.gs(R.string.uel_tt_ns_refresh)
Action.AUTOMATION_REMOVED -> resourceHelper.gs(R.string.uel_automation_removed)
Action.BG_REMOVED -> resourceHelper.gs(R.string.uel_bg_removed)
Action.CAREPORTAL_REMOVED -> resourceHelper.gs(R.string.uel_careportal_removed)
Action.EXTENDED_BOLUS_REMOVED -> resourceHelper.gs(R.string.uel_extended_bolus_removed)
Action.FOOD -> resourceHelper.gs(R.string.uel_food)
Action.FOOD_REMOVED -> resourceHelper.gs(R.string.uel_food_removed)
Action.PROFILE_REMOVED -> resourceHelper.gs(R.string.uel_profile_removed)
Action.PROFILE_SWITCH_REMOVED -> resourceHelper.gs(R.string.uel_profile_switch_removed)
Action.RESTART_EVENTS_REMOVED -> resourceHelper.gs(R.string.uel_restart_events_removed)
Action.TREATMENT_REMOVED -> resourceHelper.gs(R.string.uel_treatment_removed)
Action.TT_REMOVED -> resourceHelper.gs(R.string.uel_tt_removed)
Action.NS_PAUSED -> resourceHelper.gs(R.string.uel_ns_paused)
Action.NS_RESUME -> resourceHelper.gs(R.string.uel_ns_resume)
Action.NS_QUEUE_CLEARED -> resourceHelper.gs(R.string.uel_ns_queue_cleared)
Action.NS_SETTINGS_COPIED -> resourceHelper.gs(R.string.uel_ns_settings_copied)
Action.ERROR_DIALOG_OK -> resourceHelper.gs(R.string.uel_error_dialog_ok)
Action.ERROR_DIALOG_MUTE -> resourceHelper.gs(R.string.uel_error_dialog_mute)
Action.ERROR_DIALOG_MUTE_5MIN -> resourceHelper.gs(R.string.uel_error_dialog_mute_5min)
Action.OBJECTIVE_STARTED -> resourceHelper.gs(R.string.uel_objective_started)
Action.OBJECTIVE_UNSTARTED -> resourceHelper.gs(R.string.uel_objective_unstarted)
Action.OBJECTIVES_SKIPPED -> resourceHelper.gs(R.string.uel_objectives_skipped)
Action.STAT_RESET -> resourceHelper.gs(R.string.uel_stat_reset)
Action.DELETE_LOGS -> resourceHelper.gs(R.string.uel_delete_logs)
Action.DELETE_FUTURE_TREATMENTS -> resourceHelper.gs(R.string.uel_delete_future_treatments)
Action.EXPORT_SETTINGS -> resourceHelper.gs(R.string.uel_export_settings)
Action.IMPORT_SETTINGS -> resourceHelper.gs(R.string.uel_import_settings)
Action.RESET_DATABASES -> resourceHelper.gs(R.string.uel_reset_databases)
Action.EXPORT_DATABASES -> resourceHelper.gs(R.string.uel_export_databases)
Action.IMPORT_DATABASES -> resourceHelper.gs(R.string.uel_import_databases)
Action.OTP_EXPORT -> resourceHelper.gs(R.string.uel_otp_export)
Action.OTP_RESET -> resourceHelper.gs(R.string.uel_otp_reset)
Action.EXPORT_CSV -> resourceHelper.gs(R.string.uel_export_csv)
Action.STOP_SMS -> resourceHelper.gs(R.string.uel_stop_sms)
Action.UNKNOWN -> resourceHelper.gs(R.string.unknown)
}
Action.BOLUS.name -> resourceHelper.gs(R.string.uel_bolus) fun translate(units: ValueWithUnit?): String = when(units) {
Action.BOLUS_ADVISOR.name -> resourceHelper.gs(R.string.uel_bolus_advisor) is ValueWithUnit.Gram -> resourceHelper.gs(R.string.shortgram)
Action.BOLUS_RECORD.name -> resourceHelper.gs(R.string.uel_bolus_record) is ValueWithUnit.Hour -> resourceHelper.gs(R.string.shorthour)
Action.EXTENDED_BOLUS.name -> resourceHelper.gs(R.string.uel_extended_bolus) is ValueWithUnit.Insulin -> resourceHelper.gs(R.string.insulin_unit_shortname)
Action.SUPERBOLUS_TBR.name -> resourceHelper.gs(R.string.uel_superbolus_tbr) is ValueWithUnit.Mgdl -> resourceHelper.gs(R.string.mgdl)
Action.CARBS.name -> resourceHelper.gs(R.string.uel_carbs) is ValueWithUnit.Minute -> resourceHelper.gs(R.string.shortminute)
Action.EXTENDED_CARBS.name -> resourceHelper.gs(R.string.uel_extended_carbs) is ValueWithUnit.Mmoll -> resourceHelper.gs(R.string.mmol)
Action.TEMP_BASAL.name -> resourceHelper.gs(R.string.uel_temp_basal) is ValueWithUnit.Percent -> resourceHelper.gs(R.string.shortpercent)
Action.TT.name -> resourceHelper.gs(R.string.uel_tt) is ValueWithUnit.UnitPerHour -> resourceHelper.gs(R.string.profile_ins_units_per_hour)
Action.NEW_PROFILE.name -> resourceHelper.gs(R.string.uel_new_profile) else -> ""
Action.CLONE_PROFILE.name -> resourceHelper.gs(R.string.uel_clone_profile) }
Action.STORE_PROFILE.name -> resourceHelper.gs(R.string.uel_store_profile)
Action.PROFILE_SWITCH.name -> resourceHelper.gs(R.string.uel_profile_switch)
Action.PROFILE_SWITCH_CLONED.name -> resourceHelper.gs(R.string.uel_profile_switch_cloned)
Action.CLOSED_LOOP_MODE.name -> resourceHelper.gs(R.string.uel_closed_loop_mode)
Action.LGS_LOOP_MODE.name -> resourceHelper.gs(R.string.uel_lgs_loop_mode)
Action.OPEN_LOOP_MODE.name -> resourceHelper.gs(R.string.uel_open_loop_mode)
Action.LOOP_DISABLED.name -> resourceHelper.gs(R.string.uel_loop_disabled)
Action.LOOP_ENABLED.name -> resourceHelper.gs(R.string.uel_loop_enabled)
Action.RECONNECT.name -> resourceHelper.gs(R.string.uel_reconnect)
Action.DISCONNECT.name -> resourceHelper.gs(R.string.uel_disconnect)
Action.RESUME.name -> resourceHelper.gs(R.string.uel_resume)
Action.SUSPEND.name -> resourceHelper.gs(R.string.uel_suspend)
Action.HW_PUMP_ALLOWED.name -> resourceHelper.gs(R.string.uel_hw_pump_allowed)
Action.CLEAR_PAIRING_KEYS.name -> resourceHelper.gs(R.string.uel_clear_pairing_keys)
Action.ACCEPTS_TEMP_BASAL.name -> resourceHelper.gs(R.string.uel_accepts_temp_basal)
Action.CANCEL_TEMP_BASAL.name -> resourceHelper.gs(R.string.uel_cancel_temp_basal)
Action.CANCEL_EXTENDED_BOLUS.name -> resourceHelper.gs(R.string.uel_cancel_extended_bolus)
Action.CANCEL_TT.name -> resourceHelper.gs(R.string.uel_cancel_tt)
Action.CAREPORTAL.name -> resourceHelper.gs(R.string.uel_careportal)
Action.CALIBRATION.name -> resourceHelper.gs(R.string.uel_calibration)
Action.PRIME_BOLUS.name -> resourceHelper.gs(R.string.uel_prime_bolus)
Action.TREATMENT.name -> resourceHelper.gs(R.string.uel_treatment)
Action.CAREPORTAL_NS_REFRESH.name -> resourceHelper.gs(R.string.uel_careportal_ns_refresh)
Action.PROFILE_SWITCH_NS_REFRESH.name -> resourceHelper.gs(R.string.uel_profile_switch_ns_refresh)
Action.TREATMENTS_NS_REFRESH.name -> resourceHelper.gs(R.string.uel_treatments_ns_refresh)
Action.TT_NS_REFRESH.name -> resourceHelper.gs(R.string.uel_tt_ns_refresh)
Action.AUTOMATION_REMOVED.name -> resourceHelper.gs(R.string.uel_automation_removed)
Action.BG_REMOVED.name -> resourceHelper.gs(R.string.uel_bg_removed)
Action.CAREPORTAL_REMOVED.name -> resourceHelper.gs(R.string.uel_careportal_removed)
Action.EXTENDED_BOLUS_REMOVED.name -> resourceHelper.gs(R.string.uel_extended_bolus_removed)
Action.FOOD_REMOVED.name -> resourceHelper.gs(R.string.uel_food_removed)
Action.PROFILE_REMOVED.name -> resourceHelper.gs(R.string.uel_profile_removed)
Action.PROFILE_SWITCH_REMOVED.name -> resourceHelper.gs(R.string.uel_profile_switch_removed)
Action.RESTART_EVENTS_REMOVED.name -> resourceHelper.gs(R.string.uel_restart_events_removed)
Action.TREATMENT_REMOVED.name -> resourceHelper.gs(R.string.uel_treatment_removed)
Action.TT_REMOVED.name -> resourceHelper.gs(R.string.uel_tt_removed)
Action.NS_PAUSED.name -> resourceHelper.gs(R.string.uel_ns_paused)
Action.NS_RESUME.name -> resourceHelper.gs(R.string.uel_ns_resume)
Action.NS_QUEUE_CLEARED.name -> resourceHelper.gs(R.string.uel_ns_queue_cleared)
Action.NS_SETTINGS_COPIED.name -> resourceHelper.gs(R.string.uel_ns_settings_copied)
Action.ERROR_DIALOG_OK.name -> resourceHelper.gs(R.string.uel_error_dialog_ok)
Action.ERROR_DIALOG_MUTE.name -> resourceHelper.gs(R.string.uel_error_dialog_mute)
Action.ERROR_DIALOG_MUTE_5MIN.name -> resourceHelper.gs(R.string.uel_error_dialog_mute_5min)
Action.OBJECTIVE_STARTED.name -> resourceHelper.gs(R.string.uel_objective_started)
Action.OBJECTIVE_UNSTARTED.name -> resourceHelper.gs(R.string.uel_objective_unstarted)
Action.OBJECTIVES_SKIPPED.name -> resourceHelper.gs(R.string.uel_objectives_skipped)
Action.STAT_RESET.name -> resourceHelper.gs(R.string.uel_stat_reset)
Action.DELETE_LOGS.name -> resourceHelper.gs(R.string.uel_delete_logs)
Action.DELETE_FUTURE_TREATMENTS.name -> resourceHelper.gs(R.string.uel_delete_future_treatments)
Action.EXPORT_SETTINGS.name -> resourceHelper.gs(R.string.uel_export_settings)
Action.IMPORT_SETTINGS.name -> resourceHelper.gs(R.string.uel_import_settings)
Action.RESET_DATABASES.name -> resourceHelper.gs(R.string.uel_reset_databases)
Action.EXPORT_DATABASES.name -> resourceHelper.gs(R.string.uel_export_databases)
Action.IMPORT_DATABASES.name -> resourceHelper.gs(R.string.uel_import_databases)
Action.OTP_EXPORT.name -> resourceHelper.gs(R.string.uel_otp_export)
Action.OTP_RESET.name -> resourceHelper.gs(R.string.uel_otp_reset)
Action.SMS_BASAL.name -> resourceHelper.gs(R.string.uel_sms_basal)
Action.SMS_BOLUS.name -> resourceHelper.gs(R.string.uel_sms_bolus)
Action.SMS_CAL.name -> resourceHelper.gs(R.string.uel_sms_cal)
Action.SMS_CARBS.name -> resourceHelper.gs(R.string.uel_sms_carbs)
Action.SMS_EXTENDED_BOLUS.name -> resourceHelper.gs(R.string.uel_sms_extended_bolus)
Action.SMS_LOOP_DISABLED.name -> resourceHelper.gs(R.string.uel_sms_loop_disabled)
Action.SMS_LOOP_ENABLED.name -> resourceHelper.gs(R.string.uel_sms_loop_enabled)
Action.SMS_LOOP_RESUME.name -> resourceHelper.gs(R.string.uel_sms_loop_resume)
Action.SMS_LOOP_SUSPEND.name -> resourceHelper.gs(R.string.uel_sms_loop_suspend)
Action.SMS_PROFILE.name -> resourceHelper.gs(R.string.uel_sms_profile)
Action.SMS_PUMP_CONNECT.name -> resourceHelper.gs(R.string.uel_sms_pump_connect)
Action.SMS_PUMP_DISCONNECT.name -> resourceHelper.gs(R.string.uel_sms_pump_disconnect)
Action.SMS_SMS.name -> resourceHelper.gs(R.string.uel_sms_sms)
Action.SMS_TT.name -> resourceHelper.gs(R.string.uel_sms_tt)
Action.TT_DELETED_FROM_NS.name -> resourceHelper.gs(R.string.uel_tt_deleted_from_ns)
Action.TT_FROM_NS.name -> resourceHelper.gs(R.string.uel_tt_from_ns)
Action.TT_CANCELED_FROM_NS.name -> resourceHelper.gs(R.string.uel_tt_canceleted_from_ns)
Action.CAREPORTAL_DELETED_FROM_NS.name -> resourceHelper.gs(R.string.uel_careportal_deleted_from_ns)
Action.CAREPORTAL_FROM_NS.name -> resourceHelper.gs(R.string.uel_careportal_from_ns)
Action.EXPORT_CSV.name -> resourceHelper.gs(R.string.uel_export_csv)
Units.Mg_Dl.name -> resourceHelper.gs(R.string.mgdl) fun translate(meterType: TherapyEvent.MeterType): String = when(meterType) {
Units.Mmol_L.name -> resourceHelper.gs(R.string.mmol) TherapyEvent.MeterType.FINGER -> resourceHelper.gs(R.string.glucosetype_finger)
Units.U.name -> resourceHelper.gs(R.string.insulin_unit_shortname) TherapyEvent.MeterType.SENSOR -> resourceHelper.gs(R.string.glucosetype_sensor)
Units.U_H.name -> resourceHelper.gs(R.string.profile_ins_units_per_hour) TherapyEvent.MeterType.MANUAL -> resourceHelper.gs(R.string.manual)
Units.G.name -> resourceHelper.gs(R.string.shortgram)
Units.M.name -> resourceHelper.gs(R.string.shortminute)
Units.H.name -> resourceHelper.gs(R.string.shorthour)
Units.Percent.name -> resourceHelper.gs(R.string.shortpercent)
Units.None.name -> ""
else -> resourceHelper.gs(R.string.unknown) else -> resourceHelper.gs(R.string.unknown)
} }
fun translate(type: TherapyEvent.Type): String = when(type) {
TherapyEvent.Type.FINGER_STICK_BG_VALUE -> resourceHelper.gs(R.string.careportal_bgcheck)
TherapyEvent.Type.SNACK_BOLUS -> resourceHelper.gs(R.string.careportal_snackbolus)
TherapyEvent.Type.MEAL_BOLUS -> resourceHelper.gs(R.string.careportal_mealbolus)
TherapyEvent.Type.CORRECTION_BOLUS -> resourceHelper.gs(R.string.careportal_correctionbolus)
TherapyEvent.Type.CARBS_CORRECTION -> resourceHelper.gs(R.string.careportal_carbscorrection)
TherapyEvent.Type.BOLUS_WIZARD -> resourceHelper.gs(R.string.boluswizard)
TherapyEvent.Type.COMBO_BOLUS -> resourceHelper.gs(R.string.careportal_combobolus)
TherapyEvent.Type.ANNOUNCEMENT -> resourceHelper.gs(R.string.careportal_announcement)
TherapyEvent.Type.NOTE -> resourceHelper.gs(R.string.careportal_note)
TherapyEvent.Type.QUESTION -> resourceHelper.gs(R.string.careportal_question)
TherapyEvent.Type.EXERCISE -> resourceHelper.gs(R.string.careportal_exercise)
TherapyEvent.Type.CANNULA_CHANGE -> resourceHelper.gs(R.string.careportal_pumpsitechange)
TherapyEvent.Type.PUMP_BATTERY_CHANGE -> resourceHelper.gs(R.string.careportal_pumpbatterychange)
TherapyEvent.Type.SENSOR_STARTED -> resourceHelper.gs(R.string.careportal_cgmsensorstart)
TherapyEvent.Type.SENSOR_STOPPED -> resourceHelper.gs(R.string.careportal_cgm_sensor_stop)
TherapyEvent.Type.SENSOR_CHANGE -> resourceHelper.gs(R.string.careportal_cgmsensorinsert)
TherapyEvent.Type.INSULIN_CHANGE -> resourceHelper.gs(R.string.careportal_insulincartridgechange)
TherapyEvent.Type.DAD_ALERT -> resourceHelper.gs(R.string.careportal_dad_alert)
TherapyEvent.Type.TEMPORARY_BASAL_START -> resourceHelper.gs(R.string.careportal_tempbasalstart)
TherapyEvent.Type.TEMPORARY_BASAL_END -> resourceHelper.gs(R.string.careportal_tempbasalend)
TherapyEvent.Type.PROFILE_SWITCH -> resourceHelper.gs(R.string.careportal_profileswitch)
TherapyEvent.Type.TEMPORARY_TARGET -> resourceHelper.gs(R.string.careportal_temporarytarget)
TherapyEvent.Type.TEMPORARY_TARGET_CANCEL -> resourceHelper.gs(R.string.careportal_temporarytargetcancel)
TherapyEvent.Type.APS_OFFLINE -> resourceHelper.gs(R.string.careportal_openapsoffline)
TherapyEvent.Type.NS_MBG -> resourceHelper.gs(R.string.careportal_mbg)
/*
TherapyEvent.Type.TEMPORARY_BASAL -> TODO()
TherapyEvent.Type.TUBE_CHANGE -> TODO()
TherapyEvent.Type.FALLING_ASLEEP -> TODO()
TherapyEvent.Type.BATTERY_EMPTY -> TODO()
TherapyEvent.Type.RESERVOIR_EMPTY -> TODO()
TherapyEvent.Type.OCCLUSION -> TODO()
TherapyEvent.Type.PUMP_STOPPED -> TODO()
TherapyEvent.Type.PUMP_STARTED -> TODO()
TherapyEvent.Type.PUMP_PAUSED -> TODO()
TherapyEvent.Type.WAKING_UP -> TODO()
TherapyEvent.Type.SICKNESS -> TODO()
TherapyEvent.Type.STRESS -> TODO()
TherapyEvent.Type.PRE_PERIOD -> TODO()
TherapyEvent.Type.ALCOHOL -> TODO()
TherapyEvent.Type.CORTISONE -> TODO()
TherapyEvent.Type.FEELING_LOW -> TODO()
TherapyEvent.Type.FEELING_HIGH -> TODO()
TherapyEvent.Type.LEAKING_INFUSION_SET -> TODO()
*/
TherapyEvent.Type.NONE -> resourceHelper.gs(R.string.unknown)
else -> resourceHelper.gs(R.string.unknown)
}
fun translate(reason: TemporaryTarget.Reason): String = when(reason) {
TemporaryTarget.Reason.CUSTOM -> resourceHelper.gs(R.string.custom)
TemporaryTarget.Reason.HYPOGLYCEMIA -> resourceHelper.gs(R.string.hypo)
TemporaryTarget.Reason.EATING_SOON -> resourceHelper.gs(R.string.eatingsoon)
TemporaryTarget.Reason.ACTIVITY -> resourceHelper.gs(R.string.activity)
TemporaryTarget.Reason.AUTOMATION -> resourceHelper.gs(R.string.automation)
TemporaryTarget.Reason.WEAR -> resourceHelper.gs(R.string.wear)
else -> resourceHelper.gs(R.string.unknown)
}
fun translate(source: Sources): String = when(source) {
/*
Sources.TreatmentDialog -> TODO()
Sources.InsulinDialog -> TODO()
Sources.CarbDialog -> TODO()
Sources.WizardDialog -> TODO()
Sources.QuickWizard -> TODO()
Sources.ExtendedBolusDialog -> TODO()
Sources.TTDialog -> TODO()
Sources.ProfileSwitchDialog -> TODO()
Sources.LoopDialog -> TODO()
Sources.TempBasalDialog -> TODO()
Sources.CalibrationDialog -> TODO()
Sources.FillDialog -> TODO()
Sources.BgCheck -> TODO()
Sources.SensorInsert -> TODO()
Sources.BatteryChange -> TODO()
Sources.Note -> TODO()
Sources.Exercise -> TODO()
Sources.Question -> TODO()
Sources.Announcement -> TODO()
Sources.Actions -> TODO()
Sources.BG -> TODO()
Sources.LocalProfile -> TODO()
Sources.Maintenance -> TODO()
Sources.NSProfile -> TODO()
Sources.Objectives -> TODO()
Sources.Treatments -> TODO()
Sources.Food -> TODO()
Sources.ConfigBuilder -> TODO()
Sources.Overview -> TODO()
Sources.Stats -> TODO()
Sources.TreatmentDialog -> TODO()
Sources.InsulinDialog -> TODO()
Sources.CarbDialog -> TODO()
Sources.WizardDialog -> TODO()
Sources.QuickWizard -> TODO()
Sources.ExtendedBolusDialog -> TODO()
Sources.TTDialog -> TODO()
Sources.ProfileSwitchDialog -> TODO()
Sources.LoopDialog -> TODO()
Sources.TempBasalDialog -> TODO()
Sources.CalibrationDialog -> TODO()
Sources.FillDialog -> TODO()
Sources.BgCheck -> TODO()
Sources.SensorInsert -> TODO()
Sources.BatteryChange -> TODO()
Sources.Note -> TODO()
Sources.Exercise -> TODO()
Sources.Question -> TODO()
Sources.Announcement -> TODO()
Sources.Actions -> TODO()
Sources.BG -> TODO()
Sources.LocalProfile -> TODO()
Sources.Maintenance -> TODO()
Sources.NSProfile -> TODO()
Sources.Objectives -> TODO()
Sources.Dana -> TODO()
Sources.DanaR -> TODO()
Sources.DanaRC -> TODO()
Sources.DanaRv2 -> TODO()
Sources.DanaRS -> TODO()
Sources.Insight -> TODO()
Sources.Combo -> TODO()
Sources.Medtronic -> TODO()
Sources.Omnipod -> TODO()
Sources.OmnipodEros -> TODO()
Sources.OmnipodDash -> TODO()
Sources.MDI -> TODO()
Sources.VirtualPump -> TODO()
Sources.Treatments -> TODO()
Sources.Food -> TODO()
Sources.ConfigBuilder -> TODO()
Sources.Overview -> TODO()
Sources.Stats -> TODO()
*/
Sources.Automation -> resourceHelper.gs(R.string.automation)
Sources.Loop -> resourceHelper.gs(R.string.loop)
Sources.NSClient -> resourceHelper.gs(R.string.ns)
Sources.Pump -> resourceHelper.gs(R.string.pump)
Sources.SMS -> resourceHelper.gs(R.string.smb_shortname)
Sources.Wear -> resourceHelper.gs(R.string.wear)
Sources.Unknown -> resourceHelper.gs(R.string.unknown)
else -> source.name
}
} }

View file

@ -0,0 +1,219 @@
package info.nightscout.androidaps.utils
import android.text.Spanned
import dagger.Reusable
import info.nightscout.androidaps.Constants
import info.nightscout.androidaps.core.R
import info.nightscout.androidaps.database.entities.UserEntry
import info.nightscout.androidaps.database.entities.UserEntry.Action
import info.nightscout.androidaps.database.entities.UserEntry.ColorGroup
import info.nightscout.androidaps.database.entities.UserEntry.Sources
import info.nightscout.androidaps.database.entities.ValueWithUnit
import info.nightscout.androidaps.interfaces.ProfileFunction
import info.nightscout.androidaps.utils.resources.ResourceHelper
import javax.inject.Inject
@Reusable
class UserEntryPresentationHelper @Inject constructor(
private val translator: Translator,
private val profileFunction: ProfileFunction,
private val resourceHelper: ResourceHelper,
private val dateUtil: DateUtil
) {
fun colorId(colorGroup: ColorGroup): Int = when (colorGroup) {
ColorGroup.InsulinTreatment -> R.color.iob
ColorGroup.BasalTreatment -> R.color.basal
ColorGroup.CarbTreatment -> R.color.carbs
ColorGroup.TT -> R.color.tempTargetConfirmation
ColorGroup.Profile -> R.color.white
ColorGroup.Loop -> R.color.loopClosed
ColorGroup.Careportal -> R.color.high
ColorGroup.Pump -> R.color.loopDisconnected
ColorGroup.Aaps -> R.color.defaulttext
else -> R.color.defaulttext
}
fun iconId(source: Sources): Int = when (source) {
Sources.TreatmentDialog -> R.drawable.icon_insulin_carbs
Sources.InsulinDialog -> R.drawable.ic_bolus
Sources.CarbDialog -> R.drawable.ic_cp_bolus_carbs
Sources.WizardDialog -> R.drawable.ic_calculator
Sources.QuickWizard -> R.drawable.ic_quick_wizard
Sources.ExtendedBolusDialog -> R.drawable.ic_actions_startextbolus
Sources.TTDialog -> R.drawable.ic_temptarget_high
Sources.ProfileSwitchDialog -> R.drawable.ic_actions_profileswitch
Sources.LoopDialog -> R.drawable.ic_loop_closed
Sources.TempBasalDialog -> R.drawable.ic_actions_starttempbasal
Sources.CalibrationDialog -> R.drawable.ic_calibration
Sources.FillDialog -> R.drawable.ic_cp_pump_canula
Sources.BgCheck -> R.drawable.ic_cp_bgcheck
Sources.SensorInsert -> R.drawable.ic_cp_cgm_insert
Sources.BatteryChange -> R.drawable.ic_cp_pump_battery
Sources.Note -> R.drawable.ic_cp_note
Sources.Exercise -> R.drawable.ic_cp_exercise
Sources.Question -> R.drawable.ic_cp_question
Sources.Announcement -> R.drawable.ic_cp_announcement
Sources.Actions -> R.drawable.ic_action
Sources.Automation -> R.drawable.ic_automation
Sources.BG -> R.drawable.ic_generic_cgm
Sources.LocalProfile -> R.drawable.ic_local_profile
Sources.Loop -> R.drawable.ic_loop_closed_white
Sources.Maintenance -> R.drawable.ic_maintenance
Sources.NSClient -> R.drawable.ic_nightscout_syncs
Sources.NSProfile -> R.drawable.ic_nightscout_profile
Sources.Objectives -> R.drawable.ic_graduation
Sources.Pump -> R.drawable.ic_generic_icon
Sources.Dana -> R.drawable.ic_danars_128
Sources.DanaR -> R.drawable.ic_danars_128
Sources.DanaRC -> R.drawable.ic_danars_128
Sources.DanaRv2 -> R.drawable.ic_danars_128
Sources.DanaRS -> R.drawable.ic_danars_128
Sources.Insight -> R.drawable.ic_insight_128
Sources.Combo -> R.drawable.ic_combo_128
Sources.Medtronic -> R.drawable.ic_veo_128
Sources.Omnipod -> R.drawable.ic_pod_128
Sources.OmnipodEros -> R.drawable.ic_pod_128
Sources.OmnipodDash -> R.drawable.ic_pod_128
Sources.MDI -> R.drawable.ic_ict
Sources.VirtualPump -> R.drawable.ic_virtual_pump
Sources.SMS -> R.drawable.ic_sms
Sources.Treatments -> R.drawable.ic_treatments
Sources.Wear -> R.drawable.ic_watch
Sources.Food -> R.drawable.ic_food
Sources.Stats -> R.drawable.ic_cp_stats
Sources.ConfigBuilder -> R.drawable.ic_generic_icon
Sources.Overview -> R.drawable.ic_generic_icon
Sources.Unknown -> R.drawable.ic_generic_icon
}
fun actionToColoredString(action: Action): Spanned = when (action) {
Action.TREATMENT -> HtmlHelper.fromHtml(coloredAction(Action.BOLUS) + " + " + coloredAction(Action.CARBS))
else -> HtmlHelper.fromHtml(coloredAction(action))
}
private fun coloredAction(action: Action): String = "<font color='${resourceHelper.gc(colorId(action.colorGroup))}'>${translator.translate(action)}</font>"
fun listToPresentationString(list: List<ValueWithUnit?>) =
list.joinToString(separator = " ", transform = this::toPresentationString)
private fun toPresentationString(valueWithUnit: ValueWithUnit?): String = when (valueWithUnit) {
is ValueWithUnit.Gram -> "${valueWithUnit.value}${translator.translate(valueWithUnit)}"
is ValueWithUnit.Hour -> "${valueWithUnit.value}${translator.translate(valueWithUnit)}"
is ValueWithUnit.Minute -> "${valueWithUnit.value}${translator.translate(valueWithUnit)}"
is ValueWithUnit.Percent -> "${valueWithUnit.value}${translator.translate(valueWithUnit)}"
is ValueWithUnit.Insulin -> DecimalFormatter.to2Decimal(valueWithUnit.value) + translator.translate(valueWithUnit)
is ValueWithUnit.UnitPerHour -> DecimalFormatter.to2Decimal(valueWithUnit.value) + translator.translate(valueWithUnit)
is ValueWithUnit.SimpleInt -> valueWithUnit.value.toString()
is ValueWithUnit.SimpleString -> valueWithUnit.value
is ValueWithUnit.StringResource -> resourceHelper.gs(valueWithUnit.value, *(valueWithUnit.params.map { it.value() }.toTypedArray())) //Todo Fix StringResource with Param
// is XXXValueWithUnit.StringResource -> if (valueWithUnit.params.size > 0 ) valueWithUnit.params.joinToString(separator = " ") { value -> toPresentationString(value) } else resourceHelper.gs(valueWithUnit.value) //To help debugging
is ValueWithUnit.TherapyEventMeterType -> translator.translate(valueWithUnit.value)
is ValueWithUnit.TherapyEventTTReason -> translator.translate(valueWithUnit.value)
is ValueWithUnit.TherapyEventType -> translator.translate(valueWithUnit.value)
is ValueWithUnit.Timestamp -> dateUtil.dateAndTimeAndSecondsString(valueWithUnit.value)
is ValueWithUnit.Mgdl -> {
if (profileFunction.getUnits() == Constants.MGDL) DecimalFormatter.to0Decimal(valueWithUnit.value) + translator.translate(valueWithUnit)
else DecimalFormatter.to1Decimal(valueWithUnit.value / Constants.MMOLL_TO_MGDL) + translator.translate(valueWithUnit)
}
is ValueWithUnit.Mmoll -> {
if (profileFunction.getUnits() == Constants.MGDL) DecimalFormatter.to0Decimal(valueWithUnit.value) + translator.translate(valueWithUnit)
else DecimalFormatter.to1Decimal(valueWithUnit.value * Constants.MMOLL_TO_MGDL) + translator.translate(valueWithUnit)
}
ValueWithUnit.UNKNOWN -> ""
null -> ""
}
fun userEntriesToCsv(userEntries: List<UserEntry>): String {
return getCsvHeader() + userEntries.joinToString("\n") { entry -> getCsvEntry(entry) }
}
private fun getCsvHeader() = resourceHelper.gs(R.string.ue_csv_header,
csvString(R.string.ue_timestamp),
csvString(R.string.date),
csvString(R.string.ue_utc_offset),
csvString(R.string.ue_action),
csvString(R.string.eventtype),
csvString(R.string.ue_source),
csvString(R.string.careportal_note),
csvString(R.string.ue_formated_string),
csvString(R.string.event_time_label),
csvString(if (profileFunction.getUnits() == Constants.MGDL) R.string.mgdl else R.string.mmol),
csvString(R.string.shortgram),
csvString(R.string.insulin_unit_shortname),
csvString(R.string.profile_ins_units_per_hour),
csvString(R.string.shortpercent),
csvString(R.string.shorthour),
csvString(R.string.shortminute),
csvString(R.string.ue_none)
) + "\n"
private fun getCsvEntry(entry: UserEntry): String {
val fullvalueWithUnitList = ArrayList<ValueWithUnit?>(entry.values)
var timestampRec = "" + entry.timestamp
var dateTimestampRev = dateUtil.dateAndTimeAndSecondsString(entry.timestamp)
var utcOffset = dateUtil.timeString(entry.utcOffset)
var action = csvString(entry.action)
var therapyEvent = ""
var source = translator.translate(entry.source)
var note = csvString(entry.note)
var stringResource = ""
var timestamp = ""
var bg = ""
var gram = ""
var insulin = ""
var unitPerHour = ""
var percent = ""
var hour = ""
var minute = ""
var other = ""
for (valueWithUnit in entry.values) {
if (valueWithUnit is ValueWithUnit.StringResource) fullvalueWithUnitList.addAll(valueWithUnit.params)
}
for (valueWithUnit in fullvalueWithUnitList.filterNotNull()) {
when (valueWithUnit) {
is ValueWithUnit.Gram -> gram = valueWithUnit.value.toString()
is ValueWithUnit.Hour -> hour = valueWithUnit.value.toString()
is ValueWithUnit.Minute -> minute = valueWithUnit.value.toString()
is ValueWithUnit.Percent -> percent = valueWithUnit.value.toString()
is ValueWithUnit.Insulin -> insulin = DecimalFormatter.to2Decimal(valueWithUnit.value)
is ValueWithUnit.UnitPerHour -> unitPerHour = DecimalFormatter.to2Decimal(valueWithUnit.value)
is ValueWithUnit.SimpleInt -> other = other.addWithSeparator(valueWithUnit.value)
is ValueWithUnit.SimpleString -> other = other.addWithSeparator(valueWithUnit.value)
is ValueWithUnit.StringResource -> stringResource = stringResource.addWithSeparator(resourceHelper.gs(valueWithUnit.value, *(valueWithUnit.params.map { it.value() }.toTypedArray())))
is ValueWithUnit.TherapyEventMeterType -> therapyEvent = therapyEvent.addWithSeparator(translator.translate(valueWithUnit.value))
is ValueWithUnit.TherapyEventTTReason -> therapyEvent = therapyEvent.addWithSeparator(translator.translate(valueWithUnit.value))
is ValueWithUnit.TherapyEventType -> therapyEvent = therapyEvent.addWithSeparator(translator.translate(valueWithUnit.value))
is ValueWithUnit.Timestamp -> timestamp = dateUtil.dateAndTimeAndSecondsString(valueWithUnit.value)
is ValueWithUnit.Mgdl -> {
bg = if (profileFunction.getUnits() == Constants.MGDL) DecimalFormatter.to0Decimal(valueWithUnit.value)
else DecimalFormatter.to1Decimal(valueWithUnit.value / Constants.MMOLL_TO_MGDL)
}
is ValueWithUnit.Mmoll -> {
bg = if (profileFunction.getUnits() == Constants.MGDL) DecimalFormatter.to0Decimal(valueWithUnit.value)
else DecimalFormatter.to1Decimal(valueWithUnit.value * Constants.MMOLL_TO_MGDL)
}
ValueWithUnit.UNKNOWN -> Unit
}
}
therapyEvent = csvString(therapyEvent)
stringResource = csvString(stringResource)
other = csvString(other)
return "$timestampRec;$dateTimestampRev;$utcOffset;$action;$therapyEvent;$source;$note;$stringResource;$timestamp;$bg;$gram;$insulin;$unitPerHour;$percent;$hour;$minute;$other"
}
private fun csvString(action: Action): String = "\"" + translator.translate(action).replace("\"", "\"\"") + "\""
private fun csvString(id: Int): String = if (id != 0) "\"" + resourceHelper.gs(id).replace("\"", "\"\"") + "\"" else ""
private fun csvString(s: String): String = if (s != "") "\"" + s.replace("\"", "\"\"") + "\"" else ""
private fun String.addWithSeparator(add: Any) =
this + (if (this.isBlank()) "" else " / ") + add.toString()
}

View file

@ -1,19 +0,0 @@
package info.nightscout.androidaps.utils.extensions
import info.nightscout.androidaps.core.R
import info.nightscout.androidaps.database.entities.UserEntry.*
fun ColorGroup.colorId(): Int {
return when (this) {
ColorGroup.InsulinTreatment -> R.color.basal
ColorGroup.CarbTreatment -> R.color.carbs
ColorGroup.TT -> R.color.tempTargetConfirmation
ColorGroup.Profile -> R.color.white
ColorGroup.Loop -> R.color.loopClosed
ColorGroup.Careportal -> R.color.high
ColorGroup.Pump -> R.color.iob
ColorGroup.Aaps -> R.color.defaulttext
else -> R.color.defaulttext
}
}

View file

@ -0,0 +1,51 @@
package info.nightscout.androidaps.utils.serialisation
import com.google.gson.Gson
import com.google.gson.GsonBuilder
import com.google.gson.TypeAdapter
import com.google.gson.TypeAdapterFactory
import com.google.gson.reflect.TypeToken
import com.google.gson.stream.JsonReader
import com.google.gson.stream.JsonWriter
import kotlin.jvm.internal.Reflection
import kotlin.reflect.KClass
object SealedClassHelper {
val gson: Gson = GsonBuilder().registerTypeAdapterFactory(
object : TypeAdapterFactory {
override fun <T : Any> create(gson: Gson, type: TypeToken<T>): TypeAdapter<T> {
val kClass = Reflection.getOrCreateKotlinClass(type.rawType)
return if (kClass.sealedSubclasses.any()) {
SealedClassTypeAdapter(kClass, gson)
} else
gson.getDelegateAdapter(this, type)
}
}).create()
private class SealedClassTypeAdapter<T : Any>(private val kClass: KClass<Any>, val gson: Gson) : TypeAdapter<T>() {
override fun read(jsonReader: JsonReader): T? {
jsonReader.beginObject()
val nextName = jsonReader.nextName()
val innerClass = kClass.sealedSubclasses.firstOrNull { it.simpleName == nextName }
?: throw Exception("$nextName is not a child of the sealed class ${kClass.qualifiedName}")
val x = gson.fromJson<T>(jsonReader, innerClass.javaObjectType)
jsonReader.endObject()
// if there a static object, actually return that
return innerClass.objectInstance as T? ?: x
}
override fun write(out: JsonWriter, value: T) {
val jsonString = gson.toJson(value)
val name = value.javaClass.canonicalName
if (name != null) {
out.beginObject()
out.name(name.splitToSequence(".").last()).jsonValue(jsonString)
out.endObject()
}
}
}
}
inline fun <reified T> Gson.fromJson(json: String): T = fromJson(json, object : TypeToken<T>() {}.type)

View file

@ -0,0 +1,14 @@
package info.nightscout.androidaps.utils.serialisation
import info.nightscout.androidaps.database.entities.ValueWithUnit
object ValueWithUnitSerialiser {
fun toSealedClassJson(list: List<ValueWithUnit>): String = list.map(::ValueWithUnitWrapper)
.let(SealedClassHelper.gson::toJson)
fun fromJson(string: String): List<ValueWithUnit> = SealedClassHelper.gson
.fromJson<List<ValueWithUnitWrapper>>(string).map { it.wrapped }
private class ValueWithUnitWrapper(val wrapped: ValueWithUnit)
}

Some files were not shown because too many files have changed in this diff Show more