From 2fe2559f67d325eaa14827de8acfe1d532c3fe18 Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Mon, 19 Aug 2019 14:06:04 -0700 Subject: [PATCH] new colorscheme showing trip time so far --- editor/src/render/map.rs | 12 ++++++++++++ sim/src/mechanics/car.rs | 2 ++ sim/src/mechanics/driving.rs | 3 +++ sim/src/mechanics/parking.rs | 1 + sim/src/mechanics/walking.rs | 6 ++++++ sim/src/render.rs | 3 +++ 6 files changed, 27 insertions(+) diff --git a/editor/src/render/map.rs b/editor/src/render/map.rs index a4ce6ac974..4b1fc0f115 100644 --- a/editor/src/render/map.rs +++ b/editor/src/render/map.rs @@ -381,6 +381,8 @@ impl AgentCache { } } + // TODO The perf is a little slow compared to when we just returned a bunch of Pt2Ds + // without the extra data. Try plumbing a callback that directly populates batch. let mut batch = GeomBatch::new(); let radius = Distance::meters(10.0) / g.canvas.cam_zoom; for agent in primary.sim.get_unzoomed_agents(&primary.map) { @@ -411,11 +413,13 @@ fn osm_rank_to_color(cs: &ColorScheme, rank: usize) -> Color { } // TODO Show a little legend when it's first activated. +// TODO ETA till goal... #[derive(Clone, Copy, PartialEq)] pub enum AgentColorScheme { VehicleTypes, Delay, RemainingDistance, + TripTimeSoFar, } impl Cloneable for AgentColorScheme {} @@ -431,6 +435,7 @@ impl AgentColorScheme { }, AgentColorScheme::Delay => delay_color(agent.time_spent_blocked), AgentColorScheme::RemainingDistance => percent_color(agent.percent_dist_crossed), + AgentColorScheme::TripTimeSoFar => delay_color(agent.trip_time_so_far), } } @@ -450,6 +455,7 @@ impl AgentColorScheme { } AgentColorScheme::Delay => delay_color(input.time_spent_blocked), AgentColorScheme::RemainingDistance => percent_color(input.percent_dist_crossed), + AgentColorScheme::TripTimeSoFar => delay_color(input.trip_time_so_far), } } @@ -464,6 +470,7 @@ impl AgentColorScheme { }, AgentColorScheme::Delay => delay_color(input.time_spent_blocked), AgentColorScheme::RemainingDistance => percent_color(input.percent_dist_crossed), + AgentColorScheme::TripTimeSoFar => delay_color(input.trip_time_so_far), } } @@ -478,6 +485,7 @@ impl AgentColorScheme { } AgentColorScheme::Delay => delay_color(input.time_spent_blocked), AgentColorScheme::RemainingDistance => percent_color(input.percent_dist_crossed), + AgentColorScheme::TripTimeSoFar => delay_color(input.trip_time_so_far), } } @@ -495,6 +503,10 @@ impl AgentColorScheme { AgentColorScheme::RemainingDistance, "by distance remaining to goal".to_string(), ), + ( + AgentColorScheme::TripTimeSoFar, + "by trip time so far".to_string(), + ), ] } } diff --git a/sim/src/mechanics/car.rs b/sim/src/mechanics/car.rs index 6b8ae2500d..2a4c0a8087 100644 --- a/sim/src/mechanics/car.rs +++ b/sim/src/mechanics/car.rs @@ -14,6 +14,7 @@ pub struct Car { pub router: Router, pub trip: TripID, pub blocked_since: Option, + pub started_at: Duration, // In reverse order -- most recently left is first. The sum length of these must be >= // vehicle.length. @@ -146,6 +147,7 @@ impl Car { .map(|t| now - t) .unwrap_or(Duration::ZERO), percent_dist_crossed: path.crossed_so_far() / path.total_length(), + trip_time_so_far: now - self.started_at, } } } diff --git a/sim/src/mechanics/driving.rs b/sim/src/mechanics/driving.rs index eca2c74f70..4bb34cd869 100644 --- a/sim/src/mechanics/driving.rs +++ b/sim/src/mechanics/driving.rs @@ -86,6 +86,7 @@ impl DrivingSimState { state: CarState::Queued, last_steps: VecDeque::new(), blocked_since: None, + started_at: now, trip: params.trip, }; if params.maybe_parked_car.is_some() { @@ -672,6 +673,7 @@ impl DrivingSimState { .map(|t| now - t) .unwrap_or(Duration::ZERO), percent_dist_crossed: path.crossed_so_far() / path.total_length(), + trip_time_so_far: now - car.started_at, }); } } @@ -760,6 +762,7 @@ impl DrivingSimState { "Blocked for {}", car.blocked_since.map(|t| now - t).unwrap_or(Duration::ZERO) ), + format!("Trip time so far: {}", now - car.started_at), format!("{:?}", car.state), ]) } diff --git a/sim/src/mechanics/parking.rs b/sim/src/mechanics/parking.rs index decd810d5e..2b42a72d43 100644 --- a/sim/src/mechanics/parking.rs +++ b/sim/src/mechanics/parking.rs @@ -110,6 +110,7 @@ impl ParkingSimState { label: None, time_spent_blocked: Duration::ZERO, percent_dist_crossed: 0.0, + trip_time_so_far: Duration::ZERO, body: map .get_l(lane) diff --git a/sim/src/mechanics/walking.rs b/sim/src/mechanics/walking.rs index a5e7c44bc7..541fc0a562 100644 --- a/sim/src/mechanics/walking.rs +++ b/sim/src/mechanics/walking.rs @@ -54,6 +54,7 @@ impl WalkingSimState { ), speed: params.speed, blocked_since: None, + started_at: now, path: params.path, goal: params.goal, trip: params.trip, @@ -239,6 +240,7 @@ impl WalkingSimState { "Blocked for {}", p.blocked_since.map(|t| now - t).unwrap_or(Duration::ZERO) ), + format!("Trip time so far: {}", now - p.started_at), format!("{:?}", p.state), ] } @@ -271,6 +273,7 @@ impl WalkingSimState { pos: ped.get_draw_ped(now, map).pos, time_spent_blocked: ped.blocked_since.map(|t| now - t).unwrap_or(Duration::ZERO), percent_dist_crossed: ped.path.crossed_so_far() / ped.path.total_length(), + trip_time_so_far: now - ped.started_at, }); } @@ -380,6 +383,8 @@ struct Pedestrian { state: PedState, speed: Speed, blocked_since: Option, + // TODO organize analytics better. + started_at: Duration, path: Path, goal: SidewalkSpot, @@ -505,6 +510,7 @@ impl Pedestrian { .map(|t| now - t) .unwrap_or(Duration::ZERO), percent_dist_crossed: self.path.crossed_so_far() / self.path.total_length(), + trip_time_so_far: now - self.started_at, } } diff --git a/sim/src/render.rs b/sim/src/render.rs index abcfd6315f..84de97f8f2 100644 --- a/sim/src/render.rs +++ b/sim/src/render.rs @@ -13,6 +13,7 @@ pub struct DrawPedestrianInput { pub on: Traversable, pub time_spent_blocked: Duration, pub percent_dist_crossed: f64, + pub trip_time_so_far: Duration, } pub struct DrawPedCrowdInput { @@ -32,6 +33,7 @@ pub struct DrawCarInput { pub label: Option, pub time_spent_blocked: Duration, pub percent_dist_crossed: f64, + pub trip_time_so_far: Duration, // Starts at the BACK of the car. pub body: PolyLine, @@ -51,6 +53,7 @@ pub struct UnzoomedAgent { pub pos: Pt2D, pub time_spent_blocked: Duration, pub percent_dist_crossed: f64, + pub trip_time_so_far: Duration, } // TODO Can we return borrows instead? Nice for time travel, not for main sim?