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

View file

@ -82,11 +82,11 @@ class BGSourceFragment : DaggerFragment() {
.observeOn(aapsSchedulers.io) .observeOn(aapsSchedulers.io)
.debounce(1L, TimeUnit.SECONDS) .debounce(1L, TimeUnit.SECONDS)
.subscribe({ .subscribe({
disposable += repository disposable += repository
.compatGetBgReadingsDataFromTime(now - millsToThePast, false) .compatGetBgReadingsDataFromTime(now - millsToThePast, false)
.observeOn(aapsSchedulers.main) .observeOn(aapsSchedulers.main)
.subscribe { list -> binding.recyclerview.swapAdapter(RecyclerViewAdapter(list), true) } .subscribe { list -> binding.recyclerview.swapAdapter(RecyclerViewAdapter(list), true) }
}, fabricPrivacy::logException) }, fabricPrivacy::logException)
} }
@Synchronized @Synchronized
@ -117,6 +117,12 @@ class BGSourceFragment : DaggerFragment() {
holder.binding.value.text = glucoseValue.valueToUnitsString(profileFunction.getUnits()) holder.binding.value.text = glucoseValue.valueToUnitsString(profileFunction.getUnits())
holder.binding.direction.setImageResource(glucoseValue.trendArrow.directionToIcon()) holder.binding.direction.setImageResource(glucoseValue.trendArrow.directionToIcon())
holder.binding.remove.tag = glucoseValue 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 override fun getItemCount(): Int = glucoseValues.size
@ -132,7 +138,7 @@ 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, rh.gs(R.string.removerecord), text, Runnable { 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.dexcom_app_patched -> Sources.Dexcom
R.string.eversense -> Sources.Eversense R.string.eversense -> Sources.Eversense
R.string.Glimp -> Sources.Glimp R.string.Glimp -> Sources.Glimp
@ -144,8 +150,10 @@ class BGSourceFragment : DaggerFragment() {
R.string.xdrip -> Sources.Xdrip R.string.xdrip -> Sources.Xdrip
else -> Sources.Unknown else -> Sources.Unknown
} }
uel.log(Action.BG_REMOVED, source, uel.log(
ValueWithUnit.Timestamp(glucoseValue.timestamp)) Action.BG_REMOVED, source,
ValueWithUnit.Timestamp(glucoseValue.timestamp)
)
disposable += repository.runTransaction(InvalidateGlucoseValueTransaction(glucoseValue.id)).subscribe() disposable += repository.runTransaction(InvalidateGlucoseValueTransaction(glucoseValue.id)).subscribe()
}) })
} }

View file

@ -12,64 +12,57 @@
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"> android:gravity="center"
android:orientation="horizontal">
<LinearLayout <TextView
android:layout_width="match_parent" android:id="@+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="center" android:text="16:55"
android:orientation="horizontal"> android:textStyle="bold" />
<TextView <TextView
android:id="@+id/date" android:id="@+id/value"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="16:55" android:paddingStart="10dp"
android:textStyle="bold" /> android:text="Name"
android:textStyle="bold" />
<TextView <ImageView
android:id="@+id/value" android:id="@+id/direction"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:paddingStart="10dp" android:layout_gravity="center_vertical"
android:text="Name" card_view:srcCompat="@drawable/ic_flat" />
android:textStyle="bold" />
<ImageView <TextView
android:id="@+id/direction" android:id="@+id/ns"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="wrap_content"
android:layout_gravity="center_vertical" android:paddingStart="10dp"
card_view:srcCompat="@drawable/ic_flat" /> android:text="NS"
android:textAlignment="viewEnd"
android:textColor="@color/colorSetTempButton" />
<TextView <TextView
android:id="@+id/ns" android:id="@+id/invalid"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingStart="10dp" android:paddingStart="10dp"
android:text="NS" android:text="@string/invalid"
android:textAlignment="viewEnd" android:textColor="@android:color/holo_red_light" />
android:textColor="@color/colorSetTempButton" />
<TextView <TextView
android:id="@+id/invalid" android:id="@+id/remove"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingStart="10dp" android:paddingStart="10dp"
android:text="@string/invalid" android:paddingEnd="5dp"
android:textColor="@android:color/holo_red_light" /> android:text="@string/remove_button"
android:textAlignment="viewEnd"
<TextView android:textColor="@android:color/holo_orange_light" />
android:id="@+id/remove"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingEnd="5dp"
android:paddingStart="10dp"
android:text="@string/remove_button"
android:textAlignment="viewEnd"
android:textColor="@android:color/holo_orange_light" />
</LinearLayout>
</LinearLayout> </LinearLayout>