api3_common/agg.rs
1use crate::abi::Int;
2use crate::DataPoint;
3use std::ops::Div;
4
5/// The Manager for handling multiple datapoints
6pub struct Aggregator;
7
8impl Aggregator {
9 pub fn agg(datapoints: &[DataPoint]) -> DataPoint {
10 let value = Int::from(0);
11 let timestamp = 0u32;
12 for d in datapoints {
13 value.checked_add(d.value).expect("value overflow");
14 timestamp
15 .checked_add(d.timestamp)
16 .expect("timestamp overflow");
17 }
18 let l = datapoints.len();
19 DataPoint::new(value.div(l), timestamp / l as u32)
20 }
21}