mark too close BG records
This commit is contained in:
parent
21818546e7
commit
6ba6cd6edd
3 changed files with 65 additions and 62 deletions
|
@ -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) {
|
||||||
|
|
|
@ -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
|
||||||
|
@ -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()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,11 +9,6 @@
|
||||||
card_view:cardUseCompatPadding="true"
|
card_view:cardUseCompatPadding="true"
|
||||||
card_view:contentPadding="6dp">
|
card_view:contentPadding="6dp">
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:orientation="vertical">
|
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
@ -63,14 +58,12 @@
|
||||||
android:id="@+id/remove"
|
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:paddingEnd="5dp"
|
|
||||||
android:paddingStart="10dp"
|
android:paddingStart="10dp"
|
||||||
|
android:paddingEnd="5dp"
|
||||||
android:text="@string/remove_button"
|
android:text="@string/remove_button"
|
||||||
android:textAlignment="viewEnd"
|
android:textAlignment="viewEnd"
|
||||||
android:textColor="@android:color/holo_orange_light" />
|
android:textColor="@android:color/holo_orange_light" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
</androidx.cardview.widget.CardView>
|
</androidx.cardview.widget.CardView>
|
||||||
|
|
Loading…
Reference in a new issue