use std::{future::Future, pin::Pin};
use crate::{data::Data, entities::metrics::Model as Metrics};
use itertools::Itertools;
use sea_orm::DatabaseConnection;
pub type BoxFuture = Pin<Box<dyn Future<Output = anyhow::Result<Data>> + Send>>;
pub fn rab_linear_model(ci_g_w: f32) -> impl Fn(&Vec<&Metrics>, f32) -> Data {
return move |metrics, cpu_avg_pow_w| {
let data = metrics
.into_iter()
.sorted_by(|a, b| b.time_stamp.cmp(&a.time_stamp))
.tuple_windows()
.map(|(a, b)| {
(0.5 * (a.cpu_usage + b.cpu_usage)) / 50_f64
* cpu_avg_pow_w as f64
* ((a.time_stamp - b.time_stamp) as f64 / 1000_f64)
})
.collect_vec();
let pow_w = data.iter().fold(0_f64, |x, acc| x + acc);
let co2_g_w = pow_w * ci_g_w as f64;
Data {
pow: pow_w,
co2: co2_g_w,
}
};
}
pub fn rab_nonlinear_model(
_ci: f32,
_db: &DatabaseConnection,
) -> impl Fn(&Vec<&Metrics>, f32) -> Data {
return move |_metrics, _run_id| todo!();
}