fix plot extensions
This commit is contained in:
parent
53cc4dc0df
commit
70ab60f98c
@ -54,7 +54,7 @@ public abstract class DeviceConstructor(
|
|||||||
/**
|
/**
|
||||||
* Register a property and provide a direct reader for it
|
* Register a property and provide a direct reader for it
|
||||||
*/
|
*/
|
||||||
public fun <T : Any, S: DeviceState<T>> property(
|
public fun <T, S: DeviceState<T>> property(
|
||||||
state: S,
|
state: S,
|
||||||
descriptorBuilder: PropertyDescriptor.() -> Unit = {},
|
descriptorBuilder: PropertyDescriptor.() -> Unit = {},
|
||||||
nameOverride: String? = null,
|
nameOverride: String? = null,
|
||||||
@ -104,7 +104,7 @@ public abstract class DeviceConstructor(
|
|||||||
/**
|
/**
|
||||||
* Create and register a virtual mutable property with optional [callback]
|
* Create and register a virtual mutable property with optional [callback]
|
||||||
*/
|
*/
|
||||||
public fun <T : Any> virtualProperty(
|
public fun <T> virtualProperty(
|
||||||
metaConverter: MetaConverter<T>,
|
metaConverter: MetaConverter<T>,
|
||||||
initialState: T,
|
initialState: T,
|
||||||
descriptorBuilder: PropertyDescriptor.() -> Unit = {},
|
descriptorBuilder: PropertyDescriptor.() -> Unit = {},
|
||||||
|
@ -28,7 +28,7 @@ public open class DeviceGroup(
|
|||||||
) : DeviceHub, CachingDevice {
|
) : DeviceHub, CachingDevice {
|
||||||
|
|
||||||
internal class Property(
|
internal class Property(
|
||||||
val state: DeviceState<out Any>,
|
val state: DeviceState<*>,
|
||||||
val descriptor: PropertyDescriptor,
|
val descriptor: PropertyDescriptor,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -82,7 +82,7 @@ public open class DeviceGroup(
|
|||||||
/**
|
/**
|
||||||
* Register a new property based on [DeviceState]. Properties could be modified dynamically
|
* Register a new property based on [DeviceState]. Properties could be modified dynamically
|
||||||
*/
|
*/
|
||||||
public fun registerProperty(descriptor: PropertyDescriptor, state: DeviceState<out Any>) {
|
public fun registerProperty(descriptor: PropertyDescriptor, state: DeviceState<*>) {
|
||||||
val name = descriptor.name.parseAsName()
|
val name = descriptor.name.parseAsName()
|
||||||
require(properties[name] == null) { "Can't add property with name $name. It already exists." }
|
require(properties[name] == null) { "Can't add property with name $name. It already exists." }
|
||||||
properties[name] = Property(state, descriptor)
|
properties[name] = Property(state, descriptor)
|
||||||
|
@ -50,7 +50,7 @@ public operator fun <T> MutableDeviceState<T>.setValue(thisRef: Any?, property:
|
|||||||
this.value = value
|
this.value = value
|
||||||
}
|
}
|
||||||
|
|
||||||
public var <T : Any> MutableDeviceState<T>.valueAsMeta: Meta
|
public var <T> MutableDeviceState<T>.valueAsMeta: Meta
|
||||||
get() = converter.convert(value)
|
get() = converter.convert(value)
|
||||||
set(arg) {
|
set(arg) {
|
||||||
value = converter.read(arg)
|
value = converter.read(arg)
|
||||||
|
@ -184,7 +184,6 @@ public fun Plot.plotBooleanState(
|
|||||||
private fun <T> Flow<T>.chunkedByPeriod(duration: Duration): Flow<List<T>> {
|
private fun <T> Flow<T>.chunkedByPeriod(duration: Duration): Flow<List<T>> {
|
||||||
val collector: ArrayDeque<T> = ArrayDeque<T>()
|
val collector: ArrayDeque<T> = ArrayDeque<T>()
|
||||||
return channelFlow {
|
return channelFlow {
|
||||||
coroutineScope {
|
|
||||||
launch {
|
launch {
|
||||||
while (isActive) {
|
while (isActive) {
|
||||||
delay(duration)
|
delay(duration)
|
||||||
@ -196,7 +195,6 @@ private fun <T> Flow<T>.chunkedByPeriod(duration: Duration): Flow<List<T>> {
|
|||||||
collector.add(it)
|
collector.add(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun List<Instant>.averageTime(): Instant {
|
private fun List<Instant>.averageTime(): Instant {
|
||||||
@ -224,7 +222,7 @@ public fun Plot.plotAveragedDeviceProperty(
|
|||||||
): Job = scatter(configuration).run {
|
): Job = scatter(configuration).run {
|
||||||
val data = TimeData()
|
val data = TimeData()
|
||||||
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(), missingValue.asValue())
|
||||||
} else {
|
} else {
|
||||||
val time = eventList.map { it.time }.averageTime()
|
val time = eventList.map { it.time }.averageTime()
|
||||||
|
Loading…
Reference in New Issue
Block a user