.filter(GtfsRealtime.FeedEntity::hasTripUpdate) .map(GtfsRealtime.FeedEntity::getTripUpdate) .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()); final int[] boardEdges = staticGtfs.getBoardEdgesForTrip().get(key); final int[] leaveEdges = staticGtfs.getAlightEdgesForTrip().get(key); if (boardEdges == null || leaveEdges == null) { logger.warn("Trip not found: {}", tripUpdate.getTrip()); return; tripUpdate.getStopTimeUpdateList().stream() .filter(stopTimeUpdate -> stopTimeUpdate.getScheduleRelationship() == SKIPPED) .mapToInt(GtfsRealtime.TripUpdate.StopTimeUpdate::getStopSequence) 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); int boardEdge = boardEdges[stopTime.stop_sequence]; int departureNode = graphHopperStorage.getEdgeIteratorState(boardEdge, Integer.MIN_VALUE).getAdjNode(); int delayedBoardEdge = gtfsReader.addDelayedBoardEdge(timezone, tripUpdate.getTrip(), stopTime.stop_sequence, stopTime.departure_time + timeOffset, departureNode, validOnDay); delaysForBoardEdges.put(delayedBoardEdge, departureDelay * 1000); .filter(GtfsRealtime.FeedEntity::hasTripUpdate) .map(GtfsRealtime.FeedEntity::getTripUpdate) .filter(tripUpdate -> tripUpdate.getTrip().getScheduleRelationship() == GtfsRealtime.TripDescriptor.ScheduleRelationship.ADDED)
public Builder mergeFrom(com.google.transit.realtime.GtfsRealtime.TripUpdate other) { if (other == com.google.transit.realtime.GtfsRealtime.TripUpdate.getDefaultInstance()) return this; if (other.hasTrip()) { mergeTrip(other.getTrip()); if (other.hasVehicle()) { mergeVehicle(other.getVehicle()); if (other.hasTimestamp()) { setTimestamp(other.getTimestamp()); if (other.hasDelay()) { setDelay(other.getDelay()); this.mergeUnknownFields(other.getUnknownFields()); return this;
Preconditions.checkArgument(tripUpdate.getStopTimeUpdateCount() == stops.size(), "number of stop should match the number of stop time updates"); final List<StopTime> stopTimes = new ArrayList<>(tripUpdate.getStopTimeUpdateCount()); for (int index = 0; index < tripUpdate.getStopTimeUpdateCount(); ++index) { final StopTimeUpdate stopTimeUpdate = tripUpdate.getStopTimeUpdate(index); final Stop stop = stops.get(index); if (index == tripUpdate.getStopTimeUpdateCount() - 1) { stopTime.setPickupType(1); // No pickup available } else {
if (entity.hasTripUpdate()) { GtfsRealtime.TripUpdate tripUpdate = entity.getTripUpdate(); long tripUpdateTimestamp = tripUpdate.getTimestamp(); List<GtfsRealtime.TripUpdate.StopTimeUpdate> stopTimeUpdates = tripUpdate.getStopTimeUpdateList(); if (stopTimeUpdates != null) { Long previousArrivalTime = null;
int gtfsStopTimeIndex = 0; String tripId = null; if (tripUpdate.hasTrip() && tripUpdate.getTrip().hasTripId()) { tripId = tripUpdate.getTrip().getTripId(); gtfsStopTimes = gtfsMetadata.getTripStopTimes().get(tripId); List<GtfsRealtime.TripUpdate.StopTimeUpdate> rtStopTimeUpdateList = tripUpdate.getStopTimeUpdateList();
if (entity.hasTripUpdate()) { GtfsRealtime.TripUpdate tripUpdate = entity.getTripUpdate(); if (!tripUpdate.getTrip().hasTripId()) { checkW006(entity, tripUpdate.getTrip(), errorListW006); } else { String tripId = tripUpdate.getTrip().getTripId(); Trip trip = gtfsMetadata.getTrips().get(tripId); if (trip == null) { if (!GtfsUtils.isAddedTrip(tripUpdate.getTrip())) { if (GtfsUtils.isAddedTrip(tripUpdate.getTrip())) { if (tripUpdate.getTrip().hasStartTime()) { checkE023(tripUpdate, tripUpdate.getTrip(), gtfsMetadata, errorListE023); if (tripUpdate.getTrip().hasStartTime()) { checkE020(tripUpdate, tripUpdate.getTrip(), errorListE020); checkE021(tripUpdate, tripUpdate.getTrip(), errorListE021); checkE004(tripUpdate, tripUpdate.getTrip(), gtfsMetadata, errorListE004); checkE024(tripUpdate, tripUpdate.getTrip(), gtfsMetadata, errorListE024); checkE035(entity, tripUpdate.getTrip(), gtfsMetadata, errorListE035); List<GtfsRealtime.TripUpdate.StopTimeUpdate> stopTimeUpdateList = tripUpdate.getStopTimeUpdateList(); for (GtfsRealtime.TripUpdate.StopTimeUpdate stopTimeUpdate : stopTimeUpdateList) { if (tripUpdate.hasTrip()) { checkW009(entity, tripUpdate.getTrip(), errorListW009);
if (tripUpdate.hasExtension(GtfsRealtimeOneBusAway.obaTripUpdate) && onBestTrip) { OneBusAwayTripUpdate obaTripUpdate = tripUpdate.getExtension(GtfsRealtimeOneBusAway.obaTripUpdate); if (obaTripUpdate.hasDelay()) { if (tripUpdate.hasDelay() && onBestTrip) { best.scheduleDeviation = tripUpdate.getDelay(); best.tripId = tripId; tripUpdateHasDelay = true; if (tripUpdate.hasTimestamp() && onBestTrip) { best.timestamp = tripUpdate.getTimestamp() * 1000; for (StopTimeUpdate stopTimeUpdate : tripUpdate.getStopTimeUpdateList()) { BlockStopTimeEntry blockStopTime = getBlockStopTimeForStopTimeUpdate(result, tripUpdate, stopTimeUpdate, blockTrip.getStopTimes(), if (timepointPredictions.size() == 1 && tripUpdates.get(0).getStopTimeUpdateList().size() == 1) { singleTimepointRecord = true;
if (tu.hasVehicle() && tu.getVehicle().hasId() && StringUtils.isNotBlank(tu.getVehicle().getId())) { TripDescriptor td = tu.getTrip(); long time = tu.hasTimestamp() ? tu.getTimestamp() * 1000 : currentTime(); BlockDescriptor bd = getTripDescriptorAsBlockDescriptor(result, td, time); TripUpdate tu = bestTripByVehicleId.get(vehicleId); long time = tu.hasTimestamp() ? tu.getTimestamp() * 1000 : currentTime(); update.block = getTripDescriptorAsBlockDescriptor(result, tu.getTrip(), time); update.tripUpdates = new ArrayList<TripUpdate>(tripUpdates); update.bestTrip = tu.getTrip().getTripId(); if (tu.hasVehicle() && tu.getVehicle().hasId()) { vehicleId = getVehicleId(tu); break;
if (entity.hasTripUpdate() && hasTripId(entity.getTripUpdate())) { tripUpdateCount++; String tripId = entity.getTripUpdate().getTrip().getTripId(); String vehicleId = ""; if (entity.getTripUpdate().hasVehicle() && entity.getTripUpdate().getVehicle().hasId()) { vehicleId = entity.getTripUpdate().getVehicle().getId();
GtfsRealtime.TripUpdate tripUpdate = entity.getTripUpdate(); List<Frequency> frequenceTypeOneList = gtfsMetadata.getExactTimesOneTrips().get(tripUpdate.getTrip().getTripId()); if (frequenceTypeOneList != null) { boolean foundMatch = false; _log.debug("start time = " + startTime); _log.debug("formatted start time = " + gtfsStartTimeString); if (tripUpdate.getTrip().getStartTime().equals(gtfsStartTimeString)) { String prefix = "GTFS-rt trip_id " + tripUpdate.getTrip().getTripId() + " has start_time of " + tripUpdate.getTrip().getStartTime() + " and GTFS frequencies.txt start_time is " + gtfsStartTimeString + " with a headway of " + headwaySecs + " seconds "; RuleUtils.addOccurrence(E019, prefix, errorListE019, _log);
GtfsRealtime.TripUpdate tripUpdate = entity.getTripUpdate(); if (StringUtils.isEmpty(tripUpdate.getVehicle().getId())) {
List<StopTimeUpdate> stopTimes = update.getStopTimeUpdateList(); for(StopTimeUpdate stopTime : stopTimes) if(update.getTrip().hasDirectionId()) direction=""+update.getTrip().getDirectionId(); if (update.getTrip() != null) { Trip trip = dbConfig.getTrip(update.getTrip().getTripId()); if (trip != null) { direction = trip.getDirectionId(); } else { logger.error("Got tripTag={} but no such trip in " + "the configuration.", update.getTrip().getTripId()); + "directionId={}, tripId={}, vehicleId={}, " + "stopId={}, prediction={}, isArrival={}", update.getTrip().getRouteId(), direction, update.getTrip().getTripId(), update.getVehicle().getId(), stopTime.getStopId(), new Date(stopTime.getArrival().getTime()*1000), true); update.getTrip().getRouteId(), direction, stopTime.getStopId(), update.getTrip().getTripId(), update.getVehicle().getId(), new Date(stopTime.getArrival().getTime()*1000) , new Date(feed.getHeader().getTimestamp()*1000), update.getTrip().getRouteId(), direction,
if (entity.hasTripUpdate()) { GtfsRealtime.TripUpdate tripUpdate = entity.getTripUpdate(); List<GtfsRealtime.TripUpdate.StopTimeUpdate> stopTimeUpdateList = tripUpdate.getStopTimeUpdateList(); for (GtfsRealtime.TripUpdate.StopTimeUpdate stopTimeUpdate : stopTimeUpdateList) { if (stopTimeUpdate.hasStopId()) { String prefix = "trip_id " + tripUpdate.getTrip().getTripId() + " stop_id " + stopTimeUpdate.getStopId(); if (!gtfsMetadata.getStopIds().contains(stopTimeUpdate.getStopId())) {
GtfsRealtime.TripUpdate tripUpdate = entity.getTripUpdate(); if (gtfsMetadata.getExactTimesZeroTripIds().contains(tripUpdate.getTrip().getTripId())) { if (!tripUpdate.getTrip().hasStartDate()) { RuleUtils.addOccurrence(E006, "trip_id " + tripUpdate.getTrip().getTripId() + " is missing start_date", errorListE006, _log); if (!tripUpdate.getTrip().hasStartTime()) { RuleUtils.addOccurrence(E006, "trip_id " + tripUpdate.getTrip().getTripId() + " is missing start_time", errorListE006, _log); if (!(!tripUpdate.getTrip().hasScheduleRelationship() || tripUpdate.getTrip().getScheduleRelationship().equals(GtfsRealtime.TripDescriptor.ScheduleRelationship.UNSCHEDULED))) { RuleUtils.addOccurrence(E013, "trip_id " + tripUpdate.getTrip().getTripId() + " schedule_relationship " + tripUpdate.getTrip().getScheduleRelationship(), errorListE013, _log); if (!tripUpdate.hasVehicle() || !tripUpdate.getVehicle().hasId()) { RuleUtils.addOccurrence(W005, "trip_id " + tripUpdate.getTrip().getTripId(), errorListW005, _log);
public Builder mergeFrom(com.google.transit.realtime.GtfsRealtime.TripUpdate other) { if (other == com.google.transit.realtime.GtfsRealtime.TripUpdate.getDefaultInstance()) return this; if (other.hasTrip()) { mergeTrip(other.getTrip()); if (other.hasVehicle()) { mergeVehicle(other.getVehicle()); if (other.hasTimestamp()) { setTimestamp(other.getTimestamp()); if (other.hasDelay()) { setDelay(other.getDelay()); this.mergeUnknownFields(other.getUnknownFields()); return this;
if (entity.hasTripUpdate()) { TripUpdateModel tu = new TripUpdateModel(); TripDescriptor t = entity.getTripUpdate().getTrip(); if (entity.getTripUpdate().hasTimestamp()) { timestamp = entity.getTripUpdate().getTimestamp() * 1000; if (entity.getTripUpdate().hasDelay()) { tu.setDelay(entity.getTripUpdate().getDelay()); VehicleDescriptor vehicle = entity.getTripUpdate().getVehicle(); if (vehicle != null) { tu.setVehicleId(vehicle.getId()); for (StopTimeUpdate stu : entity.getTripUpdate().getStopTimeUpdateList()) { StopTimeUpdateModel stopTimeUpdate = readStopTimeUpdate(stu, tu.getScheduleRelationship());
public final boolean isInitialized() { byte isInitialized = memoizedIsInitialized; if (isInitialized != -1) return isInitialized == 1; if (!hasTrip()) { memoizedIsInitialized = 0; return false; } if (!getTrip().isInitialized()) { memoizedIsInitialized = 0; return false; } if (hasVehicle()) { if (!getVehicle().isInitialized()) { memoizedIsInitialized = 0; return false; } } for (int i = 0; i < getStopTimeUpdateCount(); i++) { if (!getStopTimeUpdate(i).isInitialized()) { memoizedIsInitialized = 0; return false; } } if (!extensionsAreInitialized()) { memoizedIsInitialized = 0; return false; } memoizedIsInitialized = 1; return true; }
/** * Returns vehicle and trip IDs text (vehicle_id X trip_id = Y) for the given entity if the entity is a VehiclePosition, or the trip ID text (trip_id = Y) for the given entity if the entity is a TripUpdate * * @param entity Either the VehiclePosition or TripUpdate for which to generate the ID text * @return vehicle and trip IDs text (vehicle_id X trip_id = Y) for the given entity if the entity is a VehiclePosition, or the trip ID text (trip_id = Y) for the given entity if the entity is a TripUpdate */ public static String getVehicleAndTripIdText(Object entity) { if (!(entity instanceof GtfsRealtime.VehiclePosition || entity instanceof GtfsRealtime.TripUpdate)) { throw new IllegalArgumentException("entity must be instance of VehiclePosition or TripUpdate"); } String ids = null; if (entity instanceof GtfsRealtime.VehiclePosition) { GtfsRealtime.VehiclePosition vp = (GtfsRealtime.VehiclePosition) entity; ids = "vehicle_id " + vp.getVehicle().getId() + " trip_id " + vp.getTrip().getTripId(); } else if (entity instanceof GtfsRealtime.TripUpdate) { GtfsRealtime.TripUpdate tu = (GtfsRealtime.TripUpdate) entity; ids = "trip_id " + tu.getTrip().getTripId(); } return ids; }
/** * Returns vehicle and route IDs text (vehicle_id X route_id = Y) for the given entity if the entity is a VehiclePosition, or the route ID text (route_id = Y) for the given entity if the entity is a TripUpdate * * @param entity Either the VehiclePosition or TripUpdate for which to generate the ID text * @return vehicle and route IDs text (vehicle_id X route_id = Y) for the given entity if the entity is a VehiclePosition, or the route ID text (route_id = Y) for the given entity if the entity is a TripUpdate */ public static String getVehicleAndRouteId(Object entity) { if (!(entity instanceof GtfsRealtime.VehiclePosition || entity instanceof GtfsRealtime.TripUpdate)) { throw new IllegalArgumentException("entity must be instance of VehiclePosition or TripUpdate"); } String ids = null; if (entity instanceof GtfsRealtime.VehiclePosition) { GtfsRealtime.VehiclePosition vp = (GtfsRealtime.VehiclePosition) entity; ids = "vehicle_id " + vp.getVehicle().getId() + " route_id " + vp.getTrip().getRouteId(); } else if (entity instanceof GtfsRealtime.TripUpdate) { GtfsRealtime.TripUpdate tu = (GtfsRealtime.TripUpdate) entity; ids = "route_id " + tu.getTrip().getRouteId(); } return ids; }
/** * Checks E041 "trip doesn't have any stop_time_updates", and adds any errors to the provided error list. * * @param entity entity that the trip_update is from * @param tripUpdate the trip_update to examine * @param errors the list to add the errors to */ private void checkE041(GtfsRealtime.FeedEntity entity, GtfsRealtime.TripUpdate tripUpdate, List<OccurrenceModel> errors) { if (tripUpdate.getStopTimeUpdateCount() < 1) { if (tripUpdate.hasTrip() && tripUpdate.getTrip().hasScheduleRelationship() && tripUpdate.getTrip().getScheduleRelationship().equals(GtfsRealtime.TripDescriptor.ScheduleRelationship.CANCELED)) { // No errors - the trip was canceled, so it doesn't need any stop_time_updates - return return; } RuleUtils.addOccurrence(ValidationRules.E041, GtfsUtils.getTripId(entity, tripUpdate), errors, _log); } }