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

Fix SIRI update travel back in time #5867

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,31 @@ void testAddJourney() {
);
}

@Test
void testAddedJourneyWithInvalidScheduledData() {
var env = RealtimeTestEnvironment.siri();

// Create an extra journey with invalid planned data (travel back in time)
// and valid real time data
var createExtraJourney = new SiriEtBuilder(env.getDateTimeHelper())
.withEstimatedVehicleJourneyCode("newJourney")
.withIsExtraJourney(true)
.withOperatorRef(env.operator1Id.getId())
.withLineRef(env.route1Id.getId())
.withEstimatedCalls(builder ->
builder
.call(env.stopA1)
.departAimedExpected("10:58", "10:48")
.call(env.stopB1)
.arriveAimedExpected("10:08", "10:58")
)
.buildEstimatedTimetableDeliveries();

var result = env.applyEstimatedTimetable(createExtraJourney);
assertEquals(0, result.successful());
assertFailure(UpdateError.UpdateErrorType.NEGATIVE_HOP_TIME, result);
}

@Test
void testReplaceJourney() {
var env = RealtimeTestEnvironment.siri();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,11 @@ Result<TripUpdate, UpdateError> build() {
aimedStopTimes,
transitModel.getDeduplicator()
);
// validate the scheduled trip times
// they are in general superseded by real-time trip times
// but in case of trip cancellation, OTP will fall back to scheduled trip times
// therefore they must be valid
tripTimes.validateNonIncreasingTimes();
vpaturet marked this conversation as resolved.
Show resolved Hide resolved
tripTimes.setServiceCode(transitModel.getServiceCodes().get(trip.getServiceId()));
pattern.add(tripTimes);
RealTimeTripTimes updatedTripTimes = tripTimes.copyScheduledTimes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,15 @@ public void setRealTimeState(final RealTimeState realTimeState) {
*
* @throws org.opentripplanner.transit.model.framework.DataValidationException of the first error
* found.
*
* Note! This is a duplicate (almost) of the same method in ScheduledTripTimes.
* We should aim for just one implementation. We need to decide how to do this.
* A common abstract base class would simplify it, but may lead to other problems and performance
* overhead. We should look back on this after refactoring
* the rest of the timetable classes (calendar/patterns).
*/
vpaturet marked this conversation as resolved.
Show resolved Hide resolved
public void validateNonIncreasingTimes() {
final int nStops = arrivalTimes.length;
final int nStops = scheduledTripTimes.getNumStops();
int prevDep = -9_999_999;
for (int s = 0; s < nStops; s++) {
final int arr = getArrivalTime(s);
Expand Down
Loading