1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
//! Processing strategies for combining source data into signal values.
//!
//! This module provides processors that transform multiple input values from
//! various sources into a single output value. Each processor implements a different
//! strategy for combining these values, such as taking the median or weighted median.
//!
//! The module provides:
//!
//! - The [`Processor`] enum which represents different processing strategies
//! - Specialized processor implementations in submodules
//! - Error handling for the processing operations
//!
//! # Available Processors
//!
//! The following processing strategies are available:
//!
//! - [`Median`](median::MedianProcessor) - Computes the median of the input values
//! - [`WeightedMedian`](weighted_median::WeightedMedianProcessor) - Computes a weighted median based on configurable weights
//!
//! # Extensibility
//!
//! This module is designed to be extensible. New processing strategies can be added by:
//!
//! 1. Creating a new processor implementation in a submodule
//! 2. Adding a new variant to the [`Processor`] enum
//! 3. Implementing the necessary logic in the `name` and `process` methods
//!
//! # Usage in Registry
//!
//! Processors are used within the registry system to define how source data should be
//! combined into a single value for each signal. Each signal specifies a processor
//! and its configuration parameters.
use ;
use Decimal;
use ;
use Error;
/// Error type for processor operations.
///
/// This error is returned when a processor encounters an issue while
/// processing data, such as insufficient data points or mathematical errors.
///
/// # Examples
///
/// ```
/// use bothan_lib::registry::processor::ProcessError;
///
/// let error = ProcessError::new("Insufficient data points");
/// assert_eq!(error.to_string(), "Insufficient data points");
/// ```
/// 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 values
/// * `WeightedMedian` - 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));
/// ```