private void validateTripUpdate(GtfsReader.TripWithStopTimes tripUpdate) { com.conveyal.gtfs.model.Trip originalTrip = gtfsFeed.trips.get(tripUpdate.trip.trip_id); try { Iterable<StopTime> interpolatedStopTimesForTrip = gtfsFeed.getInterpolatedStopTimesForTrip(tripUpdate.trip.trip_id); long nStopTimes = StreamSupport.stream(interpolatedStopTimesForTrip.spliterator(), false).count(); logger.trace("Original stop times: {} Updated stop times: {}", nStopTimes, tripUpdate.stopTimes.size()); if (nStopTimes != tripUpdate.stopTimes.size()) { logger.error("Original stop times: {} Updated stop times: {}", nStopTimes, tripUpdate.stopTimes.size()); } } catch (GTFSFeed.FirstAndLastStopsDoNotHaveTimes firstAndLastStopsDoNotHaveTimes) { throw new RuntimeException(firstAndLastStopsDoNotHaveTimes); } }
Transfers(GTFSFeed feed) { this.transfersToStop = feed.transfers.values().stream().collect(Collectors.groupingBy(t -> t.to_stop_id)); this.transfersFromStop = feed.transfers.values().stream().collect(Collectors.groupingBy(t -> t.from_stop_id)); this.routesByStop = feed.stop_times.values().stream() .collect(Collectors.groupingBy(stopTime -> stopTime.stop_id, Collectors.mapping(stopTime -> feed.trips.get(stopTime.trip_id).route_id, Collectors.toSet()))); }
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; } }
List<TripWithStopTimes> trips = unsortedTrips.stream() .map(trip -> { Service service = feed.services.get(trip.service_id); BitSet validOnDay = new BitSet((int) DAYS.between(startDate, endDate)); for (LocalDate date = startDate; !date.isAfter(endDate); date = date.plusDays(1)) {
/** * Returns a trip geometry object (LineString) for a given trip id. * If the trip has a shape reference, this will be used for the geometry. * Otherwise, the ordered stoptimes will be used. * * @param trip_id trip id of desired trip geometry * @return the LineString representing the trip geometry. * @see LineString */ public LineString getTripGeometry(String trip_id){ CoordinateList coordinates = new CoordinateList(); LineString ls = null; Trip trip = trips.get(trip_id); // If trip has shape_id, use it to generate geometry. if (trip.shape_id != null) { Shape shape = getShape(trip.shape_id); if (shape != null) ls = shape.geometry; } // Use the ordered stoptimes. if (ls == null) { ls = getStraightLineForStops(trip_id); } return ls; }
public LineString getStraightLineForStops(String trip_id) { CoordinateList coordinates = new CoordinateList(); LineString ls = null; Trip trip = trips.get(trip_id); Iterable<StopTime> stopTimes; stopTimes = getOrderedStopTimesForTrip(trip.trip_id); if (Iterables.size(stopTimes) > 1) { for (StopTime stopTime : stopTimes) { Stop stop = stops.get(stopTime.stop_id); Double lat = stop.stop_lat; Double lon = stop.stop_lon; coordinates.add(new Coordinate(lon, lat)); } ls = gf.createLineString(coordinates.toCoordinateArray()); } // set ls equal to null if there is only one stopTime to avoid an exception when creating linestring else{ ls = null; } return ls; }
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) { 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();
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<>());
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);
@Override public byte[] get(Object key) { return this.treeMap.get(key); }
public int getSegmentTypeById(long id) { if(!segmentTypeMap.containsKey(id)) { StreetSegment segment = (StreetSegment)map.get(id); segmentTypeMap.put(id, segment.streetType); } return segmentTypeMap.get(id); }
public static Integer getStopTimesCount(GTFSFeed feed, String agencyId) { int count = 0; for (StopTime stopTime : feed.stop_times.values()) { Trip trip = feed.trips.get(stopTime.trip_id); Route route = feed.routes.get(trip.route_id); if (agencyId.equals(route.agency_id)) { count++; } } return count; }
public List<SpatialDataItem> getByEnvelope(Envelope env) { List<Long> ids = getIdsByEnvelope(env); List<SpatialDataItem> items = new ArrayList<>(); for (long id : ids) { items.add(map.get(id)); } return items; }
/** Get the likely time zone for a stop using the agency of the first stop time encountered for the stop. */ public ZoneId getAgencyTimeZoneForStop (String stop_id) { StopTime stopTime = getStopTimesForStop(stop_id).iterator().next(); Trip trip = this.trips.get(stopTime.trip_id); Route route = this.routes.get(trip.route_id); Agency agency = route.agency_id != null ? this.agency.get(route.agency_id) : this.agency.get(0); return ZoneId.of(agency.agency_timezone); }
/** Get list of distinct trips (filters out multiple visits by a trip) a given stop_id. */ public List<Trip> getDistinctTripsForStop (String stop_id) { return getStopTimesForStop(stop_id).stream() .map(stopTime -> this.trips.get(stopTime.trip_id)) .distinct() .collect(Collectors.toList()); }
/** Get list of stop_times for a given stop_id. */ public List<StopTime> getStopTimesForStop (String stop_id) { SortedSet<Tuple2<String, Tuple2>> index = this.stopStopTimeSet .subSet(new Tuple2<>(stop_id, null), new Tuple2(stop_id, Fun.HI)); return index.stream() .map(tuple -> this.stop_times.get(tuple.b)) .collect(Collectors.toList()); }
public List<Trip> getTripsForService (String service_id) { SortedSet<Tuple2<String, String>> index = this.tripsPerService .subSet(new Tuple2<>(service_id, null), new Tuple2(service_id, Fun.HI)); return index.stream() .map(tuple -> this.trips.get(tuple.b)) .collect(Collectors.toList()); }
/** Get list of services for each date of service. */ public List<Service> getServicesForDate (LocalDate date) { String dateString = date.format(dateFormatter); SortedSet<Tuple2<String, String>> index = this.servicesPerDate .subSet(new Tuple2<>(dateString, null), new Tuple2(dateString, Fun.HI)); return index.stream() .map(tuple -> this.services.get(tuple.b)) .collect(Collectors.toList()); }
@Benchmark public void readKey(final Reader r, final Blackhole bh) { for (final int key : r.keys) { if (r.intKey) { r.wkb.putInt(0, key); } else { r.wkb.putStringWithoutLengthUtf8(0, r.padKey(key)); } bh.consume(r.map.get(r.wkb.byteArray())); } }