use of com.conveyal.gtfs.model.Service in project graphhopper by graphhopper.
the class GtfsReader method buildPtNetwork.
private void buildPtNetwork() {
HashMultimap<String, Trip> blockTrips = HashMultimap.create();
for (Trip trip : feed.trips.values()) {
if (trip.block_id != null) {
blockTrips.put(trip.block_id, trip);
} else {
blockTrips.put("non-block-trip" + trip.trip_id, trip);
}
}
blockTrips.asMap().values().forEach(unsortedTrips -> {
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)) {
if (service.activeOn(date)) {
validOnDay.set((int) DAYS.between(startDate, date));
}
}
ArrayList<StopTime> stopTimes = new ArrayList<>();
getInterpolatedStopTimesForTrip(trip.trip_id).forEach(stopTimes::add);
return new TripWithStopTimes(trip, stopTimes, validOnDay, Collections.emptySet(), Collections.emptySet());
}).sorted(Comparator.comparingInt(trip -> trip.stopTimes.iterator().next().departure_time)).collect(Collectors.toList());
if (trips.stream().map(trip -> feed.getFrequencies(trip.trip.trip_id)).distinct().count() != 1) {
throw new RuntimeException("Found a block with frequency-based trips. Not supported.");
}
ZoneId zoneId = ZoneId.of(feed.agency.get(feed.routes.get(trips.iterator().next().trip.route_id).agency_id).agency_timezone);
Collection<Frequency> frequencies = feed.getFrequencies(trips.iterator().next().trip.trip_id);
if (frequencies.isEmpty()) {
addTrips(zoneId, trips, 0, false);
} else {
for (Frequency frequency : frequencies) {
for (int time = frequency.start_time; time < frequency.end_time; time += frequency.headway_secs) {
addTrips(zoneId, trips, time, true);
}
}
}
});
wireUpStops();
}
Aggregations