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

Add the ability to specify delay or skipped stops on ADDED or REPLACEMENT trips in GTFS-RT #6028

Open
wants to merge 8 commits into
base: dev-2.x
Choose a base branch
from

Conversation

miklcct
Copy link

@miklcct miklcct commented Aug 28, 2024

Summary

This PR adds the ability to support delays or skipped stops on ADDED or REPLACEMENT trips. The time is the actual estimated time of the trip, and the scheduled time is the time given minus the delay given.

Issue

Closes #6009 . The proposal is submitted to google/transit#490 as well.

Unit tests

Unit tests are added for TripUpdates which specify both time and delay in a StopTimeEvent. This case was previously assumed to be invalid and hence a new method is added to generate items. Tests are also added for ADDED trips containing skipped stops as well.

Documentation

The original // TODO: should we incorporate the delay field if present? is done by this PR.

@miklcct miklcct requested a review from a team as a code owner August 28, 2024 12:16
@miklcct miklcct force-pushed the delay_on_added_trips branch 5 times, most recently from b78e020 to 71efc46 Compare August 28, 2024 12:55
@miklcct miklcct changed the title Add the ability to specify delay on ADDED or REPLACEMENT trips in GTFS-RT. Add the ability to specify delay or skipped stops on ADDED or REPLACEMENT trips in GTFS-RT. Aug 28, 2024
Copy link

codecov bot commented Aug 29, 2024

Codecov Report

Attention: Patch coverage is 78.48101% with 17 lines in your changes missing coverage. Please review.

Project coverage is 69.74%. Comparing base (99998b8) to head (7479b54).
Report is 21 commits behind head on dev-2.x.

Files with missing lines Patch % Lines
...rg/opentripplanner/updater/trip/AddedStopTime.java 76.08% 5 Missing and 6 partials ⚠️
...pplanner/updater/trip/TimetableSnapshotSource.java 81.81% 1 Missing and 5 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             dev-2.x    #6028   +/-   ##
==========================================
  Coverage      69.73%   69.74%           
- Complexity     17315    17329   +14     
==========================================
  Files           1960     1960           
  Lines          74267    74308   +41     
  Branches        7603     7606    +3     
==========================================
+ Hits           51789    51823   +34     
- Misses         19834    19835    +1     
- Partials        2644     2650    +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@optionsome optionsome self-requested a review August 29, 2024 10:29
Copy link
Member

@optionsome optionsome left a comment

Choose a reason for hiding this comment

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

ADDED and REPLACEMENT updates don't have many users in the OTP community (I think REPLACEMENT is slowly being replaced by new additions to the GTFS specifications, but I'm not fully up-to-date on the status of those drafts), but we are open to these implementations being fixed and/or improved.

I doubt this will break any existing OTP deployments as I think your interpretation of how delay should be used is the only reasonable one. Similarly, I think previously someone might have just left out a stop in an ADDED trip if it was no longer used but having this possibility to mark them as SKIPPED shouldn't negatively affect anyone. If someone is opposed to these changes, let us know.

The only small question mark is that should we wait for some comments from the GTFS community on your suggestion before this is merged or not. Hopefully, the suggestion to the GTFS specification goes through so there is no longer any gray area around these usages.

@@ -838,12 +845,30 @@ private Result<UpdateSuccess, UpdateError> addTripToGraphAndBuffer(
);

// Update all times to mark trip times as realtime
// TODO: should we incorporate the delay field if present?
// TODO: This is based on the proposal at https://github.com/google/transit/issues/490
Copy link
Member

Choose a reason for hiding this comment

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

I don't know if we should keep the TODO in this comment.

Copy link
Author

Choose a reason for hiding this comment

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

Shall I remove this comment for now, or wait until I further work on the proposal?

Comment on lines 859 to 864
final int arrivalDelay = stopTimeUpdate.hasArrival()
? stopTimeUpdate.getArrival().hasDelay() ? stopTimeUpdate.getArrival().getDelay() : 0
: 0;
final int departureDelay = stopTimeUpdate.hasDeparture()
? stopTimeUpdate.getDeparture().hasDelay() ? stopTimeUpdate.getDeparture().getDelay() : 0
: 0;
Copy link
Member

Choose a reason for hiding this comment

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

These are a bit difficult to read. Perhaps using if check for the stopTimeUpdate.hasArrival/Departure would be more readable.

Copy link
Author

Choose a reason for hiding this comment

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

If I use an if statement, the variable can't be made final, and its generally preferred to avoid mutable variable if I can.

Copy link
Member

Choose a reason for hiding this comment

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

I agree with @optionsome. These checks are very hard to read. You should move them into the class AddedStopTime, encapsulate them and write Javadoc.

Can you please do that for all the other checks in this methods even the ones that were already there?

@miklcct
Copy link
Author

miklcct commented Aug 30, 2024

REPLACEMENT is officially deprecated, and the behaviour of ADDED remains unspecified. The proposal addresses DUPLICATED (which has a clearly defined behaviour) as well as ADDED.

Google uses ADDED to duplicate an existing trip to run it at another time, which is now officially migrated to DUPLICATED in the standard, while OpenTripPlanner requires specifying the whole trip and allows arbitrary pattern for ADDED trips, which fits the use case to add trips which are not based on existing patterns (which Google doesn't support).

To my understanding there isn't a way in the official GTFS-RT standard to add arbitrary new realtime trips into a route not based on an existing pattern (even Google doesn't support that). Even in the OpenTripPlanner implementation it is impossible to specify headsigns of added trips (both at trip and stop level) but this will be another issue to solve.

GTFS-TripModification proposal can be used for diverted trips but it isn't supported in OpenTripPlanner yet and it is much more complicated to just replacing the whole trip in case of diversion using the deprecated REPLACEMENT feature of OpenTripPlanner.

I am thinking that we should wait for a while to see how the GTFS community progresses on trip additions / diversions / replacement, but I will have a production deployment in the next few months using this change in order to support real time added / diverted trains, which few other commercial providers support (neither Google nor Citymapper could route me via the official diversion to Battersea Park when the line to Clapham Junction was blocked unexpectedly).

Could you please let me know if there are any existing OpenTripPlanner deployments which do handle real-time diverted trips?

@miklcct
Copy link
Author

miklcct commented Aug 30, 2024

Possibly need further testing for REPLACEMENT trips:

Screenshot_20240831-002202.png

Screenshot_20240831-002226.png

@leonardehrenfried leonardehrenfried changed the title Add the ability to specify delay or skipped stops on ADDED or REPLACEMENT trips in GTFS-RT. Add the ability to specify delay or skipped stops on ADDED or REPLACEMENT trips in GTFS-RT Aug 31, 2024
@leonardehrenfried
Copy link
Member

We talked about this in today's dev meeting (to which you are welcome). We are generally ok with this interpreation of the spec but would like to see it codified in the spec.

Are you interested in un-deprecating the ADDED schedule relationship in the GTFS spec repo? google/transit#490 is a good start but can you create an actual PR which can be discussed and critiqued line by line by the community? To me the most important change I would like to see is an actually description of what ADDED means. The OTP implementation thinks that it allows you to create completely new trips but I would like to clarify.
If you're okay with trying the spec change I would support you with it.

Since the realtime code is old and has incurred lots of technical debt, we would also like to see some clean up. Are you interested in that?

@miklcct
Copy link
Author

miklcct commented Sep 3, 2024

I will be interested in cleaning up the code if it means a chance for me to get headsigns, shapes, completely new stops, etc., into the realtime updates but I would like to see how the GTFS-ServiceChanges v3.1 goes first because we commit to anything.

A major limitation of the product we are developing is the inability to specify the headsign for modified trips under the current specification, so I am relying on frontend tweaks to "correct" the headsign for trains terminating short.

@leonardehrenfried
Copy link
Member

I also found a thread on Slack about ADDED: https://mobilitydata-io.slack.com/archives/C3D321CKB/p1715957220876199

I think there will be interest in specifying it.

@leonardehrenfried
Copy link
Member

Before I review any further: are you going to convert google/transit#490 into a spec PR?

@miklcct
Copy link
Author

miklcct commented Sep 3, 2024

I plan to do so but not in these few days.

@miklcct
Copy link
Author

miklcct commented Sep 6, 2024

I also found a thread on Slack about ADDED: https://mobilitydata-io.slack.com/archives/C3D321CKB/p1715957220876199

I think there will be interest in specifying it.

I have submitted the Google Form but haven't received any invitation link yet.

@leonardehrenfried
Copy link
Member

@miklcct did you get access to the MB slack?

@miklcct
Copy link
Author

miklcct commented Sep 11, 2024

@miklcct did you get access to the MB slack?

Still no invitation received in my mailbox (checked spam as well as inbox) despite submitted the form multiple times.

@leonardehrenfried
Copy link
Member

I posted the following message. I hope an admin will help you soon.

image

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.

It is not possible to provide both scheduled time and delay for an ADDED / REPLACEMENT trip in GTFS-RT.
4 participants