-
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?
Changes from 2 commits
aeaa862
0208cbf
a7ff17b
dcc9067
fa0f0b2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,17 +5,24 @@ | |
| import static org.opentripplanner.updater.trip.UpdateIncrementality.FULL_DATASET; | ||
|
|
||
| import com.google.transit.realtime.GtfsRealtime; | ||
| import java.time.Duration; | ||
| import java.time.LocalDate; | ||
| import java.time.ZoneId; | ||
| import java.util.List; | ||
| import java.util.Objects; | ||
| import org.opentripplanner.DateTimeHelper; | ||
| import org.opentripplanner.model.TimetableSnapshot; | ||
| import org.opentripplanner.routing.algorithm.raptoradapter.transit.RaptorTransitData; | ||
| import org.opentripplanner.routing.algorithm.raptoradapter.transit.TransitTuningParameters; | ||
| import org.opentripplanner.routing.algorithm.raptoradapter.transit.mappers.RaptorTransitDataMapper; | ||
| import org.opentripplanner.routing.algorithm.raptoradapter.transit.mappers.RealTimeRaptorTransitDataUpdater; | ||
| import org.opentripplanner.routing.api.request.RouteRequest; | ||
| import org.opentripplanner.routing.graph.Graph; | ||
| import org.opentripplanner.transit.model._data.TimetableRepositoryForTest; | ||
| import org.opentripplanner.transit.model.framework.FeedScopedId; | ||
| import org.opentripplanner.transit.model.network.TripPattern; | ||
| import org.opentripplanner.transit.model.site.RegularStop; | ||
| import org.opentripplanner.transit.model.site.StopTransferPriority; | ||
| import org.opentripplanner.transit.model.timetable.TripTimes; | ||
| import org.opentripplanner.transit.model.timetable.TripTimesStringBuilder; | ||
| import org.opentripplanner.transit.service.DefaultTransitService; | ||
|
|
@@ -55,8 +62,14 @@ public static RealtimeTestEnvironmentBuilder of() { | |
| this.timetableRepository = timetableRepository; | ||
|
|
||
| this.timetableRepository.index(); | ||
| this.timetableRepository.setRaptorTransitData( | ||
| RaptorTransitDataMapper.map(new TestTransitTuningParameters(), timetableRepository) | ||
| ); | ||
| this.timetableRepository.setRealtimeRaptorTransitData( | ||
| new RaptorTransitData(timetableRepository.getRaptorTransitData()) | ||
| ); | ||
| this.snapshotManager = new TimetableSnapshotManager( | ||
| null, | ||
| new RealTimeRaptorTransitDataUpdater(timetableRepository), | ||
|
||
| TimetableSnapshotParameters.PUBLISH_IMMEDIATELY, | ||
| () -> defaultServiceDate | ||
| ); | ||
|
|
@@ -212,4 +225,37 @@ private UpdateResult applyEstimatedTimetable( | |
| private void commitTimetableSnapshot() { | ||
| snapshotManager.purgeAndCommit(); | ||
| } | ||
|
|
||
| private static class TestTransitTuningParameters implements TransitTuningParameters { | ||
|
|
||
| @Override | ||
| public boolean enableStopTransferPriority() { | ||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| public Integer stopBoardAlightDuringTransferCost(StopTransferPriority key) { | ||
| return 0; | ||
| } | ||
|
|
||
| @Override | ||
| public int transferCacheMaxSize() { | ||
| return 0; | ||
| } | ||
|
|
||
| @Override | ||
| public Duration maxSearchWindow() { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public List<Duration> pagingSearchWindowAdjustments() { | ||
| return List.of(); | ||
| } | ||
|
|
||
| @Override | ||
| public List<RouteRequest> transferCacheRequests() { | ||
| return List.of(); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -456,6 +456,67 @@ public void testUpdateWithNoData() { | |
| }); | ||
| } | ||
|
|
||
| @Test | ||
| public void testUpdateWithUnchangedTripAndStopProperties() { | ||
| var tripDescriptorBuilder = tripDescriptorBuilder(TRIP_ID); | ||
|
|
||
| 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); | ||
|
||
|
|
||
| GtfsRealtime.TripUpdate tripUpdate = tripUpdateBuilder.build(); | ||
| var result = TripTimesUpdater.createUpdatedTripTimesFromGtfsRt( | ||
| timetable, | ||
| new TripUpdate(tripUpdate), | ||
| TIME_ZONE, | ||
| SERVICE_DATE, | ||
| ForwardsDelayPropagationType.DEFAULT, | ||
| BackwardsDelayPropagationType.REQUIRED_NO_DATA | ||
| ); | ||
|
|
||
| assertTrue(result.isSuccess()); | ||
|
|
||
| result.ifSuccess(p -> { | ||
| assertTrue(p.updatedDropoff().isEmpty(), "dropoffs are not modified"); | ||
| assertTrue(p.updatedPickup().isEmpty(), "pickups are not modified"); | ||
| assertTrue(p.replacedStopIndices().isEmpty(), "stop indices are not modified"); | ||
| assertEquals( | ||
| "foo", | ||
| p.tripTimes().getHeadsign(0).toString(), | ||
| "headsigns [1] are not modified" | ||
| ); | ||
| assertEquals( | ||
| "foo", | ||
| p.tripTimes().getHeadsign(1).toString(), | ||
| "headsigns [2] are not modified" | ||
| ); | ||
| assertEquals( | ||
| "foo", | ||
| p.tripTimes().getHeadsign(2).toString(), | ||
| "headsigns [3] are not modified" | ||
| ); | ||
| }); | ||
| } | ||
|
|
||
| @Test | ||
| public void testUpdateWithTripAndStopProperties() { | ||
| var tripDescriptorBuilder = tripDescriptorBuilder(TRIP_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.
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.