feat: metrics now have only 1 query field

X is always current timestamp, and everything is a timeserie by default
This commit is contained in:
əlemi 2022-11-07 00:48:34 +01:00
parent 66b43551bd
commit d7856a921e
Signed by: alemi
GPG key ID: A4895B84D311642C
7 changed files with 68 additions and 103 deletions

View file

@ -13,8 +13,7 @@ pub struct Model {
pub id: i64, pub id: i64,
pub name: String, pub name: String,
pub source_id: i64, pub source_id: i64,
pub query_x: String, pub query: String,
pub query_y: String,
pub color: i32, pub color: i32,
pub position: i32, pub position: i32,
} }
@ -54,17 +53,10 @@ impl ActiveModelBehavior for ActiveModel {}
impl Model { impl Model {
pub fn extract(&self, value: &serde_json::Value) -> Result<PlotPoint, FetchError> { pub fn extract(&self, value: &serde_json::Value) -> Result<PlotPoint, FetchError> {
let x: f64; let x = Utc::now().timestamp() as f64;
if self.query_x.len() > 0 { let y = jql::walker(value, self.query.as_str())?
x = jql::walker(value, self.query_x.as_str())?
.as_f64()
.ok_or(FetchError::JQLError("X query is null".to_string()))?; // TODO what if it's given to us as a string?
} else {
x = Utc::now().timestamp() as f64;
}
let y = jql::walker(value, self.query_y.as_str())?
.as_f64() .as_f64()
.ok_or(FetchError::JQLError("Y query is null".to_string()))?; .ok_or(FetchError::JQLError("query result is null".to_string()))?;
Ok(PlotPoint { x, y }) Ok(PlotPoint { x, y })
} }
} }
@ -75,8 +67,7 @@ impl Default for Model {
id: 0, id: 0,
name: "".into(), name: "".into(),
source_id: 0, source_id: 0,
query_x: "".into(), query: "".into(),
query_y: "".into(),
color: 0, color: 0,
position: 0, position: 0,
} }

View file

@ -10,7 +10,6 @@ pub struct Model {
pub name: String, pub name: String,
pub view_scroll: bool, pub view_scroll: bool,
pub view_size: i32, pub view_size: i32,
pub timeserie: bool,
pub height: i32, pub height: i32,
pub position: i32, pub position: i32,
pub reduce_view: bool, pub reduce_view: bool,
@ -41,7 +40,6 @@ impl Default for Model {
name: "".into(), name: "".into(),
view_scroll: true, view_scroll: true,
view_size: 1000, view_size: 1000,
timeserie: true,
height: 100, height: 100,
position: 0, position: 0,
reduce_view: false, reduce_view: false,

View file

@ -1,4 +1,4 @@
use eframe::{egui::{Ui, Layout, Sense, color_picker::show_color_at, TextEdit}, emath::Align, epaint::Color32}; use eframe::{egui::{Ui, Sense, color_picker::show_color_at, TextEdit}, epaint::Color32};
use crate::{data::entities, util::unpack_color}; use crate::{data::entities, util::unpack_color};
@ -17,26 +17,9 @@ fn color_square(ui: &mut Ui, color:Color32) {
} }
} }
pub fn _metric_display_ui(ui: &mut Ui, metric: &entities::metrics::Model, _width: f32) {
ui.horizontal(|ui| {
color_square(ui, unpack_color(metric.color));
ui.label(&metric.name);
ui.with_layout(Layout::top_down(Align::RIGHT), |ui| {
ui.horizontal(|ui| {
ui.label("panel: ???");
ui.label(format!("y: {}", metric.query_y));
// if let Some(query_x) = metric.query_x {
// ui.label(format!("x: {}", query_x));
// }
})
});
});
}
pub fn metric_edit_ui(ui: &mut Ui, metric: &entities::metrics::Model) { pub fn metric_edit_ui(ui: &mut Ui, metric: &entities::metrics::Model) {
let mut name = metric.name.clone(); let mut name = metric.name.clone();
let mut query_x = metric.query_x.clone(); let mut query = metric.query.clone();
let mut query_y = metric.query_y.clone();
ui.horizontal(|ui| { ui.horizontal(|ui| {
// ui.color_edit_button_srgba(&mut unpack_color(metric.color)); // ui.color_edit_button_srgba(&mut unpack_color(metric.color));
color_square(ui, unpack_color(metric.color)); color_square(ui, unpack_color(metric.color));
@ -47,13 +30,8 @@ pub fn metric_edit_ui(ui: &mut Ui, metric: &entities::metrics::Model) {
.hint_text("name") .hint_text("name")
.show(ui); .show(ui);
ui.separator(); ui.separator();
TextEdit::singleline(&mut query_x) TextEdit::singleline(&mut query)
.desired_width(available / 4.0) .desired_width(available / 2.0)
.interactive(false)
.hint_text("x")
.show(ui);
TextEdit::singleline(&mut query_y)
.desired_width(available / 4.0)
.interactive(false) .interactive(false)
.hint_text("y") .hint_text("y")
.show(ui); .show(ui);

View file

@ -159,56 +159,54 @@ pub fn panel_body_ui(
} }
if panel.timeserie { if panel.view_scroll {
if panel.view_scroll { let now = (Utc::now().timestamp() as f64) - (60.0 * panel.view_offset as f64);
let now = (Utc::now().timestamp() as f64) - (60.0 * panel.view_offset as f64); p = p.include_x(now)
p = p.include_x(now) .include_x(now + (panel.view_size as f64 * 3.0))
.include_x(now + (panel.view_size as f64 * 3.0)) .include_x(now - (panel.view_size as f64 * 60.0)); // ??? TODO
.include_x(now - (panel.view_size as f64 * 60.0)); // ??? TODO
}
p = p
.x_axis_formatter(|x, _range| timestamp_to_str(x as i64, true, false))
.label_formatter(|name, value| {
if !name.is_empty() {
return format!(
"{}\nx = {}\ny = {:.1}",
name,
timestamp_to_str(value.x as i64, false, true),
value.y
);
} else {
return format!(
"x = {}\ny = {:.1}",
timestamp_to_str(value.x as i64, false, true),
value.y
);
}
})
.x_grid_spacer(|grid| {
let offset = Local::now().offset().local_minus_utc() as i64;
let (start, end) = grid.bounds;
let mut counter = (start as i64) - ((start as i64) % 3600);
let mut out: Vec<GridMark> = Vec::new();
loop {
counter += 3600;
if counter > end as i64 {
break;
}
if (counter + offset) % 86400 == 0 {
out.push(GridMark {
value: counter as f64,
step_size: 86400 as f64,
})
} else if counter % 3600 == 0 {
out.push(GridMark {
value: counter as f64,
step_size: 3600 as f64,
});
}
}
return out;
});
} }
p = p
.x_axis_formatter(|x, _range| timestamp_to_str(x as i64, true, false))
.label_formatter(|name, value| {
if !name.is_empty() {
return format!(
"{}\nx = {}\ny = {:.1}",
name,
timestamp_to_str(value.x as i64, false, true),
value.y
);
} else {
return format!(
"x = {}\ny = {:.1}",
timestamp_to_str(value.x as i64, false, true),
value.y
);
}
})
.x_grid_spacer(|grid| {
let offset = Local::now().offset().local_minus_utc() as i64;
let (start, end) = grid.bounds;
let mut counter = (start as i64) - ((start as i64) % 3600);
let mut out: Vec<GridMark> = Vec::new();
loop {
counter += 3600;
if counter > end as i64 {
break;
}
if (counter + offset) % 86400 == 0 {
out.push(GridMark {
value: counter as f64,
step_size: 86400 as f64,
})
} else if counter % 3600 == 0 {
out.push(GridMark {
value: counter as f64,
step_size: 3600 as f64,
});
}
}
return out;
});
let mut lines : Vec<Line> = Vec::new(); let mut lines : Vec<Line> = Vec::new();
let now = Utc::now().timestamp() as f64; let now = Utc::now().timestamp() as f64;

View file

@ -113,7 +113,6 @@ impl EditingModel {
name: Set(panel.name.clone()), name: Set(panel.name.clone()),
view_scroll: Set(panel.view_scroll), view_scroll: Set(panel.view_scroll),
view_size: Set(panel.view_size), view_size: Set(panel.view_size),
timeserie: Set(panel.timeserie),
height: Set(panel.height), height: Set(panel.height),
position: Set(panel.position), position: Set(panel.position),
reduce_view: Set(panel.reduce_view), reduce_view: Set(panel.reduce_view),
@ -150,8 +149,7 @@ impl EditingModel {
name: Set(metric.name.clone()), name: Set(metric.name.clone()),
source_id: Set(metric.source_id), source_id: Set(metric.source_id),
color: Set(metric.color), color: Set(metric.color),
query_x: Set(metric.query_x.clone()), query: Set(metric.query.clone()),
query_y: Set(metric.query_y.clone()),
position: Set(metric.position), position: Set(metric.position),
} }
}, },
@ -251,11 +249,11 @@ pub fn popup_edit_ui(
ui.selectable_value(&mut metric.source_id, s.id, s.name.as_str()); ui.selectable_value(&mut metric.source_id, s.id, s.name.as_str());
} }
}); });
TextEdit::singleline(&mut metric.query_x) // TextEdit::singleline(&mut metric.query_x)
.hint_text("x") // .hint_text("x")
.show(ui); // .show(ui);
TextEdit::singleline(&mut metric.query_y) TextEdit::singleline(&mut metric.query)
.hint_text("y") .hint_text("query")
.show(ui); .show(ui);
}, },
} }
@ -292,8 +290,12 @@ pub fn header(app: &mut App, ui: &mut Ui, frame: &mut Frame) {
app.refresh_data(); app.refresh_data();
} }
ui.separator(); ui.separator();
let last_edit = app.edit; // replace panels when going into edit mode
ui.checkbox(&mut app.edit, "edit"); ui.checkbox(&mut app.edit, "edit");
if app.edit { if app.edit {
if !last_edit { // TODO kinda cheap fix having it down here
app.panels = app.view.panels.borrow().clone();
}
if ui.button("reset").clicked() { if ui.button("reset").clicked() {
app.panels = app.view.panels.borrow().clone(); app.panels = app.view.panels.borrow().clone();
} }

View file

@ -14,9 +14,8 @@ pub fn _serialize_values(values: &Vec<PlotPoint>, metric: &entities::metrics::Mo
let mut wtr = csv::Writer::from_writer(std::fs::File::create(path)?); let mut wtr = csv::Writer::from_writer(std::fs::File::create(path)?);
// DAMN! VVVVV // DAMN! VVVVV
let name = metric.name.as_str(); let name = metric.name.as_str();
let q_x = metric.query_x.as_str(); let q = metric.query.as_str();
let q_y = metric.query_y.as_str(); wtr.write_record(&[name, q, "1"])?;
wtr.write_record(&[name, q_x, q_y])?;
// DAMN! AAAAA // DAMN! AAAAA
for v in values { for v in values {
wtr.serialize(("", v.x, v.y))?; wtr.serialize(("", v.x, v.y))?;

View file

@ -171,7 +171,6 @@ impl AppState {
name: Set(v.name.clone()), name: Set(v.name.clone()),
view_scroll: Set(v.view_scroll), view_scroll: Set(v.view_scroll),
view_size: Set(v.view_size), view_size: Set(v.view_size),
timeserie: Set(v.timeserie),
height: Set(v.height), height: Set(v.height),
position: Set(v.position), position: Set(v.position),
reduce_view: Set(v.reduce_view), reduce_view: Set(v.reduce_view),