use crate::abi::Int;
use crate::DataPoint;
use std::ops::Div;
pub struct Aggregator;
impl Aggregator {
pub fn agg(datapoints: &[DataPoint]) -> DataPoint {
let value = Int::from(0);
let timestamp = 0u32;
for d in datapoints {
value.checked_add(d.value).expect("value overflow");
timestamp
.checked_add(d.timestamp)
.expect("timestamp overflow");
}
let l = datapoints.len();
DataPoint::new(value.div(l), timestamp / l as u32)
}
}