mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-01 10:44:56 +03:00
simplify traffic signal challenge's communication of main score. move
count/duration comparators to a more general place.
This commit is contained in:
parent
d3fe865ad9
commit
78344ee2a4
@ -50,6 +50,7 @@ impl Histogram {
|
||||
|
||||
let min_y = 0;
|
||||
let max_y = bars.iter().map(|(_, _, cnt)| *cnt).max().unwrap();
|
||||
let mut outlines = Vec::new();
|
||||
for (idx, (min, max, cnt)) in bars.into_iter().enumerate() {
|
||||
let color = if max < Duration::ZERO {
|
||||
Color::RED
|
||||
@ -72,10 +73,7 @@ impl Histogram {
|
||||
Pt2D::new(width * percent_x_right, height),
|
||||
) {
|
||||
batch.push(color, rect.clone());
|
||||
batch.push(
|
||||
Color::BLACK.alpha(0.5),
|
||||
rect.to_outline(Distance::meters(0.5)),
|
||||
);
|
||||
outlines.push(rect.to_outline(Distance::meters(1.5)));
|
||||
rect_labels.push((
|
||||
rect,
|
||||
Text::from(Line(format!(
|
||||
@ -88,6 +86,7 @@ impl Histogram {
|
||||
));
|
||||
}
|
||||
}
|
||||
batch.extend(Color::BLACK, outlines);
|
||||
|
||||
let histogram = Histogram {
|
||||
draw: DrawBoth::new(ctx, batch, Vec::new()),
|
||||
|
@ -1,8 +1,8 @@
|
||||
use crate::render::ExtraShapeID;
|
||||
use crate::ui::PerMapUI;
|
||||
use abstutil::Timer;
|
||||
use abstutil::{prettyprint_usize, Timer};
|
||||
use ezgui::{Color, Line, Text, TextSpan};
|
||||
use geom::Pt2D;
|
||||
use geom::{Duration, Pt2D};
|
||||
use map_model::{AreaID, BuildingID, BusStopID, IntersectionID, LaneID, RoadID, TurnID};
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use sim::{AgentID, CarID, PedestrianID, TripID};
|
||||
@ -237,3 +237,44 @@ pub fn nice_map_name(name: &str) -> &str {
|
||||
_ => name,
|
||||
}
|
||||
}
|
||||
|
||||
// Shorter is better
|
||||
pub fn cmp_duration_shorter(now: Duration, baseline: Duration) -> Vec<TextSpan> {
|
||||
if now.epsilon_eq(baseline) {
|
||||
vec![Line("same as baseline")]
|
||||
} else if now < baseline {
|
||||
vec![
|
||||
Line((baseline - now).to_string()).fg(Color::GREEN),
|
||||
Line(" faster"),
|
||||
]
|
||||
} else if now > baseline {
|
||||
vec![
|
||||
Line((now - baseline).to_string()).fg(Color::RED),
|
||||
Line(" slower"),
|
||||
]
|
||||
} else {
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
|
||||
// Fewer is better
|
||||
pub fn cmp_count_fewer(now: usize, baseline: usize) -> TextSpan {
|
||||
if now < baseline {
|
||||
Line(format!("{} fewer", prettyprint_usize(baseline - now))).fg(Color::GREEN)
|
||||
} else if now > baseline {
|
||||
Line(format!("{} more", prettyprint_usize(now - baseline))).fg(Color::RED)
|
||||
} else {
|
||||
Line("same as baseline")
|
||||
}
|
||||
}
|
||||
|
||||
// More is better
|
||||
pub fn cmp_count_more(now: usize, baseline: usize) -> TextSpan {
|
||||
if now < baseline {
|
||||
Line(format!("{} fewer", prettyprint_usize(baseline - now))).fg(Color::RED)
|
||||
} else if now > baseline {
|
||||
Line(format!("{} more", prettyprint_usize(now - baseline))).fg(Color::GREEN)
|
||||
} else {
|
||||
Line("same as baseline")
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
use crate::common::ShowBusRoute;
|
||||
use crate::game::{State, Transition};
|
||||
use crate::helpers::ID;
|
||||
use crate::helpers::{cmp_count_fewer, cmp_count_more, cmp_duration_shorter};
|
||||
use crate::managed::{Callback, ManagedGUIState, WrappedComposite};
|
||||
use crate::sandbox::gameplay::{cmp_count_fewer, cmp_count_more, cmp_duration_shorter};
|
||||
use crate::sandbox::SandboxMode;
|
||||
use crate::ui::UI;
|
||||
use abstutil::prettyprint_usize;
|
||||
@ -122,11 +122,12 @@ fn finished_trips_summary_prebaked(ctx: &EventCtx, ui: &UI) -> ManagedWidget {
|
||||
]);
|
||||
if now_all.count() > 0 && baseline_all.count() > 0 {
|
||||
for stat in Statistic::all() {
|
||||
txt.add(Line(format!(" {}: {} ", stat, now_all.select(stat))));
|
||||
txt.add(Line(format!(" {}: {} (", stat, now_all.select(stat))));
|
||||
txt.append_all(cmp_duration_shorter(
|
||||
now_all.select(stat),
|
||||
baseline_all.select(stat),
|
||||
));
|
||||
txt.append(Line(")"));
|
||||
}
|
||||
}
|
||||
|
||||
@ -140,8 +141,9 @@ fn finished_trips_summary_prebaked(ctx: &EventCtx, ui: &UI) -> ManagedWidget {
|
||||
]);
|
||||
if a.count() > 0 && b.count() > 0 {
|
||||
for stat in Statistic::all() {
|
||||
txt.add(Line(format!(" {}: {} ", stat, a.select(stat))));
|
||||
txt.add(Line(format!(" {}: {} (", stat, a.select(stat))));
|
||||
txt.append_all(cmp_duration_shorter(a.select(stat), b.select(stat)));
|
||||
txt.append(Line(")"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,8 @@
|
||||
use crate::game::Transition;
|
||||
use crate::helpers::cmp_count_fewer;
|
||||
use crate::managed::WrappedComposite;
|
||||
use crate::render::InnerAgentColorScheme;
|
||||
use crate::sandbox::gameplay::{
|
||||
challenge_controller, cmp_count_fewer, manage_acs, GameplayMode, GameplayState,
|
||||
};
|
||||
use crate::sandbox::gameplay::{challenge_controller, manage_acs, GameplayMode, GameplayState};
|
||||
use crate::ui::UI;
|
||||
use abstutil::prettyprint_usize;
|
||||
use ezgui::{hotkey, layout, EventCtx, GfxCtx, Key, Line, ModalMenu, Text};
|
||||
|
@ -1,8 +1,7 @@
|
||||
use crate::game::Transition;
|
||||
use crate::helpers::{cmp_count_more, cmp_duration_shorter};
|
||||
use crate::managed::WrappedComposite;
|
||||
use crate::sandbox::gameplay::{
|
||||
challenge_controller, cmp_count_more, cmp_duration_shorter, GameplayMode, GameplayState,
|
||||
};
|
||||
use crate::sandbox::gameplay::{challenge_controller, GameplayMode, GameplayState};
|
||||
use crate::ui::UI;
|
||||
use abstutil::prettyprint_usize;
|
||||
use ezgui::{layout, EventCtx, GfxCtx, Line, ModalMenu, Text};
|
||||
@ -90,39 +89,12 @@ pub fn faster_trips_panel(mode: TripMode, ui: &UI) -> Text {
|
||||
}
|
||||
|
||||
for stat in Statistic::all() {
|
||||
txt.add(Line(format!("{}: {} ", stat, now.select(stat))));
|
||||
txt.add(Line(format!("{}: {} (", stat, now.select(stat))));
|
||||
txt.append_all(cmp_duration_shorter(
|
||||
now.select(stat),
|
||||
baseline.select(stat),
|
||||
));
|
||||
txt.append(Line(")"));
|
||||
}
|
||||
txt
|
||||
}
|
||||
|
||||
pub fn small_faster_trips_panel(mode: TripMode, ui: &UI) -> Text {
|
||||
let time = ui.primary.sim.time();
|
||||
let now = ui.primary.sim.get_analytics().finished_trips(time, mode);
|
||||
let baseline = ui.prebaked().finished_trips(time, mode);
|
||||
|
||||
let mut txt = Text::new();
|
||||
txt.add_appended(vec![
|
||||
Line(format!(
|
||||
"{} finished {} trips (",
|
||||
prettyprint_usize(now.count()),
|
||||
mode
|
||||
)),
|
||||
cmp_count_more(now.count(), baseline.count()),
|
||||
Line(")"),
|
||||
]);
|
||||
if now.count() == 0 || baseline.count() == 0 {
|
||||
return txt;
|
||||
}
|
||||
|
||||
let stat = Statistic::P50;
|
||||
txt.add(Line(format!("{}: {} ", stat, now.select(stat))));
|
||||
txt.append_all(cmp_duration_shorter(
|
||||
now.select(stat),
|
||||
baseline.select(stat),
|
||||
));
|
||||
txt
|
||||
}
|
||||
|
@ -1,12 +1,12 @@
|
||||
use crate::common::Overlays;
|
||||
use crate::game::{msg, Transition};
|
||||
use crate::helpers::cmp_duration_shorter;
|
||||
use crate::managed::WrappedComposite;
|
||||
use crate::sandbox::gameplay::faster_trips::small_faster_trips_panel;
|
||||
use crate::sandbox::gameplay::{
|
||||
challenge_controller, manage_overlays, GameplayMode, GameplayState,
|
||||
};
|
||||
use crate::ui::UI;
|
||||
use ezgui::{hotkey, layout, EventCtx, GfxCtx, Key, ModalMenu};
|
||||
use ezgui::{hotkey, layout, EventCtx, GfxCtx, Key, Line, ModalMenu, Text};
|
||||
use geom::{Duration, Statistic, Time};
|
||||
use map_model::{IntersectionID, Map};
|
||||
use sim::{BorderSpawnOverTime, OriginDestination, Scenario, TripMode};
|
||||
@ -82,8 +82,20 @@ impl GameplayState for FixTrafficSignals {
|
||||
|
||||
if self.time != ui.primary.sim.time() {
|
||||
self.time = ui.primary.sim.time();
|
||||
self.menu
|
||||
.set_info(ctx, small_faster_trips_panel(TripMode::Drive, ui));
|
||||
// TODO Put this in the top-center panel
|
||||
let mut txt = Text::new();
|
||||
let (now, _, _) = ui.primary.sim.get_analytics().all_finished_trips(self.time);
|
||||
let (baseline, _, _) = ui.prebaked().all_finished_trips(self.time);
|
||||
txt.add(Line("Average trip time: "));
|
||||
if now.count() > 0 && baseline.count() > 0 {
|
||||
txt.append_all(cmp_duration_shorter(
|
||||
now.select(Statistic::Mean),
|
||||
baseline.select(Statistic::Mean),
|
||||
));
|
||||
} else {
|
||||
txt.append(Line("same as baseline"));
|
||||
}
|
||||
self.menu.set_info(ctx, txt);
|
||||
}
|
||||
|
||||
if self.menu.action("final score") {
|
||||
|
@ -14,10 +14,10 @@ use crate::managed::{WrappedComposite, WrappedOutcome};
|
||||
use crate::render::{AgentColorScheme, InnerAgentColorScheme};
|
||||
use crate::sandbox::SandboxMode;
|
||||
use crate::ui::UI;
|
||||
use abstutil::{prettyprint_usize, Timer};
|
||||
use abstutil::Timer;
|
||||
use ezgui::{
|
||||
lctrl, Choice, Color, Composite, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Key, Line,
|
||||
ManagedWidget, ModalMenu, Text, TextSpan, VerticalAlignment, Wizard,
|
||||
ManagedWidget, ModalMenu, Text, VerticalAlignment, Wizard,
|
||||
};
|
||||
use geom::{Duration, Polygon};
|
||||
use map_model::{EditCmd, Map, MapEdits};
|
||||
@ -298,49 +298,6 @@ fn manage_acs(
|
||||
}
|
||||
}
|
||||
|
||||
// Shorter is better
|
||||
pub fn cmp_duration_shorter(now: Duration, baseline: Duration) -> Vec<TextSpan> {
|
||||
if now.epsilon_eq(baseline) {
|
||||
vec![Line(" (same as baseline)")]
|
||||
} else if now < baseline {
|
||||
vec![
|
||||
Line(" ("),
|
||||
Line((baseline - now).to_string()).fg(Color::GREEN),
|
||||
Line(" faster)"),
|
||||
]
|
||||
} else if now > baseline {
|
||||
vec![
|
||||
Line(" ("),
|
||||
Line((now - baseline).to_string()).fg(Color::RED),
|
||||
Line(" slower)"),
|
||||
]
|
||||
} else {
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
|
||||
// Fewer is better
|
||||
pub fn cmp_count_fewer(now: usize, baseline: usize) -> TextSpan {
|
||||
if now < baseline {
|
||||
Line(format!("{} fewer", prettyprint_usize(baseline - now))).fg(Color::GREEN)
|
||||
} else if now > baseline {
|
||||
Line(format!("{} more", prettyprint_usize(now - baseline))).fg(Color::RED)
|
||||
} else {
|
||||
Line("same as baseline")
|
||||
}
|
||||
}
|
||||
|
||||
// More is better
|
||||
pub fn cmp_count_more(now: usize, baseline: usize) -> TextSpan {
|
||||
if now < baseline {
|
||||
Line(format!("{} fewer", prettyprint_usize(baseline - now))).fg(Color::RED)
|
||||
} else if now > baseline {
|
||||
Line(format!("{} more", prettyprint_usize(now - baseline))).fg(Color::GREEN)
|
||||
} else {
|
||||
Line("same as baseline")
|
||||
}
|
||||
}
|
||||
|
||||
pub fn challenge_controller(
|
||||
ctx: &mut EventCtx,
|
||||
gameplay: GameplayMode,
|
||||
|
@ -1,8 +1,9 @@
|
||||
use crate::common::Overlays;
|
||||
use crate::game::{Transition, WizardState};
|
||||
use crate::helpers::cmp_duration_shorter;
|
||||
use crate::managed::WrappedComposite;
|
||||
use crate::sandbox::gameplay::{
|
||||
challenge_controller, cmp_duration_shorter, manage_overlays, GameplayMode, GameplayState,
|
||||
challenge_controller, manage_overlays, GameplayMode, GameplayState,
|
||||
};
|
||||
use crate::sandbox::SandboxMode;
|
||||
use crate::ui::UI;
|
||||
|
Loading…
Reference in New Issue
Block a user