guh
This commit is contained in:
@@ -48,11 +48,15 @@ impl Component for Menu {
|
||||
.name("Battery")
|
||||
.marker(ratatui::symbols::Marker::Dot)
|
||||
.graph_type(ratatui::widgets::GraphType::Line)
|
||||
.style(Color::Black);
|
||||
let x_axis = Axis::default().title("timeframe");
|
||||
.style(Color::White);
|
||||
let x_axis = Axis::default()
|
||||
.title("timeframe")
|
||||
.bounds([0., 86400.])
|
||||
.labels(["00:00", "06:00", "12:00", "18:00", "00:00"]);
|
||||
let y_axis = Axis::default()
|
||||
.title("Charge")
|
||||
.labels(["0%", "50%", "100%"]);
|
||||
.labels(["0%", "50%", "100%"])
|
||||
.bounds([0., 100.]);
|
||||
let graph_widget = Chart::new(vec![data_set]).x_axis(x_axis).y_axis(y_axis);
|
||||
f.render_widget(graph_widget, graph);
|
||||
}
|
||||
@@ -77,10 +81,11 @@ impl Menu {
|
||||
|
||||
// println!("{:#?}", data);
|
||||
let split_data = SplitData {
|
||||
r#static: data.data_static,
|
||||
chunks: data.data_chunks,
|
||||
};
|
||||
|
||||
self.data = split_data.timeframe(0, 9999999999999);
|
||||
// println!("{:#?}", self.data);
|
||||
// println!("{:?}", self.data);
|
||||
}
|
||||
}
|
||||
|
||||
+41
-1
@@ -1,3 +1,7 @@
|
||||
use std::time::SystemTime;
|
||||
use std::time::UNIX_EPOCH;
|
||||
|
||||
use data::BatteryStatic;
|
||||
use data::DataChunk;
|
||||
|
||||
pub trait Graphable {
|
||||
@@ -18,11 +22,47 @@ impl Graphable for SplitData {
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
filtered
|
||||
return self.normalise_data(&filtered, Calender::Day(1));
|
||||
}
|
||||
}
|
||||
|
||||
enum Calender {
|
||||
Day(i32),
|
||||
}
|
||||
impl SplitData {
|
||||
fn normalise_data(&self, data: &[(f64, f64)], metric: Calender) -> Vec<(f64, f64)> {
|
||||
let mut result = Vec::new();
|
||||
|
||||
// Extract the day from the Calender enum
|
||||
let day = match metric {
|
||||
Calender::Day(d) => d,
|
||||
};
|
||||
let a = SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.unwrap()
|
||||
.as_secs();
|
||||
|
||||
let day = a / 86400;
|
||||
|
||||
// Calculate the start of the day (00:00:00) in Unix timestamp
|
||||
let start_of_day = (day as i64 * 86400) as f64;
|
||||
let end_of_day = start_of_day + 86400.0; // End of the day
|
||||
|
||||
// Extract today's data and normalise
|
||||
for &(timestamp, value) in data {
|
||||
if timestamp >= start_of_day && timestamp < end_of_day {
|
||||
let relative_time = timestamp - start_of_day; // Time since start of day
|
||||
let normalised_value = (value / self.r#static.total_capacity as f64) * 100.0; // Percentage of battery
|
||||
result.push((relative_time, normalised_value));
|
||||
}
|
||||
}
|
||||
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct SplitData {
|
||||
pub r#static: BatteryStatic,
|
||||
pub chunks: Vec<DataChunk>,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user