Add UserEntry for Automation rules (PS, TT, Loop)

This commit is contained in:
Philoul 2021-03-27 12:05:07 +01:00
parent 2e59dd3112
commit f8a38889a3
8 changed files with 39 additions and 0 deletions

View file

@ -4,12 +4,15 @@ import androidx.annotation.DrawableRes
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.automation.R
import info.nightscout.androidaps.data.PumpEnactResult
import info.nightscout.androidaps.database.entities.UserEntry
import info.nightscout.androidaps.database.entities.UserEntry.*
import info.nightscout.androidaps.events.EventRefreshOverview
import info.nightscout.androidaps.interfaces.CommandQueueProvider
import info.nightscout.androidaps.interfaces.ConfigBuilderInterface
import info.nightscout.androidaps.interfaces.LoopInterface
import info.nightscout.androidaps.interfaces.PluginBase
import info.nightscout.androidaps.interfaces.PluginType
import info.nightscout.androidaps.logging.UserEntryLogger
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.queue.Callback
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 commandQueue: CommandQueueProvider
@Inject lateinit var rxBus: RxBusWrapper
@Inject lateinit var uel: UserEntryLogger
override fun friendlyName(): Int = 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()) {
(loopPlugin as PluginBase).setPluginEnabled(PluginType.LOOP, false)
configBuilderPlugin.storeSettings("ActionLoopDisable")
uel.log(UserEntry.Action.LOOP_DISABLED, ValueWithUnit(Sources.Automation))
commandQueue.cancelTempBasal(true, object : Callback() {
override fun run() {
rxBus.send(EventRefreshOverview("ActionLoopDisable"))

View file

@ -4,11 +4,14 @@ import androidx.annotation.DrawableRes
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.automation.R
import info.nightscout.androidaps.data.PumpEnactResult
import info.nightscout.androidaps.database.entities.UserEntry
import info.nightscout.androidaps.database.entities.UserEntry.*
import info.nightscout.androidaps.events.EventRefreshOverview
import info.nightscout.androidaps.interfaces.ConfigBuilderInterface
import info.nightscout.androidaps.interfaces.LoopInterface
import info.nightscout.androidaps.interfaces.PluginBase
import info.nightscout.androidaps.interfaces.PluginType
import info.nightscout.androidaps.logging.UserEntryLogger
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.queue.Callback
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 configBuilderPlugin: ConfigBuilderInterface
@Inject lateinit var rxBus: RxBusWrapper
@Inject lateinit var uel: UserEntryLogger
override fun friendlyName(): Int = 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)
configBuilderPlugin.storeSettings("ActionLoopEnable")
rxBus.send(EventRefreshOverview("ActionLoopEnable"))
uel.log(UserEntry.Action.LOOP_ENABLED, ValueWithUnit(Sources.Automation))
callback.result(PumpEnactResult(injector).success(true).comment(R.string.ok))?.run()
} else {
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 info.nightscout.androidaps.automation.R
import info.nightscout.androidaps.data.PumpEnactResult
import info.nightscout.androidaps.database.entities.UserEntry
import info.nightscout.androidaps.database.entities.UserEntry.*
import info.nightscout.androidaps.events.EventRefreshOverview
import info.nightscout.androidaps.interfaces.ConfigBuilderInterface
import info.nightscout.androidaps.interfaces.LoopInterface
import info.nightscout.androidaps.logging.UserEntryLogger
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.queue.Callback
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 configBuilderPlugin: ConfigBuilderInterface
@Inject lateinit var rxBus: RxBusWrapper
@Inject lateinit var uel: UserEntryLogger
override fun friendlyName(): Int = 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")
loopPlugin.createOfflineEvent(0)
rxBus.send(EventRefreshOverview("ActionLoopResume"))
uel.log(UserEntry.Action.RESUME, ValueWithUnit(Sources.Automation))
callback.result(PumpEnactResult(injector).success(true).comment(R.string.ok))?.run()
} else {
callback.result(PumpEnactResult(injector).success(true).comment(R.string.notsuspended))?.run()

View file

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

View file

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

View file

@ -5,7 +5,10 @@ import androidx.annotation.DrawableRes
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.automation.R
import info.nightscout.androidaps.data.PumpEnactResult
import info.nightscout.androidaps.database.entities.UserEntry
import info.nightscout.androidaps.database.entities.UserEntry.*
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.InputDuration
import info.nightscout.androidaps.plugins.general.automation.elements.InputPercent
@ -21,6 +24,7 @@ import javax.inject.Inject
class ActionProfileSwitchPercent(injector: HasAndroidInjector) : Action(injector) {
@Inject lateinit var resourceHelper: ResourceHelper
@Inject lateinit var activePlugin: ActivePluginProvider
@Inject lateinit var uel: UserEntryLogger
var pct = InputPercent()
var duration = InputDuration(30, InputDuration.TimeUnit.MINUTES)
@ -37,6 +41,7 @@ class ActionProfileSwitchPercent(injector: HasAndroidInjector) : Action(injector
}
override fun doAction(callback: Callback) {
uel.log(UserEntry.Action.PROFILE_SWITCH, ValueWithUnit(Sources.Automation), ValueWithUnit(pct.value.toInt(), Units.Percent), ValueWithUnit(duration.value, Units.M))
activePlugin.activeTreatments.doProfileSwitch(duration.value, pct.value.toInt(), 0)
callback.result(PumpEnactResult(injector).success(true).comment(R.string.ok))?.run()
}

View file

@ -9,10 +9,13 @@ import info.nightscout.androidaps.data.Profile
import info.nightscout.androidaps.data.PumpEnactResult
import info.nightscout.androidaps.database.AppRepository
import info.nightscout.androidaps.database.entities.TemporaryTarget
import info.nightscout.androidaps.database.entities.UserEntry
import info.nightscout.androidaps.database.entities.UserEntry.*
import info.nightscout.androidaps.database.transactions.InsertTemporaryTargetAndCancelCurrentTransaction
import info.nightscout.androidaps.interfaces.ActivePluginProvider
import info.nightscout.androidaps.interfaces.ProfileFunction
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.InputDuration
import info.nightscout.androidaps.plugins.general.automation.elements.InputTempTarget
@ -39,6 +42,7 @@ class ActionStartTempTarget(injector: HasAndroidInjector) : Action(injector) {
@Inject lateinit var repository: AppRepository
@Inject lateinit var nsUpload: NSUpload
@Inject lateinit var profileFunction: ProfileFunction
@Inject lateinit var uel: UserEntryLogger
private val disposable = CompositeDisposable()
@ -58,6 +62,7 @@ class ActionStartTempTarget(injector: HasAndroidInjector) : Action(injector) {
.subscribe({ result ->
result.inserted.forEach { nsUpload.uploadTempTarget(it) }
result.updated.forEach { nsUpload.updateTempTarget(it) }
uel.log(UserEntry.Action.TT, ValueWithUnit(Sources.Automation), ValueWithUnit(TemporaryTarget.Reason.AUTOMATION.text, Units.TherapyEvent), ValueWithUnit(tt().lowTarget, Units.Mg_Dl), ValueWithUnit(tt().highTarget, Units.Mg_Dl, tt().lowTarget!=tt().highTarget), ValueWithUnit(TimeUnit.MILLISECONDS.toMinutes(tt().duration).toInt(), Units.M))
callback.result(PumpEnactResult(injector).success(true).comment(R.string.ok))?.run()
}, {
aapsLogger.error(LTag.BGSOURCE, "Error while saving temporary target", it)

View file

@ -4,9 +4,11 @@ import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.automation.R
import info.nightscout.androidaps.data.PumpEnactResult
import info.nightscout.androidaps.database.AppRepository
import info.nightscout.androidaps.database.entities.UserEntry
import info.nightscout.androidaps.database.transactions.CancelCurrentTemporaryTargetIfAnyTransaction
import info.nightscout.androidaps.interfaces.ActivePluginProvider
import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.logging.UserEntryLogger
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
import info.nightscout.androidaps.queue.Callback
import info.nightscout.androidaps.utils.DateUtil
@ -22,6 +24,7 @@ class ActionStopTempTarget(injector: HasAndroidInjector) : Action(injector) {
@Inject lateinit var repository: AppRepository
@Inject lateinit var nsUpload: NSUpload
@Inject lateinit var dateUtil: DateUtil
@Inject lateinit var uel: UserEntryLogger
private val disposable = CompositeDisposable()
@ -32,6 +35,7 @@ class ActionStopTempTarget(injector: HasAndroidInjector) : Action(injector) {
override fun doAction(callback: Callback) {
disposable += repository.runTransactionForResult(CancelCurrentTemporaryTargetIfAnyTransaction(DateUtil.now()))
.subscribe({ result ->
uel.log(UserEntry.Action.CANCEL_TT, UserEntry.ValueWithUnit(UserEntry.Sources.Automation))
result.updated.forEach { nsUpload.updateTempTarget(it) }
}, {
aapsLogger.error(LTag.BGSOURCE, "Error while saving temporary target", it)