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);
}
}
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();
}
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());
}
}
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);
}
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();
}
Aggregations