From 7e300a519395108d4fca108f2518ab420bedc778 Mon Sep 17 00:00:00 2001 From: Doloro1978 Date: Sun, 22 Mar 2026 11:16:12 +0000 Subject: [PATCH] guh --- src/tui/dashboard.rs | 13 +++++++++---- src/tui/data_graph.rs | 42 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 5 deletions(-) diff --git a/src/tui/dashboard.rs b/src/tui/dashboard.rs index 491e737..e24b546 100644 --- a/src/tui/dashboard.rs +++ b/src/tui/dashboard.rs @@ -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); } } diff --git a/src/tui/data_graph.rs b/src/tui/data_graph.rs index efda464..de1abea 100644 --- a/src/tui/data_graph.rs +++ b/src/tui/data_graph.rs @@ -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, }