use of org.opentripplanner.standalone.CommandLineParameters in project OpenTripPlanner by opentripplanner.
the class RoutersTest method getRouterInfoReturnsFirstAndLastValidDateForGraph.
@Test
public void getRouterInfoReturnsFirstAndLastValidDateForGraph() {
final CalendarServiceData calendarService = new CalendarServiceData();
final List<ServiceDate> serviceDates = new ArrayList<ServiceDate>() {
{
add(new ServiceDate(2015, 10, 1));
add(new ServiceDate(2015, 11, 1));
}
};
calendarService.putServiceDatesForServiceId(new AgencyAndId("NA", "1"), serviceDates);
final Graph graph = new Graph();
graph.updateTransitFeedValidity(calendarService);
graph.expandToInclude(0, 100);
OTPServer otpServer = new OTPServer(new CommandLineParameters(), new GraphService());
otpServer.getGraphService().registerGraph("A", new MemoryGraphSource("A", graph));
Routers routerApi = new Routers();
routerApi.otpServer = otpServer;
RouterInfo info = routerApi.getGraphId("A");
assertNotNull(info.transitServiceStarts);
assertNotNull(info.transitServiceEnds);
assertTrue(info.transitServiceStarts < info.transitServiceEnds);
}
use of org.opentripplanner.standalone.CommandLineParameters in project OpenTripPlanner by opentripplanner.
the class OtpsEntryPoint method fromArgs.
/**
* Create an OTP scripting entry point using the same command-line parameters as used by the OTP
* application. This is useful when using scripting from an outside environment, using OTP as a
* library. For example in jython the following script 'myscript.py':
*
* <pre>
* #!/usr/bin/jython
* from org.opentripplanner.scripting.api import OtpsEntryPoint
* otp = OtpsEntryPoint.fromArgs([ "-g", "." ])
* ...
* </pre>
*
* One can then run jython with:
*
* <pre>
* CLASSPATH=otp.jar jython myscript.py
* </pre>
*
* @param args Command-line arguments, as used by the application.
* @return The "otp" scripting facade bean.
* @throws Exception
*/
public static OtpsEntryPoint fromArgs(String[] args) throws Exception {
if (args == null)
args = new String[0];
CommandLineParameters params = new CommandLineParameters();
@SuppressWarnings("unused") JCommander jc = new JCommander(params, args);
// Force analyst
params.analyst = true;
params.infer();
OTPMain otpMain = new OTPMain(params);
if (// TODO Enable this
params.build != null)
throw new IllegalArgumentException("Building from script is not yet supported.");
if (// This would be weird
params.scriptFile != null)
throw new IllegalArgumentException("Scripting from script is not supported.");
if (// Useless
params.visualize)
throw new IllegalArgumentException("Vizualizer from script is not supported.");
if (// Why not?
params.server)
throw new IllegalArgumentException("Server from script is not supported.");
otpMain.run();
return new OtpsEntryPoint(otpMain.otpServer);
}
use of org.opentripplanner.standalone.CommandLineParameters in project OpenTripPlanner by opentripplanner.
the class RoutersTest method testRouters.
@Test
public void testRouters() {
OTPServer otpServer = new OTPServer(new CommandLineParameters(), new GraphService());
otpServer.getGraphService().registerGraph("", new MemoryGraphSource(null, new Graph()));
otpServer.getGraphService().registerGraph("A", new MemoryGraphSource("", new Graph()));
otpServer.getGraphService().getRouter("A").graph.addVertex(new ExitVertex(null, "A", 0, 0, 0));
otpServer.getGraphService().getRouter("A").graph.addVertex(new ExitVertex(null, "B", 0, 1, 0));
otpServer.getGraphService().getRouter("A").graph.addVertex(new ExitVertex(null, "C", 1, 1, 0));
// this needs to be added since convex hull isn't lazy loaded anymore
otpServer.getGraphService().getRouter("A").graph.calculateConvexHull();
otpServer.getGraphService().getRouter("").graph.calculateConvexHull();
// this needs to be added since it is otherwise calculated during OSM/Transit loading
// which doesn't happen in this test
otpServer.getGraphService().getRouter("A").graph.calculateEnvelope();
otpServer.getGraphService().getRouter("").graph.calculateEnvelope();
Routers routerApi = new Routers();
routerApi.otpServer = otpServer;
RouterList routers = routerApi.getRouterIds();
assertEquals(2, routers.routerInfo.size());
RouterInfo router0 = routers.routerInfo.get(0);
RouterInfo router1 = routers.routerInfo.get(1);
RouterInfo otherRouter;
RouterInfo defaultRouter;
if (router0.routerId.equals("")) {
defaultRouter = router0;
otherRouter = router1;
} else {
defaultRouter = router1;
otherRouter = router0;
}
assertEquals("", defaultRouter.routerId);
assertEquals("A", otherRouter.routerId);
assertTrue(otherRouter.polygon.getArea() > 0);
}
use of org.opentripplanner.standalone.CommandLineParameters in project OpenTripPlanner by opentripplanner.
the class ClusterGraphBuilder method getGraph.
/**
* Return the graph for the given unique identifier for graph builder inputs on S3.
* If this is the same as the last graph built, just return the pre-built graph.
* If not, build the graph from the inputs, fetching them from S3 to the local cache as needed.
*/
public synchronized Graph getGraph(String graphId) {
LOG.info("Finding a graph for ID {}", graphId);
if (graphId.equals(currGraphId)) {
LOG.info("GraphID has not changed. Reusing the last graph that was built.");
return currGraph;
}
// The location of the inputs that will be used to build this graph
File graphDataDirectory = new File(GRAPH_CACHE_DIR, graphId);
// If we don't have a local copy of the inputs, fetch graph data as a ZIP from S3 and unzip it
if (!graphDataDirectory.exists() || graphDataDirectory.list().length == 0) {
LOG.info("Downloading graph input files.");
graphDataDirectory.mkdirs();
S3Object graphDataZipObject = s3.getObject(graphBucket, graphId + ".zip");
ZipInputStream zis = new ZipInputStream(graphDataZipObject.getObjectContent());
try {
ZipEntry entry;
while ((entry = zis.getNextEntry()) != null) {
File entryDestination = new File(graphDataDirectory, entry.getName());
// Are both these mkdirs calls necessary?
entryDestination.getParentFile().mkdirs();
if (entry.isDirectory())
entryDestination.mkdirs();
else {
OutputStream entryFileOut = new FileOutputStream(entryDestination);
IOUtils.copy(zis, entryFileOut);
entryFileOut.close();
}
}
zis.close();
} catch (Exception e) {
// TODO delete graph cache dir which is probably corrupted
LOG.info("Error retrieving graph files", e);
}
} else {
LOG.info("Graph input files were found locally. Using these files from the cache.");
}
// Now we have a local copy of these graph inputs. Make a graph out of them.
CommandLineParameters params = new CommandLineParameters();
params.build = new File(GRAPH_CACHE_DIR, graphId);
params.inMemory = true;
GraphBuilder graphBuilder = GraphBuilder.forDirectory(params, params.build);
graphBuilder.run();
Graph graph = graphBuilder.getGraph();
graph.routerId = graphId;
graph.index(new DefaultStreetVertexIndexFactory());
graph.index.clusterStopsAsNeeded();
this.currGraphId = graphId;
this.currGraph = graph;
return graph;
}
Aggregations