use of org.opentripplanner.gtfs.GtfsContext 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();
}
use of org.opentripplanner.gtfs.GtfsContext in project OpenTripPlanner by opentripplanner.
the class TestHopFactory method setUp.
public void setUp() throws Exception {
GtfsContext context = GtfsLibrary.readGtfs(new File(ConstantsForTests.FAKE_GTFS));
graph = new Graph();
GTFSPatternHopFactory factory = new GTFSPatternHopFactory(context);
factory.run(graph);
graph.putService(CalendarServiceData.class, GtfsLibrary.createCalendarServiceData(context.getDao()));
feedId = context.getFeedId().getId();
}
use of org.opentripplanner.gtfs.GtfsContext in project OpenTripPlanner by opentripplanner.
the class TestFares method testKCM.
public void testKCM() throws Exception {
Graph gg = new Graph();
GtfsContext context = GtfsLibrary.readGtfs(new File(ConstantsForTests.KCM_GTFS));
GTFSPatternHopFactory factory = new GTFSPatternHopFactory(context);
factory.setFareServiceFactory(new SeattleFareServiceFactory());
factory.run(gg);
gg.putService(CalendarServiceData.class, GtfsLibrary.createCalendarServiceData(context.getDao()));
RoutingRequest options = new RoutingRequest();
String feedId = gg.getFeedIds().iterator().next();
String vertex0 = feedId + ":2010";
String vertex1 = feedId + ":2140";
ShortestPathTree spt;
GraphPath path = null;
FareService fareService = gg.getService(FareService.class);
long offPeakStartTime = TestUtils.dateInSeconds("America/Los_Angeles", 2016, 5, 24, 5, 0, 0);
options.dateTime = offPeakStartTime;
options.setRoutingContext(gg, vertex0, vertex1);
spt = aStar.getShortestPathTree(options);
path = spt.getPath(gg.getVertex(vertex1), true);
Fare costOffPeak = fareService.getCost(path);
assertEquals(costOffPeak.getFare(FareType.regular), new Money(new WrappedCurrency("USD"), 250));
long onPeakStartTime = TestUtils.dateInSeconds("America/Los_Angeles", 2016, 5, 24, 8, 0, 0);
options.dateTime = onPeakStartTime;
options.setRoutingContext(gg, vertex0, vertex1);
spt = aStar.getShortestPathTree(options);
path = spt.getPath(gg.getVertex(vertex1), true);
Fare costOnPeak = fareService.getCost(path);
assertEquals(costOnPeak.getFare(FareType.regular), new Money(new WrappedCurrency("USD"), 275));
}
use of org.opentripplanner.gtfs.GtfsContext in project OpenTripPlanner by opentripplanner.
the class TestFares method testBasic.
public void testBasic() throws Exception {
Graph gg = new Graph();
GtfsContext context = GtfsLibrary.readGtfs(new File(ConstantsForTests.CALTRAIN_GTFS));
GTFSPatternHopFactory factory = new GTFSPatternHopFactory(context);
factory.run(gg);
gg.putService(CalendarServiceData.class, GtfsLibrary.createCalendarServiceData(context.getDao()));
RoutingRequest options = new RoutingRequest();
String feedId = gg.getFeedIds().iterator().next();
long startTime = TestUtils.dateInSeconds("America/Los_Angeles", 2009, 8, 7, 12, 0, 0);
options.dateTime = startTime;
options.setRoutingContext(gg, feedId + ":Millbrae Caltrain", feedId + ":Mountain View Caltrain");
ShortestPathTree spt;
GraphPath path = null;
spt = aStar.getShortestPathTree(options);
path = spt.getPath(gg.getVertex(feedId + ":Mountain View Caltrain"), true);
FareService fareService = gg.getService(FareService.class);
Fare cost = fareService.getCost(path);
assertEquals(cost.getFare(FareType.regular), new Money(new WrappedCurrency("USD"), 425));
}
use of org.opentripplanner.gtfs.GtfsContext in project OpenTripPlanner by opentripplanner.
the class TestGraphPath method setUp.
public void setUp() throws Exception {
GtfsContext context = GtfsLibrary.readGtfs(new File(ConstantsForTests.FAKE_GTFS));
graph = new Graph();
GTFSPatternHopFactory hl = new GTFSPatternHopFactory(context);
hl.run(graph);
graph.putService(CalendarServiceData.class, GtfsLibrary.createCalendarServiceData(context.getDao()));
}
Aggregations