except for layout/style, I think the trip/agent panels now have the

right information
This commit is contained in:
Dustin Carlino 2020-04-03 13:02:23 -07:00
parent 88bad05d39
commit 2d4095fd8d
8 changed files with 65 additions and 26 deletions

View File

@ -108,7 +108,12 @@ pub fn people(ctx: &mut EventCtx, app: &App, details: &mut Details, id: Building
rows.push(Widget::col(vec![
Btn::text_bg1(p.to_string()).build_def(ctx, None),
if let Some((t, mode)) = next_trip {
format!("Leaving in {} to {}", t - app.primary.sim.time(), mode).draw_text(ctx)
format!(
"Leaving in {} to {}",
t - app.primary.sim.time(),
mode.verb()
)
.draw_text(ctx)
} else {
"Staying inside".draw_text(ctx)
},

View File

@ -460,7 +460,7 @@ fn throughput<F: Fn(&Analytics, Time) -> BTreeMap<TripMode, Vec<(Time, usize)>>>
let mut series = get_data(app.primary.sim.get_analytics(), app.primary.sim.time())
.into_iter()
.map(|(m, pts)| Series {
label: m.to_string(),
label: m.ongoing_verb().to_string(),
color: color_for_mode(m, app),
pts,
})
@ -469,7 +469,7 @@ fn throughput<F: Fn(&Analytics, Time) -> BTreeMap<TripMode, Vec<(Time, usize)>>>
// 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),
label: format!("{} (baseline)", m.ongoing_verb()),
color: color_for_mode(m, app).alpha(0.3),
pts,
});

View File

@ -55,11 +55,13 @@ pub fn trips(
}
TripResult::TripDoesntExist => unreachable!(),
};
let (_, _, _, trip_mode) = sim.trip_info(*t);
// TODO Style wrong. Button should be the entire row.
rows.push(
Widget::row(vec![
t.to_string().draw_text(ctx),
Line(trip_mode.ongoing_verb()).secondary().draw(ctx),
if trip_status == "ongoing" {
// TODO Padding doesn't work without wrapping in a row
Widget::row(vec![Line(trip_status)

View File

@ -9,13 +9,13 @@ use ezgui::{
};
use geom::{Angle, Distance, Duration, Polygon, Pt2D, Time};
use map_model::{Map, Path, PathStep};
use sim::{TripEndpoint, TripID, TripPhase, TripPhaseType};
use sim::{AgentID, TripEndpoint, TripID, TripPhase, TripPhaseType, VehicleType};
pub fn details(ctx: &mut EventCtx, app: &App, trip: TripID, details: &mut Details) -> Widget {
let map = &app.primary.map;
let sim = &app.primary.sim;
let phases = sim.get_analytics().get_trip_phases(trip, map);
let (start_time, trip_start, trip_end, trip_mode) = sim.trip_info(trip);
let (start_time, trip_start, trip_end, _) = sim.trip_info(trip);
let end_time = phases.last().as_ref().and_then(|p| p.end_time);
if phases.is_empty() {
@ -27,7 +27,6 @@ pub fn details(ctx: &mut EventCtx, app: &App, trip: TripID, details: &mut Detail
return Widget::col(make_table(
ctx,
vec![
("Type", trip_mode.to_string()),
("Departure", start_time.ampm_tostring()),
("From", name1),
("To", name2),
@ -39,14 +38,22 @@ pub fn details(ctx: &mut EventCtx, app: &App, trip: TripID, details: &mut Detail
// Describe properties of the trip
let total_trip_time = end_time.unwrap_or_else(|| sim.time()) - phases[0].start_time;
// TODO Depict differently
col.extend(make_table(ctx, vec![("Type", trip_mode.to_string())]));
// Describe this leg of the trip
let progress_along_path = if let Some(a) = sim.trip_to_agent(trip).ok() {
let props = sim.agent_properties(a);
// TODO we want the current TripPhaseType.describe here
let activity = "here";
// This is different than the entire TripMode, and also not the current TripPhaseType.
// Sigh.
let activity = match a {
AgentID::Pedestrian(_) => "walking",
AgentID::Car(c) => match c.1 {
VehicleType::Car => "driving",
VehicleType::Bike => "biking",
// TODO And probably riding a bus is broken, I don't know how that gets mapped right
// now
VehicleType::Bus => "riding the bus",
},
};
// TODO Style needs work. Like, always.
@ -99,7 +106,10 @@ pub fn details(ctx: &mut EventCtx, app: &App, trip: TripID, details: &mut Detail
Some(props.dist_crossed / props.total_dist)
} else {
// The trip is finished
// TODO total time
col.push(Widget::row(vec![
Line("Trip time").secondary().draw(ctx).margin_right(20),
total_trip_time.to_string().draw_text(ctx),
]));
None
};

View File

@ -130,7 +130,11 @@ fn trips_summary_prebaked(ctx: &EventCtx, app: &App) -> Widget {
let a = &now_per_mode[&mode];
let b = &baseline_per_mode[&mode];
txt.add_appended(vec![
Line(format!("{} {} trips (", prettyprint_usize(a.count()), mode)),
Line(format!(
"{} trips {} (",
prettyprint_usize(a.count()),
mode.ongoing_verb()
)),
cmp_count_more(a.count(), b.count()),
Line(")"),
]);
@ -209,9 +213,9 @@ fn trips_summary_not_prebaked(ctx: &EventCtx, app: &App) -> Widget {
for mode in TripMode::all() {
let a = &per_mode[&mode];
txt.add(Line(format!(
"{} {} trips",
"{} trips {}",
prettyprint_usize(a.count()),
mode
mode.ongoing_verb()
)));
if a.count() > 0 {
for stat in Statistic::all() {
@ -243,7 +247,13 @@ fn trips_summary_not_prebaked(ctx: &EventCtx, app: &App) -> Widget {
fn finished_trips_plot(ctx: &EventCtx, app: &App) -> Widget {
let mut lines: Vec<(String, Color, Option<TripMode>)> = TripMode::all()
.into_iter()
.map(|m| (m.to_string(), color_for_mode(m, app), Some(m)))
.map(|m| {
(
m.ongoing_verb().to_string(),
color_for_mode(m, app),
Some(m),
)
})
.collect();
lines.push(("aborted".to_string(), Color::PURPLE.alpha(0.5), None));

View File

@ -67,7 +67,11 @@ fn gridlock_panel(app: &App) -> Text {
let a = now_per_mode[&mode].count();
let b = baseline_per_mode[&mode].count();
txt.add_appended(vec![
Line(format!(" {}: {} (", mode, prettyprint_usize(a))),
Line(format!(
" {}: {} (",
mode.ongoing_verb(),
prettyprint_usize(a)
)),
cmp_count_fewer(a, b),
Line(")"),
]);

View File

@ -23,7 +23,7 @@ impl FasterTrips {
top_center: challenge_controller(
ctx,
mode,
&format!("Faster {} Trips Challenge", trip_mode),
&format!("Faster Trips {} Challenge", trip_mode.ongoing_verb()),
Vec::new(),
),
})
@ -87,9 +87,9 @@ fn faster_trips_panel(mode: TripMode, app: &App) -> Text {
let mut txt = Text::new();
txt.add_appended(vec![
Line(format!(
"{} {} trips (",
"{} trips {} (",
prettyprint_usize(now.count()),
mode
mode.ongoing_verb()
)),
cmp_count_more(now.count(), baseline.count()),
Line(")"),

View File

@ -794,15 +794,23 @@ impl TripMode {
},
}
}
}
impl std::fmt::Display for TripMode {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
pub fn verb(self) -> &'static str {
match self {
TripMode::Walk => write!(f, "walk"),
TripMode::Bike => write!(f, "bike"),
TripMode::Transit => write!(f, "transit"),
TripMode::Drive => write!(f, "drive"),
TripMode::Walk => "walk",
TripMode::Bike => "bike",
TripMode::Transit => "use transit",
TripMode::Drive => "drive",
}
}
// If I used "present participle" in a method name, I'd never live it down.
pub fn ongoing_verb(self) -> &'static str {
match self {
TripMode::Walk => "walking",
TripMode::Bike => "biking",
TripMode::Transit => "using transit",
TripMode::Drive => "driving",
}
}
}