Skip to content

Commit c36c241

Browse files
committed
cleanup constraints
1 parent b50e255 commit c36c241

5 files changed

Lines changed: 20 additions & 182 deletions

File tree

gui/src/backend.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,10 +342,6 @@ impl Backend {
342342
return self.data_store_mut().set_value::<M>(value, time);
343343
}
344344

345-
fn debug_name<M: MetricTrait>() -> String {
346-
format!("{:?}", M::default())
347-
}
348-
349345
pub fn current_value<M: MetricTrait>(&self) -> Option<M::Value> {
350346
return self.data_store().current_value::<M>(self.fc_time());
351347
}

gui/src/frontend/constraints.rs

Lines changed: 0 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::marker::PhantomData;
2-
31
use egui::{Color32, RichText};
42
use strum::{EnumIter, VariantNames};
53
use telemetry::Metric;
@@ -214,8 +212,6 @@ pub trait Constraint {
214212

215213
fn evaluation_as_string(&self) -> String;
216214

217-
// fn as_string(&self, _backend: &Backend) -> String;
218-
219215
fn implies<C: Constraint>(self, rhs: C) -> ImpliesConstraint<Self, C>
220216
where
221217
Self: Sized,
@@ -362,25 +358,8 @@ impl<C1: Constraint, C2: Constraint> Constraint for ImpliesConstraint<C1, C2> {
362358
return !self.lhs.check() || self.rhs.check();
363359
}
364360
fn evaluation_as_string(&self) -> String {
365-
// if self.check() {
366-
// format! {"({}) implies ({})", self.lhs.evaluation_as_string(), self.rhs.evaluation_as_string()}
367-
// } else {
368361
format! {"({}) while ({})", self.rhs.evaluation_as_string(), self.lhs.evaluation_as_string()}
369-
//}
370-
// if self.check() {
371-
// format! {"({}) => ({})", self.lhs.evaluation_as_string(), self.rhs.evaluation_as_string()}
372-
// } else {
373-
// format! {"!({}) while ({})", self.rhs.evaluation_as_string(), self.lhs.evaluation_as_string()}
374-
// }
375362
}
376-
377-
// fn as_string(&self, backend: &Backend) -> String {
378-
// format!("({}) => ({})", self.lhs.as_string(backend), self.rhs.as_string(backend))
379-
// }
380-
381-
// fn violation_reason(&self, backend: &Backend) -> String {
382-
// format!("{} && Condition is true", self.rhs.violation_reason(backend))
383-
// }
384363
}
385364

386365
#[derive(Default)]
@@ -400,22 +379,8 @@ impl<C: Constraint> Constraint for NotConstraint<C> {
400379
}
401380

402381
fn evaluation_as_string(&self) -> String {
403-
// if self.check() {
404-
// format!("is not {}", self.constraint.evaluation_as_string())
405-
// } else {
406-
// format!("is {}", self.constraint.evaluation_as_string())
407-
//}
408382
self.constraint.evaluation_as_string()
409-
//format!("{}{}", if self.check() { "!" } else { "" }, self.constraint.evaluation_as_string())
410383
}
411-
412-
// fn as_string(&self, backend: &Backend) -> String {
413-
// format!("!({})", self.constraint.as_string(backend))
414-
// }
415-
416-
// fn violation_reason(&self, backend: &Backend) -> String {
417-
// format!("!{}", self.constraint.violation_reason(backend))
418-
// }
419384
}
420385

421386
pub struct GreaterOrEqualConstraint<M: MetricTrait, C: ConstraintValue<Type = M::Value>> {
@@ -443,21 +408,7 @@ impl<M: MetricTrait, C: ConstraintValue<Type = M::Value>> Constraint for Greater
443408
} else {
444409
format!("below {}", constraint_str)
445410
}
446-
// format!(
447-
// "{} {} {}",
448-
// self.cached_metric.cached_result.as_ref().map(|v| v.to_string()).unwrap_or("N/A".to_string()),
449-
// if self.check() { ">=" } else { "<" },
450-
// self.cached_constraint.cached_result.as_ref().map(|v| v.to_string()).unwrap_or("N/A".to_string()),
451-
// )
452411
}
453-
454-
// fn as_string(&self, backend: &Backend) -> String {
455-
// format!("{:?} >= {}", M::metric(), self.value.as_string(backend))
456-
// }
457-
458-
// fn violation_reason(&self, backend: &Backend) -> String {
459-
// format!("< {}", self.value.as_string(backend))
460-
// }
461412
}
462413

463414
pub struct GreaterThanConstraint<M: MetricTrait, C: ConstraintValue<Type = M::Value>> {
@@ -485,21 +436,7 @@ impl<M: MetricTrait, C: ConstraintValue<Type = M::Value>> Constraint for Greater
485436
} else {
486437
format!("below {}", constraint_str)
487438
}
488-
// format!(
489-
// "{} {} {}",
490-
// self.cached_metric.cached_result.as_ref().map(|v| v.to_string()).unwrap_or("N/A".to_string()),
491-
// if self.check() { ">" } else { "<=" },
492-
// self.cached_constraint.cached_result.as_ref().map(|v| v.to_string()).unwrap_or("N/A".to_string()),
493-
// )
494439
}
495-
496-
// fn as_string(&self, backend: &Backend) -> String {
497-
// format!("{:?} > {}", M::metric(), self.value.as_string(backend))
498-
// }
499-
500-
// fn violation_reason(&self, backend: &Backend) -> String {
501-
// format!("<= {}", self.value.as_string(backend))
502-
// }
503440
}
504441

505442
pub struct LessOrEqualConstraint<M: MetricTrait, C: ConstraintValue<Type = M::Value>> {
@@ -527,21 +464,7 @@ impl<M: MetricTrait, C: ConstraintValue<Type = M::Value>> Constraint for LessOrE
527464
} else {
528465
format!("exceeds {}", constraint_str)
529466
}
530-
// format!(
531-
// "{} {} {}",
532-
// self.cached_metric.cached_result.as_ref().map(|v| v.to_string()).unwrap_or("N/A".to_string()),
533-
// if self.check() { "<=" } else { ">" },
534-
// self.cached_constraint.cached_result.as_ref().map(|v| v.to_string()).unwrap_or("N/A".to_string()),
535-
// )
536467
}
537-
538-
// fn as_string(&self, backend: &Backend) -> String {
539-
// format!("{:?} <= {}", M::metric(), self.value.as_string(backend))
540-
// }
541-
542-
// fn violation_reason(&self, backend: &Backend) -> String {
543-
// format!("> {}", self.value.as_string(backend))
544-
// }
545468
}
546469

547470
pub struct LessThanConstraint<M: MetricTrait, C: ConstraintValue<Type = M::Value>> {
@@ -569,21 +492,7 @@ impl<M: MetricTrait, C: ConstraintValue<Type = M::Value>> Constraint for LessTha
569492
} else {
570493
format!("exceeds {}", constraint_str)
571494
}
572-
// format!(
573-
// "{} {} {}",
574-
// self.cached_metric.cached_result.as_ref().map(|v| v.to_string()).unwrap_or("N/A".to_string()),
575-
// if self.check() { "<" } else { ">=" },
576-
// self.cached_constraint.cached_result.as_ref().map(|v| v.to_string()).unwrap_or("N/A".to_string()),
577-
// )
578495
}
579-
580-
// fn as_string(&self, backend: &Backend) -> String {
581-
// format!("{:?} < {}", M::metric(), self.value.as_string(backend))
582-
// }
583-
584-
// fn violation_reason(&self, backend: &Backend) -> String {
585-
// format!(">= {}", self.value.as_string(backend))
586-
// }
587496
}
588497

589498
pub struct SomeConstraint<M: MetricTrait> {
@@ -607,20 +516,7 @@ impl<M: MetricTrait> Constraint for SomeConstraint<M> {
607516
} else {
608517
format!("is N/A")
609518
}
610-
// format!(
611-
// "{} {} Some",
612-
// self.cached_metric.cached_result.as_ref().map(|_| "Some").unwrap_or("N/A"),
613-
// if self.check() { "==" } else { "!=" }
614-
// )
615519
}
616-
617-
// fn as_string(&self, _backend: &Backend) -> String {
618-
// format!("{:?} is Some", M::metric())
619-
// }
620-
621-
// fn violation_reason(&self, _backend: &Backend) -> String {
622-
// "N/A".to_string()
623-
// }
624520
}
625521

626522
pub struct EqualsConstraint<M: MetricTrait, C: ConstraintValue<Type = M::Value>> {
@@ -649,18 +545,4 @@ impl<M: MetricTrait, C: ConstraintValue<Type = M::Value>> Constraint for EqualsC
649545
format!("is not {}", constraint_str)
650546
}
651547
}
652-
// format!(
653-
// "{} {} {}",
654-
// self.cached_metric.cached_result.as_ref().map(|v| v.to_string()).unwrap_or("N/A".to_string()),
655-
// if self.check() { "==" } else { "!=" },
656-
// self.cached_constraint.cached_result.as_ref().map(|v| v.to_string()).unwrap_or("N/A".to_string()),
657-
// )
658-
// }
659-
// fn as_string(&self, backend: &Backend) -> String {
660-
// format!("{:?} == {}", M::metric(), self.value.as_string(backend))
661-
// }
662-
663-
// fn violation_reason(&self, backend: &Backend) -> String {
664-
// format!("!= {}", self.value.as_string(backend))
665-
// }
666548
}

gui/src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,7 @@ impl Sam {
261261
};
262262
let backend = &mut self.backends[id];
263263
self.frontend.metric_monitor_mut().evaluate_constraints(backend);
264-
let mut active_constraint_mask = self.frontend.metric_monitor().active_constraint_mask().clone();
265-
MetricStatusBar::show(ctx, backend, &mut self.frontend, &mut active_constraint_mask);
266-
*self.frontend.metric_monitor_mut().active_constraint_mask_mut() = active_constraint_mask;
264+
MetricStatusBar::show(ctx, backend, &mut self.frontend);
267265
match tab {
268266
GuiTab::Launch => egui::CentralPanel::default().show(ctx, |_ui| {}).inner,
269267
GuiTab::Plot => self.plot_tab.main_ui(ctx, backend, &mut self.settings, &mut self.frontend, enabled),

gui/src/panels/metric_status_bar.rs

Lines changed: 17 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::{cmp::Ordering, collections::HashMap, sync::LazyLock};
22

3-
use egui::{Align, ComboBox, FontId, Layout, TextFormat, Ui, text::LayoutJob};
3+
use egui::{Align, FontId, Layout, TextFormat, Ui, text::LayoutJob};
44
use itertools::Itertools;
55
use strum::IntoEnumIterator;
66
use telemetry::Metric;
@@ -25,16 +25,6 @@ fn display(metric: &Metric, backend: &Backend, metric_monitor: &MetricMonitor, u
2525
ui.label(name);
2626
ui.label(val);
2727

28-
//let worst_constraint_result =
29-
// metric_monitor.constraint_results().get(metric).map(|res| res.iter().max()).unwrap_or_default();
30-
// worst_constraint_result
31-
// .map(|constraint| {
32-
// ui.label(constraint.result().symbol());
33-
// })
34-
// .unwrap_or_else(|| {
35-
// ui.allocate_response(Vec2::ZERO, Sense::hover());
36-
// });
37-
3828
if metric_monitor.is_pinned(&metric) {
3929
ui.label("📌");
4030
}
@@ -76,7 +66,6 @@ fn display(metric: &Metric, backend: &Backend, metric_monitor: &MetricMonitor, u
7666
0f32,
7767
TextFormat {
7868
color: theme.foreground_weak,
79-
//color: result.result().color(),
8069
..Default::default()
8170
},
8271
);
@@ -115,16 +104,14 @@ impl MetricStatusBar {
115104
return name_m1.cmp(&name_m2);
116105
}
117106

118-
pub fn show(
119-
ctx: &egui::Context,
120-
backend: &mut Backend,
121-
frontend: &mut Frontend,
122-
active_constraint_mask: &mut Vec<ConstraintResult>,
123-
) {
107+
pub fn show(ctx: &egui::Context, backend: &mut Backend, frontend: &mut Frontend) {
124108
let num_metrics_to_display = frontend.metric_monitor().pinned_metrics().len()
125-
+ Self::filter_constraints(frontend.metric_monitor().constraint_results(), active_constraint_mask)
126-
.keys()
127-
.count();
109+
+ Self::filter_constraints(
110+
frontend.metric_monitor().constraint_results(),
111+
frontend.metric_monitor().active_constraint_mask(),
112+
)
113+
.keys()
114+
.count();
128115
let has_open_popups = frontend.popup_manager().has_any_open_popup(&METRIC_MONITOR_FILTER_BUTTON_ID);
129116
egui::SidePanel::left("Monitor Panel").show_animated(
130117
ctx,
@@ -136,7 +123,7 @@ impl MetricStatusBar {
136123
ui.add_space(50.0);
137124
let mut active_constraints = vec![];
138125
for result in ConstraintResult::iter() {
139-
if active_constraint_mask.contains(&result) {
126+
if frontend.metric_monitor().active_constraint_mask().contains(&result) {
140127
active_constraints.push(true);
141128
} else {
142129
active_constraints.push(false);
@@ -150,51 +137,26 @@ impl MetricStatusBar {
150137
}
151138
},
152139
);
153-
active_constraint_mask.clear();
140+
frontend.metric_monitor_mut().active_constraint_mask_mut().clear();
154141
for (i, result) in ConstraintResult::iter().enumerate() {
155142
if active_constraints[i] {
156-
active_constraint_mask.push(result);
143+
frontend.metric_monitor_mut().active_constraint_mask_mut().push(result);
157144
}
158145
}
159146
});
160147
});
161148

162-
// ui.horizontal(|ui| {
163-
// ui.vertical_centered(|ui| {
164-
// ui.heading("Monitored Metrics");
165-
// });
166-
// });
167-
// //ui.allocate_ui_with_layout(ui.min_size(), Layout::left_to_right(Align::RIGHT), |ui| {
168-
// let mut active_constraints = vec![];
169-
// for result in ConstraintResult::iter() {
170-
// if active_constraint_mask.contains(&result) {
171-
// active_constraints.push(true);
172-
// } else {
173-
// active_constraints.push(false);
174-
// }
175-
// }
176-
// egui::ComboBox::new(*METRIC_MONITOR_FILTER_BUTTON_ID, "").selected_text("Filter").show_ui(ui, |ui| {
177-
// for (i, result) in ConstraintResult::iter().enumerate() {
178-
// ui.checkbox(&mut active_constraints[i], result.string());
179-
// }
180-
// });
181-
// active_constraint_mask.clear();
182-
// for (i, result) in ConstraintResult::iter().enumerate() {
183-
// if active_constraints[i] {
184-
// active_constraint_mask.push(result);
185-
// }
186-
// }
187-
188-
//})
189149
ui.separator();
190150
egui::Grid::new("monitor_panel_metrics").striped(true).show(ui, |ui| {
191151
for metric in frontend.metric_monitor().pinned_metrics() {
192152
display(metric, backend, frontend.metric_monitor(), ui);
193153
}
194-
for metric in
195-
Self::filter_constraints(frontend.metric_monitor().constraint_results(), active_constraint_mask)
196-
.keys()
197-
.sorted_by(|m1, m2| Self::cmp_metric_for_display(m1, m2, frontend.metric_monitor()))
154+
for metric in Self::filter_constraints(
155+
frontend.metric_monitor().constraint_results(),
156+
frontend.metric_monitor().active_constraint_mask(),
157+
)
158+
.keys()
159+
.sorted_by(|m1, m2| Self::cmp_metric_for_display(m1, m2, frontend.metric_monitor()))
198160
{
199161
if !frontend.metric_monitor().is_pinned(metric) {
200162
display(metric, backend, frontend.metric_monitor(), ui);

gui/src/widgets/time_line.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ impl TimelineStateFunctions for ProcedureStep {
170170
.unwrap_or(ProcedureStep::Verification), //TODO Hans: Think about this
171171
self.hotkey(),
172172
(
173-
PopupContentData::<ModalDialog, _>::new(move |ui, frontend, backend| {
173+
PopupContentData::<ModalDialog, _>::new(move |ui, _frontend, backend| {
174174
let mut button_clicked = false;
175175
let theme = ThemeColors::new(ui.ctx());
176176
let response = ui
@@ -292,7 +292,7 @@ impl TimelineStateFunctions for HyacinthAnomalousState {
292292
.unwrap_or(false),
293293
self.hotkey(),
294294
(
295-
PopupContentData::<ModalDialog, _>::new(move |ui, frontend, backend| {
295+
PopupContentData::<ModalDialog, _>::new(move |ui, _frontend, backend| {
296296
let theme = ThemeColors::new(ui.ctx());
297297
let mut button_clicked = false;
298298
let response = ui

0 commit comments

Comments
 (0)