simple final score for fixing traffic signals
@@ -4,7 +4,7 @@ use crate::sandbox::gameplay::{manage_overlays, GameplayState};
use crate::sandbox::overlays::Overlays;
use crate::ui::UI;
use ezgui::{hotkey, EventCtx, Key, ModalMenu};
-use geom::Time;
+use geom::{Duration, Statistic, Time};
use sim::TripMode;
pub struct FixTrafficSignals {
@@ -19,6 +19,7 @@ impl FixTrafficSignals {
vec![
(hotkey(Key::F), "find slowest traffic signals"),
(hotkey(Key::H), "help"),
+ (hotkey(Key::S), "final score"),
],
ctx,
),
@@ -68,6 +69,56 @@ impl GameplayState for FixTrafficSignals {
"(Due to budget cuts, none of the vehicle-actuated signals are working -- don't worry if you don't know what these are.)",
])));
}
+
+ if menu.action("final score") {
+ return Some(Transition::Push(msg("Final score", final_score(ui))));
+ }
+
+ if ui.primary.sim.time() >= Time::END_OF_DAY {
+ // TODO Stop the challenge somehow
+ return Some(Transition::Push(msg("Final score", final_score(ui))));
+ }
+
None
}
}
+
+fn final_score(ui: &UI) -> Vec<String> {
+ let time = ui.primary.sim.time();
+ let now = ui
+ .primary
+ .sim
+ .get_analytics()
+ .finished_trips(time, TripMode::Drive);
+ let baseline = ui.prebaked.finished_trips(time, TripMode::Drive);
+ // TODO Annoying to repeat this everywhere; any refactor possible?
+ if now.count() == 0 || baseline.count() == 0 {
+ return vec!["No data yet, run the simulation for longer".to_string()];
+ }
+ let now_50p = now.select(Statistic::P50);
+ let baseline_50p = baseline.select(Statistic::P50);
+ let mut lines = Vec::new();
+
+ if time < Time::END_OF_DAY {
+ lines.push(format!("You have to run the simulation until the end of the day to get final results; {} to go", Time::END_OF_DAY - time));
+ }
+
+ if now_50p < baseline_50p - Duration::seconds(30.0) {
+ lines.push(format!(
+ "COMPLETED! 50%ile trip times are now {}, which is {} faster than the baseline {}",
+ now_50p,
+ baseline_50p - now_50p,
+ baseline_50p
+ ));
+ } else if now_50p < baseline_50p {
+ lines.push(format!("Almost there! 50%ile trip times are now {}, which is {} faster than the baseline {}. Can you reduce the times by 30s?", now_50p, baseline_50p - now_50p, baseline_50p));
+ } else if now_50p.epsilon_eq(baseline_50p) {
+ lines.push(format!(
+ "... Did you change anything? 50% ile trip times are {}, same as the baseline",
+ now_50p
+ ));
+ } else {
+ lines.push(format!("Err... how did you make things WORSE?! 50%ile trip times are {}, which is {} slower than the baseline {}", now_50p, now_50p - baseline_50p, baseline_50p));
+ }
+ lines
+}
