tripDescriptor.getTripId(), tripDescriptor.getRouteId(), edges(partition).map(edgeLabel -> edgeLabel.edgeIteratorState).collect(Collectors.toList()).get(0).getName(),
public StopTime getStopTime(GTFSFeed staticFeed, GtfsRealtime.TripDescriptor tripDescriptor, Label.Transition t, Instant boardTime, int stopSequence) { StopTime stopTime = staticFeed.stop_times.get(new Fun.Tuple2<>(tripDescriptor.getTripId(), stopSequence)); if (stopTime == null) { return getTripUpdate(staticFeed, tripDescriptor, t, boardTime).get().stopTimes.get(stopSequence-1); } else { return stopTime; } }
Set<Integer> cancelledArrivals = new HashSet<>(); Set<Integer> cancelledDepartures = new HashSet<>(); Trip originalTrip = feed.trips.get(tripUpdate.getTrip().getTripId()); Trip trip = new Trip(); if (originalTrip != null) { trip.route_id = originalTrip.route_id; } else { trip.trip_id = tripUpdate.getTrip().getTripId(); trip.route_id = tripUpdate.getTrip().getRouteId(); Iterable<StopTime> interpolatedStopTimesForTrip; try { interpolatedStopTimesForTrip = feed.getInterpolatedStopTimesForTrip(tripUpdate.getTrip().getTripId()); } catch (GTFSFeed.FirstAndLastStopsDoNotHaveTimes firstAndLastStopsDoNotHaveTimes) { throw new RuntimeException(firstAndLastStopsDoNotHaveTimes); int nextStopSequence = stopTimes.isEmpty() ? 1 : stopTimes.get(stopTimes.size()-1).stop_sequence+1; for (int i=nextStopSequence; i<stopTimeUpdate.getStopSequence(); i++) { StopTime previousOriginalStopTime = feed.stop_times.get(new Fun.Tuple2(tripUpdate.getTrip().getTripId(), i)); if (previousOriginalStopTime == null) { continue; // This can and does happen. Stop sequence numbers can be left out. final StopTime originalStopTime = feed.stop_times.get(new Fun.Tuple2(tripUpdate.getTrip().getTripId(), stopTimeUpdate.getStopSequence())); if (originalStopTime != null) { StopTime updatedStopTime = originalStopTime.clone();
/** * Checks rule E030 - "GTFS-rt alert trip_id does not belong to GTFS-rt alert route_id in GTFS trips.txt" and adds * any errors that are found to the provided errors list * * @param entity feed entity to examine that contains an alert * @param entitySelector EntitySelector that has both a routeId and a tripDescriptor * @param gtfsMetadata metadata for the static GTFS data * @param errors list to add any errors for E030 to */ private void checkE030(GtfsRealtime.FeedEntity entity, GtfsRealtime.EntitySelector entitySelector, GtfsMetadata gtfsMetadata, List<OccurrenceModel> errors) { String routeId = entitySelector.getRouteId(); GtfsRealtime.TripDescriptor tripDescriptor = entitySelector.getTrip(); if (tripDescriptor.hasTripId()) { Trip gtfsTrip = gtfsMetadata.getTrips().get(tripDescriptor.getTripId()); if (gtfsTrip != null && !routeId.equals(gtfsTrip.getRoute().getId().getId())) { String prefix = "alert ID " + entity.getId() + " informed_entity.trip.trip_id " + tripDescriptor.getTripId() + " does not belong to informed_entity.route_id " + routeId + " (GTFS says it belongs to route_id " + gtfsTrip.getRoute().getId().getId() + ")"; RuleUtils.addOccurrence(E030, prefix, errors, _log); } } }
/** * Checks rule E024 - "trip direction_id does not match GTFS data" and adds any errors that are found to the provided error list * * @param entity The VehiclePosition or TripUpdate that contains the data to be evaluated for rule E024 * @param trip The TripDescriptor be evaluated for rule E024 * @param gtfsMetadata metadata for the static GTFS data * @param errors list to add any errors for E024 to */ private void checkE024(Object entity, GtfsRealtime.TripDescriptor trip, GtfsMetadata gtfsMetadata, List<OccurrenceModel> errors) { if (trip.hasDirectionId()) { int directionId = trip.getDirectionId(); Trip gtfsTrip = gtfsMetadata.getTrips().get(trip.getTripId()); if (gtfsTrip != null && (gtfsTrip.getDirectionId() == null || !gtfsTrip.getDirectionId().equals(String.valueOf(directionId)))) { String prefix = "GTFS-rt " + GtfsUtils.getVehicleAndTripIdText(entity) + " trip.direction_id is " + directionId + " but GTFS trip.direction_id is " + gtfsTrip.getDirectionId(); RuleUtils.addOccurrence(E024, prefix, errors, _log); } } }
/** * <code>optional string trip_id = 1;</code> * * <pre> * The trip_id from the GTFS feed that this selector refers to. * For non frequency-based trips, this field is enough to uniquely identify * the trip. For frequency-based trip, start_time and start_date might also be * necessary. * </pre> */ public Builder clearTripId() { bitField0_ = (bitField0_ & ~0x00000001); tripId_ = getDefaultInstance().getTripId(); onChanged(); return this; } /**
/** * Returns the trip_id for the given TripDescriptor if one exists, if not the entity ID is returned in the format * "trip_id 1234" or "entity ID 4321". * * @param entity the entity that the TripUpdate belongs to * @param tripDescriptor the tripDescriptor to get the ID for * @return the trip_id for the given TripUpdate if one exists, if not the entity ID is returned in the format "trip_id 1234" or "entity ID 4321". */ public static String getTripId(GtfsRealtime.FeedEntity entity, GtfsRealtime.TripDescriptor tripDescriptor) { return tripDescriptor.hasTripId() ? "trip_id " + tripDescriptor.getTripId() : "entity ID " + entity.getId(); }
.filter(tripUpdate -> tripUpdate.getTrip().getScheduleRelationship() == GtfsRealtime.TripDescriptor.ScheduleRelationship.SCHEDULED) .forEach(tripUpdate -> { Collection<Frequency> frequencies = feed.getFrequencies(tripUpdate.getTrip().getTripId()); int timeOffset = (tripUpdate.getTrip().hasStartTime() && !frequencies.isEmpty()) ? LocalTime.parse(tripUpdate.getTrip().getStartTime()).toSecondOfDay() : 0; String key = GtfsStorage.tripKey(tripUpdate.getTrip(), !frequencies.isEmpty()); return; final StopTime originalStopTime = feed.stop_times.get(new Fun.Tuple2(tripUpdate.getTrip().getTripId(), stopTime.stop_sequence)); int arrivalDelay = stopTime.arrival_time - originalStopTime.arrival_time; delaysForAlightEdges.put(leaveEdges[stopTime.stop_sequence], arrivalDelay * 1000); .forEach(tripUpdate -> { Trip trip = new Trip(); trip.trip_id = tripUpdate.getTrip().getTripId(); trip.route_id = tripUpdate.getTrip().getRouteId(); final List<StopTime> stopTimes = tripUpdate.getStopTimeUpdateList().stream()
return null; String tripId = tripDescriptor.getTripId(); int tripIndex = getTripIndex(tripId); if (tripIndex == -1) {
tripId = informed.getTrip().getTripId();
String tripId = tripDescriptor.getTripId(); Trip trip = getTripForTripId(feedId, tripId); if (trip == null) {
final String tripId = tripDescriptor.getTripId(); final Trip trip = getTripForTripId(feedId, tripId); if (trip != null) {
/** * Handle GTFS-RT TripUpdate message containing a MODIFIED trip. * * @param graph graph to update * @param trip trip that is modified * @param tripUpdate GTFS-RT TripUpdate message * @param stops the stops of each StopTimeUpdate in the TripUpdate message * @param feedId * @param serviceDate service date for modified trip * @return true iff successful */ private boolean handleModifiedTrip(final Graph graph, final Trip trip, final TripUpdate tripUpdate, final List<Stop> stops, final String feedId, final ServiceDate serviceDate) { // Preconditions Preconditions.checkNotNull(stops); Preconditions.checkArgument(tripUpdate.getStopTimeUpdateCount() == stops.size(), "number of stop should match the number of stop time updates"); // Cancel scheduled trip final String tripId = tripUpdate.getTrip().getTripId(); cancelScheduledTrip(feedId, tripId, serviceDate); // Check whether trip id has been used for previously ADDED/MODIFIED trip message and cancel // previously created trip cancelPreviouslyAddedTrip(feedId, tripId, serviceDate); // Add new trip final boolean success = addTripToGraphAndBuffer(feedId, graph, trip, tripUpdate, stops, serviceDate, RealTimeState.MODIFIED); return success; }
int addDelayedBoardEdge(ZoneId zoneId, GtfsRealtime.TripDescriptor tripDescriptor, int stopSequence, int departureTime, int departureNode, BitSet validOnDay) { Trip trip = feed.trips.get(tripDescriptor.getTripId()); StopTime stopTime = feed.stop_times.get(new Fun.Tuple2(tripDescriptor.getTripId(), stopSequence)); Stop stop = feed.stops.get(stopTime.stop_id); Map<GtfsStorageI.PlatformDescriptor, NavigableMap<Integer, Integer>> departureTimelineNodesByRoute = departureTimelinesByStop.computeIfAbsent(stopTime.stop_id, s -> new HashMap<>());
private boolean handleScheduledTrip(final TripUpdate tripUpdate, final String feedId, final ServiceDate serviceDate) { final TripDescriptor tripDescriptor = tripUpdate.getTrip(); // This does not include Agency ID or feed ID, trips are feed-unique and we currently assume a single static feed. final String tripId = tripDescriptor.getTripId(); final TripPattern pattern = getPatternForTripId(feedId, tripId); if (pattern == null) { LOG.warn("No pattern found for tripId {}, skipping TripUpdate.", tripId); return false; } if (tripUpdate.getStopTimeUpdateCount() < 1) { LOG.warn("TripUpdate contains no updates, skipping."); return false; } // Apply update on the *scheduled* time table and set the updated trip times in the buffer final TripTimes updatedTripTimes = pattern.scheduledTimetable.createUpdatedTripTimes(tripUpdate, timeZone, serviceDate); if (updatedTripTimes == null) { return false; } // Make sure that updated trip times have the correct real time state updatedTripTimes.setRealTimeState(RealTimeState.UPDATED); final boolean success = buffer.update(feedId, pattern, updatedTripTimes, serviceDate); return success; }
private boolean handleCanceledTrip(final TripUpdate tripUpdate, final String feedId, final ServiceDate serviceDate) { boolean success = false; if (tripUpdate.getTrip().hasTripId()) { // Try to cancel scheduled trip final String tripId = tripUpdate.getTrip().getTripId(); final boolean cancelScheduledSuccess = cancelScheduledTrip(feedId, tripId, serviceDate); // Try to cancel previously added trip final boolean cancelPreviouslyAddedSuccess = cancelPreviouslyAddedTrip(feedId, tripId, serviceDate); if (cancelScheduledSuccess || cancelPreviouslyAddedSuccess) { success = true; } else { LOG.warn("No pattern found for tripId {}, skipping TripUpdate.", tripId); } } else { LOG.warn("No trip id in CANCELED trip update, skipping TripUpdate."); } return success; }
/** * <code>optional string trip_id = 1;</code> * * <pre> * The trip_id from the GTFS feed that this selector refers to. * For non frequency-based trips, this field is enough to uniquely identify * the trip. For frequency-based trip, start_time and start_date might also be * necessary. * </pre> */ public Builder clearTripId() { bitField0_ = (bitField0_ & ~0x00000001); tripId_ = getDefaultInstance().getTripId(); onChanged(); return this; } /**
private String createId(String id, EntitySelector informed) { return id + " " + (informed.hasAgencyId () ? informed.getAgencyId () : " null ") + " " + (informed.hasRouteId () ? informed.getRouteId () : " null ") + " " + (informed.hasTrip() && informed.getTrip().hasDirectionId() ? informed.getTrip().hasDirectionId() : " null ") + " " + (informed.hasRouteType () ? informed.getRouteType () : " null ") + " " + (informed.hasStopId () ? informed.getStopId () : " null ") + " " + (informed.hasTrip() && informed.getTrip().hasTripId() ? informed.getTrip().getTripId() : " null "); }