Improve ProfileHelper graphs
This commit is contained in:
parent
578d4ca674
commit
899270b7e0
4 changed files with 51 additions and 20 deletions
|
@ -10,8 +10,8 @@ import info.nightscout.androidaps.core.R
|
||||||
import info.nightscout.androidaps.interfaces.Profile
|
import info.nightscout.androidaps.interfaces.Profile
|
||||||
import info.nightscout.androidaps.utils.Round
|
import info.nightscout.androidaps.utils.Round
|
||||||
import java.text.NumberFormat
|
import java.text.NumberFormat
|
||||||
import java.util.ArrayList
|
|
||||||
import kotlin.math.max
|
import kotlin.math.max
|
||||||
|
import kotlin.math.min
|
||||||
|
|
||||||
class BasalProfileGraph : GraphView {
|
class BasalProfileGraph : GraphView {
|
||||||
|
|
||||||
|
@ -22,8 +22,9 @@ class BasalProfileGraph : GraphView {
|
||||||
removeAllSeries()
|
removeAllSeries()
|
||||||
val basalArray: MutableList<DataPoint> = ArrayList()
|
val basalArray: MutableList<DataPoint> = ArrayList()
|
||||||
for (hour in 0..23) {
|
for (hour in 0..23) {
|
||||||
basalArray.add(DataPoint(hour.toDouble(), profile.getBasalTimeFromMidnight(hour * 60 * 60)))
|
val basal = profile.getBasalTimeFromMidnight(hour * 60 * 60)
|
||||||
basalArray.add(DataPoint((hour + 1).toDouble(), 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 basalDataPoints: Array<DataPoint> = Array(basalArray.size) { i -> basalArray[i] }
|
||||||
val basalSeries: LineGraphSeries<DataPoint> = LineGraphSeries(basalDataPoints)
|
val basalSeries: LineGraphSeries<DataPoint> = LineGraphSeries(basalDataPoints)
|
||||||
|
@ -41,7 +42,7 @@ class BasalProfileGraph : GraphView {
|
||||||
|
|
||||||
val nf: NumberFormat = NumberFormat.getInstance()
|
val nf: NumberFormat = NumberFormat.getInstance()
|
||||||
nf.maximumFractionDigits = 1
|
nf.maximumFractionDigits = 1
|
||||||
gridLabelRenderer.setLabelFormatter(DefaultLabelFormatter(nf, nf))
|
gridLabelRenderer.labelFormatter = DefaultLabelFormatter(nf, nf)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun show(profile1: Profile, profile2: Profile) {
|
fun show(profile1: Profile, profile2: Profile) {
|
||||||
|
@ -49,9 +50,14 @@ class BasalProfileGraph : GraphView {
|
||||||
|
|
||||||
// profile 1
|
// profile 1
|
||||||
val basalArray1: MutableList<DataPoint> = ArrayList()
|
val basalArray1: MutableList<DataPoint> = ArrayList()
|
||||||
|
var minBasal = 1000.0
|
||||||
|
var maxBasal = 0.0
|
||||||
for (hour in 0..23) {
|
for (hour in 0..23) {
|
||||||
basalArray1.add(DataPoint(hour.toDouble(), profile1.getBasalTimeFromMidnight(hour * 60 * 60)))
|
val basal = profile1.getBasalTimeFromMidnight(hour * 60 * 60)
|
||||||
basalArray1.add(DataPoint((hour + 1).toDouble(), 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] })
|
val basalSeries1: LineGraphSeries<DataPoint> = LineGraphSeries(Array(basalArray1.size) { i -> basalArray1[i] })
|
||||||
addSeries(basalSeries1)
|
addSeries(basalSeries1)
|
||||||
|
@ -61,8 +67,11 @@ class BasalProfileGraph : GraphView {
|
||||||
// profile 2
|
// profile 2
|
||||||
val basalArray2: MutableList<DataPoint> = ArrayList()
|
val basalArray2: MutableList<DataPoint> = ArrayList()
|
||||||
for (hour in 0..23) {
|
for (hour in 0..23) {
|
||||||
basalArray2.add(DataPoint(hour.toDouble(), profile2.getBasalTimeFromMidnight(hour * 60 * 60)))
|
val basal = profile2.getBasalTimeFromMidnight(hour * 60 * 60)
|
||||||
basalArray2.add(DataPoint((hour + 1).toDouble(), 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] })
|
val basalSeries2: LineGraphSeries<DataPoint> = LineGraphSeries(Array(basalArray2.size) { i -> basalArray2[i] })
|
||||||
addSeries(basalSeries2)
|
addSeries(basalSeries2)
|
||||||
|
@ -75,8 +84,12 @@ class BasalProfileGraph : GraphView {
|
||||||
viewport.setMinX(0.0)
|
viewport.setMinX(0.0)
|
||||||
viewport.setMaxX(24.0)
|
viewport.setMaxX(24.0)
|
||||||
viewport.isYAxisBoundsManual = true
|
viewport.isYAxisBoundsManual = true
|
||||||
viewport.setMinY(0.0)
|
viewport.setMinY(Round.floorTo(minBasal / 1.1, 0.5))
|
||||||
viewport.setMaxY(Round.ceilTo(max(profile1.getMaxDailyBasal(), profile2.getMaxDailyBasal()) * 1.1, 0.5))
|
viewport.setMaxY(Round.ceilTo(maxBasal * 1.1, 0.5))
|
||||||
gridLabelRenderer.numHorizontalLabels = 13
|
gridLabelRenderer.numHorizontalLabels = 13
|
||||||
|
|
||||||
|
val nf: NumberFormat = NumberFormat.getInstance()
|
||||||
|
nf.maximumFractionDigits = 1
|
||||||
|
gridLabelRenderer.labelFormatter = DefaultLabelFormatter(nf, nf)
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -10,8 +10,8 @@ import info.nightscout.androidaps.core.R
|
||||||
import info.nightscout.androidaps.interfaces.Profile
|
import info.nightscout.androidaps.interfaces.Profile
|
||||||
import info.nightscout.androidaps.utils.Round
|
import info.nightscout.androidaps.utils.Round
|
||||||
import java.text.NumberFormat
|
import java.text.NumberFormat
|
||||||
import java.util.*
|
|
||||||
import kotlin.math.max
|
import kotlin.math.max
|
||||||
|
import kotlin.math.min
|
||||||
|
|
||||||
class IcProfileGraph : GraphView {
|
class IcProfileGraph : GraphView {
|
||||||
|
|
||||||
|
@ -44,17 +44,19 @@ class IcProfileGraph : GraphView {
|
||||||
|
|
||||||
val nf: NumberFormat = NumberFormat.getInstance()
|
val nf: NumberFormat = NumberFormat.getInstance()
|
||||||
nf.maximumFractionDigits = 1
|
nf.maximumFractionDigits = 1
|
||||||
gridLabelRenderer.setLabelFormatter(DefaultLabelFormatter(nf, nf))
|
gridLabelRenderer.labelFormatter = DefaultLabelFormatter(nf, nf)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun show(profile1: Profile, profile2: Profile) {
|
fun show(profile1: Profile, profile2: Profile) {
|
||||||
removeAllSeries()
|
removeAllSeries()
|
||||||
|
|
||||||
|
var minIc = 1000.0
|
||||||
var maxIc = 0.0
|
var maxIc = 0.0
|
||||||
// ic 1
|
// ic 1
|
||||||
val icArray1: MutableList<DataPoint> = ArrayList()
|
val icArray1: MutableList<DataPoint> = ArrayList()
|
||||||
for (hour in 0..23) {
|
for (hour in 0..23) {
|
||||||
val ic = profile1.getIcTimeFromMidnight(hour * 60 * 60)
|
val ic = profile1.getIcTimeFromMidnight(hour * 60 * 60)
|
||||||
|
minIc = min(minIc, ic)
|
||||||
maxIc = max(maxIc, ic)
|
maxIc = max(maxIc, ic)
|
||||||
icArray1.add(DataPoint(hour.toDouble(), ic))
|
icArray1.add(DataPoint(hour.toDouble(), ic))
|
||||||
icArray1.add(DataPoint((hour + 1).toDouble(), ic))
|
icArray1.add(DataPoint((hour + 1).toDouble(), ic))
|
||||||
|
@ -68,6 +70,7 @@ class IcProfileGraph : GraphView {
|
||||||
val icArray2: MutableList<DataPoint> = ArrayList()
|
val icArray2: MutableList<DataPoint> = ArrayList()
|
||||||
for (hour in 0..23) {
|
for (hour in 0..23) {
|
||||||
val ic = profile2.getIcTimeFromMidnight(hour * 60 * 60)
|
val ic = profile2.getIcTimeFromMidnight(hour * 60 * 60)
|
||||||
|
minIc = min(minIc, ic)
|
||||||
maxIc = max(maxIc, ic)
|
maxIc = max(maxIc, ic)
|
||||||
icArray2.add(DataPoint(hour.toDouble(), ic))
|
icArray2.add(DataPoint(hour.toDouble(), ic))
|
||||||
icArray2.add(DataPoint((hour + 1).toDouble(), ic))
|
icArray2.add(DataPoint((hour + 1).toDouble(), ic))
|
||||||
|
@ -82,8 +85,12 @@ class IcProfileGraph : GraphView {
|
||||||
viewport.setMinX(0.0)
|
viewport.setMinX(0.0)
|
||||||
viewport.setMaxX(24.0)
|
viewport.setMaxX(24.0)
|
||||||
viewport.isYAxisBoundsManual = true
|
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))
|
viewport.setMaxY(Round.ceilTo(maxIc * 1.1, 0.5))
|
||||||
gridLabelRenderer.numHorizontalLabels = 13
|
gridLabelRenderer.numHorizontalLabels = 13
|
||||||
|
|
||||||
|
val nf: NumberFormat = NumberFormat.getInstance()
|
||||||
|
nf.maximumFractionDigits = 1
|
||||||
|
gridLabelRenderer.labelFormatter = DefaultLabelFormatter(nf, nf)
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -11,6 +11,7 @@ import info.nightscout.androidaps.interfaces.Profile
|
||||||
import info.nightscout.androidaps.utils.Round
|
import info.nightscout.androidaps.utils.Round
|
||||||
import java.text.NumberFormat
|
import java.text.NumberFormat
|
||||||
import kotlin.math.max
|
import kotlin.math.max
|
||||||
|
import kotlin.math.min
|
||||||
|
|
||||||
class IsfProfileGraph : GraphView {
|
class IsfProfileGraph : GraphView {
|
||||||
|
|
||||||
|
@ -45,18 +46,20 @@ class IsfProfileGraph : GraphView {
|
||||||
|
|
||||||
val nf: NumberFormat = NumberFormat.getInstance()
|
val nf: NumberFormat = NumberFormat.getInstance()
|
||||||
nf.maximumFractionDigits = 1
|
nf.maximumFractionDigits = 1
|
||||||
gridLabelRenderer.setLabelFormatter(DefaultLabelFormatter(nf, nf))
|
gridLabelRenderer.labelFormatter = DefaultLabelFormatter(nf, nf)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun show(profile1: Profile, profile2: Profile) {
|
fun show(profile1: Profile, profile2: Profile) {
|
||||||
removeAllSeries()
|
removeAllSeries()
|
||||||
|
|
||||||
|
var minIsf = 1000.0
|
||||||
var maxIsf = 0.0
|
var maxIsf = 0.0
|
||||||
val units = profile1.units
|
val units = profile1.units
|
||||||
// isf 1
|
// isf 1
|
||||||
val isfArray1: MutableList<DataPoint> = ArrayList()
|
val isfArray1: MutableList<DataPoint> = ArrayList()
|
||||||
for (hour in 0..23) {
|
for (hour in 0..23) {
|
||||||
val isf = Profile.fromMgdlToUnits(profile1.getIsfMgdlTimeFromMidnight(hour * 60 * 60), units)
|
val isf = Profile.fromMgdlToUnits(profile1.getIsfMgdlTimeFromMidnight(hour * 60 * 60), units)
|
||||||
|
minIsf = min(minIsf, isf)
|
||||||
maxIsf = max(maxIsf, isf)
|
maxIsf = max(maxIsf, isf)
|
||||||
isfArray1.add(DataPoint(hour.toDouble(), isf))
|
isfArray1.add(DataPoint(hour.toDouble(), isf))
|
||||||
isfArray1.add(DataPoint((hour + 1).toDouble(), isf))
|
isfArray1.add(DataPoint((hour + 1).toDouble(), isf))
|
||||||
|
@ -70,6 +73,7 @@ class IsfProfileGraph : GraphView {
|
||||||
val isfArray2: MutableList<DataPoint> = ArrayList()
|
val isfArray2: MutableList<DataPoint> = ArrayList()
|
||||||
for (hour in 0..23) {
|
for (hour in 0..23) {
|
||||||
val isf = Profile.fromMgdlToUnits(profile2.getIsfMgdlTimeFromMidnight(hour * 60 * 60), units)
|
val isf = Profile.fromMgdlToUnits(profile2.getIsfMgdlTimeFromMidnight(hour * 60 * 60), units)
|
||||||
|
minIsf = min(minIsf, isf)
|
||||||
maxIsf = max(maxIsf, isf)
|
maxIsf = max(maxIsf, isf)
|
||||||
isfArray2.add(DataPoint(hour.toDouble(), isf))
|
isfArray2.add(DataPoint(hour.toDouble(), isf))
|
||||||
isfArray2.add(DataPoint((hour + 1).toDouble(), isf))
|
isfArray2.add(DataPoint((hour + 1).toDouble(), isf))
|
||||||
|
@ -84,8 +88,12 @@ class IsfProfileGraph : GraphView {
|
||||||
viewport.setMinX(0.0)
|
viewport.setMinX(0.0)
|
||||||
viewport.setMaxX(24.0)
|
viewport.setMaxX(24.0)
|
||||||
viewport.isYAxisBoundsManual = true
|
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))
|
viewport.setMaxY(Round.ceilTo(maxIsf * 1.1, 0.5))
|
||||||
gridLabelRenderer.numHorizontalLabels = 13
|
gridLabelRenderer.numHorizontalLabels = 13
|
||||||
|
|
||||||
|
val nf: NumberFormat = NumberFormat.getInstance()
|
||||||
|
nf.maximumFractionDigits = 1
|
||||||
|
gridLabelRenderer.labelFormatter = DefaultLabelFormatter(nf, nf)
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -7,12 +7,12 @@ import com.jjoe64.graphview.GraphView
|
||||||
import info.nightscout.androidaps.core.R
|
import info.nightscout.androidaps.core.R
|
||||||
import info.nightscout.androidaps.interfaces.GlucoseUnit
|
import info.nightscout.androidaps.interfaces.GlucoseUnit
|
||||||
import info.nightscout.androidaps.interfaces.Profile
|
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.AreaGraphSeries
|
||||||
import info.nightscout.androidaps.plugins.general.overview.graphExtensions.DoubleDataPoint
|
import info.nightscout.androidaps.plugins.general.overview.graphExtensions.DoubleDataPoint
|
||||||
|
import info.nightscout.androidaps.utils.Round
|
||||||
import java.text.NumberFormat
|
import java.text.NumberFormat
|
||||||
import java.util.ArrayList
|
|
||||||
import kotlin.math.max
|
import kotlin.math.max
|
||||||
|
import kotlin.math.min
|
||||||
|
|
||||||
class TargetBgProfileGraph : GraphView {
|
class TargetBgProfileGraph : GraphView {
|
||||||
|
|
||||||
|
@ -48,18 +48,20 @@ class TargetBgProfileGraph : GraphView {
|
||||||
|
|
||||||
val nf: NumberFormat = NumberFormat.getInstance()
|
val nf: NumberFormat = NumberFormat.getInstance()
|
||||||
nf.maximumFractionDigits = if (units == GlucoseUnit.MMOL) 1 else 0
|
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) {
|
fun show(profile1: Profile, profile2: Profile) {
|
||||||
|
|
||||||
removeAllSeries()
|
removeAllSeries()
|
||||||
val targetArray1: MutableList<DoubleDataPoint> = ArrayList()
|
val targetArray1: MutableList<DoubleDataPoint> = ArrayList()
|
||||||
|
var minValue = 1000.0
|
||||||
var maxValue = 0.0
|
var maxValue = 0.0
|
||||||
val units = profile1.units
|
val units = profile1.units
|
||||||
for (hour in 0..23) {
|
for (hour in 0..23) {
|
||||||
val valueLow = Profile.fromMgdlToUnits(profile1.getTargetLowMgdlTimeFromMidnight(hour * 60 * 60), units)
|
val valueLow = Profile.fromMgdlToUnits(profile1.getTargetLowMgdlTimeFromMidnight(hour * 60 * 60), units)
|
||||||
val valueHigh = Profile.fromMgdlToUnits(profile1.getTargetHighMgdlTimeFromMidnight(hour * 60 * 60), units)
|
val valueHigh = Profile.fromMgdlToUnits(profile1.getTargetHighMgdlTimeFromMidnight(hour * 60 * 60), units)
|
||||||
|
minValue = min(minValue, valueLow)
|
||||||
maxValue = max(maxValue, valueHigh)
|
maxValue = max(maxValue, valueHigh)
|
||||||
targetArray1.add(DoubleDataPoint(hour.toDouble(), valueLow, valueHigh))
|
targetArray1.add(DoubleDataPoint(hour.toDouble(), valueLow, valueHigh))
|
||||||
targetArray1.add(DoubleDataPoint((hour + 1).toDouble(), valueLow, valueHigh))
|
targetArray1.add(DoubleDataPoint((hour + 1).toDouble(), valueLow, valueHigh))
|
||||||
|
@ -73,6 +75,7 @@ class TargetBgProfileGraph : GraphView {
|
||||||
for (hour in 0..23) {
|
for (hour in 0..23) {
|
||||||
val valueLow = Profile.fromMgdlToUnits(profile2.getTargetLowMgdlTimeFromMidnight(hour * 60 * 60), units)
|
val valueLow = Profile.fromMgdlToUnits(profile2.getTargetLowMgdlTimeFromMidnight(hour * 60 * 60), units)
|
||||||
val valueHigh = Profile.fromMgdlToUnits(profile2.getTargetHighMgdlTimeFromMidnight(hour * 60 * 60), units)
|
val valueHigh = Profile.fromMgdlToUnits(profile2.getTargetHighMgdlTimeFromMidnight(hour * 60 * 60), units)
|
||||||
|
minValue = min(minValue, valueLow)
|
||||||
maxValue = max(maxValue, valueHigh)
|
maxValue = max(maxValue, valueHigh)
|
||||||
targetArray2.add(DoubleDataPoint(hour.toDouble(), valueLow, valueHigh))
|
targetArray2.add(DoubleDataPoint(hour.toDouble(), valueLow, valueHigh))
|
||||||
targetArray2.add(DoubleDataPoint((hour + 1).toDouble(), valueLow, valueHigh))
|
targetArray2.add(DoubleDataPoint((hour + 1).toDouble(), valueLow, valueHigh))
|
||||||
|
@ -87,13 +90,13 @@ class TargetBgProfileGraph : GraphView {
|
||||||
viewport.setMinX(0.0)
|
viewport.setMinX(0.0)
|
||||||
viewport.setMaxX(24.0)
|
viewport.setMaxX(24.0)
|
||||||
viewport.isYAxisBoundsManual = true
|
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))
|
viewport.setMaxY(Round.ceilTo(maxValue * 1.1, 0.5))
|
||||||
gridLabelRenderer.numHorizontalLabels = 13
|
gridLabelRenderer.numHorizontalLabels = 13
|
||||||
gridLabelRenderer.verticalLabelsColor = targetSeries1.color
|
gridLabelRenderer.verticalLabelsColor = targetSeries1.color
|
||||||
|
|
||||||
val nf: NumberFormat = NumberFormat.getInstance()
|
val nf: NumberFormat = NumberFormat.getInstance()
|
||||||
nf.maximumFractionDigits = if (units == GlucoseUnit.MMOL) 1 else 0
|
nf.maximumFractionDigits = if (units == GlucoseUnit.MMOL) 1 else 0
|
||||||
gridLabelRenderer.setLabelFormatter(DefaultLabelFormatter(nf, nf))
|
gridLabelRenderer.labelFormatter = DefaultLabelFormatter(nf, nf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue