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

(feat)(core): Add traffic congestion segments to the main Route #293

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

engali94
Copy link

@engali94 engali94 commented Oct 8, 2024

This approach involves:

  1. Adding a property or method to the main Route struct to retrieve congestion segments.
  2. Each adapter would be responsible for extracting and mapping its specific congestion data to a common format when converting from the adapter-specific route to the main Route.

Pros:

  • Keeps the congestion data close to the route data it belongs to.
  • Provides a unified interface for accessing congestion data across different platforms.

Cons:

  • Slightly increases the complexity of the core Route struct.

This is the implementation of #292

Copy link
Contributor

@ianthetechie ianthetechie left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @engali94!

I think @Archdoog is currently working on the best way(s) to expose annotations up to users (maybe that should be an RFD? 😉). I think that our current ideal scenario is to not make the route struct larger unless a field is likely to be supported by the vast majority of likely implementations. For example, we made the decision to expose voice and banner instructions at the step level because this is a de facto standard now (though it's still optional).

I'm not sure if traffic congestion warrants that level of treatment, but we DO want to get common data models and processing code into the codebase. I think the current idea is to push the whole set of annotations up at the step level (not the full route level, since usually this is more actionable at the step level, but apps could reshape this into a route-long traffic layer after fetching a route, for example, to preserve this across the trip even when steps are dropped).

Annotations at the step level have landed as of #261. #287 was just opened yesterday, and shows the approach that @Archdoog currently has in mind, which is to transform AnyAnnotations in Swift/Kotlin (still TODO). We'll provide the basic types in library code, as well as common annotation formats (ex: Valhalla). The beauty is that if your own server does something different, you just write your own struct (using the shared models, like speed limit and traffic congestion + anything that may be proprietary).

TL;DR, I think we can, with a bit of discussion, get all of the pros without the cons (which you correctly identified in your description :D).

Hopefully that makes sense, thanks for reading this tome, and thanks in advance for your patience as this part of the code is still in flux on our side :)

Comment on lines +118 to +131
fn haversine_distance(coord1: &GeographicCoordinate, coord2: &GeographicCoordinate) -> f64 {
const EARTH_RADIUS: f64 = 6371000.0;

let lat1 = coord1.lat.to_radians();
let lat2 = coord2.lat.to_radians();
let delta_lat = (coord2.lat - coord1.lat).to_radians();
let delta_lon = (coord2.lng - coord1.lng).to_radians();

let a =
(delta_lat / 2.0).sin().powi(2) + lat1.cos() * lat2.cos() * (delta_lon / 2.0).sin().powi(2);
let c = 2.0 * a.sqrt().atan2((1.0 - a).sqrt());

EARTH_RADIUS * c
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm pretty hesitant to hand-roll code like this when good library implementations already exist. If you search for haversine in the codebase, you'll find several uses of this over geometry structs (for which we use the geo crate).

Copy link
Author

Choose a reason for hiding this comment

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

hi @ianthetechie I appreciate you very detailed review, I am very willing to discuss it further
do you have any better/faster mean of communication to discuss this further?

Copy link
Contributor

Choose a reason for hiding this comment

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

@engali94 yes! Feel free to reach out on Slack (link in the README); feel free to DM (Ian Wagner).

Copy link
Contributor

Choose a reason for hiding this comment

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

@engali94 quick bump here to let you know that I'm available on Slack either via DM or in the #ferrostar channel. Not sure if this works for you time zone-wise, but we also have a regular meeting at 1:00 UTC on Tuesdays (Monday 6pm Pacific / 10am Seoul) to review PRs and discuss direction. Shoot me a message if you'd like to join.


while end_index < geometry.len() - 1 && remaining_distance > 0.0 {
let segment_distance =
haversine_distance(&geometry[end_index], &geometry[end_index + 1]);
Copy link
Contributor

Choose a reason for hiding this comment

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

It's worth noting that, since the approach proposed is parsing annotation data from an OSRM-ish source, that all "OSRM-compatible" APIs I'm aware of include a distance annotation too! We don't currently leverage that, but we very well could try to use that if it's available to save work doing thousands of tiny checks.

(This isn't a "we must do it this way" but a request for discussion btw.)

Sources:

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.

2 participants