pub struct MedianProcessor {
pub min_source_count: usize,
}Expand description
Processor that calculates the median of input values.
The MedianProcessor computes the median of a set of input values, requiring a minimum
number of data sources to be present. This provides a robust measure of central tendency
that is resistant to outliers in the data.
§Minimum Source Count
The processor requires at least min_source_count data points to calculate a median.
If fewer data points are provided, processing will fail with an error.
§Median Calculation
- For odd number of values, returns the middle value after sorting
- For even number of values, returns the average of the two middle values
§Examples
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 with 5 values
let data = vec![
("source1".to_string(), Decimal::new(100, 0)),
("source2".to_string(), Decimal::new(200, 0)),
("source3".to_string(), Decimal::new(300, 0)),
("source4".to_string(), Decimal::new(400, 0)),
("source5".to_string(), Decimal::new(500, 0)),
];
let result = processor.process(data).unwrap();
assert_eq!(result, Decimal::new(300, 0)); // Median is 300Fields§
§min_source_count: usizeThe minimum number of sources required to calculate the median.
If fewer than this number of data points are provided, the processing will fail with an error.
Implementations§
Source§impl MedianProcessor
impl MedianProcessor
Sourcepub fn new(min_source_count: usize) -> Self
pub fn new(min_source_count: usize) -> Self
Creates a new MedianProcessor with the specified minimum source count.
The minimum source count determines how many data points are required at minimum to calculate a valid median. This helps ensure the result has sufficient statistical significance.
§Examples
use bothan_lib::registry::processor::median::MedianProcessor;
// Create a processor that requires at least 3 sources
let processor = MedianProcessor::new(3);Sourcepub fn process(&self, data: Vec<Decimal>) -> Result<Decimal, ProcessError>
pub fn process(&self, data: Vec<Decimal>) -> Result<Decimal, ProcessError>
Calculates the median of the provided decimal values.
This method computes the median of the input values, failing if there are fewer data points than the required minimum.
§Errors
Returns a ProcessError if there are fewer than min_source_count data points.
Trait Implementations§
Source§impl<'__de, __Context> BorrowDecode<'__de, __Context> for MedianProcessor
impl<'__de, __Context> BorrowDecode<'__de, __Context> for MedianProcessor
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 Clone for MedianProcessor
impl Clone for MedianProcessor
Source§fn clone(&self) -> MedianProcessor
fn clone(&self) -> MedianProcessor
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for MedianProcessor
impl Debug for MedianProcessor
Source§impl<__Context> Decode<__Context> for MedianProcessor
impl<__Context> Decode<__Context> for MedianProcessor
Source§impl<'de> Deserialize<'de> for MedianProcessor
impl<'de> Deserialize<'de> for MedianProcessor
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>,
Source§impl Encode for MedianProcessor
impl Encode for MedianProcessor
Source§impl PartialEq for MedianProcessor
impl PartialEq for MedianProcessor
Source§impl Serialize for MedianProcessor
impl Serialize for MedianProcessor
impl StructuralPartialEq for MedianProcessor
Auto Trait Implementations§
impl Freeze for MedianProcessor
impl RefUnwindSafe for MedianProcessor
impl Send for MedianProcessor
impl Sync for MedianProcessor
impl Unpin for MedianProcessor
impl UnwindSafe for MedianProcessor
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