@@ -179,7 +179,7 @@ private static int[] findLeaveEdgesForTrip(GtfsStorage staticGtfs, String feedKe
179
179
.flatMap (e -> StreamSupport .stream (staticGtfs .getPtGraph ().backEdgesAround (e .getAdjNode ()).spliterator (), false ))
180
180
.flatMap (e -> StreamSupport .stream (staticGtfs .getPtGraph ().backEdgesAround (e .getAdjNode ()).spliterator (), false ))
181
181
.filter (e -> e .getType () == GtfsStorage .EdgeType .ALIGHT )
182
- .filter (e -> normalize (e .getAttrs ().tripDescriptor ). equals ( tripUpdate .getTrip ()))
182
+ .filter (e -> isDescribedBy (e .getAttrs ().tripDescriptor , tripUpdate .getTrip ()))
183
183
.min (Comparator .comparingInt (e -> e .getAttrs ().stop_sequence ));
184
184
if (firstAlighting .isEmpty ()) {
185
185
return null ;
@@ -198,7 +198,7 @@ private static int[] findBoardEdgesForTrip(GtfsStorage staticGtfs, String feedKe
198
198
.flatMap (e -> StreamSupport .stream (staticGtfs .getPtGraph ().edgesAround (e .getAdjNode ()).spliterator (), false ))
199
199
.flatMap (e -> StreamSupport .stream (staticGtfs .getPtGraph ().edgesAround (e .getAdjNode ()).spliterator (), false ))
200
200
.filter (e -> e .getType () == GtfsStorage .EdgeType .BOARD )
201
- .filter (e -> normalize (e .getAttrs ().tripDescriptor ). equals ( tripUpdate .getTrip ()))
201
+ .filter (e -> isDescribedBy (e .getAttrs ().tripDescriptor , tripUpdate .getTrip ()))
202
202
.min (Comparator .comparingInt (e -> e .getAttrs ().stop_sequence ));
203
203
if (firstBoarding .isEmpty ()) {
204
204
return null ;
@@ -209,6 +209,18 @@ private static int[] findBoardEdgesForTrip(GtfsStorage staticGtfs, String feedKe
209
209
return collectWithPadding (boardEdges );
210
210
}
211
211
212
+ private static boolean isDescribedBy (GtfsRealtime .TripDescriptor a , GtfsRealtime .TripDescriptor b ) {
213
+ // a is a descriptor of a trip in our database, static or realtime
214
+ // b is a descriptor of a trip in a trip update in the literal current rt feed
215
+ if (a .hasTripId () && !a .getTripId ().equals (b .getTripId ())) {
216
+ return false ;
217
+ }
218
+ if (a .hasStartTime () && !a .getStartTime ().equals (b .getStartTime ())) {
219
+ return false ;
220
+ }
221
+ return true ;
222
+ }
223
+
212
224
private static int [] collectWithPadding (Stream <PtGraph .PtEdge > boardEdges ) {
213
225
IntArrayList result = new IntArrayList ();
214
226
boardEdges .forEach (boardEdge -> {
@@ -280,17 +292,16 @@ SortedSet<PtGraph.PtEdge> getAdditionalEdgesTo(int node) {
280
292
return additionalEdgesByAdjNode .subSet (new PtGraph .PtEdge (0 , 0 , node , null ), new PtGraph .PtEdge (0 , 0 , node +1 , null ));
281
293
}
282
294
283
- public Optional <GtfsReader .TripWithStopTimes > getTripUpdate (GTFSFeed staticFeed , GtfsRealtime .TripDescriptor tripDescriptor , Instant boardTime ) {
295
+ public Optional <GtfsReader .TripWithStopTimes > getTripUpdate (GTFSFeed staticFeed , GtfsRealtime .TripDescriptor trip , Instant boardTime ) {
284
296
try {
285
- logger .trace ("getTripUpdate {}" , tripDescriptor );
297
+ logger .trace ("getTripUpdate {}" , trip );
286
298
if (!isThisRealtimeUpdateAboutThisLineRun (boardTime )) {
287
299
return Optional .empty ();
288
300
} else {
289
- GtfsRealtime .TripDescriptor normalizedTripDescriptor = normalize (tripDescriptor );
290
301
return feedMessages .values ().stream ().flatMap (feedMessage -> feedMessage .getEntityList ().stream ()
291
302
.filter (e -> e .hasTripUpdate ())
292
303
.map (e -> e .getTripUpdate ())
293
- .filter (tu -> normalize ( tu .getTrip ()). equals ( normalizedTripDescriptor ))
304
+ .filter (tu -> isDescribedBy ( trip , tu .getTrip ()))
294
305
.map (tu -> toTripWithStopTimes (staticFeed , tu )))
295
306
.findFirst ();
296
307
}
@@ -306,10 +317,6 @@ public Optional<GtfsReader.TripWithStopTimes> getTripUpdate(GTFSFeed staticFeed,
306
317
}
307
318
}
308
319
309
- public static GtfsRealtime .TripDescriptor normalize (GtfsRealtime .TripDescriptor tripDescriptor ) {
310
- return GtfsRealtime .TripDescriptor .newBuilder (tripDescriptor ).clearRouteId ().build ();
311
- }
312
-
313
320
public static GtfsReader .TripWithStopTimes toTripWithStopTimes (GTFSFeed feed , GtfsRealtime .TripUpdate tripUpdate ) {
314
321
ZoneId timezone = ZoneId .of (feed .agency .values ().stream ().findFirst ().get ().agency_timezone );
315
322
logger .trace ("{}" , tripUpdate .getTrip ());
0 commit comments