-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Improve handling of realtime updated StopPatterns #6909
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
base: dev-2.x
Are you sure you want to change the base?
Improve handling of realtime updated StopPatterns #6909
Conversation
This avoids planning trips with old trip patterns leading to invalid itineraries.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev-2.x #6909 +/- ##
=============================================
+ Coverage 72.22% 72.29% +0.07%
- Complexity 20148 20198 +50
=============================================
Files 2186 2188 +2
Lines 81152 81203 +51
Branches 8139 8141 +2
=============================================
+ Hits 58609 58703 +94
+ Misses 19666 19636 -30
+ Partials 2877 2864 -13 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| .getTransitService() | ||
| .getRealtimeRaptorTransitData() | ||
| .getTripPatternsForRunningDate(SERVICE_DATE) | ||
| .stream() | ||
| .map(TripPatternForDate::getTripPattern) | ||
| .map(RoutingTripPattern::getPattern) | ||
| .map(AbstractTransitEntity::getId) | ||
| .map(Object::toString) | ||
| .toList() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is repeated several times. Can you extract a reusable method, perhaps in RealtimeTestEnv?
It will probably heavily collide with #6899 but worth it nonetheless.
| /** | ||
| * Tests that stops can be SKIPPED for a trip which repeats times for consecutive stops. | ||
| * | ||
| * @link <a href="https://github.com/opentripplanner/OpenTripPlanner/issues/6848">issue</a> | ||
| */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please update or remove.
| GtfsRealtime.TripUpdate.Builder tripUpdateBuilder = GtfsRealtime.TripUpdate.newBuilder(); | ||
| tripUpdateBuilder.setTrip(tripDescriptorBuilder); | ||
| tripUpdateBuilder.getTripPropertiesBuilder().setTripHeadsign("foo"); | ||
| StopTimeUpdate.Builder stopTimeUpdateBuilder = tripUpdateBuilder.addStopTimeUpdateBuilder(0); | ||
| stopTimeUpdateBuilder.setStopSequence(1); | ||
| stopTimeUpdateBuilder.getArrivalBuilder().setDelay(0); | ||
| stopTimeUpdateBuilder.getDepartureBuilder().setDelay(0); | ||
| stopTimeUpdateBuilder.getStopTimePropertiesBuilder().setStopHeadsign("foo"); | ||
| stopTimeUpdateBuilder.getStopTimePropertiesBuilder().setAssignedStopId("A"); | ||
| stopTimeUpdateBuilder = tripUpdateBuilder.addStopTimeUpdateBuilder(1); | ||
| stopTimeUpdateBuilder.setStopSequence(2); | ||
| stopTimeUpdateBuilder | ||
| .getStopTimePropertiesBuilder() | ||
| .setPickupType(StopTimeUpdate.StopTimeProperties.DropOffPickupType.REGULAR); | ||
| stopTimeUpdateBuilder | ||
| .getStopTimePropertiesBuilder() | ||
| .setDropOffType(StopTimeUpdate.StopTimeProperties.DropOffPickupType.REGULAR); | ||
| stopTimeUpdateBuilder.setScheduleRelationship(StopTimeUpdate.ScheduleRelationship.SCHEDULED); | ||
| stopTimeUpdateBuilder = tripUpdateBuilder.addStopTimeUpdateBuilder(2); | ||
| stopTimeUpdateBuilder.setStopSequence(3); | ||
| stopTimeUpdateBuilder.getArrivalBuilder().setDelay(0); | ||
| stopTimeUpdateBuilder.getDepartureBuilder().setDelay(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know that the other tests in this class do the same, but I find the repetition pretty grating.
Can you please make this a little less verbose?
| this.timetableRepository.setRaptorTransitData( | ||
| RaptorTransitDataMapper.map(new TestTransitTuningParameters(), timetableRepository) | ||
| ); | ||
| this.timetableRepository.setRealtimeRaptorTransitData( | ||
| new RaptorTransitData(timetableRepository.getRaptorTransitData()) | ||
| ); | ||
| this.snapshotManager = new TimetableSnapshotManager( | ||
| null, | ||
| new RealTimeRaptorTransitDataUpdater(timetableRepository), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's great that we are adding test coverage to this critical, yet poorly-understood component.
| } else { | ||
| LOG.warn("Could not fetch timetable for {}", pattern); | ||
| LOG.warn("Could not fetch timetable for {}, removing.", pattern); | ||
| patternsForDate.remove(tripPatternForDate); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the most important change in the PR. I absolutely support changing this class but I'm having a hard time understanding the consequences of this change: the code is very complex with several collections updating each other.
If you have a better understanding, do you have time to walk me through the code? Maybe @vpaturet is interested as well.
| public void tripNotFoundInPattern() { | ||
| // non-existing trip | ||
| var tripDescriptorBuilder = tripDescriptorBuilder("b"); | ||
| var nonExistingTripId = "b"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, thanks for this. I didn't expect you to fix the whole file.
leonardehrenfried
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this already in good shape. @vpaturet what do you think of a group review session about RealTimeRaptorTransitDataUpdater?
| this.timetableRepository = timetableRepository; | ||
| } | ||
|
|
||
| public void update( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you have the knowledge to do so, can you add some Javadoc to this method?
|
Lets have a group session to look at this after @leonardehrenfried is back from vacation. |
…-gtfs-rt-patterns
8b54a10 to
5e81f97
Compare
| this.timetableRepository = timetableRepository; | ||
| } | ||
|
|
||
| /// Updates the real-time [RaptorTransitData] to use the modified timetables. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you make this proper Javadoc, please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or is this now valid Markdown-ish Javadoc?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use the correct Javadoc syntax here please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We discussed this while you were gone. Apparently IntelliJ IDEA already supports this new markdown format and then no one was really against using it. However, we didn't discuss it too much and not sure what is the way forward with it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it's fine. i was unaware that it will be officially supported. Intellij is the only place I would read Javadoc so I don't care if other tools don't.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it is Markdown-ish javadoc
| var rt = GtfsRtTestHelper.of(env); | ||
| var tripUpdate1 = new TripUpdateBuilder(TRIP_1_ID, SERVICE_DATE, SCHEDULED, TIME_ZONE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| var rt = GtfsRtTestHelper.of(env); | |
| var tripUpdate1 = new TripUpdateBuilder(TRIP_1_ID, SERVICE_DATE, SCHEDULED, TIME_ZONE) | |
| var rt = GtfsRtTestHelper.of(env); | |
| var tripUpdate1 = rt.tripUpdateScheduled(TRIP_1_ID) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also change the other places.
5e81f97 to
d7df30d
Compare
leonardehrenfried
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a few smaller things that I would like to see changed, but we're close.
|
I have just confirmed that this patch does NOT fix #6197 . The problem still exists using your branch. |
leonardehrenfried
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fix the Javadoc, otherwise I'm good to approve.
There is a remaining risk but it's managable, IMO.
Summary
Two somewhat related issues are improved relating to realtime stop pattern modifications:
StopPatternandTripPatternwas created if any of headsign, stop id, pickup or alight type were set, even if the value remained the same.A check is added that the values are actually modified.
TripPatternForDatevalues could be used if a trip's stop pattern changed, which could lead to transit planning using an old/invalid version.When applying updates
RealTimeRaptorTransitDataUpdaterremovesTripPatternForDates without a correspondingTimetable.Issue
Unit tests
New tests are added for the improvements.
Documentation
No changes.