Add UserEntry for Wear

This commit is contained in:
Philoul 2021-03-27 00:58:01 +01:00
parent b329971d9a
commit 2e59dd3112
4 changed files with 21 additions and 4 deletions

View file

@ -17,6 +17,7 @@ import info.nightscout.androidaps.database.AppRepository
import info.nightscout.androidaps.database.ValueWrapper
import info.nightscout.androidaps.database.entities.TemporaryTarget
import info.nightscout.androidaps.database.entities.TherapyEvent
import info.nightscout.androidaps.database.entities.UserEntry.*
import info.nightscout.androidaps.database.interfaces.end
import info.nightscout.androidaps.database.transactions.CancelCurrentTemporaryTargetIfAnyTransaction
import info.nightscout.androidaps.database.transactions.InsertTemporaryTargetAndCancelCurrentTransaction
@ -24,6 +25,7 @@ import info.nightscout.androidaps.db.Source
import info.nightscout.androidaps.db.TDD
import info.nightscout.androidaps.interfaces.*
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.UserEntryLogger
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
@ -82,6 +84,7 @@ class ActionStringHandler @Inject constructor(
private val config: Config,
private val databaseHelper: DatabaseHelperInterface,
private val repository: AppRepository,
private val uel: UserEntryLogger,
private val nsUpload: NSUpload
) {
@ -105,7 +108,7 @@ class ActionStringHandler @Inject constructor(
}
@Synchronized
private fun handleInitiate(actionString: String) {
fun handleInitiate(actionString: String) {
if (!sp.getBoolean(R.string.key_wear_control, false)) return
lastBolusWizard = null
var rTitle = "CONFIRM" //TODO: i18n
@ -546,8 +549,10 @@ class ActionStringHandler @Inject constructor(
if (carbs > 0) {
if (duration == 0) {
carbsGenerator.createCarb(carbs, time, TherapyEvent.Type.CARBS_CORRECTION.text, "watch")
uel.log(Action.CARBS, ValueWithUnit(Sources.Wear), ValueWithUnit(time, Units.Timestamp), ValueWithUnit(carbs, Units.G))
} else {
carbsGenerator.generateCarbs(carbs, time, duration, "watch eCarbs")
uel.log(Action.EXTENDED_CARBS, ValueWithUnit(Sources.Wear), ValueWithUnit(time, Units.Timestamp), ValueWithUnit(carbs, Units.G), ValueWithUnit(duration, Units.H))
}
}
}
@ -575,11 +580,12 @@ class ActionStringHandler @Inject constructor(
return
}
//send profile to pump
uel.log(Action.PROFILE_SWITCH, ValueWithUnit(Sources.Wear), ValueWithUnit(percentage, Units.Percent), ValueWithUnit(timeshift, Units.H, timeshift != 0))
activePlugin.activeTreatments.doProfileSwitch(0, percentage, timeshift)
}
private fun generateTempTarget(duration: Int, low: Double, high: Double) {
if (duration != 0)
if (duration != 0) {
disposable += repository.runTransactionForResult(InsertTemporaryTargetAndCancelCurrentTransaction(
timestamp = System.currentTimeMillis(),
duration = TimeUnit.MINUTES.toMillis(duration.toLong()),
@ -592,13 +598,16 @@ class ActionStringHandler @Inject constructor(
}, {
aapsLogger.error("Error while saving temporary target", it)
})
else
uel.log(Action.TT, ValueWithUnit(Sources.Wear), ValueWithUnit(TemporaryTarget.Reason.WEAR.text, Units.TherapyEvent), ValueWithUnit(low, profileFunction.getUnits()), ValueWithUnit(high, profileFunction.getUnits(), low!=high), ValueWithUnit(duration, Units.M))
} else {
disposable += repository.runTransactionForResult(CancelCurrentTemporaryTargetIfAnyTransaction(System.currentTimeMillis()))
.subscribe({ result ->
result.updated.forEach { nsUpload.updateTempTarget(it) }
}, {
aapsLogger.error("Error while saving temporary target", it)
})
uel.log(Action.CANCEL_TT, ValueWithUnit(Sources.Wear), ValueWithUnit(TemporaryTarget.Reason.WEAR.text, Units.TherapyEvent))
}
}
private fun doFillBolus(amount: Double) {
@ -606,6 +615,7 @@ class ActionStringHandler @Inject constructor(
detailedBolusInfo.insulin = amount
detailedBolusInfo.isValid = false
detailedBolusInfo.source = Source.USER
uel.log(Action.PRIME_BOLUS, ValueWithUnit(Sources.Wear), ValueWithUnit(amount, Units.U, amount != 0.0))
commandQueue.bolus(detailedBolusInfo, object : Callback() {
override fun run() {
if (!result.success) {
@ -624,6 +634,12 @@ class ActionStringHandler @Inject constructor(
detailedBolusInfo.source = Source.USER
val storesCarbs = activePlugin.activePump.pumpDescription.storesCarbInfo
if (detailedBolusInfo.insulin > 0 || storesCarbs) {
val action = when {
amount.equals(0.0) -> Action.CARBS
carbs.equals(0) -> Action.BOLUS
else -> Action.TREATMENT
}
uel.log(action, ValueWithUnit(Sources.Wear), ValueWithUnit(amount, Units.U, amount != 0.0), ValueWithUnit(carbs, Units.G, carbs != 0))
commandQueue.bolus(detailedBolusInfo, object : Callback() {
override fun run() {
if (!result.success) {

View file

@ -42,6 +42,7 @@ fun Sources.iconId(): Int {
Sources.Automation -> R.drawable.ic_automation
Sources.Loop -> R.drawable.ic_loop_closed_white
Sources.NSClient -> R.drawable.ic_nightscout_syncs
Sources.Wear -> R.drawable.ic_watch
else -> -1
}
}

View file

@ -102,7 +102,7 @@ data class UserEntry(
constructor(lvalue: Long, unit: Units, condition:Boolean = true) : this(0.0,0, lvalue, "", unit, condition)
constructor(svalue: String, unit:Units) : this(0.0,0, 0, svalue, unit, svalue != "")
constructor(source: Sources) : this(0.0,0, 0, source.text, Units.Source, true)
constructor(dvalue: Double, unit:String) : this(dvalue,0, 0, "", Units.fromText(unit))
constructor(dvalue: Double, unit:String, condition:Boolean = true) : this(dvalue,0, 0, "", Units.fromText(unit), condition)
constructor(rStringRef: Int, nbParam: Long) : this(0.0, rStringRef, nbParam, "", Units.R_String, !rStringRef.equals(0)) // additionnal constructors for formated strings with additional values as parameters (define number of parameters as long
fun value() : Any {