trip timeline shows relative duration of each phase [rebuild]

This commit is contained in:
Dustin Carlino 2020-03-06 08:58:52 -08:00
parent b835f8a6f7
commit 4eae0c8394
3 changed files with 46 additions and 36 deletions

View File

@ -919,6 +919,9 @@ fn trip_details(
ctx,
);
let trip_start_time = phases[0].start_time;
let trip_end_time = phases.last().as_ref().and_then(|p| p.end_time);
// Start
{
match trip_start {
@ -981,7 +984,7 @@ fn trip_details(
let mut txt = Text::from(Line("jump to goal"));
txt.add(Line(bldg.just_address(map)));
if let Some(t) = phases.last().as_ref().and_then(|p| p.end_time) {
if let Some(t) = trip_end_time {
txt.add(Line(t.ampm_tostring()));
}
goal_btn = goal_btn.change_tooltip(txt);
@ -1007,7 +1010,7 @@ fn trip_details(
let mut txt = Text::from(Line("jump to goal"));
txt.add(Line(i.name(map)));
if let Some(t) = phases.last().as_ref().and_then(|p| p.end_time) {
if let Some(t) = trip_end_time {
txt.add(Line(t.ampm_tostring()));
}
goal_btn = goal_btn.change_tooltip(txt);
@ -1032,9 +1035,10 @@ fn trip_details(
};
}
let total_duration_so_far =
trip_end_time.unwrap_or_else(|| app.primary.sim.time()) - phases[0].start_time;
let total_width = 0.3 * ctx.canvas.window_width;
// TODO Width proportional to duration of this phase!
let phase_width = total_width / (phases.len() as f64);
let mut timeline = Vec::new();
let num_phases = phases.len();
for (idx, p) in phases.into_iter().enumerate() {
@ -1052,19 +1056,23 @@ fn trip_details(
"- Started at {}",
p.start_time.ampm_tostring()
)));
if let Some(t2) = p.end_time {
txt.add(Line(format!(
"- Ended at {} (duration: {})",
t2,
t2 - p.start_time
)));
let duration = if let Some(t2) = p.end_time {
let d = t2 - p.start_time;
txt.add(Line(format!("- Ended at {} (duration: {})", t2, d)));
d
} else {
txt.add(Line(format!(
"- Ongoing (duration so far: {})",
app.primary.sim.time() - p.start_time
)));
}
let d = app.primary.sim.time() - p.start_time;
txt.add(Line(format!("- Ongoing (duration so far: {})", d)));
d
};
// TODO Problems when this is really low?
let percent_duration = duration / total_duration_so_far;
txt.add(Line(format!(
"- {}% of trip duration",
(100.0 * percent_duration) as usize
)));
let phase_width = total_width * percent_duration;
let rect = Polygon::rectangle(phase_width, 15.0);
let mut normal = GeomBatch::from(vec![(color, rect.clone())]);
if idx == num_phases - 1 {
@ -1128,10 +1136,20 @@ fn trip_details(
timeline.insert(0, ManagedWidget::btn(start_btn).margin(5));
timeline.push(ManagedWidget::btn(goal_btn).margin(5));
let mut table = vec![
("Trip start".to_string(), trip_start_time.ampm_tostring()),
("Duration".to_string(), total_duration_so_far.to_string()),
];
if let Some(t) = trip_end_time {
table.push(("Trip end".to_string(), t.ampm_tostring()));
}
let mut col = vec![ManagedWidget::row(timeline)
.evenly_spaced()
.margin_above(25)];
col.extend(make_table(ctx, table));
(
ManagedWidget::row(timeline)
.evenly_spaced()
.margin_above(25),
ManagedWidget::col(col),
TripDetails {
id: trip,
unzoomed: unzoomed.upload(ctx),

View File

@ -905,17 +905,17 @@ impl DrivingSimState {
},
),
(
"Trip time so far".to_string(),
(now - car.started_at).to_string(),
),
(
"Percent of entire trip spent waiting".to_string(),
"Percent of driving time spent waiting".to_string(),
format!(
"{}%",
(100.0 * (car.total_blocked_time + time_spent_waiting) / (now - car.started_at))
as usize
),
),
(
"Time spent waiting right here".to_string(),
time_spent_waiting.to_string(),
),
(
"Lanes remaining in path".to_string(),
path.num_lanes().to_string(),
@ -928,10 +928,6 @@ impl DrivingSimState {
path.total_length().describe_rounded()
),
),
(
"Time spent waiting right here".to_string(),
time_spent_waiting.to_string(),
),
];
// No owner
if id.1 == VehicleType::Bus {

View File

@ -268,17 +268,17 @@ impl WalkingSimState {
let props = vec![
(
"Trip time so far".to_string(),
(now - p.started_at).to_string(),
),
(
"Percent of entire trip spent waiting".to_string(),
"Percent of walking time spent waiting".to_string(),
format!(
"{}%",
(100.0 * (p.total_blocked_time + time_spent_waiting) / (now - p.started_at))
as usize
),
),
(
"Time spent waiting right here".to_string(),
time_spent_waiting.to_string(),
),
(
"Lanes remaining in path".to_string(),
p.path.num_lanes().to_string(),
@ -291,10 +291,6 @@ impl WalkingSimState {
p.path.total_length().describe_rounded()
),
),
(
"Time spent waiting right here".to_string(),
time_spent_waiting.to_string(),
),
];
let mut extra = Vec::new();
if let PedState::WaitingForBus(r, _) = p.state {