Skip to content

Commit 5e81f97

Browse files
committed
Add tests and documentation for RealTimeRaptorTransitDataUpdater
1 parent fa0f0b2 commit 5e81f97

File tree

3 files changed

+388
-9
lines changed

3 files changed

+388
-9
lines changed

application/src/main/java/org/opentripplanner/routing/algorithm/raptoradapter/transit/mappers/RealTimeRaptorTransitDataUpdater.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.opentripplanner.routing.algorithm.raptoradapter.transit.RaptorTransitData;
1717
import org.opentripplanner.routing.algorithm.raptoradapter.transit.TripPatternForDate;
1818
import org.opentripplanner.routing.algorithm.raptoradapter.transit.constrainedtransfer.TransferIndexGenerator;
19+
import org.opentripplanner.transit.model.network.StopPattern;
1920
import org.opentripplanner.transit.model.network.TripPattern;
2021
import org.opentripplanner.transit.model.timetable.TripIdAndServiceDate;
2122
import org.opentripplanner.transit.model.timetable.TripTimes;
@@ -66,6 +67,31 @@ public RealTimeRaptorTransitDataUpdater(TimetableRepository timetableRepository)
6667
this.timetableRepository = timetableRepository;
6768
}
6869

70+
/// Updates the real-time [RaptorTransitData] to use the modified timetables.
71+
///
72+
/// This method bridges the different update approaches:
73+
/// 1. `updatedTimetables` and `timetables` only contains [Timetable]s with real-time
74+
/// updates. This means that removed items are not present.
75+
/// 2. [RaptorTransitData] requires applying the changes to a previous snapshot: adding,
76+
/// updating and removing timetables.
77+
///
78+
/// To support this the method has three tasks:
79+
/// 1. Collect [TripPatternForDate]s which have invalidated data (`oldTripPatternsForDate`).
80+
/// Trips may change in multiple ways and because of that may move between [TripPattern]s. To
81+
/// track a [TripIdAndServiceDate] it's previous state needs to be stored so that all relevant
82+
/// places may be updated.
83+
/// * a trip may have a new (real-time) Timetable, which results in two updated [Timetable]s
84+
/// * a trip may move between scheduled [StopPattern]s and/or real-time [StopPattern]s
85+
/// 2. Collect [TripPatternForDate]s which have valid data (`newTripPatternsForDate`).
86+
/// There are two options:
87+
/// 1. an update was received
88+
/// 2. no update was received, and so the previous updated should be removed. If the update
89+
/// was for a scheduled trip, then the schedule should be restored.
90+
/// 3. Remove the `oldTripPatternsForDate` and add the `newTripPatternsForDate` to the
91+
/// [RaptorTransitData].
92+
///
93+
/// @param updatedTimetables that changed with the current snapshot
94+
/// @param timetables which are affected by real-time updates
6995
public void update(
7096
Collection<Timetable> updatedTimetables,
7197
Map<TripPattern, SortedSet<Timetable>> timetables

application/src/test/java/org/opentripplanner/updater/trip/GtfsRtTestHelper.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ public UpdateResult applyTripUpdate(
5555
return applyTripUpdates(List.of(update), incrementality);
5656
}
5757

58+
public UpdateResult applyTripUpdates(List<GtfsRealtime.TripUpdate> updates) {
59+
return applyTripUpdates(updates, FULL_DATASET);
60+
}
61+
5862
public UpdateResult applyTripUpdates(
5963
List<GtfsRealtime.TripUpdate> updates,
6064
UpdateIncrementality incrementality

0 commit comments

Comments
 (0)