Skip to content

Commit d7df30d

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

File tree

3 files changed

+387
-9
lines changed

3 files changed

+387
-9
lines changed

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,31 @@ public RealTimeRaptorTransitDataUpdater(TimetableRepository timetableRepository)
6666
this.timetableRepository = timetableRepository;
6767
}
6868

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