pub enum Processor {
Median(MedianProcessor),
WeightedMedian(WeightedMedianProcessor),
}Expand description
Represents different strategies for processing source data into a signal value.
The Processor enum encapsulates different algorithms for combining multiple
input values from various sources into a single output value. Each variant
contains its own configuration parameters.
§Variants
Median- Computes the median of the input valuesWeightedMedian- Computes a weighted median based on configured weights
§Examples
Creating a median processor:
use bothan_lib::registry::processor::{Processor, median::MedianProcessor};
use serde_json::json;
// Create a processor from JSON
let json_data = json!({
"function": "median",
"params": {
"min_source_count": 3
}
});
let processor: Processor = serde_json::from_value(json_data).unwrap();
assert_eq!(processor.name(), "median");Using a processor:
use bothan_lib::registry::processor::{Processor, median::MedianProcessor};
use rust_decimal::Decimal;
// Create a median processor that requires at least 3 sources
let processor = Processor::Median(MedianProcessor { min_source_count: 3 });
// Process some data
let data = vec![
("source1".to_string(), Decimal::new(100, 0)),
("source2".to_string(), Decimal::new(200, 0)),
("source3".to_string(), Decimal::new(300, 0)),
];
let result = processor.process(data).unwrap();
assert_eq!(result, Decimal::new(200, 0));Variants§
Median(MedianProcessor)
Median processor that computes the median of input values.
WeightedMedian(WeightedMedianProcessor)
Weighted median processor that applies weights to input values.
Implementations§
Source§impl Processor
impl Processor
Sourcepub fn name(&self) -> &str
pub fn name(&self) -> &str
Returns the name of the processor.
This method returns a string identifier for the processor type, which can be used for logging, debugging, or serialization purposes.
Sourcepub fn process(
&self,
data: Vec<(String, Decimal)>,
) -> Result<Decimal, ProcessError>
pub fn process( &self, data: Vec<(String, Decimal)>, ) -> Result<Decimal, ProcessError>
Processes input data into a single output value.
This method applies the processor’s algorithm to the input data to produce a single output value. The input data consists of pairs of source identifiers and their corresponding values.
§Errors
Returns a ProcessError if the processing operation fails, such as when:
- There are insufficient data points
- The data does not meet the processor’s requirements
- A mathematical error occurs during processing
Trait Implementations§
Source§impl<'__de, __Context> BorrowDecode<'__de, __Context> for Processor
impl<'__de, __Context> BorrowDecode<'__de, __Context> for Processor
Source§fn borrow_decode<__D: BorrowDecoder<'__de, Context = __Context>>(
decoder: &mut __D,
) -> Result<Self, DecodeError>
fn borrow_decode<__D: BorrowDecoder<'__de, Context = __Context>>( decoder: &mut __D, ) -> Result<Self, DecodeError>
Source§impl<'de> Deserialize<'de> for Processor
impl<'de> Deserialize<'de> for Processor
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl StructuralPartialEq for Processor
Auto Trait Implementations§
impl Freeze for Processor
impl RefUnwindSafe for Processor
impl Send for Processor
impl Sync for Processor
impl Unpin for Processor
impl UnwindSafe for Processor
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request