Can request consumption history
This commit is contained in:
@ -97,6 +97,30 @@ impl ConsumptionHistoryFile {
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Get the total runtime of a relay during a given time window
|
||||
pub fn get_history(
|
||||
r#type: ConsumptionHistoryType,
|
||||
from: u64,
|
||||
to: u64,
|
||||
interval: u64,
|
||||
) -> anyhow::Result<Vec<EnergyConsumption>> {
|
||||
let mut res = Vec::with_capacity(((to - from) / interval) as usize);
|
||||
let mut file = Self::open(from, r#type)?;
|
||||
let mut curr_time = from;
|
||||
|
||||
while curr_time < to {
|
||||
if !file.contains_time(curr_time) {
|
||||
file = Self::open(curr_time, r#type)?;
|
||||
}
|
||||
|
||||
res.push(file.get_consumption(curr_time)?);
|
||||
|
||||
curr_time += interval;
|
||||
}
|
||||
|
||||
Ok(res)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
Reference in New Issue
Block a user