Improve ProfileHelper graphs

This commit is contained in:
Milos Kozak 2022-03-19 23:39:25 +01:00
parent 578d4ca674
commit 899270b7e0
4 changed files with 51 additions and 20 deletions

View file

@ -10,8 +10,8 @@ import info.nightscout.androidaps.core.R
import info.nightscout.androidaps.interfaces.Profile
import info.nightscout.androidaps.utils.Round
import java.text.NumberFormat
import java.util.ArrayList
import kotlin.math.max
import kotlin.math.min
class BasalProfileGraph : GraphView {
@ -22,8 +22,9 @@ class BasalProfileGraph : GraphView {
removeAllSeries()
val basalArray: MutableList<DataPoint> = ArrayList()
for (hour in 0..23) {
basalArray.add(DataPoint(hour.toDouble(), profile.getBasalTimeFromMidnight(hour * 60 * 60)))
basalArray.add(DataPoint((hour + 1).toDouble(), profile.getBasalTimeFromMidnight(hour * 60 * 60)))
val basal = profile.getBasalTimeFromMidnight(hour * 60 * 60)
basalArray.add(DataPoint(hour.toDouble(), basal))
basalArray.add(DataPoint((hour + 1).toDouble(), basal))
}
val basalDataPoints: Array<DataPoint> = Array(basalArray.size) { i -> basalArray[i] }
val basalSeries: LineGraphSeries<DataPoint> = LineGraphSeries(basalDataPoints)
@ -41,7 +42,7 @@ class BasalProfileGraph : GraphView {
val nf: NumberFormat = NumberFormat.getInstance()
nf.maximumFractionDigits = 1
gridLabelRenderer.setLabelFormatter(DefaultLabelFormatter(nf, nf))
gridLabelRenderer.labelFormatter = DefaultLabelFormatter(nf, nf)
}
fun show(profile1: Profile, profile2: Profile) {
@ -49,9 +50,14 @@ class BasalProfileGraph : GraphView {
// profile 1
val basalArray1: MutableList<DataPoint> = ArrayList()
var minBasal = 1000.0
var maxBasal = 0.0
for (hour in 0..23) {
basalArray1.add(DataPoint(hour.toDouble(), profile1.getBasalTimeFromMidnight(hour * 60 * 60)))
basalArray1.add(DataPoint((hour + 1).toDouble(), profile1.getBasalTimeFromMidnight(hour * 60 * 60)))
val basal = profile1.getBasalTimeFromMidnight(hour * 60 * 60)
minBasal = min(minBasal, basal)
maxBasal = max(maxBasal, basal)
basalArray1.add(DataPoint(hour.toDouble(), basal))
basalArray1.add(DataPoint((hour + 1).toDouble(), basal))
}
val basalSeries1: LineGraphSeries<DataPoint> = LineGraphSeries(Array(basalArray1.size) { i -> basalArray1[i] })
addSeries(basalSeries1)
@ -61,8 +67,11 @@ class BasalProfileGraph : GraphView {
// profile 2
val basalArray2: MutableList<DataPoint> = ArrayList()
for (hour in 0..23) {
basalArray2.add(DataPoint(hour.toDouble(), profile2.getBasalTimeFromMidnight(hour * 60 * 60)))
basalArray2.add(DataPoint((hour + 1).toDouble(), profile2.getBasalTimeFromMidnight(hour * 60 * 60)))
val basal = profile2.getBasalTimeFromMidnight(hour * 60 * 60)
minBasal = min(minBasal, basal)
maxBasal = max(maxBasal, basal)
basalArray2.add(DataPoint(hour.toDouble(), basal))
basalArray2.add(DataPoint((hour + 1).toDouble(), basal))
}
val basalSeries2: LineGraphSeries<DataPoint> = LineGraphSeries(Array(basalArray2.size) { i -> basalArray2[i] })
addSeries(basalSeries2)
@ -75,8 +84,12 @@ class BasalProfileGraph : GraphView {
viewport.setMinX(0.0)
viewport.setMaxX(24.0)
viewport.isYAxisBoundsManual = true
viewport.setMinY(0.0)
viewport.setMaxY(Round.ceilTo(max(profile1.getMaxDailyBasal(), profile2.getMaxDailyBasal()) * 1.1, 0.5))
viewport.setMinY(Round.floorTo(minBasal / 1.1, 0.5))
viewport.setMaxY(Round.ceilTo(maxBasal * 1.1, 0.5))
gridLabelRenderer.numHorizontalLabels = 13
val nf: NumberFormat = NumberFormat.getInstance()
nf.maximumFractionDigits = 1
gridLabelRenderer.labelFormatter = DefaultLabelFormatter(nf, nf)
}
}

View file

@ -10,8 +10,8 @@ import info.nightscout.androidaps.core.R
import info.nightscout.androidaps.interfaces.Profile
import info.nightscout.androidaps.utils.Round
import java.text.NumberFormat
import java.util.*
import kotlin.math.max
import kotlin.math.min
class IcProfileGraph : GraphView {
@ -44,17 +44,19 @@ class IcProfileGraph : GraphView {
val nf: NumberFormat = NumberFormat.getInstance()
nf.maximumFractionDigits = 1
gridLabelRenderer.setLabelFormatter(DefaultLabelFormatter(nf, nf))
gridLabelRenderer.labelFormatter = DefaultLabelFormatter(nf, nf)
}
fun show(profile1: Profile, profile2: Profile) {
removeAllSeries()
var minIc = 1000.0
var maxIc = 0.0
// ic 1
val icArray1: MutableList<DataPoint> = ArrayList()
for (hour in 0..23) {
val ic = profile1.getIcTimeFromMidnight(hour * 60 * 60)
minIc = min(minIc, ic)
maxIc = max(maxIc, ic)
icArray1.add(DataPoint(hour.toDouble(), ic))
icArray1.add(DataPoint((hour + 1).toDouble(), ic))
@ -68,6 +70,7 @@ class IcProfileGraph : GraphView {
val icArray2: MutableList<DataPoint> = ArrayList()
for (hour in 0..23) {
val ic = profile2.getIcTimeFromMidnight(hour * 60 * 60)
minIc = min(minIc, ic)
maxIc = max(maxIc, ic)
icArray2.add(DataPoint(hour.toDouble(), ic))
icArray2.add(DataPoint((hour + 1).toDouble(), ic))
@ -82,8 +85,12 @@ class IcProfileGraph : GraphView {
viewport.setMinX(0.0)
viewport.setMaxX(24.0)
viewport.isYAxisBoundsManual = true
viewport.setMinY(0.0)
viewport.setMinY(Round.floorTo(minIc / 1.1, 0.5))
viewport.setMaxY(Round.ceilTo(maxIc * 1.1, 0.5))
gridLabelRenderer.numHorizontalLabels = 13
val nf: NumberFormat = NumberFormat.getInstance()
nf.maximumFractionDigits = 1
gridLabelRenderer.labelFormatter = DefaultLabelFormatter(nf, nf)
}
}

View file

@ -11,6 +11,7 @@ import info.nightscout.androidaps.interfaces.Profile
import info.nightscout.androidaps.utils.Round
import java.text.NumberFormat
import kotlin.math.max
import kotlin.math.min
class IsfProfileGraph : GraphView {
@ -45,18 +46,20 @@ class IsfProfileGraph : GraphView {
val nf: NumberFormat = NumberFormat.getInstance()
nf.maximumFractionDigits = 1
gridLabelRenderer.setLabelFormatter(DefaultLabelFormatter(nf, nf))
gridLabelRenderer.labelFormatter = DefaultLabelFormatter(nf, nf)
}
fun show(profile1: Profile, profile2: Profile) {
removeAllSeries()
var minIsf = 1000.0
var maxIsf = 0.0
val units = profile1.units
// isf 1
val isfArray1: MutableList<DataPoint> = ArrayList()
for (hour in 0..23) {
val isf = Profile.fromMgdlToUnits(profile1.getIsfMgdlTimeFromMidnight(hour * 60 * 60), units)
minIsf = min(minIsf, isf)
maxIsf = max(maxIsf, isf)
isfArray1.add(DataPoint(hour.toDouble(), isf))
isfArray1.add(DataPoint((hour + 1).toDouble(), isf))
@ -70,6 +73,7 @@ class IsfProfileGraph : GraphView {
val isfArray2: MutableList<DataPoint> = ArrayList()
for (hour in 0..23) {
val isf = Profile.fromMgdlToUnits(profile2.getIsfMgdlTimeFromMidnight(hour * 60 * 60), units)
minIsf = min(minIsf, isf)
maxIsf = max(maxIsf, isf)
isfArray2.add(DataPoint(hour.toDouble(), isf))
isfArray2.add(DataPoint((hour + 1).toDouble(), isf))
@ -84,8 +88,12 @@ class IsfProfileGraph : GraphView {
viewport.setMinX(0.0)
viewport.setMaxX(24.0)
viewport.isYAxisBoundsManual = true
viewport.setMinY(0.0)
viewport.setMinY(Round.floorTo(minIsf / 1.1, 0.5))
viewport.setMaxY(Round.ceilTo(maxIsf * 1.1, 0.5))
gridLabelRenderer.numHorizontalLabels = 13
val nf: NumberFormat = NumberFormat.getInstance()
nf.maximumFractionDigits = 1
gridLabelRenderer.labelFormatter = DefaultLabelFormatter(nf, nf)
}
}

View file

@ -7,12 +7,12 @@ import com.jjoe64.graphview.GraphView
import info.nightscout.androidaps.core.R
import info.nightscout.androidaps.interfaces.GlucoseUnit
import info.nightscout.androidaps.interfaces.Profile
import info.nightscout.androidaps.utils.Round
import info.nightscout.androidaps.plugins.general.overview.graphExtensions.AreaGraphSeries
import info.nightscout.androidaps.plugins.general.overview.graphExtensions.DoubleDataPoint
import info.nightscout.androidaps.utils.Round
import java.text.NumberFormat
import java.util.ArrayList
import kotlin.math.max
import kotlin.math.min
class TargetBgProfileGraph : GraphView {
@ -48,18 +48,20 @@ class TargetBgProfileGraph : GraphView {
val nf: NumberFormat = NumberFormat.getInstance()
nf.maximumFractionDigits = if (units == GlucoseUnit.MMOL) 1 else 0
gridLabelRenderer.setLabelFormatter(DefaultLabelFormatter(nf, nf))
gridLabelRenderer.labelFormatter = DefaultLabelFormatter(nf, nf)
}
fun show(profile1: Profile, profile2: Profile) {
removeAllSeries()
val targetArray1: MutableList<DoubleDataPoint> = ArrayList()
var minValue = 1000.0
var maxValue = 0.0
val units = profile1.units
for (hour in 0..23) {
val valueLow = Profile.fromMgdlToUnits(profile1.getTargetLowMgdlTimeFromMidnight(hour * 60 * 60), units)
val valueHigh = Profile.fromMgdlToUnits(profile1.getTargetHighMgdlTimeFromMidnight(hour * 60 * 60), units)
minValue = min(minValue, valueLow)
maxValue = max(maxValue, valueHigh)
targetArray1.add(DoubleDataPoint(hour.toDouble(), valueLow, valueHigh))
targetArray1.add(DoubleDataPoint((hour + 1).toDouble(), valueLow, valueHigh))
@ -73,6 +75,7 @@ class TargetBgProfileGraph : GraphView {
for (hour in 0..23) {
val valueLow = Profile.fromMgdlToUnits(profile2.getTargetLowMgdlTimeFromMidnight(hour * 60 * 60), units)
val valueHigh = Profile.fromMgdlToUnits(profile2.getTargetHighMgdlTimeFromMidnight(hour * 60 * 60), units)
minValue = min(minValue, valueLow)
maxValue = max(maxValue, valueHigh)
targetArray2.add(DoubleDataPoint(hour.toDouble(), valueLow, valueHigh))
targetArray2.add(DoubleDataPoint((hour + 1).toDouble(), valueLow, valueHigh))
@ -87,13 +90,13 @@ class TargetBgProfileGraph : GraphView {
viewport.setMinX(0.0)
viewport.setMaxX(24.0)
viewport.isYAxisBoundsManual = true
viewport.setMinY(0.0)
viewport.setMinY(Round.floorTo(minValue / 1.1, 0.5))
viewport.setMaxY(Round.ceilTo(maxValue * 1.1, 0.5))
gridLabelRenderer.numHorizontalLabels = 13
gridLabelRenderer.verticalLabelsColor = targetSeries1.color
val nf: NumberFormat = NumberFormat.getInstance()
nf.maximumFractionDigits = if (units == GlucoseUnit.MMOL) 1 else 0
gridLabelRenderer.setLabelFormatter(DefaultLabelFormatter(nf, nf))
gridLabelRenderer.labelFormatter = DefaultLabelFormatter(nf, nf)
}
}