DataPointWithLabelInterface -> kt

This commit is contained in:
Milos Kozak 2021-11-23 22:20:59 +01:00
parent 477dca0ede
commit 090994ab51
11 changed files with 115 additions and 189 deletions

View file

@ -20,18 +20,21 @@ class BolusDataPoint @Inject constructor(
override fun getX(): Double = data.timestamp.toDouble() override fun getX(): Double = data.timestamp.toDouble()
override fun getY(): Double = if (data.type == Bolus.Type.SMB) defaultValueHelper.determineLowLine() else yValue override fun getY(): Double = if (data.type == Bolus.Type.SMB) defaultValueHelper.determineLowLine() else yValue
override fun getLabel(): String = DecimalFormatter.toPumpSupportedBolus(data.amount, activePlugin.activePump, rh) override val label
override fun getDuration(): Long = 0 get() = DecimalFormatter.toPumpSupportedBolus(data.amount, activePlugin.activePump, rh)
override fun getSize(): Float = 2f override val duration = 0L
override val size = 2f
override fun getShape(): PointsWithLabelGraphSeries.Shape = override val shape
if (data.type == Bolus.Type.SMB) PointsWithLabelGraphSeries.Shape.SMB get() = if (data.type == Bolus.Type.SMB) PointsWithLabelGraphSeries.Shape.SMB else PointsWithLabelGraphSeries.Shape.BOLUS
else PointsWithLabelGraphSeries.Shape.BOLUS
override fun getColor(): Int = override val color
if (data.type == Bolus.Type.SMB) rh.gc(R.color.tempbasal) get() =
else if (data.isValid) Color.CYAN when {
else rh.gc(android.R.color.holo_red_light) data.type == Bolus.Type.SMB -> rh.gc(R.color.tempbasal)
data.isValid -> Color.CYAN
else -> rh.gc(android.R.color.holo_red_light)
}
override fun setY(y: Double) { override fun setY(y: Double) {
yValue = y yValue = y

View file

@ -14,15 +14,11 @@ class CarbsDataPoint @Inject constructor(
override fun getX(): Double = data.timestamp.toDouble() override fun getX(): Double = data.timestamp.toDouble()
override fun getY(): Double = yValue override fun getY(): Double = yValue
override fun getLabel(): String = rh.gs(R.string.format_carbs, data.amount.toInt()) override val label get() = rh.gs(R.string.format_carbs, data.amount.toInt())
override fun getDuration(): Long = 0 override val duration = 0L
override fun getSize(): Float = 2f override val size = 2f
override val shape = PointsWithLabelGraphSeries.Shape.CARBS
override fun getShape(): PointsWithLabelGraphSeries.Shape = PointsWithLabelGraphSeries.Shape.CARBS override val color get() = if (data.isValid) rh.gc(R.color.carbs) else rh.gc(android.R.color.holo_red_light)
override fun getColor(): Int =
if (data.isValid) rh.gc(R.color.carbs)
else rh.gc(android.R.color.holo_red_light)
override fun setY(y: Double) { override fun setY(y: Double) {
yValue = y yValue = y

View file

@ -17,9 +17,9 @@ class EffectiveProfileSwitchDataPoint @Inject constructor(
yValue = y yValue = y
} }
override fun getLabel(): String = data.originalCustomizedName override val label get() = data.originalCustomizedName
override fun getDuration(): Long = 0 override val duration = 0L
override fun getShape(): PointsWithLabelGraphSeries.Shape = PointsWithLabelGraphSeries.Shape.PROFILE override val shape = PointsWithLabelGraphSeries.Shape.PROFILE
override fun getSize(): Float = 10f override val size = 10f
override fun getColor(): Int = Color.CYAN override val color = Color.CYAN
} }

View file

@ -13,11 +13,11 @@ class ExtendedBolusDataPoint @Inject constructor(
override fun getX(): Double = data.timestamp.toDouble() override fun getX(): Double = data.timestamp.toDouble()
override fun getY(): Double = yValue override fun getY(): Double = yValue
override fun getLabel(): String = data.toStringTotal() override val label get() = data.toStringTotal()
override fun getDuration(): Long = data.duration override val duration get() = data.duration
override fun getSize(): Float = 10f override val size = 10f
override fun getShape(): PointsWithLabelGraphSeries.Shape = PointsWithLabelGraphSeries.Shape.EXTENDEDBOLUS override val shape = PointsWithLabelGraphSeries.Shape.EXTENDEDBOLUS
override fun getColor(): Int = Color.CYAN override val color = Color.CYAN
override fun setY(y: Double) { override fun setY(y: Double) {
yValue = y yValue = y

View file

@ -19,44 +19,36 @@ class GlucoseValueDataPoint @Inject constructor(
fun valueToUnits(units: GlucoseUnit): Double = fun valueToUnits(units: GlucoseUnit): Double =
if (units == GlucoseUnit.MGDL) data.value else data.value * Constants.MGDL_TO_MMOLL if (units == GlucoseUnit.MGDL) data.value else data.value * Constants.MGDL_TO_MMOLL
override fun getX(): Double { override fun getX(): Double = data.timestamp.toDouble()
return data.timestamp.toDouble() override fun getY(): Double = valueToUnits(profileFunction.getUnits())
}
override fun getY(): Double {
return valueToUnits(profileFunction.getUnits())
}
override fun setY(y: Double) {} override fun setY(y: Double) {}
override fun getLabel(): String? = null override val label: String? = null
override fun getDuration(): Long = 0 override val duration = 0L
override fun getShape(): PointsWithLabelGraphSeries.Shape = override val shape get() = if (isPrediction) PointsWithLabelGraphSeries.Shape.PREDICTION else PointsWithLabelGraphSeries.Shape.BG
if (isPrediction) PointsWithLabelGraphSeries.Shape.PREDICTION override val size = 1f
else PointsWithLabelGraphSeries.Shape.BG override val color: Int
get() {
override fun getSize(): Float = 1f val units = profileFunction.getUnits()
val lowLine = defaultValueHelper.determineLowLine()
override fun getColor(): Int { val highLine = defaultValueHelper.determineHighLine()
val units = profileFunction.getUnits() return when {
val lowLine = defaultValueHelper.determineLowLine() isPrediction -> predictionColor
val highLine = defaultValueHelper.determineHighLine() valueToUnits(units) < lowLine -> rh.gc(R.color.low)
return when { valueToUnits(units) > highLine -> rh.gc(R.color.high)
isPrediction -> predictionColor else -> rh.gc(R.color.inrange)
valueToUnits(units) < lowLine -> rh.gc(R.color.low) }
valueToUnits(units) > highLine -> rh.gc(R.color.high)
else -> rh.gc(R.color.inrange)
} }
}
val predictionColor: Int val predictionColor: Int
get() { get() {
return when (data.sourceSensor) { return when (data.sourceSensor) {
GlucoseValue.SourceSensor.IOB_PREDICTION -> rh.gc(R.color.iob) GlucoseValue.SourceSensor.IOB_PREDICTION -> rh.gc(R.color.iob)
GlucoseValue.SourceSensor.COB_PREDICTION -> rh.gc(R.color.cob) GlucoseValue.SourceSensor.COB_PREDICTION -> rh.gc(R.color.cob)
GlucoseValue.SourceSensor.A_COB_PREDICTION -> -0x7f000001 and rh.gc(R.color.cob) GlucoseValue.SourceSensor.A_COB_PREDICTION -> -0x7f000001 and rh.gc(R.color.cob)
GlucoseValue.SourceSensor.UAM_PREDICTION -> rh.gc(R.color.uam) GlucoseValue.SourceSensor.UAM_PREDICTION -> rh.gc(R.color.uam)
GlucoseValue.SourceSensor.ZT_PREDICTION -> rh.gc(R.color.zt) GlucoseValue.SourceSensor.ZT_PREDICTION -> rh.gc(R.color.zt)
else -> R.color.white else -> R.color.white
} }
} }

View file

@ -20,9 +20,9 @@ class InMemoryGlucoseValueDataPoint @Inject constructor(
override fun getX(): Double = data.timestamp.toDouble() override fun getX(): Double = data.timestamp.toDouble()
override fun getY(): Double = valueToUnits(profileFunction.getUnits()) override fun getY(): Double = valueToUnits(profileFunction.getUnits())
override fun setY(y: Double) {} override fun setY(y: Double) {}
override fun getLabel(): String? = null override val label: String? = null
override fun getDuration(): Long = 0 override val duration = 0L
override fun getShape(): PointsWithLabelGraphSeries.Shape = PointsWithLabelGraphSeries.Shape.BUCKETED_BG override val shape = PointsWithLabelGraphSeries.Shape.BUCKETED_BG
override fun getSize(): Float = 0.3f override val size = 0.3f
override fun getColor(): Int = rh.gc(R.color.white) override val color get() = rh.gc(R.color.white)
} }

View file

@ -19,9 +19,7 @@ class TherapyEventDataPoint @Inject constructor(
private var yValue = 0.0 private var yValue = 0.0
override fun getX(): Double { override fun getX(): Double = data.timestamp.toDouble()
return data.timestamp.toDouble()
}
override fun getY(): Double { override fun getY(): Double {
val units = profileFunction.getUnits() val units = profileFunction.getUnits()
@ -46,30 +44,29 @@ class TherapyEventDataPoint @Inject constructor(
yValue = y yValue = y
} }
override fun getLabel(): String? = override val label get() = if (data.note.isNullOrBlank().not()) data.note else translator.translate(data.type)
if (data.note.isNullOrBlank().not()) data.note override val duration get() = data.duration
else translator.translate(data.type) override val shape
get() =
when {
data.type == TherapyEvent.Type.NS_MBG -> PointsWithLabelGraphSeries.Shape.MBG
data.type == TherapyEvent.Type.FINGER_STICK_BG_VALUE -> PointsWithLabelGraphSeries.Shape.BGCHECK
data.type == TherapyEvent.Type.ANNOUNCEMENT -> PointsWithLabelGraphSeries.Shape.ANNOUNCEMENT
data.type == TherapyEvent.Type.APS_OFFLINE -> PointsWithLabelGraphSeries.Shape.OPENAPSOFFLINE
data.type == TherapyEvent.Type.EXERCISE -> PointsWithLabelGraphSeries.Shape.EXERCISE
duration > 0 -> PointsWithLabelGraphSeries.Shape.GENERALWITHDURATION
else -> PointsWithLabelGraphSeries.Shape.GENERAL
}
override fun getDuration(): Long = data.duration override val size get() = if (rh.gb(R.bool.isTablet)) 12.0f else 10.0f
override fun getShape(): PointsWithLabelGraphSeries.Shape = override val color
when { get() =
data.type == TherapyEvent.Type.NS_MBG -> PointsWithLabelGraphSeries.Shape.MBG when (data.type) {
data.type == TherapyEvent.Type.FINGER_STICK_BG_VALUE -> PointsWithLabelGraphSeries.Shape.BGCHECK TherapyEvent.Type.ANNOUNCEMENT -> rh.gc(R.color.notificationAnnouncement)
data.type == TherapyEvent.Type.ANNOUNCEMENT -> PointsWithLabelGraphSeries.Shape.ANNOUNCEMENT TherapyEvent.Type.NS_MBG -> Color.RED
data.type == TherapyEvent.Type.APS_OFFLINE -> PointsWithLabelGraphSeries.Shape.OPENAPSOFFLINE TherapyEvent.Type.FINGER_STICK_BG_VALUE -> Color.RED
data.type == TherapyEvent.Type.EXERCISE -> PointsWithLabelGraphSeries.Shape.EXERCISE TherapyEvent.Type.EXERCISE -> Color.BLUE
duration > 0 -> PointsWithLabelGraphSeries.Shape.GENERALWITHDURATION TherapyEvent.Type.APS_OFFLINE -> Color.GRAY and -0x7f000001
else -> PointsWithLabelGraphSeries.Shape.GENERAL else -> Color.GRAY
} }
override fun getSize(): Float = if (rh.gb(R.bool.isTablet)) 12.0f else 10.0f
override fun getColor(): Int =
when (data.type) {
TherapyEvent.Type.ANNOUNCEMENT -> rh.gc(R.color.notificationAnnouncement)
TherapyEvent.Type.NS_MBG -> Color.RED
TherapyEvent.Type.FINGER_STICK_BG_VALUE -> Color.RED
TherapyEvent.Type.EXERCISE -> Color.BLUE
TherapyEvent.Type.APS_OFFLINE -> Color.GRAY and -0x7f000001
else -> Color.GRAY
}
} }

View file

@ -664,13 +664,15 @@ public class WatchUpdaterService extends WearableListenerService implements Goog
IobTotal bolusIob = iobCobCalculator.calculateIobFromBolus().round(); IobTotal bolusIob = iobCobCalculator.calculateIobFromBolus().round();
IobTotal basalIob = iobCobCalculator.calculateIobFromTempBasalsIncludingConvertedExtended().round(); IobTotal basalIob = iobCobCalculator.calculateIobFromTempBasalsIncludingConvertedExtended().round();
iobSum = DecimalFormatter.INSTANCE.to2Decimal(bolusIob.iob + basalIob.basaliob); iobSum = DecimalFormatter.INSTANCE.to2Decimal(bolusIob.getIob() + basalIob.getBasaliob());
iobDetail = "(" + DecimalFormatter.INSTANCE.to2Decimal(bolusIob.iob) + "|" + DecimalFormatter.INSTANCE.to2Decimal(basalIob.basaliob) + ")"; iobDetail =
"(" + DecimalFormatter.INSTANCE.to2Decimal(bolusIob.getIob()) + "|" + DecimalFormatter.INSTANCE.to2Decimal(basalIob.getBasaliob()) + ")";
cobString = iobCobCalculator.getCobInfo(false, "WatcherUpdaterService").generateCOBString(); cobString = iobCobCalculator.getCobInfo(false, "WatcherUpdaterService").generateCOBString();
currentBasal = generateBasalString(); currentBasal = generateBasalString();
//bgi //bgi
double bgi = -(bolusIob.activity + basalIob.activity) * 5 * Profile.Companion.fromMgdlToUnits(profile.getIsfMgdl(), profileFunction.getUnits()); double bgi =
-(bolusIob.getActivity() + basalIob.getActivity()) * 5 * Profile.Companion.fromMgdlToUnits(profile.getIsfMgdl(), profileFunction.getUnits());
bgiString = "" + ((bgi >= 0) ? "+" : "") + DecimalFormatter.INSTANCE.to1Decimal(bgi); bgiString = "" + ((bgi >= 0) ? "+" : "") + DecimalFormatter.INSTANCE.to1Decimal(bgi);
status = generateStatusString(profile, currentBasal, iobSum, iobDetail, bgiString); status = generateStatusString(profile, currentBasal, iobSum, iobDetail, bgiString);

View file

@ -10,18 +10,18 @@ import org.json.JSONObject
@Suppress("SpellCheckingInspection") @Suppress("SpellCheckingInspection")
class IobTotal(val time: Long) : DataPointWithLabelInterface { class IobTotal(val time: Long) : DataPointWithLabelInterface {
@JvmField var iob = 0.0 var iob = 0.0
@JvmField var activity = 0.0 var activity = 0.0
@JvmField var bolussnooze = 0.0 var bolussnooze = 0.0
@JvmField var basaliob = 0.0 var basaliob = 0.0
@JvmField var netbasalinsulin = 0.0 var netbasalinsulin = 0.0
@JvmField var hightempinsulin = 0.0 var hightempinsulin = 0.0
// oref1 // oref1
@JvmField var lastBolusTime: Long = 0 var lastBolusTime: Long = 0
var iobWithZeroTemp: IobTotal? = null var iobWithZeroTemp: IobTotal? = null
@JvmField var netInsulin = 0.0 // for calculations from temp basals only var netInsulin = 0.0 // for calculations from temp basals only
@JvmField var extendedBolusInsulin = 0.0 // total insulin for extended bolus var extendedBolusInsulin = 0.0 // total insulin for extended bolus
fun copy(): IobTotal { fun copy(): IobTotal {
val i = IobTotal(time) val i = IobTotal(time)
i.iob = iob i.iob = iob
@ -104,36 +104,14 @@ class IobTotal(val time: Long) : DataPointWithLabelInterface {
} }
// DataPoint interface // DataPoint interface
private var color = 0 override var color = 0
override fun getX(): Double { override fun getX(): Double = time.toDouble()
return time.toDouble() override fun getY(): Double = iob
}
override fun getY(): Double {
return iob
}
override fun setY(y: Double) {} override fun setY(y: Double) {}
override val label = ""
override fun getLabel(): String { override val duration = 0L
return "" override val shape = PointsWithLabelGraphSeries.Shape.IOBPREDICTION
} override val size = 0.5f
override fun getDuration(): Long {
return 0
}
override fun getShape(): PointsWithLabelGraphSeries.Shape {
return PointsWithLabelGraphSeries.Shape.IOBPREDICTION
}
override fun getSize(): Float {
return 0.5f
}
override fun getColor(): Int {
return color
}
fun setColor(color: Int): IobTotal { fun setColor(color: Int): IobTotal {
this.color = color this.color = color

View file

@ -1,58 +0,0 @@
package info.nightscout.androidaps.plugins.general.overview.graphExtensions;
/**
* GraphView
* Copyright (C) 2014 Jonas Gehring
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License,
* with the "Linking Exception", which can be found at the license.txt
* file in this program.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* with the "Linking Exception" along with this program; if not,
* write to the author Jonas Gehring <g.jjoe64@gmail.com>.
*/
/**
* Added by mike
*/
import com.jjoe64.graphview.series.DataPointInterface;
/**
* interface of data points. Implement this in order
* to use your class in {@link com.jjoe64.graphview.series.Series}.
*
* You can also use the default implementation {@link com.jjoe64.graphview.series.DataPoint} so
* you do not have to implement it for yourself.
*
* @author jjoe64
*/
public interface DataPointWithLabelInterface extends DataPointInterface{
/**
* @return the x value
*/
double getX();
/**
* @return the y value
*/
double getY();
void setY(double y);
/**
* @return the label value
*/
String getLabel();
long getDuration();
PointsWithLabelGraphSeries.Shape getShape();
float getSize();
int getColor();
}

View file

@ -0,0 +1,16 @@
package info.nightscout.androidaps.plugins.general.overview.graphExtensions
import com.jjoe64.graphview.series.DataPointInterface
interface DataPointWithLabelInterface : DataPointInterface {
override fun getX(): Double
override fun getY(): Double
fun setY(y: Double)
val label: String?
val duration: Long
val shape: PointsWithLabelGraphSeries.Shape?
val size: Float
val color: Int
}