show bucketed data in dev mode
This commit is contained in:
parent
a6b67b2bb7
commit
639328bdc3
13 changed files with 88 additions and 40 deletions
|
@ -295,7 +295,8 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() {
|
||||||
graphData.addInRangeArea(fromTime, toTime, lowLine, highLine)
|
graphData.addInRangeArea(fromTime, toTime, lowLine, highLine)
|
||||||
|
|
||||||
// **** BG ****
|
// **** BG ****
|
||||||
graphData.addBgReadings(fromTime, toTime, lowLine, highLine, null)
|
graphData.addBgReadings(fromTime, toTime, highLine, null)
|
||||||
|
if (buildHelper.isDev()) graphData.addBucketedData(fromTime, toTime)
|
||||||
|
|
||||||
// add target line
|
// add target line
|
||||||
graphData.addTargetLine(fromTime, toTime, profile, null)
|
graphData.addTargetLine(fromTime, toTime, profile, null)
|
||||||
|
|
|
@ -862,8 +862,9 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
|
||||||
|
|
||||||
// **** BG ****
|
// **** BG ****
|
||||||
if (predictionsAvailable && menuChartSettings[0][OverviewMenus.CharType.PRE.ordinal])
|
if (predictionsAvailable && menuChartSettings[0][OverviewMenus.CharType.PRE.ordinal])
|
||||||
graphData.addBgReadings(fromTime, toTime, lowLine, highLine, apsResult?.predictions?.map { bg-> GlucoseValueDataPoint(bg, defaultValueHelper, profileFunction, resourceHelper) }?.toMutableList())
|
graphData.addBgReadings(fromTime, toTime, highLine, apsResult?.predictions?.map { bg-> GlucoseValueDataPoint(bg, defaultValueHelper, profileFunction, resourceHelper) }?.toMutableList())
|
||||||
else graphData.addBgReadings(fromTime, toTime, lowLine, highLine, null)
|
else graphData.addBgReadings(fromTime, toTime, highLine, null)
|
||||||
|
if (buildHelper.isDev()) graphData.addBucketedData(fromTime, toTime)
|
||||||
|
|
||||||
// Treatments
|
// Treatments
|
||||||
graphData.addTreatments(fromTime, endTime)
|
graphData.addTreatments(fromTime, endTime)
|
||||||
|
|
|
@ -61,10 +61,23 @@ class GraphData(
|
||||||
units = profileFunction.getUnits()
|
units = profileFunction.getUnits()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("UNUSED_PARAMETER")
|
fun addBucketedData(fromTime: Long, toTime: Long) {
|
||||||
fun addBgReadings(fromTime: Long, toTime: Long, lowLine: Double, highLine: Double, predictions: MutableList<GlucoseValueDataPoint>?) {
|
val bucketedData = iobCobCalculator.bucketedData ?: return
|
||||||
|
if (bucketedData.isEmpty()) {
|
||||||
|
aapsLogger.debug("No bucketed data.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val bucketedListArray: MutableList<DataPointWithLabelInterface> = ArrayList()
|
||||||
|
for (inMemoryGlucoseValue in bucketedData) {
|
||||||
|
if (inMemoryGlucoseValue.timestamp < fromTime || inMemoryGlucoseValue.timestamp > toTime) continue
|
||||||
|
bucketedListArray.add(InMemoryGlucoseValueDataPoint(inMemoryGlucoseValue, qgiprofileFunction, resourceHelper))
|
||||||
|
}
|
||||||
|
addSeries(PointsWithLabelGraphSeries(Array(bucketedListArray.size) { i -> bucketedListArray[i] }))
|
||||||
|
}
|
||||||
|
|
||||||
|
fun addBgReadings(fromTime: Long, toTime: Long, highLine: Double, predictions: MutableList<GlucoseValueDataPoint>?) {
|
||||||
var maxBgValue = Double.MIN_VALUE
|
var maxBgValue = Double.MIN_VALUE
|
||||||
bgReadingsArray = iobCobCalculator.bgReadings
|
bgReadingsArray = repository.compatGetBgReadingsDataFromTime(fromTime, toTime, true).blockingGet()
|
||||||
if (bgReadingsArray?.isEmpty() != false) {
|
if (bgReadingsArray?.isEmpty() != false) {
|
||||||
aapsLogger.debug("No BG data.")
|
aapsLogger.debug("No BG data.")
|
||||||
maxY = if (units == Constants.MGDL) 180.0 else 10.0
|
maxY = if (units == Constants.MGDL) 180.0 else 10.0
|
||||||
|
|
|
@ -52,7 +52,7 @@ class GlucoseValueDataPoint @Inject constructor(
|
||||||
return when (data.sourceSensor) {
|
return when (data.sourceSensor) {
|
||||||
GlucoseValue.SourceSensor.IOB_PREDICTION -> resourceHelper.gc(R.color.iob)
|
GlucoseValue.SourceSensor.IOB_PREDICTION -> resourceHelper.gc(R.color.iob)
|
||||||
GlucoseValue.SourceSensor.COB_PREDICTION -> resourceHelper.gc(R.color.cob)
|
GlucoseValue.SourceSensor.COB_PREDICTION -> resourceHelper.gc(R.color.cob)
|
||||||
GlucoseValue.SourceSensor.aCOB_PREDICTION -> -0x7f000001 and resourceHelper.gc(R.color.cob)
|
GlucoseValue.SourceSensor.A_COB_PREDICTION -> -0x7f000001 and resourceHelper.gc(R.color.cob)
|
||||||
GlucoseValue.SourceSensor.UAM_PREDICTION -> resourceHelper.gc(R.color.uam)
|
GlucoseValue.SourceSensor.UAM_PREDICTION -> resourceHelper.gc(R.color.uam)
|
||||||
GlucoseValue.SourceSensor.ZT_PREDICTION -> resourceHelper.gc(R.color.zt)
|
GlucoseValue.SourceSensor.ZT_PREDICTION -> resourceHelper.gc(R.color.zt)
|
||||||
else -> R.color.white
|
else -> R.color.white
|
||||||
|
@ -62,7 +62,7 @@ class GlucoseValueDataPoint @Inject constructor(
|
||||||
private val isPrediction: Boolean
|
private val isPrediction: Boolean
|
||||||
get() = data.sourceSensor == GlucoseValue.SourceSensor.IOB_PREDICTION ||
|
get() = data.sourceSensor == GlucoseValue.SourceSensor.IOB_PREDICTION ||
|
||||||
data.sourceSensor == GlucoseValue.SourceSensor.COB_PREDICTION ||
|
data.sourceSensor == GlucoseValue.SourceSensor.COB_PREDICTION ||
|
||||||
data.sourceSensor == GlucoseValue.SourceSensor.aCOB_PREDICTION ||
|
data.sourceSensor == GlucoseValue.SourceSensor.A_COB_PREDICTION ||
|
||||||
data.sourceSensor == GlucoseValue.SourceSensor.UAM_PREDICTION ||
|
data.sourceSensor == GlucoseValue.SourceSensor.UAM_PREDICTION ||
|
||||||
data.sourceSensor == GlucoseValue.SourceSensor.ZT_PREDICTION
|
data.sourceSensor == GlucoseValue.SourceSensor.ZT_PREDICTION
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
package info.nightscout.androidaps.plugins.general.overview.graphExtensions
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.Constants
|
||||||
|
import info.nightscout.androidaps.core.R
|
||||||
|
import info.nightscout.androidaps.data.InMemoryGlucoseValue
|
||||||
|
import info.nightscout.androidaps.interfaces.ProfileFunction
|
||||||
|
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class InMemoryGlucoseValueDataPoint @Inject constructor(
|
||||||
|
val data: InMemoryGlucoseValue,
|
||||||
|
private val profileFunction: ProfileFunction,
|
||||||
|
private val resourceHelper: ResourceHelper
|
||||||
|
) : DataPointWithLabelInterface {
|
||||||
|
|
||||||
|
fun valueToUnits(units: String): Double =
|
||||||
|
if (units == Constants.MGDL) data.value else data.value * Constants.MGDL_TO_MMOLL
|
||||||
|
|
||||||
|
override fun getX(): Double = data.timestamp.toDouble()
|
||||||
|
override fun getY(): Double = valueToUnits(profileFunction.getUnits())
|
||||||
|
override fun setY(y: Double) {}
|
||||||
|
override fun getLabel(): String? = null
|
||||||
|
override fun getDuration(): Long = 0
|
||||||
|
override fun getShape(): PointsWithLabelGraphSeries.Shape = PointsWithLabelGraphSeries.Shape.BUCKETED_BG
|
||||||
|
override fun getSize(): Float = 0.3f
|
||||||
|
override fun getColor(): Int = resourceHelper.gc(R.color.white)
|
||||||
|
}
|
|
@ -1,9 +1,2 @@
|
||||||
package info.nightscout.androidaps.plugins.iob.iobCobCalculator
|
package info.nightscout.androidaps.plugins.iob.iobCobCalculator
|
||||||
|
|
||||||
import info.nightscout.androidaps.database.entities.GlucoseValue
|
|
||||||
|
|
||||||
class InMemoryGlucoseValue @JvmOverloads constructor(var timestamp: Long = 0L, var value: Double = 0.0, var interpolated: Boolean = false) {
|
|
||||||
|
|
||||||
constructor(gv: GlucoseValue) : this(gv.timestamp, gv.value)
|
|
||||||
// var generated : value doesn't correspond to real value with timestamp close to real BG
|
|
||||||
}
|
|
|
@ -5,6 +5,7 @@ import androidx.collection.LongSparseArray
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.androidaps.Constants
|
import info.nightscout.androidaps.Constants
|
||||||
import info.nightscout.androidaps.R
|
import info.nightscout.androidaps.R
|
||||||
|
import info.nightscout.androidaps.data.InMemoryGlucoseValue
|
||||||
import info.nightscout.androidaps.data.IobTotal
|
import info.nightscout.androidaps.data.IobTotal
|
||||||
import info.nightscout.androidaps.data.MealData
|
import info.nightscout.androidaps.data.MealData
|
||||||
import info.nightscout.androidaps.data.Profile
|
import info.nightscout.androidaps.data.Profile
|
||||||
|
@ -77,8 +78,9 @@ open class IobCobCalculatorPlugin @Inject constructor(
|
||||||
private var absIobTable = LongSparseArray<IobTotal>() // oldest at index 0, absolute insulin in the body
|
private var absIobTable = LongSparseArray<IobTotal>() // oldest at index 0, absolute insulin in the body
|
||||||
private var autosensDataTable = LongSparseArray<AutosensData>() // oldest at index 0
|
private var autosensDataTable = LongSparseArray<AutosensData>() // oldest at index 0
|
||||||
private var basalDataTable = LongSparseArray<BasalData>() // oldest at index 0
|
private var basalDataTable = LongSparseArray<BasalData>() // oldest at index 0
|
||||||
@Volatile override var bgReadings: List<GlucoseValue> = listOf() // newest at index 0
|
override var bgReadings: List<GlucoseValue> = listOf() // newest at index 0
|
||||||
@Volatile var bucketedData: MutableList<InMemoryGlucoseValue>? = null
|
|
||||||
|
@Volatile override var bucketedData: MutableList<InMemoryGlucoseValue>? = null
|
||||||
|
|
||||||
// we need to make sure that bucketed_data will always have the same timestamp for correct use of cached values
|
// we need to make sure that bucketed_data will always have the same timestamp for correct use of cached values
|
||||||
// once referenceTime != null all bucketed data should be (x * 5min) from referenceTime
|
// once referenceTime != null all bucketed data should be (x * 5min) from referenceTime
|
||||||
|
@ -780,7 +782,16 @@ open class IobCobCalculatorPlugin @Inject constructor(
|
||||||
|
|
||||||
override fun calculateIobFromBolus(): IobTotal = calculateIobFromBolusToTime(dateUtil.now())
|
override fun calculateIobFromBolus(): IobTotal = calculateIobFromBolusToTime(dateUtil.now())
|
||||||
|
|
||||||
override fun calculateIobFromBolusToTime(toTime: Long): IobTotal {
|
/**
|
||||||
|
* Calculate IobTotal from boluses and extended to provided timestamp.
|
||||||
|
* NOTE: Only isValid == true boluses are included
|
||||||
|
* NOTE: if faking by TBR by extended boluses is enabled, extended boluses are not included
|
||||||
|
* and are calculated towards temporary basals
|
||||||
|
*
|
||||||
|
* @param toTime timestamp in milliseconds
|
||||||
|
* @return calculated iob
|
||||||
|
*/
|
||||||
|
private fun calculateIobFromBolusToTime(toTime: Long): IobTotal {
|
||||||
val total = IobTotal(toTime)
|
val total = IobTotal(toTime)
|
||||||
val profile = profileFunction.getProfile() ?: return total
|
val profile = profileFunction.getProfile() ?: return total
|
||||||
val dia = profile.dia
|
val dia = profile.dia
|
||||||
|
|
|
@ -63,8 +63,8 @@ class RandomBgPlugin @Inject constructor(
|
||||||
|
|
||||||
init {
|
init {
|
||||||
refreshLoop = Runnable {
|
refreshLoop = Runnable {
|
||||||
handleNewData()
|
|
||||||
loopHandler.postDelayed(refreshLoop, T.mins(interval).msecs())
|
loopHandler.postDelayed(refreshLoop, T.mins(interval).msecs())
|
||||||
|
handleNewData()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
package info.nightscout.androidaps.data
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.database.entities.GlucoseValue
|
||||||
|
|
||||||
|
class InMemoryGlucoseValue @JvmOverloads constructor(var timestamp: Long = 0L, var value: Double = 0.0, var interpolated: Boolean = false) {
|
||||||
|
|
||||||
|
constructor(gv: GlucoseValue) : this(gv.timestamp, gv.value)
|
||||||
|
// var generated : value doesn't correspond to real value with timestamp close to real BG
|
||||||
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
package info.nightscout.androidaps.interfaces
|
package info.nightscout.androidaps.interfaces
|
||||||
|
|
||||||
import androidx.collection.LongSparseArray
|
import androidx.collection.LongSparseArray
|
||||||
|
import info.nightscout.androidaps.data.InMemoryGlucoseValue
|
||||||
import info.nightscout.androidaps.data.IobTotal
|
import info.nightscout.androidaps.data.IobTotal
|
||||||
import info.nightscout.androidaps.data.MealData
|
import info.nightscout.androidaps.data.MealData
|
||||||
import info.nightscout.androidaps.data.Profile
|
import info.nightscout.androidaps.data.Profile
|
||||||
|
@ -17,6 +18,7 @@ interface IobCobCalculator {
|
||||||
|
|
||||||
val dataLock: Any
|
val dataLock: Any
|
||||||
var bgReadings: List<GlucoseValue>
|
var bgReadings: List<GlucoseValue>
|
||||||
|
var bucketedData: MutableList<InMemoryGlucoseValue>?
|
||||||
|
|
||||||
val mealData: MealData
|
val mealData: MealData
|
||||||
fun getAutosensDataTable(): LongSparseArray<AutosensData>
|
fun getAutosensDataTable(): LongSparseArray<AutosensData>
|
||||||
|
@ -33,6 +35,7 @@ interface IobCobCalculator {
|
||||||
fun slowAbsorptionPercentage(timeInMinutes: Int): Double
|
fun slowAbsorptionPercentage(timeInMinutes: Int): Double
|
||||||
fun convertToJSONArray(iobArray: Array<IobTotal>): JSONArray
|
fun convertToJSONArray(iobArray: Array<IobTotal>): JSONArray
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return last valid (>39) GlucoseValue from database or null if db is empty
|
* Return last valid (>39) GlucoseValue from database or null if db is empty
|
||||||
*
|
*
|
||||||
|
@ -66,17 +69,6 @@ interface IobCobCalculator {
|
||||||
*/
|
*/
|
||||||
fun calculateIobFromBolus(): IobTotal
|
fun calculateIobFromBolus(): IobTotal
|
||||||
|
|
||||||
/**
|
|
||||||
* Calculate IobTotal from boluses and extended to provided timestamp.
|
|
||||||
* NOTE: Only isValid == true boluses are included
|
|
||||||
* NOTE: if faking by TBR by extended boluses is enabled, extended boluses are not included
|
|
||||||
* and are calculated towards temporary basals
|
|
||||||
*
|
|
||||||
* @param timestamp timestamp in milliseconds
|
|
||||||
* @return calculated iob
|
|
||||||
*/
|
|
||||||
fun calculateIobFromBolusToTime(toTime: Long): IobTotal
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get running temporary basal at time
|
* Get running temporary basal at time
|
||||||
*
|
*
|
||||||
|
|
|
@ -215,7 +215,7 @@ open class APSResult @Inject constructor(val injector: HasAndroidInjector) {
|
||||||
noise = 0.0,
|
noise = 0.0,
|
||||||
value = iob.getInt(i).toDouble(),
|
value = iob.getInt(i).toDouble(),
|
||||||
timestamp = startTime + i * 5 * 60 * 1000L,
|
timestamp = startTime + i * 5 * 60 * 1000L,
|
||||||
sourceSensor = GlucoseValue.SourceSensor.aCOB_PREDICTION,
|
sourceSensor = GlucoseValue.SourceSensor.A_COB_PREDICTION,
|
||||||
trendArrow = GlucoseValue.TrendArrow.NONE
|
trendArrow = GlucoseValue.TrendArrow.NONE
|
||||||
)
|
)
|
||||||
array.add(gv)
|
array.add(gv)
|
||||||
|
|
|
@ -70,7 +70,8 @@ public class PointsWithLabelGraphSeries<E extends DataPointWithLabelInterface> e
|
||||||
GENERAL,
|
GENERAL,
|
||||||
GENERALWITHDURATION,
|
GENERALWITHDURATION,
|
||||||
COBFAILOVER,
|
COBFAILOVER,
|
||||||
IOBPREDICTION
|
IOBPREDICTION,
|
||||||
|
BUCKETED_BG
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -200,7 +201,7 @@ public class PointsWithLabelGraphSeries<E extends DataPointWithLabelInterface> e
|
||||||
mPaint.setStyle(Paint.Style.FILL);
|
mPaint.setStyle(Paint.Style.FILL);
|
||||||
mPaint.setStrokeWidth(0);
|
mPaint.setStrokeWidth(0);
|
||||||
canvas.drawCircle(endX, endY, value.getSize() * scaledPxSize, mPaint);
|
canvas.drawCircle(endX, endY, value.getSize() * scaledPxSize, mPaint);
|
||||||
} else if (value.getShape() == Shape.BG || value.getShape() == Shape.IOBPREDICTION) {
|
} else if (value.getShape() == Shape.BG || value.getShape() == Shape.IOBPREDICTION || value.getShape() == Shape.BUCKETED_BG) {
|
||||||
mPaint.setColor(value.getColor());
|
mPaint.setColor(value.getColor());
|
||||||
mPaint.setStyle(Paint.Style.FILL);
|
mPaint.setStyle(Paint.Style.FILL);
|
||||||
mPaint.setStrokeWidth(0);
|
mPaint.setStrokeWidth(0);
|
||||||
|
|
|
@ -93,11 +93,11 @@ data class GlucoseValue(
|
||||||
@SerializedName("Random") RANDOM("Random"),
|
@SerializedName("Random") RANDOM("Random"),
|
||||||
@SerializedName("Unknown") UNKNOWN("Unknown"),
|
@SerializedName("Unknown") UNKNOWN("Unknown"),
|
||||||
|
|
||||||
@SerializedName("IOBPrediction") IOB_PREDICTION("IOBPrediction"),
|
IOB_PREDICTION("IOBPrediction"),
|
||||||
@SerializedName("aCOBPrediction") aCOB_PREDICTION("aCOBPrediction"),
|
A_COB_PREDICTION("aCOBPrediction"),
|
||||||
@SerializedName("COBPrediction") COB_PREDICTION("COBPrediction"),
|
COB_PREDICTION("COBPrediction"),
|
||||||
@SerializedName("UAMPrediction") UAM_PREDICTION("UAMPrediction"),
|
UAM_PREDICTION("UAMPrediction"),
|
||||||
@SerializedName("ZTPrediction") ZT_PREDICTION("ZTPrediction")
|
ZT_PREDICTION("ZTPrediction"),
|
||||||
;
|
;
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
Loading…
Reference in a new issue