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

Dynamic Rerouting #286

Open
wants to merge 11 commits into
base: dev
Choose a base branch
from
Open

Dynamic Rerouting #286

wants to merge 11 commits into from

Conversation

br648
Copy link
Contributor

@br648 br648 commented Jan 9, 2025

Checklist

  • Appropriate branch selected (all PRs must first be merged to dev before they can be merged to master)
  • Any modified or new methods or classes have helpful JavaDoc and code is thoroughly commented
  • The description lists all applicable issues this PR seeks to resolve
  • The description lists any configuration setting(s) that differ from the default settings
  • All tests and CI builds passing

Description

Adds the ability for a traveler to reroute from their current location if deviated from the original trip. A new itinerary is retrieved from OTP (replacing the original trip) and if available tracking and instructions will be based on this instead. Subsequent rerouting will replace previous rerouted trips.

Copy link
Collaborator

@binh-dam-ibigroup binh-dam-ibigroup left a comment

Choose a reason for hiding this comment

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

First round of comments after a first read.

Comment on lines 248 to 250
OtpGraphQLVariables query = trackedJourney.trip.otp2QueryParams;
query.fromPlace = new Coordinates(trackedJourney.lastLocation()).getCoordinates();
query.time = getTimeNowAsString();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Extract a method and write unit tests for it.

Copy link
Collaborator

@binh-dam-ibigroup binh-dam-ibigroup left a comment

Choose a reason for hiding this comment

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

Here are the next changes I think are needed to get an instruction that matches the rerouted itinerary:

var trackedJourney = tripData.journey;
if (trackedJourney != null) {
if (rerouteTrip(tripData)) {
return doUpdateTracking(request, tripData, false);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Interesting, POST-ing a rerouting request returned a "no-instruction" response instead of a new instruction. Let me dig more.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, POST-ing a track update with the same, originally deviated position should have updated to an on-track position with an updated instruction, but it stayed on the "deviated" status instead.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This line calls the linked piece of code, where the matching itinerary should be a clone of the journey state's matching itinerary, not of the saved itineary.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We probably need to add or update the flag for updateTracking so that no new tracked journey is created, but the rerouting gives directions as if it were the beginning of the trip.

@binh-dam-ibigroup binh-dam-ibigroup removed their assignment Jan 13, 2025
@br648 br648 assigned binh-dam-ibigroup and unassigned br648 Jan 15, 2025
if (tripData != null) {
var trackedJourney = tripData.journey;
return trackedJourney != null && updateTripWithNewItinerary(trackedJourney);
if (trackedJourney != null) {
return updateTripWithNewItinerary(trackedJourney);
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 probably notify companions/observers of that change.

Copy link
Collaborator

Choose a reason for hiding this comment

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

If the traveler takes the trip, it will likely still within the active trip monitoring window, and trip monitoring will attempt to replace journeyState.matchingItinerary with an itinerary matching the original one. To prevent that, if rerouting has occured, getQueryParamsForTargetZonedDateTime should also plug the most recent rerouting location that is saved in TrackedJourney.

// Confirm traveler is no longer 'deviated'.
updateTrackingResponse = JsonUtils.getPOJOFromJSON(response.responseBody, TrackingResponse.class);
assertNotEquals(TripStatus.DEVIATED.name(), updateTrackingResponse.tripStatus);

Copy link
Collaborator

Choose a reason for hiding this comment

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

Try to insert a call to CheckMonitoredTrip and assert that it doesn't revert the matching itinerary to what was before.

}

/** Provides a mock OTP 'plan' rerouted response. */
public Supplier<OtpResponse> mockOtpPlanResponse() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Rename to mockOtpReroutedPlanResponse or something similar.

Copy link
Collaborator

@binh-dam-ibigroup binh-dam-ibigroup left a comment

Choose a reason for hiding this comment

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

Make field itinerary in RerouteResponse public, and make the itinerary monitor process also apply the updated origin location so it can update the rerouted itinerary with realtime updates, if any.

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