Search in sources :

Example 1 with CalendarServiceData

use of org.onebusaway.gtfs.model.calendar.CalendarServiceData in project onebusaway-application-modules by camsys.

the class CalendarServiceDataTask method run.

public void run() {
    CalendarServiceDataFactoryImpl factory = new CalendarServiceDataFactoryImpl();
    factory.setGtfsDao(_dao);
    factory.setExcludeFutureServiceDatesInDays(_excludeFutureServiceDatesInDays);
    CalendarServiceData data = factory.createData();
    data.makeReadOnly();
    try {
        ObjectSerializationLibrary.writeObject(_bundle.getCalendarServiceDataPath(), data);
        _refreshService.refresh(RefreshableResources.CALENDAR_DATA);
    } catch (IOException e) {
        throw new IllegalStateException("error serializing service calendar data", e);
    }
}
Also used : CalendarServiceData(org.onebusaway.gtfs.model.calendar.CalendarServiceData) IOException(java.io.IOException) CalendarServiceDataFactoryImpl(org.onebusaway.gtfs.impl.calendar.CalendarServiceDataFactoryImpl)

Example 2 with CalendarServiceData

use of org.onebusaway.gtfs.model.calendar.CalendarServiceData in project onebusaway-application-modules by camsys.

the class StopTimeServiceImplTest method setup.

@Before
public void setup() {
    _factory = new BlockIndexFactoryServiceImpl();
    _stop = stop("stopId", 47.0, -122.0);
    _stopId = _stop.getId();
    TransitGraphDao graph = Mockito.mock(TransitGraphDao.class);
    Mockito.when(graph.getStopEntryForId(_stop.getId(), true)).thenReturn(_stop);
    CalendarServiceData data = new CalendarServiceData();
    data.putDatesForLocalizedServiceId(lsid("sA"), Arrays.asList(date("2009-09-01 00:00"), date("2009-09-02 00:00")));
    data.putDatesForLocalizedServiceId(lsid("sB"), Arrays.asList(date("2009-09-03 00:00")));
    CalendarServiceImpl calendarService = new CalendarServiceImpl();
    calendarService.setData(data);
    _calendarService = new ExtendedCalendarServiceImpl();
    _calendarService.setCalendarService(calendarService);
    _blockIndexService = Mockito.mock(BlockIndexService.class);
    _service = new StopTimeServiceImpl();
    _service.setTransitGraphDao(graph);
    _service.setCalendarService(_calendarService);
    _service.setBlockIndexService(_blockIndexService);
    BlockConfigurationEntry bcA = blockConfiguration(block("bA"), serviceIds(lsids("sA"), lsids()));
    BlockConfigurationEntry bcB = blockConfiguration(block("bB"), serviceIds(lsids("sB"), lsids()));
    _transitGraphDao = Mockito.mock(TransitGraphDao.class);
    Mockito.when(_transitGraphDao.getAllBlocks()).thenReturn(Arrays.asList(bcA.getBlock(), bcB.getBlock()));
    _calendarService.setTransitGraphDao(_transitGraphDao);
    _calendarService.start();
}
Also used : CalendarServiceData(org.onebusaway.gtfs.model.calendar.CalendarServiceData) TransitGraphDao(org.onebusaway.transit_data_federation.services.transit_graph.TransitGraphDao) CalendarServiceImpl(org.onebusaway.gtfs.impl.calendar.CalendarServiceImpl) BlockIndexService(org.onebusaway.transit_data_federation.services.blocks.BlockIndexService) BlockIndexFactoryServiceImpl(org.onebusaway.transit_data_federation.impl.blocks.BlockIndexFactoryServiceImpl) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry) Before(org.junit.Before)

Example 3 with CalendarServiceData

use of org.onebusaway.gtfs.model.calendar.CalendarServiceData in project onebusaway-application-modules by camsys.

the class RefreshableCalendarServiceImpl method setup.

@PostConstruct
@Refreshable(dependsOn = RefreshableResources.CALENDAR_DATA)
public void setup() throws IOException, ClassNotFoundException {
    File path = _bundle.getCalendarServiceDataPath();
    if (path.exists()) {
        CalendarServiceData data = ObjectSerializationLibrary.readObject(path);
        setData(data);
    } else {
        setData(new CalendarServiceData());
    }
}
Also used : CalendarServiceData(org.onebusaway.gtfs.model.calendar.CalendarServiceData) File(java.io.File) Refreshable(org.onebusaway.container.refresh.Refreshable) PostConstruct(javax.annotation.PostConstruct)

Example 4 with CalendarServiceData

use of org.onebusaway.gtfs.model.calendar.CalendarServiceData in project onebusaway-application-modules by camsys.

the class BlockConfigurationEntriesFactoryTest method before.

@Before
public void before() {
    /**
     **
     * Calendar Service
     ***
     */
    _calendarService = new CalendarServiceImpl();
    CalendarServiceData data = new CalendarServiceData();
    _calendarService.setData(data);
    addServiceDates(data, "sA", new ServiceDate(2010, 9, 10), new ServiceDate(2010, 9, 11));
    addServiceDates(data, "sB", new ServiceDate(2010, 9, 11), new ServiceDate(2010, 9, 12));
    /**
     **
     * Service Id Cache
     ***
     */
    ServiceIdOverlapCache serviceIdOverlapCache = new ServiceIdOverlapCache();
    serviceIdOverlapCache.setCalendarService(_calendarService);
    /**
     **
     * ShapePointsService
     ***
     */
    ShapePointHelper shapePointService = Mockito.mock(ShapePointHelper.class);
    ShapePointsFactory shapePointsFactory = new ShapePointsFactory();
    shapePointsFactory.addPoint(0, 0);
    Mockito.when(shapePointService.getShapePointsForShapeId((AgencyAndId) Mockito.any())).thenReturn(shapePointsFactory.create());
    /**
     **
     * Factory
     ***
     */
    _factory = new BlockConfigurationEntriesFactory();
    _factory.setServiceIdOverlapCache(serviceIdOverlapCache);
    _factory.setShapePointHelper(shapePointService);
}
Also used : CalendarServiceData(org.onebusaway.gtfs.model.calendar.CalendarServiceData) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) ShapePointsFactory(org.onebusaway.transit_data_federation.model.ShapePointsFactory) CalendarServiceImpl(org.onebusaway.gtfs.impl.calendar.CalendarServiceImpl) ShapePointHelper(org.onebusaway.transit_data_federation.bundle.tasks.ShapePointHelper) Before(org.junit.Before)

Example 5 with CalendarServiceData

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

the class GtfsModule method buildGraph.

@Override
public void buildGraph(Graph graph, HashMap<Class<?>, Object> extra) {
    // 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();
    MultiCalendarServiceImpl service = new MultiCalendarServiceImpl();
    GtfsStopContext stopContext = new GtfsStopContext();
    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;
            GtfsMutableRelationalDao dao = new GtfsRelationalDaoImpl();
            GtfsContext context = GtfsLibrary.createContext(gtfsBundle.getFeedId(), dao, service);
            GTFSPatternHopFactory hf = new GTFSPatternHopFactory(context);
            hf.setStopContext(stopContext);
            hf.setFareServiceFactory(_fareServiceFactory);
            hf.setMaxStopToShapeSnapDistance(gtfsBundle.getMaxStopToShapeSnapDistance());
            loadBundle(gtfsBundle, graph, dao);
            CalendarServiceDataFactoryImpl csfactory = new CalendarServiceDataFactoryImpl();
            csfactory.setGtfsDao(dao);
            CalendarServiceData data = csfactory.createData();
            service.addData(data, dao);
            hf.subwayAccessTime = gtfsBundle.subwayAccessTime;
            hf.maxInterlineDistance = gtfsBundle.maxInterlineDistance;
            hf.run(graph);
            if (gtfsBundle.doesTransfersTxtDefineStationPaths()) {
                hf.createTransfersTxtTransfers();
            }
            if (gtfsBundle.linkStopsToParentStations) {
                hf.linkStopsToParentStations(graph);
            }
            if (gtfsBundle.parentStationTransfers) {
                hf.createParentStationTransfers();
            }
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    // We need to save the calendar service data so we can use it later
    CalendarServiceData data = service.getData();
    graph.putService(CalendarServiceData.class, data);
    graph.updateTransitFeedValidity(data);
    graph.hasTransit = true;
    graph.calculateTransitCenter();
}
Also used : GtfsMutableRelationalDao(org.onebusaway.gtfs.services.GtfsMutableRelationalDao) CalendarServiceData(org.onebusaway.gtfs.model.calendar.CalendarServiceData) GtfsBundle(org.opentripplanner.graph_builder.model.GtfsBundle) GtfsContext(org.opentripplanner.gtfs.GtfsContext) GtfsStopContext(org.opentripplanner.routing.edgetype.factory.GtfsStopContext) GtfsRelationalDaoImpl(org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl) GTFSPatternHopFactory(org.opentripplanner.routing.edgetype.factory.GTFSPatternHopFactory) IOException(java.io.IOException) CalendarServiceDataFactoryImpl(org.opentripplanner.calendar.impl.CalendarServiceDataFactoryImpl) MultiCalendarServiceImpl(org.opentripplanner.calendar.impl.MultiCalendarServiceImpl)

Aggregations

CalendarServiceData (org.onebusaway.gtfs.model.calendar.CalendarServiceData)24 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)14 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)10 CalendarServiceImpl (org.onebusaway.gtfs.impl.calendar.CalendarServiceImpl)7 Date (java.util.Date)6 Test (org.junit.Test)6 GtfsRelationalDaoImpl (org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl)6 Before (org.junit.Before)5 Agency (org.onebusaway.gtfs.model.Agency)5 LocalizedServiceId (org.onebusaway.gtfs.model.calendar.LocalizedServiceId)5 ArrayList (java.util.ArrayList)4 TimeZone (java.util.TimeZone)4 HashSet (java.util.HashSet)3 ServiceCalendarDate (org.onebusaway.gtfs.model.ServiceCalendarDate)3 IOException (java.io.IOException)2 CalendarServiceDataFactoryImpl (org.onebusaway.gtfs.impl.calendar.CalendarServiceDataFactoryImpl)2 ServiceCalendar (org.onebusaway.gtfs.model.ServiceCalendar)2 Trip (org.onebusaway.gtfs.model.Trip)2 ServiceInterval (org.onebusaway.gtfs.model.calendar.ServiceInterval)2 TransitGraphDao (org.onebusaway.transit_data_federation.services.transit_graph.TransitGraphDao)2