mark too close BG records

This commit is contained in:
Milos Kozak 2021-11-30 22:03:19 +01:00
parent 21818546e7
commit 6ba6cd6edd
3 changed files with 65 additions and 62 deletions

View file

@ -7,13 +7,13 @@ import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.bus.RxBus
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventBucketedDataCreated
import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.T
import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.rxkotlin.plusAssign
import java.util.*
import javax.inject.Inject
import javax.inject.Singleton
import kotlin.math.abs
@ -26,7 +26,8 @@ class BgQualityCheckPlugin @Inject constructor(
private val rxBus: RxBus,
private val iobCobCalculator: IobCobCalculator,
private val aapsSchedulers: AapsSchedulers,
private val fabricPrivacy: FabricPrivacy
private val fabricPrivacy: FabricPrivacy,
private val dateUtil: DateUtil
) : PluginBase(
PluginDescription()
.mainType(PluginType.CONSTRAINTS)
@ -70,6 +71,7 @@ class BgQualityCheckPlugin @Inject constructor(
return value
}
@Suppress("CascadeIf")
fun processBgData() {
val readings = iobCobCalculator.ads.getBgReadingsDataTableCopy()
for (i in readings.indices)
@ -77,7 +79,7 @@ class BgQualityCheckPlugin @Inject constructor(
if (abs(readings[i].timestamp - readings[i + 1].timestamp) <= T.secs(20).msecs()) {
state = State.DOUBLED
aapsLogger.debug(LTag.CORE, "BG similar. Turning on red state.\n${readings[i]}\n${readings[i+1]}")
message = rh.gs(R.string.bg_too_close, readings[i].toString(), readings[i+1].toString())
message = rh.gs(R.string.bg_too_close, dateUtil.dateAndTimeAndSecondsString(readings[i].timestamp), dateUtil.dateAndTimeAndSecondsString(readings[i+1].timestamp))
return
}
if (iobCobCalculator.ads.lastUsed5minCalculation == true) {

View file

@ -117,6 +117,12 @@ class BGSourceFragment : DaggerFragment() {
holder.binding.value.text = glucoseValue.valueToUnitsString(profileFunction.getUnits())
holder.binding.direction.setImageResource(glucoseValue.trendArrow.directionToIcon())
holder.binding.remove.tag = glucoseValue
if (position > 0) {
val previous = glucoseValues[position - 1]
val diff = previous.timestamp - glucoseValue.timestamp
if (diff < T.secs(20).msecs())
holder.binding.root.setBackgroundColor(rh.gc(R.color.errorAlertBackground))
}
}
override fun getItemCount(): Int = glucoseValues.size
@ -132,7 +138,7 @@ class BGSourceFragment : DaggerFragment() {
activity?.let { activity ->
val text = dateUtil.dateAndTimeString(glucoseValue.timestamp) + "\n" + glucoseValue.valueToUnitsString(profileFunction.getUnits())
OKDialog.showConfirmation(activity, rh.gs(R.string.removerecord), text, Runnable {
val source = when((activePlugin.activeBgSource as PluginBase).pluginDescription.pluginName) {
val source = when ((activePlugin.activeBgSource as PluginBase).pluginDescription.pluginName) {
R.string.dexcom_app_patched -> Sources.Dexcom
R.string.eversense -> Sources.Eversense
R.string.Glimp -> Sources.Glimp
@ -144,8 +150,10 @@ class BGSourceFragment : DaggerFragment() {
R.string.xdrip -> Sources.Xdrip
else -> Sources.Unknown
}
uel.log(Action.BG_REMOVED, source,
ValueWithUnit.Timestamp(glucoseValue.timestamp))
uel.log(
Action.BG_REMOVED, source,
ValueWithUnit.Timestamp(glucoseValue.timestamp)
)
disposable += repository.runTransaction(InvalidateGlucoseValueTransaction(glucoseValue.id)).subscribe()
})
}

View file

@ -9,11 +9,6 @@
card_view:cardUseCompatPadding="true"
card_view:contentPadding="6dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -63,14 +58,12 @@
android:id="@+id/remove"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingEnd="5dp"
android:paddingStart="10dp"
android:paddingEnd="5dp"
android:text="@string/remove_button"
android:textAlignment="viewEnd"
android:textColor="@android:color/holo_orange_light" />
</LinearLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>