.filter(stopTimeUpdate -> stopTimeUpdate.getScheduleRelationship() == SKIPPED) .mapToInt(GtfsRealtime.TripUpdate.StopTimeUpdate::getStopSequence) .forEach(skippedStopSequenceNumber -> { .map(stopTimeUpdate -> { final StopTime stopTime = new StopTime(); stopTime.stop_sequence = stopTimeUpdate.getStopSequence(); stopTime.stop_id = stopTimeUpdate.getStopId(); stopTime.trip_id = trip.trip_id; final ZonedDateTime arrival_time = Instant.ofEpochSecond(stopTimeUpdate.getArrival().getTime()).atZone(timezone); stopTime.arrival_time = (int) Duration.between(arrival_time.truncatedTo(ChronoUnit.DAYS), arrival_time).getSeconds(); final ZonedDateTime departure_time = Instant.ofEpochSecond(stopTimeUpdate.getArrival().getTime()).atZone(timezone); stopTime.departure_time = (int) Duration.between(departure_time.truncatedTo(ChronoUnit.DAYS), departure_time).getSeconds(); return stopTime;
boolean match = false; if (update != null) { if (update.hasStopSequence()) { match = update.getStopSequence() == newTimes.getStopSequence(i); } else if (update.hasStopId()) { match = pattern.getStop(i).getId().getId().equals(update.getStopId()); update.hasScheduleRelationship() ? update.getScheduleRelationship() : StopTimeUpdate.ScheduleRelationship.SCHEDULED; if (scheduleRelationship == StopTimeUpdate.ScheduleRelationship.SKIPPED) { long today = updateServiceDate.getAsDate(timeZone).getTime() / 1000; if (update.hasArrival()) { StopTimeEvent arrival = update.getArrival(); if (arrival.hasDelay()) { delay = arrival.getDelay(); if (update.hasDeparture()) { StopTimeEvent departure = update.getDeparture(); if (departure.hasDelay()) { delay = departure.getDelay();
int stopSequenceCeiling = Math.max(stopTimeUpdateListWithSentinel.isEmpty() ? 0 : stopTimeUpdateListWithSentinel.get(stopTimeUpdateListWithSentinel.size() - 1).getStopSequence(), StreamSupport.stream(interpolatedStopTimesForTrip.spliterator(), false).mapToInt(stopTime -> stopTime.stop_sequence).max().orElse(0) ) + 1; stopTimeUpdateListWithSentinel.add(GtfsRealtime.TripUpdate.StopTimeUpdate.newBuilder().setStopSequence(stopSequenceCeiling).setScheduleRelationship(NO_DATA).build()); for (GtfsRealtime.TripUpdate.StopTimeUpdate stopTimeUpdate : stopTimeUpdateListWithSentinel) { 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) { final StopTime originalStopTime = feed.stop_times.get(new Fun.Tuple2(tripUpdate.getTrip().getTripId(), stopTimeUpdate.getStopSequence())); if (originalStopTime != null) { StopTime updatedStopTime = originalStopTime.clone(); if (stopTimeUpdate.getScheduleRelationship() == NO_DATA) { delay = 0; if (stopTimeUpdate.hasArrival()) { delay = stopTimeUpdate.getArrival().getDelay(); logger.trace("stop_sequence {} scheduled arrival {} updated arrival {}", stopTimeUpdate.getStopSequence(), originalStopTime.arrival_time, updatedStopTime.arrival_time); time = updatedStopTime.arrival_time; if (stopTimeUpdate.hasDeparture()) { delay = stopTimeUpdate.getDeparture().getDelay(); logger.trace("stop_sequence {} scheduled departure {} updated departure {}", stopTimeUpdate.getStopSequence(), originalStopTime.departure_time, updatedStopTime.departure_time); time = updatedStopTime.departure_time; stopTimes.add(updatedStopTime); logger.trace("Number of stop times: {}", stopTimes.size()); if (stopTimeUpdate.getScheduleRelationship() == SKIPPED) {
String previousDepartureTimeText = null; for (GtfsRealtime.TripUpdate.StopTimeUpdate stopTimeUpdate : stopTimeUpdates) { String stopDescription = stopTimeUpdate.hasStopSequence() ? " stop_sequence " + stopTimeUpdate.getStopSequence() : " stop_id " + stopTimeUpdate.getStopId(); Long arrivalTime = null; String arrivalTimeText; Long departureTime = null; String departureTimeText; if (stopTimeUpdate.hasArrival()) { if (stopTimeUpdate.getArrival().hasTime()) { arrivalTime = stopTimeUpdate.getArrival().getTime(); arrivalTimeText = TimestampUtils.posixToClock(arrivalTime, gtfsMetadata.getTimeZone()); if (stopTimeUpdate.hasDeparture()) { if (stopTimeUpdate.getDeparture().hasTime()) { departureTime = stopTimeUpdate.getDeparture().getTime(); departureTimeText = TimestampUtils.posixToClock(departureTime, gtfsMetadata.getTimeZone()); RuleUtils.addOccurrence(E022, prefix, e022List, _log); if (stopTimeUpdate.getArrival().hasTime() && departureTime < stopTimeUpdate.getArrival().getTime()) { TimestampUtils.posixToClock(stopTimeUpdate.getArrival().getTime(), gtfsMetadata.getTimeZone()) + " (" + stopTimeUpdate.getArrival().getTime() + ")"; RuleUtils.addOccurrence(E025, prefix, e025List, _log);
boolean unknownRtStopSequence = false; for (GtfsRealtime.TripUpdate.StopTimeUpdate stopTimeUpdate : rtStopTimeUpdateList) { if (!foundE009error && tripId != null && tripWithMultiStop.containsKey(tripId) && !stopTimeUpdate.hasStopSequence()) { previousRtStopSequence = stopTimeUpdate.getStopSequence(); previousRtStopId = stopTimeUpdate.getStopId(); if (stopTimeUpdate.hasStopSequence()) { rtStopSequenceList.add(stopTimeUpdate.getStopSequence()); if (stopTimeUpdate.hasStopId()) { rtStopIdList.add(stopTimeUpdate.getStopId()); boolean foundStopSequence = false; boolean foundStopId = false; if (stopTimeUpdate.hasStopSequence()) { if (gtfsStopSequence == stopTimeUpdate.getStopSequence()) { if (stopTimeUpdate.hasStopId()) { if (gtfsStop.getId().getId().equals(stopTimeUpdate.getStopId())) { if (stopTimeUpdate.hasStopSequence() && gtfsStopTimeIndex == gtfsStopTimes.size()) { if (!stopTimeUpdate.hasStopSequence() && foundStopId) { if (!stopTimeUpdate.hasStopSequence()) { rtStopSequenceList.add(gtfsStopSequence); addedStopSequenceFromStopId = true; RuleUtils.addOccurrence(ValidationRules.E051, "GTFS-rt " + GtfsUtils.getTripId(entity, tripUpdate) + " contains stop_sequence " + stopTimeUpdate.getStopSequence(), e051List, _log);
tpr.setTripId(stopTime.getTrip().getId()); tpr.setTimepointScheduledTime(instance.getServiceDate() + stopTime.getArrivalTime() * 1000); if (stopTimeUpdate.hasStopSequence()) { tpr.setStopSequence(stopTimeUpdate.getStopSequence());
if(stopTime.hasArrival()||stopTime.hasDeparture()) + "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); logger.info("Prediction in milliseonds is {} and converted is {}",stopTime.getArrival().getTime()*1000, new Date(stopTime.getArrival().getTime()*1000)); if(stopTime.hasArrival()) stopTime.getStopId(), update.getTrip().getTripId(), update.getVehicle().getId(), new Date(stopTime.getArrival().getTime()*1000) , new Date(feed.getHeader().getTimestamp()*1000), true, if(stopTime.hasDeparture()) stopTime.getStopId(), update.getTrip().getTripId(), update.getVehicle().getId(), new Date(stopTime.getDeparture().getTime()*1000) , new Date(feed.getHeader().getTimestamp()*1000), false, logger.debug("No predictions for vehicleId={} for stop={}",update.getVehicle().getId(),stopTime.getStopId());
StopTimeUpdate.Builder stopTimeUpdate = StopTimeUpdate.newBuilder(); stopTimeUpdate.setStopId(AgencyAndId.convertToString(tpr.getTimepointId())); stopTimeUpdate.setScheduleRelationship(com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SCHEDULED); StopEntry stop = nextStopTime.getStop(); StopTimeUpdate.Builder stopTimeUpdate = StopTimeUpdate.newBuilder(); stopTimeUpdate.setStopId(AgencyAndId.convertToString(stop.getId())); stopTimeUpdate.setStopSequence(nextStopTime.getSequence());
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())) { Integer locationType = gtfsMetadata.getStopToLocationTypeMap().get(stopTimeUpdate.getStopId()); if (locationType != null && locationType != 0) {
List<BlockStopTimeEntry> stopTimes, long serviceDate) { if (stopTimeUpdate.hasStopSequence()) { int stopSequence = stopTimeUpdate.getStopSequence(); if (!stopTimeUpdate.hasStopId()) { if (result != null) { result.addMatchedStopId(blockStopTime.getStopTime().getStop().getId().getId()); String stopTimeUpdateStopId = convertStopId(stopTimeUpdate.getStopId()); if (blockStopTime.getStopTime().getStop().getId().getId().equals( stopTimeUpdateStopId)) { if (stopTimeUpdate.hasStopId()) { int time = getTimeForStopTimeUpdate(stopTimeUpdate, serviceDate); String stopId = convertStopId(stopTimeUpdate.getStopId()); result.addUnmatchedStopId(convertStopId(stopTimeUpdate.getStopId()));
return null; StopTimeUpdateModel stum = new StopTimeUpdateModel(); if (stu.hasStopSequence()) { stum.setStopSequence(stu.getStopSequence()); if (stu.hasStopId()) { stum.setStopId(stu.getStopId()); if (stu.getArrival() != null) { if (stu.getArrival().hasDelay()) { stum.setArrivalDelay(stu.getArrival().getDelay()); if (stu.getArrival().hasTime()) { stum.setArrivalTime(new Date(stu.getArrival().getTime() * 1000)); if (stu.getArrival().hasUncertainty()) { stum.setArrivalUncertainty(stu.getArrival().getUncertainty()); if (stu.getDeparture() != null) { if (stu.getDeparture().hasDelay()) { stum.setDepartureDelay(stu.getDeparture().getDelay()); if (stu.getDeparture().hasTime()) { stum.setDepartureTime(new Date(stu.getDeparture().getTime() * 1000)); if (stu.getDeparture().hasUncertainty()) { stum.setDepartureUncertainty(stu.getDeparture().getUncertainty());
/** * Checks E046 "GTFS-rt stop_time_update without time doesn't have arrival/departure_time in GTFS", 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 stopTimeUpdate the stop_time_update to examine * @param gtfsStopTime the entry from GTFS stop_times.txt that corresponds to the provided GTFS stopTimeUpdate * @param errors the list to add the errors to */ private void checkE046(GtfsRealtime.FeedEntity entity, GtfsRealtime.TripUpdate tripUpdate, GtfsRealtime.TripUpdate.StopTimeUpdate stopTimeUpdate, StopTime gtfsStopTime, List<OccurrenceModel> errors) { StringBuilder prefixBuilder = new StringBuilder(); prefixBuilder.append("GTFS-rt " + GtfsUtils.getTripId(entity, tripUpdate) + " "); prefixBuilder.append(GtfsUtils.getStopTimeUpdateId(stopTimeUpdate) + " "); if (stopTimeUpdate.hasArrival()) { if (!stopTimeUpdate.getArrival().hasTime() && !gtfsStopTime.isArrivalTimeSet()) { String prefix = prefixBuilder.toString() + "arrival.time"; RuleUtils.addOccurrence(ValidationRules.E046, prefix, errors, _log); } } if (stopTimeUpdate.hasDeparture()) { if (!stopTimeUpdate.getDeparture().hasTime() && !gtfsStopTime.isDepartureTimeSet()) { String prefix = prefixBuilder.toString() + "departure.time"; RuleUtils.addOccurrence(ValidationRules.E046, prefix, errors, _log); } } } }
private int getTimeForStopTimeUpdate(StopTimeUpdate stopTimeUpdate, long serviceDate) { long t = currentTime(); if (stopTimeUpdate.hasArrival()) { StopTimeEvent arrival = stopTimeUpdate.getArrival(); // note that we prefer time over delay if both are present if (arrival.hasTime()) { return (int) (arrival.getTime() - serviceDate / 1000); } if (arrival.hasDelay()) { return (int) ((t - serviceDate) / 1000 - arrival.getDelay()); } } if (stopTimeUpdate.hasDeparture()) { StopTimeEvent departure = stopTimeUpdate.getDeparture(); // again we prefer time over delay if both are present if (departure.hasTime()) return (int) (departure.getTime() - serviceDate / 1000); if (departure.hasDelay()) { return (int) ((t - serviceDate) / 1000 - departure.getDelay()); } } // instead of illegal state exception we return -1 to not corrupt the read _log.debug("expected at least an arrival or departure time or delay for update: " + stopTimeUpdate); return -1; }
/** * Checks E037 - if the provided previousStopId value is the same as the current stopTimeUpdate stop_id it adds * an error to the provided error list. * * @param entity entity that the stopTimeUpdate is from * @param previousStopId the stop_id for the previous StopTimeUpdate * @param stopTimeUpdate the current stopTimeUpdate * @param errors the list to add the errors to */ private void checkE037(GtfsRealtime.FeedEntity entity, String previousStopId, GtfsRealtime.TripUpdate.StopTimeUpdate stopTimeUpdate, List<OccurrenceModel> errors) { if (!previousStopId.isEmpty() && stopTimeUpdate.hasStopId() && previousStopId.equals(stopTimeUpdate.getStopId())) { String id = GtfsUtils.getTripId(entity, entity.getTripUpdate()); StringBuilder prefix = new StringBuilder(); prefix.append(id); prefix.append(" has repeating stop_id "); prefix.append(previousStopId); if (stopTimeUpdate.hasStopSequence()) { prefix.append(" at stop_sequence "); prefix.append(stopTimeUpdate.getStopSequence()); } RuleUtils.addOccurrence(ValidationRules.E037, prefix.toString(), errors, _log); } }
public final boolean isInitialized() { byte isInitialized = memoizedIsInitialized; if (isInitialized != -1) return isInitialized == 1; if (hasArrival()) { if (!getArrival().isInitialized()) { memoizedIsInitialized = 0; return false; } } if (hasDeparture()) { if (!getDeparture().isInitialized()) { memoizedIsInitialized = 0; return false; } } if (!extensionsAreInitialized()) { memoizedIsInitialized = 0; return false; } memoizedIsInitialized = 1; return true; }
/** * Checks E043 "stop_time_update doesn't have arrival or departure", 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 stopTimeUpdate the stop_time_update to examine * @param errors the list to add the errors to */ private void checkE043(GtfsRealtime.FeedEntity entity, GtfsRealtime.TripUpdate tripUpdate, GtfsRealtime.TripUpdate.StopTimeUpdate stopTimeUpdate, List<OccurrenceModel> errors) { if (!stopTimeUpdate.hasArrival() && !stopTimeUpdate.hasDeparture()) { if (stopTimeUpdate.hasScheduleRelationship() && (stopTimeUpdate.getScheduleRelationship().equals(SKIPPED) || stopTimeUpdate.getScheduleRelationship().equals(NO_DATA))) { // stop_time_updates with SKIPPED or NO_DATA aren't required to have arrival or departures - return return; } String id = GtfsUtils.getTripId(entity, tripUpdate) + " " + GtfsUtils.getStopTimeUpdateId(stopTimeUpdate); RuleUtils.addOccurrence(ValidationRules.E043, id, errors, _log); } }
/** * Checks E044 "stop_time_update arrival/departure doesn't have delay or time", 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 stopTimeUpdate the stop_time_update to examine * @param errors the list to add the errors to */ private void checkE044(GtfsRealtime.FeedEntity entity, GtfsRealtime.TripUpdate tripUpdate, GtfsRealtime.TripUpdate.StopTimeUpdate stopTimeUpdate, List<OccurrenceModel> errors) { if (stopTimeUpdate.hasScheduleRelationship() && stopTimeUpdate.getScheduleRelationship().equals(SKIPPED)) { // SKIPPED stop_time_updates aren't required to have delay or time (arrival/departure are optional) - see #243 return; } String id = GtfsUtils.getTripId(entity, tripUpdate) + " " + GtfsUtils.getStopTimeUpdateId(stopTimeUpdate); if (stopTimeUpdate.hasArrival()) { checkE044StopTimeEvent(stopTimeUpdate.getArrival(), id + " arrival", errors); } if (stopTimeUpdate.hasDeparture()) { checkE044StopTimeEvent(stopTimeUpdate.getDeparture(), id + " departure", errors); } }
public Builder mergeFrom(com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeUpdate other) { if (other == com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeUpdate.getDefaultInstance()) return this; if (other.hasStopSequence()) { setStopSequence(other.getStopSequence()); } if (other.hasStopId()) { bitField0_ |= 0x00000002; stopId_ = other.stopId_; onChanged(); } if (other.hasArrival()) { mergeArrival(other.getArrival()); } if (other.hasDeparture()) { mergeDeparture(other.getDeparture()); } if (other.hasScheduleRelationship()) { setScheduleRelationship(other.getScheduleRelationship()); } this.mergeExtensionFields(other); this.mergeUnknownFields(other.getUnknownFields()); return this; }
/** * Checks E045 "GTFS-rt stop_time_update stop_sequence and stop_id do not match GTFS", 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 stopTimeUpdate the stop_time_update to examine * @param gtfsStopSequence the stop_sequence from the GTFS stop_times.txt data * @param stop the GTFS stop that is paired with the provided gtfsStopSequence, using stop_id from the same record in stop_times.txt * @param errors the list to add the errors to */ private void checkE045(GtfsRealtime.FeedEntity entity, GtfsRealtime.TripUpdate tripUpdate, GtfsRealtime.TripUpdate.StopTimeUpdate stopTimeUpdate, int gtfsStopSequence, Stop stop, List<OccurrenceModel> errors) { if (stopTimeUpdate.hasStopId() && !stop.getId().getId().equals(stopTimeUpdate.getStopId())) { String tripId = "GTFS-rt " + GtfsUtils.getTripId(entity, tripUpdate) + " "; String stopSequence = "stop_sequence " + stopTimeUpdate.getStopSequence(); String stopId = "stop_id " + stopTimeUpdate.getStopId(); String gtfsSummary = " but GTFS stop_sequence " + gtfsStopSequence + " has stop_id " + stop.getId().getId(); RuleUtils.addOccurrence(ValidationRules.E045, tripId + stopSequence + " has " + stopId + gtfsSummary, errors, _log); } }
/** * Checks E042 "arrival or departure provided for NO_DATA stop_time_update", 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 stopTimeUpdate the stop_time_update to examine * @param errors the list to add the errors to */ private void checkE042(GtfsRealtime.FeedEntity entity, GtfsRealtime.TripUpdate tripUpdate, GtfsRealtime.TripUpdate.StopTimeUpdate stopTimeUpdate, List<OccurrenceModel> errors) { if (stopTimeUpdate.hasScheduleRelationship() && stopTimeUpdate.getScheduleRelationship().equals(NO_DATA)) { String id = GtfsUtils.getTripId(entity, tripUpdate) + " " + GtfsUtils.getStopTimeUpdateId(stopTimeUpdate); if (stopTimeUpdate.hasArrival()) { RuleUtils.addOccurrence(ValidationRules.E042, id + " has arrival", errors, _log); } if (stopTimeUpdate.hasDeparture()) { RuleUtils.addOccurrence(ValidationRules.E042, id + " has departure", errors, _log); } } }