-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Cleanup trip times - Part A #5437
Cleanup trip times - Part A #5437
Conversation
I will take a look at the failing unit tests. |
Some of the tests are fixed by this commit: leonardehrenfried@fb2c0bb There is another flex integration test that fails with this PR and I would like to talk about it in the dev meeting. |
I've investigated why the flex integration test fails: it's because of a particularity of the current implementation of Consider the following trip:
Before this PR the following happened: in addition to creating a flex trip, we would also create a scheduled trip where the flex parts were removed. This means that the regular transit routing engine would also use this trip, but without the flex trips. It seems that this PR removed this behaviour. We need to discuss if that is desirable. |
*/ | ||
public void validateNonIncreasingTimes() { | ||
final int nStops = arrivalTimes.length; | ||
int prevDep = -9_999_999; |
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't we have this value as a constant?
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, I will fix it when doing the final cleanup of trip-times, but first I need to cleanup the usage - leaving the internals as is. Se my next comment and the PR summary.
* increasing. The first stop arrival time and the last stops depature time is NOT checked - | ||
* these should be ignored by raptor. | ||
*/ | ||
private void validateNonIncreasingTimes() { |
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.
Looks like this could be a common logic between RealtimeTripTimes and ScheduledTripTimes
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, I am not done with the refactoring - there is a lot of duplication and I have intentionally not made any changes here yet. I am refactoring the code using TripTimes first, then when I am done I know what code should be deleted, shared and kept in RT and Scheduled TripTimes - so for know ignore the duplication.
This decouple TripTimes from StopTime and make the code more readable. For example `new TripTimes(tt)`` is replaced with `tt.copyOfScheduledTimes()``.
The need to create a Deduplicator to unit test is make the unit-test setup more messy than it needs to, and it introduces a unknown into the test equation - something that is not under-test. Signed-off-by: Thomas Gran <[email protected]> # Conflicts: # src/test/java/org/opentripplanner/model/plan/legreference/ScheduledTransitLegReferenceTest.java
207bb3f
to
8297049
Compare
I have rebase this PR and removed the code that caused the problems with the |
ScheduledTripTimes(ScheduledTripTimesBuilder builder) { | ||
this.timeShift = builder.timeShift; | ||
this.serviceCode = builder.serviceCode; | ||
this.arrivalTimes = builder.arrivalTimes; | ||
this.departureTimes = builder.departureTimes; | ||
this.timepoints = builder.timepoints; | ||
this.trip = builder.trip; | ||
this.pickupBookingInfos = builder.pickupBookingInfos; | ||
this.dropOffBookingInfos = builder.dropOffBookingInfos; | ||
this.headsigns = builder.headsigns; | ||
this.headsignVias = builder.headsignVias; | ||
this.originalGtfsStopSequence = builder.originalGtfsStopSequence; | ||
} |
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 would be a good idea to add some invariant checks here. Or are there none?
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, that is the plan - and by splitting TR and schedules times the checks can differ.
src/main/java/org/opentripplanner/transit/model/timetable/ScheduledTripTimes.java
Outdated
Show resolved
Hide resolved
src/main/java/org/opentripplanner/transit/model/timetable/ScheduledTripTimes.java
Outdated
Show resolved
Hide resolved
final Trip trip, | ||
final Collection<StopTime> stopTimes, | ||
final Deduplicator deduplicator | ||
private TripTimes(final TripTimes original, int timeShiftDelta) { |
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 constructor is unused.
this.occupancyStatus = object.occupancyStatus; | ||
} | ||
|
||
public static TripTimes of(ScheduledTripTimes scheduledTripTimes) { |
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 unused.
I have reviewed and while I have questions about what the final design will be, I think it's going into the right direction. There is still quite a bit of mutability in the TripTimes class but my guess is that you will be working on this in upcoming PRs. |
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 have a few suggestions but I recognize that you are half-done so I'm happy to approve. I would be interested to hear in the dev meeting what the final design will be.
Pleace bring it up on the developer meeting, and I can go through the design a bit. I think the target is described in #4002, but to see that this is a step in that direction is maybe hard to see. But, the main thing about this PR is that TripTimes are today different for RT and Scheduled - there is switches inside the code to handle this using the same type. This of course make the code unessessary complicated. The plan is also to deal with this in separate classes. The trip-times share one thing and that is the usage in Routing and API, but this can be fixed by an interface (introduced in this PR). Then the implementation is/should be different (one of many: scheduled trip times are optimised for deduplication, RT are not). Trip-times are one of the most important classes in OTP and being compleatly DRY here is less important. I think that it will be pretty DRY in the end, but it is not were I want to start. Encapsulation and separation of concern is the most important thing first. |
90929bb
Sorry for the dismissed reviews, I have only applied the spelling fixes and merged in |
Summary
This clean up the TripTimes and split Scheduled trip-times and RealTime trip-times into different classes inheriting the same interface. This allow us to make the ScheduledTripTimes become immutable and freeze it after the graph is build.
This fixes a minor bug - it is no longer possible to create invalid ScheduledTripTimes - even with broken GTFS data (there was an error in the stop times interpolation).
This PR will validate the first departure-time and the last arrival-time to be within -12 hours and 10 days. If someone has a pattern witch last for more than 10 days we can increase the max limit. The min limit is set to -12 hours to account for time-shifting between time-zones. So, even if a feed can only have positive times, all feeds may not operate in the same time-zone.
This is the first refactoring with respect to trip-times. I will follow up this with more PRs. There are now unused code in these classes - these are left as is intentionally. This refactoring introduce a new interface for TripTimes - I have not changed all places to use this interface yet. Also, when the RealTimeTripTimes is in place, then first is the time to remove unused code.
Issue
First step to fix #5211
Unit tests
Some tests are disabled, since they uses invalid TripTimes and started failing when the validation of trip-times where added. Help to fix these test would be appreciated.
Many unit-tests are added and other are updated
Documentation
Does not apply, JavaDoc is updated.
Changelog
This is for most part a refactoring, but the result also fixes a minor bug #5211.
Bumping the serialization version id
✅