use tdd for cannula usage

This commit is contained in:
Andries Smit 2022-11-24 09:55:44 +01:00
parent c5925c4f8f
commit d7a7f6a533
2 changed files with 12 additions and 15 deletions

View file

@ -2,7 +2,6 @@ package info.nightscout.plugins.ui
import android.widget.TextView import android.widget.TextView
import androidx.annotation.StringRes import androidx.annotation.StringRes
import info.nightscout.database.entities.Bolus
import info.nightscout.database.entities.TherapyEvent import info.nightscout.database.entities.TherapyEvent
import info.nightscout.database.impl.AppRepository import info.nightscout.database.impl.AppRepository
import info.nightscout.database.impl.ValueWrapper import info.nightscout.database.impl.ValueWrapper
@ -10,6 +9,7 @@ import info.nightscout.interfaces.Config
import info.nightscout.interfaces.plugin.ActivePlugin import info.nightscout.interfaces.plugin.ActivePlugin
import info.nightscout.interfaces.pump.WarnColors import info.nightscout.interfaces.pump.WarnColors
import info.nightscout.interfaces.pump.defs.PumpType import info.nightscout.interfaces.pump.defs.PumpType
import info.nightscout.interfaces.stats.TddCalculator
import info.nightscout.interfaces.utils.DecimalFormatter import info.nightscout.interfaces.utils.DecimalFormatter
import info.nightscout.plugins.R import info.nightscout.plugins.R
import info.nightscout.plugins.sync.nsclient.extensions.age import info.nightscout.plugins.sync.nsclient.extensions.age
@ -27,7 +27,8 @@ class StatusLightHandler @Inject constructor(
private val activePlugin: ActivePlugin, private val activePlugin: ActivePlugin,
private val warnColors: WarnColors, private val warnColors: WarnColors,
private val config: Config, private val config: Config,
private val repository: AppRepository private val repository: AppRepository,
private val tddCalculator: TddCalculator
) { ) {
/** /**
@ -105,8 +106,7 @@ class StatusLightHandler @Inject constructor(
private fun handleLevel(view: TextView?, criticalSetting: Int, criticalDefaultValue: Double, warnSetting: Int, warnDefaultValue: Double, level: Double, units: String) { private fun handleLevel(view: TextView?, criticalSetting: Int, criticalDefaultValue: Double, warnSetting: Int, warnDefaultValue: Double, level: Double, units: String) {
val resUrgent = sp.getDouble(criticalSetting, criticalDefaultValue) val resUrgent = sp.getDouble(criticalSetting, criticalDefaultValue)
val resWarn = sp.getDouble(warnSetting, warnDefaultValue) val resWarn = sp.getDouble(warnSetting, warnDefaultValue)
@Suppress("SetTextI18n") view?.text = " " + DecimalFormatter.to0Decimal(level, units)
view?.text = " " + DecimalFormatter.to0Decimal(level) + units
warnColors.setColorInverse(view, level, resWarn, resUrgent) warnColors.setColorInverse(view, level, resWarn, resUrgent)
} }
@ -117,8 +117,7 @@ class StatusLightHandler @Inject constructor(
warnDefaultValue: Double, level: Double, units: String, maxReading: Double warnDefaultValue: Double, level: Double, units: String, maxReading: Double
) { ) {
if (level >= maxReading) { if (level >= maxReading) {
@Suppress("SetTextI18n") view?.text = DecimalFormatter.to0Decimal(maxReading, units)
view?.text = " ${maxReading.toInt()}+$units"
view?.setTextColor(rh.gac(view.context, R.attr.defaultTextColor)) view?.setTextColor(rh.gac(view.context, R.attr.defaultTextColor))
} else { } else {
handleLevel(view, criticalSetting, criticalDefaultValue, warnSetting, warnDefaultValue, level, units) handleLevel(view, criticalSetting, criticalDefaultValue, warnSetting, warnDefaultValue, level, units)
@ -129,11 +128,9 @@ class StatusLightHandler @Inject constructor(
val therapyEvent = repository.getLastTherapyRecordUpToNow(type).blockingGet() val therapyEvent = repository.getLastTherapyRecordUpToNow(type).blockingGet()
var usage = 0.0 var usage = 0.0
if (therapyEvent is ValueWrapper.Existing) { if (therapyEvent is ValueWrapper.Existing) {
val startTime = therapyEvent.value.timestamp val tdd = tddCalculator.calculate(therapyEvent.value.timestamp, dateUtil.now())
usage = repository.getBolusesDataFromTime(startTime, true).blockingGet() usage = tdd.totalAmount
.filter { it.type != Bolus.Type.PRIMING }
.sumOf { t -> t.amount }
} }
view?.text = " " + DecimalFormatter.to0Decimal(usage) + units view?.text = DecimalFormatter.to0Decimal(usage, units)
} }
} }

View file

@ -56,7 +56,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginEnd="20dp" android:layout_marginEnd="20dp"
android:gravity="center_vertical" android:gravity="center_vertical"
android:paddingStart="2dp" android:paddingStart="4dp"
android:paddingEnd="0dp" android:paddingEnd="0dp"
android:textSize="14sp" /> android:textSize="14sp" />
@ -128,7 +128,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginEnd="20dp" android:layout_marginEnd="20dp"
android:gravity="center_vertical" android:gravity="center_vertical"
android:paddingStart="2dp" android:paddingStart="4dp"
android:paddingEnd="0dp" android:paddingEnd="0dp"
android:textSize="14sp" android:textSize="14sp"
tools:text="15U" /> tools:text="15U" />
@ -202,7 +202,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginEnd="20dp" android:layout_marginEnd="20dp"
android:gravity="center_vertical" android:gravity="center_vertical"
android:paddingStart="2dp" android:paddingStart="4dp"
android:paddingEnd="0dp" android:paddingEnd="0dp"
android:textSize="14sp" android:textSize="14sp"
tools:text="22U" /> tools:text="22U" />
@ -277,7 +277,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginEnd="20dp" android:layout_marginEnd="20dp"
android:gravity="center_vertical" android:gravity="center_vertical"
android:paddingStart="2dp" android:paddingStart="4dp"
android:paddingEnd="0dp" android:paddingEnd="0dp"
android:textSize="14sp" android:textSize="14sp"
tools:text="70%" /> tools:text="70%" />