Skip to content

Commit

Permalink
Merge pull request #5867 from entur/fix_siri_update_travel_back_in_time
Browse files Browse the repository at this point in the history
Fix SIRI update travel back in time
  • Loading branch information
vpaturet authored Jun 7, 2024
2 parents a124558 + d84e7f5 commit 0a58d0f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
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();
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).
*/
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

0 comments on commit 0a58d0f

Please sign in to comment.