consistent wording everywhere for Before/After changes

This commit is contained in:
Dustin Carlino 2020-04-13 14:20:07 -07:00
parent 76a3ade45d
commit 0d22127b76
14 changed files with 122 additions and 124 deletions

View File

@ -400,14 +400,9 @@ impl Widget {
w.restore(ctx, prev);
}
} else if self.widget.can_restore() {
self.widget.restore(
ctx,
&prev
.top_level
.find(self.id.as_ref().unwrap())
.unwrap()
.widget,
);
if let Some(ref other) = prev.top_level.find(self.id.as_ref().unwrap()) {
self.widget.restore(ctx, &other.widget);
}
}
}

View File

@ -105,17 +105,17 @@ pub fn nice_map_name(name: &str) -> &str {
}
// 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 {
pub fn cmp_duration_shorter(after: Duration, before: Duration) -> Vec<TextSpan> {
if after.epsilon_eq(before) {
vec![Line("same")]
} else if after < before {
vec![
Line((baseline - now).to_string()).fg(Color::GREEN),
Line((before - after).to_string()).fg(Color::GREEN),
Line(" faster"),
]
} else if now > baseline {
} else if after > before {
vec![
Line((now - baseline).to_string()).fg(Color::RED),
Line((after - before).to_string()).fg(Color::RED),
Line(" slower"),
]
} else {
@ -124,12 +124,12 @@ pub fn cmp_duration_shorter(now: Duration, baseline: Duration) -> Vec<TextSpan>
}
// 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)
pub fn cmp_count_fewer(after: usize, before: usize) -> TextSpan {
if after < before {
Line(format!("{} fewer", prettyprint_usize(before - after))).fg(Color::GREEN)
} else if after > before {
Line(format!("{} more", prettyprint_usize(after - before))).fg(Color::RED)
} else {
Line("same as baseline")
Line("same")
}
}

View File

@ -62,7 +62,7 @@ pub fn traffic(
ctx,
app,
move |a, t| a.throughput_intersection(t, id, opts.bucket_size),
opts.show_baseline,
opts.show_before,
)
.margin(10),
);
@ -123,13 +123,13 @@ fn delay_plot(ctx: &EventCtx, app: &App, i: IntersectionID, opts: &DataOptions)
pts,
});
}
if opts.show_baseline {
if opts.show_before {
for (idx, (stat, pts)) in get_data(app.prebaked(), Time::END_OF_DAY)
.into_iter()
.enumerate()
{
all_series.push(Series {
label: format!("{} (baseline)", stat),
label: format!("{} (before changes)", stat),
color: app.cs.rotating_color_plot(idx).alpha(0.3),
pts,
});

View File

@ -127,7 +127,7 @@ pub fn traffic(
ctx,
app,
move |a, t| a.throughput_road(t, r, opts.bucket_size),
opts.show_baseline,
opts.show_before,
)
.margin(10),
);

View File

@ -473,7 +473,7 @@ fn throughput<F: Fn(&Analytics, Time) -> BTreeMap<TripMode, Vec<(Time, usize)>>>
ctx: &EventCtx,
app: &App,
get_data: F,
show_baseline: bool,
show_before: bool,
) -> Widget {
let mut series = get_data(app.primary.sim.get_analytics(), app.primary.sim.time())
.into_iter()
@ -483,11 +483,11 @@ fn throughput<F: Fn(&Analytics, Time) -> BTreeMap<TripMode, Vec<(Time, usize)>>>
pts,
})
.collect::<Vec<_>>();
if show_baseline {
if show_before {
// TODO Ahh these colors don't show up differently at all.
for (m, pts) in get_data(app.prebaked(), Time::END_OF_DAY) {
series.push(Series {
label: format!("{} (baseline)", m.ongoing_verb()),
label: format!("{} (before changes)", m.ongoing_verb()),
color: color_for_mode(m, app).alpha(0.3),
pts,
});
@ -554,14 +554,14 @@ pub trait ContextualActions {
#[derive(Clone, PartialEq)]
pub struct DataOptions {
pub show_baseline: bool,
pub show_before: bool,
pub bucket_size: Duration,
}
impl DataOptions {
pub fn new(app: &App) -> DataOptions {
DataOptions {
show_baseline: app.has_prebaked().is_some(),
show_before: app.has_prebaked().is_some(),
bucket_size: Duration::minutes(20),
}
}
@ -584,8 +584,7 @@ impl DataOptions {
"buckets".draw_text(ctx),
]),
if app.has_prebaked().is_some() {
// TODO Change the wording of this
Checkbox::text(ctx, "Show baseline data", None, self.show_baseline)
Checkbox::text(ctx, "Show before changes", None, self.show_before)
} else {
Widget::nothing()
},
@ -594,7 +593,7 @@ impl DataOptions {
pub fn from_controls(c: &Composite) -> DataOptions {
DataOptions {
show_baseline: c.has_widget("Show baseline data") && c.is_checked("Show baseline data"),
show_before: c.has_widget("Show before changes") && c.is_checked("Show before changes"),
bucket_size: c.dropdown_value("bucket size"),
}
}

View File

@ -98,8 +98,8 @@ pub fn trips(
assert!(wheres_waldo);
(
"finished",
open_trips.get(t).map(|show_live| {
trip::finished(ctx, app, id, open_trips, *t, *show_live, details)
open_trips.get(t).map(|show_after| {
trip::finished(ctx, app, id, open_trips, *t, *show_after, details)
}),
)
}
@ -131,13 +131,13 @@ pub fn trips(
.bg(Color::rgba(127, 250, 77, 0.2))
.padding(5)
} else if trip_status == "finished" {
if let Some(orig) = app
if let Some(before) = app
.has_prebaked()
.and_then(|_| app.prebaked().finished_trip_time(*t))
{
let (experiment, _) = app.primary.sim.finished_trip_time(*t).unwrap();
let (after, _) = app.primary.sim.finished_trip_time(*t).unwrap();
let mut txt = Text::from(Line("finished ").small());
txt.append_all(cmp_duration_shorter(experiment, orig));
txt.append_all(cmp_duration_shorter(after, before));
txt.draw(ctx)
} else {
Line("finished").small().draw(ctx)
@ -408,21 +408,21 @@ fn current_status(ctx: &EventCtx, person: &Person, map: &Map) -> Widget {
}
// TODO Dedupe with the version in helpers
fn cmp_duration_shorter(experiment: Duration, baseline: Duration) -> Vec<TextSpan> {
if experiment.epsilon_eq(baseline) {
fn cmp_duration_shorter(after: Duration, before: Duration) -> Vec<TextSpan> {
if after.epsilon_eq(before) {
vec![Line("(no change)").small()]
} else if experiment < baseline {
} else if after < before {
vec![
Line("(").small(),
Line(format!("{} faster", baseline - experiment))
Line(format!("{} faster", before - after))
.small()
.fg(Color::GREEN),
Line(")").small(),
]
} else if experiment > baseline {
} else if after > before {
vec![
Line("(").small(),
Line(format!("{} slower", experiment - baseline))
Line(format!("{} slower", after - before))
.small()
.fg(Color::RED),
Line(")").small(),

View File

@ -142,11 +142,11 @@ pub fn finished(
person: PersonID,
open_trips: &BTreeMap<TripID, bool>,
trip: TripID,
show_live: bool,
show_after: bool,
details: &mut Details,
) -> Widget {
let (start_time, _, _, _) = app.primary.sim.trip_info(trip);
let phases = if show_live {
let phases = if show_after {
app.primary
.sim
.get_analytics()
@ -165,26 +165,30 @@ pub fn finished(
start_time.ampm_tostring()
))))
.build(ctx, format!("watch {}", trip), None),
if show_live && app.has_prebaked().is_some() {
if show_after && app.has_prebaked().is_some() {
let mut open = open_trips.clone();
open.insert(trip, false);
details.hyperlinks.insert(
format!("show baseline for {}", trip),
format!("show before changes for {}", trip),
Tab::PersonTrips(person, open),
);
Btn::text_bg2("Show baseline").build(
Btn::text_bg2("Show before changes").build(
ctx,
format!("show baseline for {}", trip),
format!("show before changes for {}", trip),
None,
)
} else {
let mut open = open_trips.clone();
open.insert(trip, true);
details.hyperlinks.insert(
format!("show live for {}", trip),
format!("show after changes for {}", trip),
Tab::PersonTrips(person, open),
);
Btn::text_bg2("Show live").build(ctx, format!("show live for {}", trip), None)
Btn::text_bg2("Show after changes").build(
ctx,
format!("show after changes for {}", trip),
None,
)
},
])
.evenly_spaced(),

View File

@ -61,7 +61,7 @@ struct TripSummaries {
impl TripSummaries {
fn new(ctx: &mut EventCtx, app: &App) -> Box<dyn State> {
let mut active_agents = vec![Series {
label: "Current simulation".to_string(),
label: "After changes".to_string(),
color: Color::RED,
pts: app
.primary
@ -71,7 +71,7 @@ impl TripSummaries {
}];
if app.has_prebaked().is_some() {
active_agents.push(Series {
label: "Baseline".to_string(),
label: "Before changes".to_string(),
color: Color::BLUE.alpha(0.5),
pts: app.prebaked().active_agents(Time::END_OF_DAY),
});

View File

@ -172,18 +172,18 @@ impl GameplayState for OptimizeCommute {
fn make_top_center(ctx: &mut EventCtx, app: &App, trips: &Vec<TripID>) -> Composite {
let mut done = 0;
let mut baseline_time = Duration::ZERO;
let mut experiment_time = Duration::ZERO;
let mut before_time = Duration::ZERO;
let mut after_time = Duration::ZERO;
for t in trips {
if let Some((total, _)) = app.primary.sim.finished_trip_time(*t) {
done += 1;
experiment_time += total;
baseline_time += app.prebaked().finished_trip_time(*t).unwrap();
after_time += total;
before_time += app.prebaked().finished_trip_time(*t).unwrap();
}
}
let mut txt = Text::from(Line(format!("Total trip time: {} (", experiment_time)));
txt.append_all(cmp_duration_shorter(experiment_time, baseline_time));
let mut txt = Text::from(Line(format!("Total trip time: {} (", after_time)));
txt.append_all(cmp_duration_shorter(after_time, before_time));
txt.append(Line(")"));
Composite::new(
@ -209,26 +209,26 @@ fn make_top_center(ctx: &mut EventCtx, app: &App, trips: &Vec<TripID>) -> Compos
// True if the challenge is completed
fn final_score(app: &App, trips: &Vec<TripID>) -> (String, bool) {
let mut done = 0;
let mut baseline_time = Duration::ZERO;
let mut experiment_time = Duration::ZERO;
let mut before_time = Duration::ZERO;
let mut after_time = Duration::ZERO;
for t in trips {
if let Some((total, _)) = app.primary.sim.finished_trip_time(*t) {
done += 1;
experiment_time += total;
baseline_time += app.prebaked().finished_trip_time(*t).unwrap();
after_time += total;
before_time += app.prebaked().finished_trip_time(*t).unwrap();
}
}
// TODO Needs work
let mut verdict = format!(
"Originally, total commute time was {}. Now it's {}.",
baseline_time, experiment_time
before_time, after_time
);
write!(
&mut verdict,
" The goal is {} faster. You've done {}.",
GOAL,
baseline_time - experiment_time
before_time - after_time
)
.unwrap();
if done != trips.len() {
@ -237,7 +237,7 @@ fn final_score(app: &App, trips: &Vec<TripID>) -> (String, bool) {
(
verdict,
done == trips.len() && baseline_time - experiment_time >= GOAL,
done == trips.len() && before_time - after_time >= GOAL,
)
}

View File

@ -46,26 +46,26 @@ impl GameplayState for CreateGridlock {
// TODO Revive this data in some form
#[allow(unused)]
fn gridlock_panel(app: &App) -> Text {
let (now_all, _, now_per_mode) = app
let (after_all, _, after_per_mode) = app
.primary
.sim
.get_analytics()
.trip_times(app.primary.sim.time());
let (baseline_all, _, baseline_per_mode) = app.prebaked().trip_times(app.primary.sim.time());
let (before_all, _, before_per_mode) = app.prebaked().trip_times(app.primary.sim.time());
let mut txt = Text::new();
txt.add_appended(vec![
Line(format!(
"{} total trips (",
prettyprint_usize(now_all.count())
prettyprint_usize(after_all.count())
)),
cmp_count_fewer(now_all.count(), baseline_all.count()),
cmp_count_fewer(after_all.count(), before_all.count()),
Line(")"),
]);
for mode in TripMode::all() {
let a = now_per_mode[&mode].count();
let b = baseline_per_mode[&mode].count();
let a = after_per_mode[&mode].count();
let b = before_per_mode[&mode].count();
txt.add_appended(vec![
Line(format!(
" {}: {} (",

View File

@ -92,46 +92,46 @@ impl GameplayState for FixTrafficSignals {
// True if the challenge is completed
fn final_score(app: &App) -> (String, bool) {
let time = app.primary.sim.time();
let now = app
let after = app
.primary
.sim
.get_analytics()
.trip_times(time)
.0
.select(Statistic::Mean);
let baseline = app.prebaked().trip_times(time).0.select(Statistic::Mean);
let before = app.prebaked().trip_times(time).0.select(Statistic::Mean);
let verdict = if now < baseline - GOAL {
let verdict = if after < before - GOAL {
format!(
"COMPLETED! Average trip time is now {}, which is {} faster than the baseline {}",
now,
baseline - now,
baseline
"COMPLETED! Average trip time is {}, which is {} faster than {}",
after,
before - after,
before
)
} else if now < baseline {
} else if after < before {
format!(
"Almost there! Average trip time is now {}, which is {} faster than the baseline {}. \
Can you reduce the average by {}?",
now,
baseline - now,
baseline,
"Almost there! Average trip time is {}, which is {} faster than {}. Can you reduce \
the average by {}?",
after,
before - after,
before,
GOAL
)
} else if now.epsilon_eq(baseline) {
} else if after.epsilon_eq(before) {
format!(
"... Did you change anything? Average trip time is {}, same as the baseline",
now
"... Did you change anything? Average trip time is still {}",
after
)
} else {
format!(
"Err... how did you make things WORSE?! Average trip time is {}, which is {} slower \
than the baseline {}",
now,
now - baseline,
baseline
than {}",
after,
after - before,
before
)
};
(verdict, now < baseline - GOAL)
(verdict, after < before - GOAL)
}
// TODO Hacks in here, because I'm not convinced programatically specifying this is right. I think

View File

@ -233,7 +233,7 @@ impl GameplayState for Tutorial {
.sim
.get_analytics()
.trip_times(app.primary.sim.time());
let max = all.select(Statistic::Max);
let after = all.select(Statistic::Max);
if !tut.score_delivered {
tut.score_delivered = true;
@ -250,8 +250,8 @@ impl GameplayState for Tutorial {
);
}
// TODO Prebake results and use the normal differential stuff
let baseline = Duration::minutes(7) + Duration::seconds(15.0);
if max > baseline {
let before = Duration::minutes(7) + Duration::seconds(15.0);
if after > before {
return (
Some(Transition::Push(msg(
"All trips completed",
@ -259,7 +259,7 @@ impl GameplayState for Tutorial {
"Your changes made things worse!".to_string(),
format!(
"The slowest trip originally took {}, but now it took {}",
baseline, max
before, after
),
"".to_string(),
"Try again!".to_string(),
@ -269,7 +269,7 @@ impl GameplayState for Tutorial {
);
}
// TODO Tune. The real solution doesn't work because of sim bugs.
if max > Duration::minutes(6) + Duration::seconds(40.0) {
if after > Duration::minutes(6) + Duration::seconds(40.0) {
return (
Some(Transition::Push(msg(
"All trips completed",
@ -277,7 +277,7 @@ impl GameplayState for Tutorial {
"Nice, you helped things a bit!".to_string(),
format!(
"The slowest trip originally took {}, but now it took {}",
baseline, max
before, after
),
"".to_string(),
"See if you can do a little better though.".to_string(),
@ -292,13 +292,13 @@ impl GameplayState for Tutorial {
vec![format!(
"Awesome! The slowest trip originally took {}, but now it only \
took {}",
baseline, max
before, after
)],
))),
false,
);
}
if max <= Duration::minutes(6) + Duration::seconds(30.0) {
if after <= Duration::minutes(6) + Duration::seconds(30.0) {
tut.next();
}
return (Some(transition(ctx, app)), false);

View File

@ -367,20 +367,20 @@ impl AgentMeter {
.centered_horiz(),
);
let (now, _, _) = app
let (after, _, _) = app
.primary
.sim
.get_analytics()
.trip_times(app.primary.sim.time());
let (baseline, _, _) = app.prebaked().trip_times(app.primary.sim.time());
let (before, _, _) = app.prebaked().trip_times(app.primary.sim.time());
let mut txt = Text::from(Line(format!("{} trip time: ", stat)).secondary());
if now.count() > 0 && baseline.count() > 0 {
if after.count() > 0 && before.count() > 0 {
txt.append_all(cmp_duration_shorter(
now.select(stat),
baseline.select(stat),
after.select(stat),
before.select(stat),
));
} else {
txt.append(Line("same as baseline"));
txt.append(Line("same"));
}
txt.add(Line(format!("Goal: {} faster", goal)).secondary());
rows.push(txt.draw(ctx));

View File

@ -110,8 +110,8 @@ struct Entry {
trip: TripID,
mode: TripMode,
departure: Time,
duration: Duration,
baseline_duration: Duration,
duration_after: Duration,
duration_before: Duration,
waiting: Duration,
percent_waiting: usize,
}
@ -119,7 +119,7 @@ struct Entry {
fn make(ctx: &mut EventCtx, app: &App, sort: SortBy, descending: bool) -> Composite {
let mut data = Vec::new();
let sim = &app.primary.sim;
for (_, id, maybe_mode, duration) in &sim.get_analytics().finished_trips {
for (_, id, maybe_mode, duration_after) in &sim.get_analytics().finished_trips {
let mode = if let Some(m) = maybe_mode {
*m
} else {
@ -127,7 +127,7 @@ fn make(ctx: &mut EventCtx, app: &App, sort: SortBy, descending: bool) -> Compos
};
let (_, waiting) = sim.finished_trip_time(*id).unwrap();
let (departure, _, _, _) = sim.trip_info(*id);
let baseline_duration = if app.has_prebaked().is_some() {
let duration_before = if app.has_prebaked().is_some() {
app.prebaked().finished_trip_time(*id).unwrap()
} else {
Duration::ZERO
@ -137,19 +137,19 @@ fn make(ctx: &mut EventCtx, app: &App, sort: SortBy, descending: bool) -> Compos
trip: *id,
mode,
departure,
duration: *duration,
baseline_duration,
duration_after: *duration_after,
duration_before,
waiting,
percent_waiting: (100.0 * waiting / *duration) as usize,
percent_waiting: (100.0 * waiting / *duration_after) as usize,
});
}
match sort {
SortBy::Departure => data.sort_by_key(|x| x.departure),
SortBy::Duration => data.sort_by_key(|x| x.duration),
SortBy::RelativeDuration => data.sort_by_key(|x| x.duration - x.baseline_duration),
SortBy::Duration => data.sort_by_key(|x| x.duration_after),
SortBy::RelativeDuration => data.sort_by_key(|x| x.duration_after - x.duration_before),
SortBy::PercentChangeDuration => {
data.sort_by_key(|x| (100.0 * (x.duration / x.baseline_duration)) as isize)
data.sort_by_key(|x| (100.0 * (x.duration_after / x.duration_before)) as isize)
}
SortBy::PercentWaiting => data.sort_by_key(|x| x.percent_waiting),
}
@ -173,21 +173,21 @@ fn make(ctx: &mut EventCtx, app: &App, sort: SortBy, descending: bool) -> Compos
id_col.push(Btn::plaintext(x.trip.0.to_string()).build_def(ctx, None));
mode_col.add(Line(x.mode.ongoing_verb()));
departure_col.add(Line(x.departure.ampm_tostring()));
duration_col.add(Line(x.duration.to_string()));
duration_col.add(Line(x.duration_after.to_string()));
if app.has_prebaked().is_some() {
relative_duration_col
.add_appended(cmp_duration_shorter(x.duration, x.baseline_duration));
if x.duration == x.baseline_duration {
.add_appended(cmp_duration_shorter(x.duration_after, x.duration_before));
if x.duration_after == x.duration_before {
percent_change_duration_col.add(Line("same"));
} else if x.duration < x.baseline_duration {
} else if x.duration_after < x.duration_before {
percent_change_duration_col.add(Line(format!(
"{}% faster",
(100.0 * (1.0 - (x.duration / x.baseline_duration))) as usize
(100.0 * (1.0 - (x.duration_after / x.duration_before))) as usize
)));
} else {
percent_change_duration_col.add(Line(format!(
"{}% slower ",
(100.0 * ((x.duration / x.baseline_duration) - 1.0)) as usize
(100.0 * ((x.duration_after / x.duration_before) - 1.0)) as usize
)));
}
}