pub struct MovingAverageTransformer { /* private fields */ }Expand description
A stateful transformer that calculates a moving average over a sliding window.
§Example
use streamweave::transformers::moving_average::MovingAverageTransformer;
use streamweave::transformer::Transformer;
use futures::StreamExt;
let mut transformer = MovingAverageTransformer::new(3); // 3-item window
let input = Box::pin(futures::stream::iter(vec![1.0, 2.0, 3.0, 4.0, 5.0]));
let output = transformer.transform(input);
let results: Vec<f64> = output.collect().await;
// Window: [1] -> avg 1.0
// Window: [1,2] -> avg 1.5
// Window: [1,2,3] -> avg 2.0
// Window: [2,3,4] -> avg 3.0
// Window: [3,4,5] -> avg 4.0
assert_eq!(results, vec![1.0, 1.5, 2.0, 3.0, 4.0]);Implementations§
Source§impl MovingAverageTransformer
impl MovingAverageTransformer
Sourcepub fn with_error_strategy(self, strategy: ErrorStrategy<f64>) -> Self
pub fn with_error_strategy(self, strategy: ErrorStrategy<f64>) -> Self
Sets the error strategy for this transformer.
Sourcepub fn window_size(&self) -> usize
pub fn window_size(&self) -> usize
Returns the window size.
Trait Implementations§
Source§impl Clone for MovingAverageTransformer
impl Clone for MovingAverageTransformer
Source§impl Debug for MovingAverageTransformer
impl Debug for MovingAverageTransformer
Source§impl Input for MovingAverageTransformer
impl Input for MovingAverageTransformer
Source§impl Output for MovingAverageTransformer
impl Output for MovingAverageTransformer
Source§impl StatefulTransformer for MovingAverageTransformer
impl StatefulTransformer for MovingAverageTransformer
Source§type State = MovingAverageState
type State = MovingAverageState
The type of state maintained by this transformer.
Source§type Store = SharedMovingAverageStore
type Store = SharedMovingAverageStore
The type of state store used by this transformer.
Source§fn state_store(&self) -> &Self::Store
fn state_store(&self) -> &Self::Store
Get a reference to the state store.
Source§fn state_store_mut(&mut self) -> &mut Self::Store
fn state_store_mut(&mut self) -> &mut Self::Store
Get a mutable reference to the state store.
Source§fn reset_state(&self) -> StateResult<()>
fn reset_state(&self) -> StateResult<()>
Reset the state to its initial value.
Source§fn update_state<F>(&self, f: F) -> StateResult<Self::State>
fn update_state<F>(&self, f: F) -> StateResult<Self::State>
Update the state using a closure. Read more
Source§fn state_or_initial(&self) -> Result<Self::State, StateError>
fn state_or_initial(&self) -> Result<Self::State, StateError>
Get the current state or the initial state if not set. Read more
Source§impl Transformer for MovingAverageTransformer
impl Transformer for MovingAverageTransformer
Source§type InputPorts = (f64,)
type InputPorts = (f64,)
The input port tuple type for this transformer. Read more
Source§type OutputPorts = (f64,)
type OutputPorts = (f64,)
The output port tuple type for this transformer. Read more
Source§fn transform(&mut self, input: Self::InputStream) -> Self::OutputStream
fn transform(&mut self, input: Self::InputStream) -> Self::OutputStream
Transforms a stream of input items into a stream of output items. Read more
Source§fn set_config_impl(&mut self, config: TransformerConfig<f64>)
fn set_config_impl(&mut self, config: TransformerConfig<f64>)
Sets the configuration implementation. Read more
Source§fn get_config_impl(&self) -> &TransformerConfig<f64>
fn get_config_impl(&self) -> &TransformerConfig<f64>
Returns a reference to the configuration implementation. Read more
Source§fn get_config_mut_impl(&mut self) -> &mut TransformerConfig<f64>
fn get_config_mut_impl(&mut self) -> &mut TransformerConfig<f64>
Returns a mutable reference to the configuration implementation. Read more
Source§fn handle_error(&self, error: &StreamError<f64>) -> ErrorAction
fn handle_error(&self, error: &StreamError<f64>) -> ErrorAction
Handles an error that occurred during stream processing. Read more
Source§fn create_error_context(&self, item: Option<f64>) -> ErrorContext<f64>
fn create_error_context(&self, item: Option<f64>) -> ErrorContext<f64>
Creates an error context for error reporting. Read more
Source§fn component_info(&self) -> ComponentInfo
fn component_info(&self) -> ComponentInfo
Returns information about the component for error reporting. Read more
Source§fn with_config(&self, config: TransformerConfig<Self::Input>) -> Self
fn with_config(&self, config: TransformerConfig<Self::Input>) -> Self
Creates a new transformer instance with the given configuration. Read more
Source§fn set_config(&mut self, config: TransformerConfig<Self::Input>)
fn set_config(&mut self, config: TransformerConfig<Self::Input>)
Sets the configuration for this transformer. Read more
Source§fn config(&self) -> &TransformerConfig<Self::Input>
fn config(&self) -> &TransformerConfig<Self::Input>
Returns a reference to the transformer’s configuration. Read more
Source§fn config_mut(&mut self) -> &mut TransformerConfig<Self::Input>
fn config_mut(&mut self) -> &mut TransformerConfig<Self::Input>
Returns a mutable reference to the transformer’s configuration. Read more
Auto Trait Implementations§
impl Freeze for MovingAverageTransformer
impl !RefUnwindSafe for MovingAverageTransformer
impl Send for MovingAverageTransformer
impl Sync for MovingAverageTransformer
impl Unpin for MovingAverageTransformer
impl !UnwindSafe for MovingAverageTransformer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> TransformerPorts for T
impl<T> TransformerPorts for T
Source§type DefaultInputPorts = (<T as Input>::Input,)
type DefaultInputPorts = (<T as Input>::Input,)
The default input port tuple type (single port with the transformer’s input type).
Source§type DefaultOutputPorts = (<T as Output>::Output,)
type DefaultOutputPorts = (<T as Output>::Output,)
The default output port tuple type (single port with the transformer’s output type).