diff --git a/src/app/data/source.rs b/src/app/data/source.rs index 1baf957..5e0dba0 100644 --- a/src/app/data/source.rs +++ b/src/app/data/source.rs @@ -4,7 +4,7 @@ use eframe::egui::plot::Value; use eframe::epaint::Color32; use std::sync::RwLock; -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct Panel { pub(crate) id: i32, pub name: String, @@ -18,6 +18,7 @@ pub struct Panel { pub limit: bool, pub reduce: bool, pub shift: bool, + pub average: bool, } impl Default for Panel { @@ -35,6 +36,7 @@ impl Default for Panel { limit: false, reduce: false, shift: false, + average: false, } } } @@ -138,6 +140,7 @@ impl Metric { min_x: Option, max_x: Option, chunk_size: Option, + average: bool, ) -> Vec { let mut values = self.data.read().expect("Values RwLock poisoned").clone(); if let Some(min_x) = min_x { @@ -150,7 +153,7 @@ impl Metric { if chunk_size > 0 { // TODO make this nested if prettier let iter = values.chunks(chunk_size as usize); - values = iter.map(|x| avg_value(x)).collect(); + values = iter.map(|x| if average { avg_value(x) } else { if x.len() > 0 { x[x.len()-1] } else { Value {x: 0.0, y:0.0 }} }).collect(); } } values diff --git a/src/app/data/store.rs b/src/app/data/store.rs index 31c7dbe..99f22d3 100644 --- a/src/app/data/store.rs +++ b/src/app/data/store.rs @@ -36,7 +36,8 @@ impl SQLiteDataStore { reduce_view BOOL NOT NULL, view_chunks INT NOT NULL, shift_view BOOL NOT NULL, - view_offset INT NOT NULL + view_offset INT NOT NULL, + average_view BOOL NOT NULL );", [], )?; @@ -67,15 +68,6 @@ impl SQLiteDataStore { [], )?; -// BEGIN TRANSACTION; -// CREATE TEMPORARY TABLE t1_backup(a,b); -// INSERT INTO t1_backup SELECT a,b FROM t1; -// DROP TABLE t1; -// CREATE TABLE t1(a,b); -// INSERT INTO t1 SELECT a,b FROM t1_backup; -// DROP TABLE t1_backup; -// COMMIT; - conn.execute( "CREATE TABLE IF NOT EXISTS points ( id INTEGER PRIMARY KEY, @@ -308,6 +300,7 @@ impl SQLiteDataStore { view_chunks: row.get(10)?, shift: row.get(11)?, view_offset: row.get(12)?, + average: row.get(13)?, }) })?; @@ -356,6 +349,7 @@ impl SQLiteDataStore { view_chunks: row.get(10)?, shift: row.get(11)?, view_offset: row.get(12)?, + average: row.get(13)?, }) })? { if let Ok(p) = panel { diff --git a/src/app/gui/panel.rs b/src/app/gui/panel.rs index 728b64d..055bbf6 100644 --- a/src/app/gui/panel.rs +++ b/src/app/gui/panel.rs @@ -134,7 +134,7 @@ pub fn panel_title_ui(ui: &mut Ui, panel: &mut Panel, edit: bool) { // TODO make .prefix("x") .clamp_range(1..=1000), // TODO allow to average larger spans maybe? ); - ui.checkbox(&mut panel.average, "avg"); + ui.toggle_value(&mut panel.average, "avg"); } ui.toggle_value(&mut panel.reduce, "reduce"); }); @@ -216,7 +216,7 @@ pub fn panel_body_ui(ui: &mut Ui, panel: &mut Panel, metrics: &Vec) { let chunk_size = if panel.reduce { Some(panel.view_chunks) } else { None }; for metric in metrics { if metric.panel_id == panel.id { - let values = metric.values(min_x, max_x, chunk_size); + let values = metric.values(min_x, max_x, chunk_size, panel.average); // if !panel.timeserie && panel.view_scroll && values.len() > 0 { // let l = values.len() - 1; // p = p.include_x(values[0].x)