Search in sources :

Example 1 with CalendarServiceData

use of org.opentripplanner.model.calendar.CalendarServiceData in project OpenTripPlanner by opentripplanner.

the class GtfsModule method buildGraph.

@Override
public void buildGraph(Graph graph, HashMap<Class<?>, Object> extra, DataImportIssueStore issueStore) {
    this.issueStore = issueStore;
    // we're about to add another agency to the graph, so clear the cached timezone
    // in case it should change
    // OTP doesn't currently support multiple time zones in a single graph;
    // at least this way we catch the error and log it instead of silently ignoring
    // because the time zone from the first agency is cached
    graph.clearTimeZone();
    CalendarServiceData calendarServiceData = new CalendarServiceData();
    try {
        for (GtfsBundle gtfsBundle : gtfsBundles) {
            // apply global defaults to individual GTFSBundles (if globals have been set)
            if (cacheDirectory != null && gtfsBundle.cacheDirectory == null) {
                gtfsBundle.cacheDirectory = cacheDirectory;
            }
            if (useCached != null && gtfsBundle.useCached == null) {
                gtfsBundle.useCached = useCached;
            }
            OtpTransitServiceBuilder builder = mapGtfsDaoToInternalTransitServiceBuilder(loadBundle(gtfsBundle), gtfsBundle.getFeedId().getId(), issueStore);
            builder.limitServiceDays(transitPeriodLimit);
            calendarServiceData.add(builder.buildCalendarServiceData());
            // NB! The calls below have side effects - the builder state is updated!
            if (OTPFeature.FlexRouting.isOn()) {
                FlexTripsMapper.createFlexTrips(builder);
            }
            repairStopTimesForEachTrip(builder.getStopTimesSortedByTrip());
            // NB! The calls below have side effects - the builder state is updated!
            createTripPatterns(graph, builder, calendarServiceData.getServiceIds());
            OtpTransitService transitModel = builder.build();
            addTransitModelToGraph(graph, gtfsBundle, transitModel);
            createGeometryAndBlockProcessor(gtfsBundle, transitModel).run(graph, issueStore);
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        // Note the close method of each bundle should NOT throw an exception, so this
        // code should be safe without the try/catch block.
        gtfsBundles.forEach(GtfsBundle::close);
    }
    // We need to save the calendar service data so we can use it later
    graph.putService(org.opentripplanner.model.calendar.CalendarServiceData.class, calendarServiceData);
    graph.updateTransitFeedValidity(calendarServiceData, issueStore);
    graph.hasTransit = true;
    graph.calculateTransitCenter();
}
Also used : CalendarServiceData(org.opentripplanner.model.calendar.CalendarServiceData) OtpTransitServiceBuilder(org.opentripplanner.model.impl.OtpTransitServiceBuilder) GtfsBundle(org.opentripplanner.graph_builder.model.GtfsBundle) OtpTransitService(org.opentripplanner.model.OtpTransitService) IOException(java.io.IOException)

Example 2 with CalendarServiceData

use of org.opentripplanner.model.calendar.CalendarServiceData in project OpenTripPlanner by opentripplanner.

the class NetexModule method buildGraph.

@Override
public void buildGraph(Graph graph, HashMap<Class<?>, Object> extra, DataImportIssueStore issueStore) {
    graph.clearTimeZone();
    CalendarServiceData calendarServiceData = new CalendarServiceData();
    try {
        for (NetexBundle netexBundle : netexBundles) {
            netexBundle.checkInputs();
            OtpTransitServiceBuilder transitBuilder = netexBundle.loadBundle(graph.deduplicator, issueStore);
            transitBuilder.limitServiceDays(transitPeriodLimit);
            calendarServiceData.add(transitBuilder.buildCalendarServiceData());
            OtpTransitService otpService = transitBuilder.build();
            // TODO OTP2 - Move this into the AddTransitModelEntitiesToGraph
            // - and make sure thay also work with GTFS feeds - GTFS do no
            // - have operators and notice assignments.
            graph.getOperators().addAll(otpService.getAllOperators());
            graph.addNoticeAssignments(otpService.getNoticeAssignments());
            GtfsFeedId feedId = new GtfsFeedId.Builder().id(netexFeedId).build();
            AddTransitModelEntitiesToGraph.addToGraph(feedId, otpService, subwayAccessTime, graph);
            new GeometryAndBlockProcessor(otpService, fareServiceFactory, MAX_STOP_TO_SHAPE_SNAP_DISTANCE, maxInterlineDistance).run(graph, issueStore);
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    graph.putService(CalendarServiceData.class, calendarServiceData);
    graph.updateTransitFeedValidity(calendarServiceData, issueStore);
    graph.hasTransit = true;
    graph.calculateTransitCenter();
}
Also used : CalendarServiceData(org.opentripplanner.model.calendar.CalendarServiceData) OtpTransitServiceBuilder(org.opentripplanner.model.impl.OtpTransitServiceBuilder) GeometryAndBlockProcessor(org.opentripplanner.graph_builder.module.geometry.GeometryAndBlockProcessor) NetexBundle(org.opentripplanner.netex.loader.NetexBundle) GtfsFeedId(org.opentripplanner.graph_builder.module.GtfsFeedId) OtpTransitService(org.opentripplanner.model.OtpTransitService) OtpTransitServiceBuilder(org.opentripplanner.model.impl.OtpTransitServiceBuilder)

Example 3 with CalendarServiceData

use of org.opentripplanner.model.calendar.CalendarServiceData in project OpenTripPlanner by opentripplanner.

the class CalendarServiceDataFactoryImpl method createData.

private CalendarServiceData createData() {
    CalendarServiceData data = new CalendarServiceData();
    setTimeZonesForAgencies(data);
    int index = 0;
    for (FeedScopedId serviceId : serviceIds) {
        index++;
        LOG.debug("serviceId=" + serviceId + " (" + index + "/" + serviceIds.size() + ")");
        TimeZone serviceIdTimeZone = data.getTimeZoneForAgencyId(data.getAgencyIds().stream().filter(agency -> agency.getFeedId().equals(serviceId.getFeedId())).findAny().orElse(null));
        if (serviceIdTimeZone == null) {
            serviceIdTimeZone = TimeZone.getDefault();
        }
        Set<ServiceDate> activeDates = getServiceDatesForServiceId(serviceId, serviceIdTimeZone);
        List<ServiceDate> serviceDates = new ArrayList<>(activeDates);
        Collections.sort(serviceDates);
        data.putServiceDatesForServiceId(serviceId, serviceDates);
    }
    return data;
}
Also used : CalendarServiceData(org.opentripplanner.model.calendar.CalendarServiceData) FeedScopedId(org.opentripplanner.model.FeedScopedId) Logger(org.slf4j.Logger) Date(java.util.Date) TimeZone(java.util.TimeZone) Collection(java.util.Collection) ServiceCalendar(org.opentripplanner.model.calendar.ServiceCalendar) LoggerFactory(org.slf4j.LoggerFactory) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) Set(java.util.Set) Agency(org.opentripplanner.model.Agency) ServiceDate(org.opentripplanner.model.calendar.ServiceDate) CalendarServiceData(org.opentripplanner.model.calendar.CalendarServiceData) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) List(java.util.List) Calendar(java.util.Calendar) Map(java.util.Map) ServiceCalendarDate(org.opentripplanner.model.calendar.ServiceCalendarDate) Collections(java.util.Collections) TimeZone(java.util.TimeZone) ServiceDate(org.opentripplanner.model.calendar.ServiceDate) ArrayList(java.util.ArrayList) FeedScopedId(org.opentripplanner.model.FeedScopedId)

Aggregations

CalendarServiceData (org.opentripplanner.model.calendar.CalendarServiceData)3 OtpTransitService (org.opentripplanner.model.OtpTransitService)2 OtpTransitServiceBuilder (org.opentripplanner.model.impl.OtpTransitServiceBuilder)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 TimeZone (java.util.TimeZone)1 Collectors.groupingBy (java.util.stream.Collectors.groupingBy)1 GtfsBundle (org.opentripplanner.graph_builder.model.GtfsBundle)1 GtfsFeedId (org.opentripplanner.graph_builder.module.GtfsFeedId)1 GeometryAndBlockProcessor (org.opentripplanner.graph_builder.module.geometry.GeometryAndBlockProcessor)1 Agency (org.opentripplanner.model.Agency)1 FeedScopedId (org.opentripplanner.model.FeedScopedId)1