Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delay highlighting #363

Merged
merged 19 commits into from
Oct 10, 2020

Conversation

NoSuchThingAsRandom
Copy link
Contributor

Initial build for issue 170
Now highlights intersections and lanes for cars, bikes and walking. That have spent over the threshold (30s) time waiting.
This is highlighted on the map, and colour coordinated for the severity of the delay
In addition it is also shown as hotspots on the timeline bar, with more information available when hovered upon.

Also contains some "fixes" for Canocilsing imports @dabreegster
Including:

  • sim/src/lib.rs
  • pub use crate::render
  • geom/src/spped
  • import trim_f64 in wrong place
  • widgetry/src/text.rs
  • use crate assets in wrong place

Sam added 16 commits September 27, 2020 17:48
Bike also works, but is treated as a car, so the avg speed is flagged as very slow (Needs fix)
Now uses min of (speed limit and vehicle max speed) for the maximum speed check
Added trip blocked time query
Lots of work on tool tips
Icons are broke
Added new custom TextSpan size function
# Conflicts:
#	game/src/colors.rs
#	game/src/info/trip.rs
#	geom/src/speed.rs
#	sim/src/analytics.rs
#	sim/src/events.rs
#	sim/src/lib.rs
#	sim/src/mechanics/driving.rs
#	sim/src/mechanics/walking.rs
#	sim/src/sim/queries.rs
#	sim/src/trips.rs
#	widgetry/src/text.rs
Doesn't quite match the existing "changes"
Copy link
Collaborator

@dabreegster dabreegster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an awesome feature! I left lots of style comments; if you're pressed for time, feel free to focus on the other ones, and I can take care of the other things later.

@@ -2,24 +2,25 @@ use std::collections::BTreeMap;

use maplit::btreemap;

use geom::{ArrowCap, Distance, Duration, Percent, PolyLine, Polygon, Pt2D, Time};
use map_model::{Map, Path, PathStep};
use geom::{ArrowCap, Distance, Duration, Percent, Polygon, PolyLine, Pt2D, Time};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, the diff here reorders Polygon and PolyLine. cargo +nightly fmt undoes this. I'll poke around for an option to make it act like CLion, but we might be stuck cleaning this up from time to time.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's a tad annoying, and personally I prefer Polygon first, because it's alphabetical. But I'm not sure why cargo +nightly fmt does this?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think cargo fmt considers PolyLine as two words, split at the camel — So "Poly Line" comes before "Polygon"

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The split makes sense. I'm less opinionated about what this looks like and more interested in automating consistency (thanks to a few years working with gofmt). For now, I vote we continue to apply cargo +nightly fmt. If we can find an option or other CLI tool to align more with CLion, that's fine too as long as it's not hard for everyone to run

@@ -248,7 +248,25 @@ impl DrivingSimState {
transit: &mut TransitSimState,
) -> bool {
match car.state {
CarState::Crossing(_, _) => {
CarState::Crossing(time_int, dist_int) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, this is tricky. Crossing to Queued happens before the car reaches the end of the lane; they might even still be moving, stuck behind a slower vehicle. https://dabreegster.github.io/abstreet/trafficsim/discrete_event.html#cars gives more detail about this.

The delay at an intersection starts being counted here, at car.state = CarState::Queued { blocked_since: now }. Maybe we can just show delays at intersections and leave it a bit unspecified why the delay happened -- because of congestion upstream in the target lane, because of slow signal timing, because of a long queue of vehicles, because of a single slow vehicle in front of faster ones, etc.

But for this PR, I think it's fine to keep measuring it this way; we'll iterate on it next.

.max_speed
.unwrap_or(Speed::meters_per_second(100.0)),
);
let speed_percent: u8 = ((avg_speed / max_speed) * 100.0) as u8;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should do this calculation in analytics.rs instead. Here, just fire an Event::AgentCrossedLane(trip, lane, avg_speed, max_speed) or something. The purpose of Event is to decouple the simulation details here from whatever choices we make later in Analytics about how to group/filter/process for data analysis/visualization.

@@ -357,6 +375,14 @@ impl DrivingSimState {
// Don't schedule a retry here.
return false;
}
if let Some((trip, _)) = car.trip_and_person {
let delay = (now - blocked_since).inner_seconds() as u8;
// Maybe alter the minimum delay time to be recorded
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same, the event should always be sent with the Duration, and the filtering + transformation to u8 can happen later.

Copy link
Collaborator

@michaelkirk michaelkirk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, nice work! I pulled it down to give it a go, but I'm not yet familiar enough with the codebase to immediately understand how to see this feature in action. Can you provide instructions on how to access it?

One thing I did notice, was some undesirable spacing between the trip timeline and the mode indicator which seems new to this branch:

before (from master):
Screen Shot 2020-10-08 at 10 03 00 AM

after (as of 6c54cad):
Screen Shot 2020-10-08 at 9 51 24 AM

To clarify - this is the trip info panel that you see after clicking on an agent.

let phase_width = box_width * percent_duration;
if idx == phases.len() - 1 {
if let Some(p) = progress_along_path {
icons.push(Widget::draw_batch(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Build break, I think this has to be icons_geom now?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I think just declaring let mut icons = Vec::new() up by the others should fix it. icons_geom is for the tooltips.

@dabreegster
Copy link
Collaborator

I regenerated the prebaked analytics data. montlake stayed the same size, and lakeslice increased from 61MB to 64MB -- that's a totally fine amount, nice! After we merge, I'll immediately followup with the uploaded data.

This pretty much LGTM, minus the build break. And if you can, run cargo +nightly fmt too, to deal with the slight import order difference. Next, I'm going to attempt some refactoring of info/trip.rs next to consolidate tooltips and all the different cases for trips (future, ongoing, cancelled, finished).

@dabreegster
Copy link
Collaborator

Thanks for the PR! Going to merge this now, and follow up with the new prebaked data, some cleanups, and a fix for the timeline indicator icon.

@dabreegster dabreegster merged commit 4c5a858 into a-b-street:master Oct 10, 2020
@dabreegster dabreegster linked an issue Oct 10, 2020 that may be closed by this pull request
dabreegster added a commit that referenced this pull request Oct 10, 2020
- cargo +nightly fmt
- upload new prebaked data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Show speed / delay along a route
3 participants