From fb8ee59f148e1312ae4bbf06718d1465b391755b Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Wed, 8 Nov 2023 22:33:49 +0300 Subject: [PATCH] replace debounce by sample --- .../src/commonMain/kotlin/plotExtensions.kt | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/controls-vision/src/commonMain/kotlin/plotExtensions.kt b/controls-vision/src/commonMain/kotlin/plotExtensions.kt index 40f746b..3640ee9 100644 --- a/controls-vision/src/commonMain/kotlin/plotExtensions.kt +++ b/controls-vision/src/commonMain/kotlin/plotExtensions.kt @@ -5,9 +5,9 @@ package space.kscience.controls.vision import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.FlowPreview import kotlinx.coroutines.Job -import kotlinx.coroutines.flow.debounce import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach +import kotlinx.coroutines.flow.sample import kotlinx.coroutines.flow.transform import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock @@ -93,13 +93,13 @@ public fun Plot.plotDeviceProperty( maxAge: Duration = 1.hours, maxPoints: Int = 800, minPoints: Int = 400, - debounceDuration: Duration = 10.milliseconds, + sampling: Duration = 10.milliseconds, coroutineScope: CoroutineScope = device.context, configuration: Scatter.() -> Unit = {}, ): Job = scatter(configuration).run { val clock = device.context.clock val data = TimeData() - device.propertyMessageFlow(propertyName).debounce(debounceDuration).transform { + device.propertyMessageFlow(propertyName).sample(sampling).transform { data.append(it.time ?: clock.now(), it.value.extractValue()) data.trim(maxAge, maxPoints, minPoints) emit(data) @@ -115,11 +115,11 @@ private fun Trace.updateFromState( maxAge: Duration = 1.hours, maxPoints: Int = 800, minPoints: Int = 400, - debounceDuration: Duration = 10.milliseconds, + sampling: Duration = 10.milliseconds, ): Job { val clock = context.clock val data = TimeData() - return state.valueFlow.debounce(debounceDuration).transform { + return state.valueFlow.sample(sampling).transform { data.append(clock.now(), it.extractValue()) data.trim(maxAge, maxPoints, minPoints) }.onEach { @@ -134,10 +134,10 @@ public fun Plot.plotDeviceState( maxAge: Duration = 1.hours, maxPoints: Int = 800, minPoints: Int = 400, - debounceDuration: Duration = 10.milliseconds, + sampling: Duration = 10.milliseconds, configuration: Scatter.() -> Unit = {}, ): Job = scatter(configuration).run { - updateFromState(context, state, extractValue, maxAge, maxPoints, minPoints, debounceDuration) + updateFromState(context, state, extractValue, maxAge, maxPoints, minPoints, sampling) } @@ -147,10 +147,10 @@ public fun Plot.plotNumberState( maxAge: Duration = 1.hours, maxPoints: Int = 800, minPoints: Int = 400, - debounceDuration: Duration = 10.milliseconds, + sampling: Duration = 10.milliseconds, configuration: Scatter.() -> Unit = {}, ): Job = scatter(configuration).run { - updateFromState(context, state, { asValue() }, maxAge, maxPoints, minPoints, debounceDuration) + updateFromState(context, state, { asValue() }, maxAge, maxPoints, minPoints, sampling) } @@ -160,8 +160,8 @@ public fun Plot.plotBooleanState( maxAge: Duration = 1.hours, maxPoints: Int = 800, minPoints: Int = 400, - debounceDuration: Duration = 10.milliseconds, + sampling: Duration = 10.milliseconds, configuration: Bar.() -> Unit = {}, ): Job = bar(configuration).run { - updateFromState(context, state, { asValue() }, maxAge, maxPoints, minPoints, debounceDuration) + updateFromState(context, state, { asValue() }, maxAge, maxPoints, minPoints, sampling) } \ No newline at end of file