mirror of
https://git.alemi.dev/dashboard.git
synced 2024-11-22 15:34:54 +01:00
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:
parent
66b43551bd
commit
d7856a921e
7 changed files with 68 additions and 103 deletions
|
@ -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()
|
.as_f64()
|
||||||
.ok_or(FetchError::JQLError("X query is null".to_string()))?; // TODO what if it's given to us as a string?
|
.ok_or(FetchError::JQLError("query result is null".to_string()))?;
|
||||||
} else {
|
|
||||||
x = Utc::now().timestamp() as f64;
|
|
||||||
}
|
|
||||||
let y = jql::walker(value, self.query_y.as_str())?
|
|
||||||
.as_f64()
|
|
||||||
.ok_or(FetchError::JQLError("Y query 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,
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -159,7 +159,6 @@ 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)
|
||||||
|
@ -208,7 +207,6 @@ pub fn panel_body_ui(
|
||||||
}
|
}
|
||||||
return out;
|
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;
|
||||||
|
|
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
|
@ -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))?;
|
||||||
|
|
|
@ -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),
|
||||||
|
|
Loading…
Reference in a new issue