Change plotAveragedDeviceProperty to show last value on miss.
This commit is contained in:
parent
977500223d
commit
9eb583dfc6
@ -205,14 +205,14 @@ private fun List<Instant>.averageTime(): Instant {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Average property value by [averagingInterval]. Return [missingValue] on each sample interval if no events arrived.
|
* Average property value by [averagingInterval]. Return [startValue] on each sample interval if no events arrived.
|
||||||
*/
|
*/
|
||||||
@DFExperimental
|
@DFExperimental
|
||||||
public fun Plot.plotAveragedDeviceProperty(
|
public fun Plot.plotAveragedDeviceProperty(
|
||||||
device: Device,
|
device: Device,
|
||||||
propertyName: String,
|
propertyName: String,
|
||||||
missingValue: Double = 0.0,
|
startValue: Double = 0.0,
|
||||||
extractValue: Meta.() -> Double = { value?.double ?: missingValue },
|
extractValue: Meta.() -> Double = { value?.double ?: startValue },
|
||||||
maxAge: Duration = defaultMaxAge,
|
maxAge: Duration = defaultMaxAge,
|
||||||
maxPoints: Int = defaultMaxPoints,
|
maxPoints: Int = defaultMaxPoints,
|
||||||
minPoints: Int = defaultMinPoints,
|
minPoints: Int = defaultMinPoints,
|
||||||
@ -221,13 +221,15 @@ public fun Plot.plotAveragedDeviceProperty(
|
|||||||
configuration: Scatter.() -> Unit = {},
|
configuration: Scatter.() -> Unit = {},
|
||||||
): Job = scatter(configuration).run {
|
): Job = scatter(configuration).run {
|
||||||
val data = TimeData()
|
val data = TimeData()
|
||||||
|
var lastValue = startValue
|
||||||
device.propertyMessageFlow(propertyName).chunkedByPeriod(averagingInterval).transform { eventList ->
|
device.propertyMessageFlow(propertyName).chunkedByPeriod(averagingInterval).transform { eventList ->
|
||||||
if (eventList.isEmpty()) {
|
if (eventList.isEmpty()) {
|
||||||
data.append(Clock.System.now(), missingValue.asValue())
|
data.append(Clock.System.now(), lastValue.asValue())
|
||||||
} else {
|
} else {
|
||||||
val time = eventList.map { it.time }.averageTime()
|
val time = eventList.map { it.time }.averageTime()
|
||||||
val value = eventList.map { extractValue(it.value) }.average()
|
val value = eventList.map { extractValue(it.value) }.average()
|
||||||
data.append(time, value.asValue())
|
data.append(time, value.asValue())
|
||||||
|
lastValue = value
|
||||||
}
|
}
|
||||||
data.trim(maxAge, maxPoints, minPoints)
|
data.trim(maxAge, maxPoints, minPoints)
|
||||||
emit(data)
|
emit(data)
|
||||||
|
Loading…
Reference in New Issue
Block a user