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
|
||||
*/
|
||||
public fun <T : Any, S: DeviceState<T>> property(
|
||||
public fun <T, S: DeviceState<T>> property(
|
||||
state: S,
|
||||
descriptorBuilder: PropertyDescriptor.() -> Unit = {},
|
||||
nameOverride: String? = null,
|
||||
@ -104,7 +104,7 @@ public abstract class DeviceConstructor(
|
||||
/**
|
||||
* Create and register a virtual mutable property with optional [callback]
|
||||
*/
|
||||
public fun <T : Any> virtualProperty(
|
||||
public fun <T> virtualProperty(
|
||||
metaConverter: MetaConverter<T>,
|
||||
initialState: T,
|
||||
descriptorBuilder: PropertyDescriptor.() -> Unit = {},
|
||||
|
@ -28,7 +28,7 @@ public open class DeviceGroup(
|
||||
) : DeviceHub, CachingDevice {
|
||||
|
||||
internal class Property(
|
||||
val state: DeviceState<out Any>,
|
||||
val state: DeviceState<*>,
|
||||
val descriptor: PropertyDescriptor,
|
||||
)
|
||||
|
||||
@ -82,7 +82,7 @@ public open class DeviceGroup(
|
||||
/**
|
||||
* 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()
|
||||
require(properties[name] == null) { "Can't add property with name $name. It already exists." }
|
||||
properties[name] = Property(state, descriptor)
|
||||
|
@ -50,7 +50,7 @@ public operator fun <T> MutableDeviceState<T>.setValue(thisRef: Any?, property:
|
||||
this.value = value
|
||||
}
|
||||
|
||||
public var <T : Any> MutableDeviceState<T>.valueAsMeta: Meta
|
||||
public var <T> MutableDeviceState<T>.valueAsMeta: Meta
|
||||
get() = converter.convert(value)
|
||||
set(arg) {
|
||||
value = converter.read(arg)
|
||||
|
@ -184,7 +184,6 @@ public fun Plot.plotBooleanState(
|
||||
private fun <T> Flow<T>.chunkedByPeriod(duration: Duration): Flow<List<T>> {
|
||||
val collector: ArrayDeque<T> = ArrayDeque<T>()
|
||||
return channelFlow {
|
||||
coroutineScope {
|
||||
launch {
|
||||
while (isActive) {
|
||||
delay(duration)
|
||||
@ -196,7 +195,6 @@ private fun <T> Flow<T>.chunkedByPeriod(duration: Duration): Flow<List<T>> {
|
||||
collector.add(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun List<Instant>.averageTime(): Instant {
|
||||
@ -224,7 +222,7 @@ public fun Plot.plotAveragedDeviceProperty(
|
||||
): Job = scatter(configuration).run {
|
||||
val data = TimeData()
|
||||
device.propertyMessageFlow(propertyName).chunkedByPeriod(averagingInterval).transform { eventList ->
|
||||
if(eventList.isEmpty()){
|
||||
if (eventList.isEmpty()) {
|
||||
data.append(Clock.System.now(), missingValue.asValue())
|
||||
} else {
|
||||
val time = eventList.map { it.time }.averageTime()
|
||||
|
Loading…
Reference in New Issue
Block a user