mirror of
https://git.alemi.dev/dashboard.git
synced 2024-11-22 07:24:52 +01:00
feat!: allow to toggle averaging when reducing
This commit is contained in:
parent
11908370dd
commit
b91eee5e97
3 changed files with 11 additions and 14 deletions
|
@ -4,7 +4,7 @@ use eframe::egui::plot::Value;
|
||||||
use eframe::epaint::Color32;
|
use eframe::epaint::Color32;
|
||||||
use std::sync::RwLock;
|
use std::sync::RwLock;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Panel {
|
pub struct Panel {
|
||||||
pub(crate) id: i32,
|
pub(crate) id: i32,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
|
@ -18,6 +18,7 @@ pub struct Panel {
|
||||||
pub limit: bool,
|
pub limit: bool,
|
||||||
pub reduce: bool,
|
pub reduce: bool,
|
||||||
pub shift: bool,
|
pub shift: bool,
|
||||||
|
pub average: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Panel {
|
impl Default for Panel {
|
||||||
|
@ -35,6 +36,7 @@ impl Default for Panel {
|
||||||
limit: false,
|
limit: false,
|
||||||
reduce: false,
|
reduce: false,
|
||||||
shift: false,
|
shift: false,
|
||||||
|
average: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -138,6 +140,7 @@ impl Metric {
|
||||||
min_x: Option<f64>,
|
min_x: Option<f64>,
|
||||||
max_x: Option<f64>,
|
max_x: Option<f64>,
|
||||||
chunk_size: Option<u32>,
|
chunk_size: Option<u32>,
|
||||||
|
average: bool,
|
||||||
) -> Vec<Value> {
|
) -> Vec<Value> {
|
||||||
let mut values = self.data.read().expect("Values RwLock poisoned").clone();
|
let mut values = self.data.read().expect("Values RwLock poisoned").clone();
|
||||||
if let Some(min_x) = min_x {
|
if let Some(min_x) = min_x {
|
||||||
|
@ -150,7 +153,7 @@ impl Metric {
|
||||||
if chunk_size > 0 {
|
if chunk_size > 0 {
|
||||||
// TODO make this nested if prettier
|
// TODO make this nested if prettier
|
||||||
let iter = values.chunks(chunk_size as usize);
|
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
|
values
|
||||||
|
|
|
@ -36,7 +36,8 @@ impl SQLiteDataStore {
|
||||||
reduce_view BOOL NOT NULL,
|
reduce_view BOOL NOT NULL,
|
||||||
view_chunks INT NOT NULL,
|
view_chunks INT NOT NULL,
|
||||||
shift_view BOOL 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(
|
conn.execute(
|
||||||
"CREATE TABLE IF NOT EXISTS points (
|
"CREATE TABLE IF NOT EXISTS points (
|
||||||
id INTEGER PRIMARY KEY,
|
id INTEGER PRIMARY KEY,
|
||||||
|
@ -308,6 +300,7 @@ impl SQLiteDataStore {
|
||||||
view_chunks: row.get(10)?,
|
view_chunks: row.get(10)?,
|
||||||
shift: row.get(11)?,
|
shift: row.get(11)?,
|
||||||
view_offset: row.get(12)?,
|
view_offset: row.get(12)?,
|
||||||
|
average: row.get(13)?,
|
||||||
})
|
})
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
@ -356,6 +349,7 @@ impl SQLiteDataStore {
|
||||||
view_chunks: row.get(10)?,
|
view_chunks: row.get(10)?,
|
||||||
shift: row.get(11)?,
|
shift: row.get(11)?,
|
||||||
view_offset: row.get(12)?,
|
view_offset: row.get(12)?,
|
||||||
|
average: row.get(13)?,
|
||||||
})
|
})
|
||||||
})? {
|
})? {
|
||||||
if let Ok(p) = panel {
|
if let Ok(p) = panel {
|
||||||
|
|
|
@ -134,7 +134,7 @@ pub fn panel_title_ui(ui: &mut Ui, panel: &mut Panel, edit: bool) { // TODO make
|
||||||
.prefix("x")
|
.prefix("x")
|
||||||
.clamp_range(1..=1000), // TODO allow to average larger spans maybe?
|
.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");
|
ui.toggle_value(&mut panel.reduce, "reduce");
|
||||||
});
|
});
|
||||||
|
@ -216,7 +216,7 @@ pub fn panel_body_ui(ui: &mut Ui, panel: &mut Panel, metrics: &Vec<Metric>) {
|
||||||
let chunk_size = if panel.reduce { Some(panel.view_chunks) } else { None };
|
let chunk_size = if panel.reduce { Some(panel.view_chunks) } else { None };
|
||||||
for metric in metrics {
|
for metric in metrics {
|
||||||
if metric.panel_id == panel.id {
|
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 {
|
// if !panel.timeserie && panel.view_scroll && values.len() > 0 {
|
||||||
// let l = values.len() - 1;
|
// let l = values.len() - 1;
|
||||||
// p = p.include_x(values[0].x)
|
// p = p.include_x(values[0].x)
|
||||||
|
|
Loading…
Reference in a new issue