use of org.opentripplanner.analyst.ResultSet in project OpenTripPlanner by opentripplanner.
the class TNPropagatedTimesStore method makeIsochroneForVertices.
/**
* This bypasses a bunch of TimeSurface conversion/copy steps we were going though and makes the isochrones directly.
* This assumes that the target indexes in this router/propagatedTimesStore are vertex indexes, not pointset indexes.
* Called three times on min/avg/max to create the three elements of a ResultEnvelope.
*/
private ResultSet makeIsochroneForVertices(int[] times) {
final int spacing = 5;
final int nMax = 24;
final int cutoffMinutes = 120;
final int offroadDistanceMeters = 250;
SparseMatrixZSampleGrid<WTWD> grid = makeSampleGridForVertices(times, offroadDistanceMeters);
long t0 = System.currentTimeMillis();
DelaunayIsolineBuilder<WTWD> isolineBuilder = new DelaunayIsolineBuilder<>(grid.delaunayTriangulate(), new WTWD.IsolineMetric());
List<IsochroneData> isoData = new ArrayList<IsochroneData>();
for (int minutes = spacing, n = 0; minutes <= cutoffMinutes && n < nMax; minutes += spacing, n++) {
int seconds = minutes * 60;
WTWD z0 = new WTWD();
z0.w = 1.0;
z0.wTime = seconds;
z0.d = offroadDistanceMeters;
IsochroneData isochrone = new IsochroneData(seconds, isolineBuilder.computeIsoline(z0));
isoData.add(isochrone);
}
long t1 = System.currentTimeMillis();
ResultSet resultSet = new ResultSet();
resultSet.isochrones = new IsochroneData[isoData.size()];
isoData.toArray(resultSet.isochrones);
LOG.debug("Computed {} isochrones in {} msec", isoData.size(), (int) (t1 - t0));
return resultSet;
}
use of org.opentripplanner.analyst.ResultSet in project OpenTripPlanner by opentripplanner.
the class ResultEnvelope method explode.
/**
* Explode this result envelope into a result envelope for each contained attribute
* We do this because we need to retrieve all of the values for a particular variable quickly, in order to display the map,
* and looping over 10GB of data to do this is not tractable.
*/
public Map<String, ResultEnvelope> explode() {
Map<String, ResultEnvelope> exploded = new HashMap<String, ResultEnvelope>();
// find a non-null resultset
for (String attr : (pointEstimate != null ? pointEstimate : avgCase).histograms.keySet()) {
ResultEnvelope env = new ResultEnvelope();
for (Which which : Which.values()) {
ResultSet orig = this.get(which);
if (orig != null) {
ResultSet rs = new ResultSet();
rs.id = orig.id;
rs.histograms.put(attr, orig.histograms.get(attr));
env.put(which, rs);
env.id = this.id;
}
}
exploded.put(attr, env);
}
return exploded;
}
use of org.opentripplanner.analyst.ResultSet in project OpenTripPlanner by opentripplanner.
the class SurfaceResource method getIndicator.
/**
* Evaluate a surface at all the points in a PointSet.
* This sends back a ResultSet serialized as JSON.
* Normally we return historgrams with the number of points reached (in field 'counts') and the number of
* opportunities reached (i.e. the sum of the magnitudes of all points reached) in each one-minute bin of travel
* time.
* @param detail if true, include the travel time to every point in the pointset (which is in fact an ordered list)
*/
@GET
@Path("/{surfaceId}/indicator")
public Response getIndicator(@PathParam("surfaceId") Integer surfaceId, @QueryParam("targets") String targetPointSetId, @QueryParam("origins") String originPointSetId, @QueryParam("detail") boolean detail) {
final TimeSurface surf = otpServer.surfaceCache.get(surfaceId);
if (surf == null)
return badRequest("Invalid TimeSurface ID.");
final PointSet pset = otpServer.pointSetCache.get(targetPointSetId);
if (pset == null)
return badRequest("Missing or invalid target PointSet ID.");
Router router = otpServer.getRouter(surf.routerId);
// TODO cache this sampleset
SampleSet samples = pset.getSampleSet(router.graph);
final ResultSet indicator = new ResultSet(samples, surf, detail, detail);
if (indicator == null)
return badServer("Could not compute indicator as requested.");
return Response.ok().entity(new StreamingOutput() {
@Override
public void write(OutputStream output) throws IOException, WebApplicationException {
indicator.writeJson(output);
}
}).build();
}
use of org.opentripplanner.analyst.ResultSet in project OpenTripPlanner by opentripplanner.
the class PropagatedTimesStore method makeIsochroneForVertices.
/**
* This bypasses a bunch of TimeSurface conversion/copy steps we were going though and makes the isochrones directly.
* This assumes that the target indexes in this router/propagatedTimesStore are vertex indexes, not pointset indexes.
* Called three times on min/avg/max to create the three elements of a ResultEnvelope.
*/
private ResultSet makeIsochroneForVertices(int[] times) {
final int spacing = 5;
final int nMax = 24;
final int cutoffMinutes = 120;
final double gridSize = IsochroneGenerator.GRID_SIZE_METERS;
final double offroadDistanceMeters = gridSize * IsochroneGenerator.WALK_DISTANCE_GRID_SIZE_RATIO;
SparseMatrixZSampleGrid<WTWD> grid = makeSampleGridForVertices(times, gridSize);
long t0 = System.currentTimeMillis();
DelaunayIsolineBuilder<WTWD> isolineBuilder = new DelaunayIsolineBuilder<>(grid.delaunayTriangulate(), new WTWD.IsolineMetric());
List<IsochroneData> isoData = new ArrayList<IsochroneData>();
for (int minutes = spacing, n = 0; minutes <= cutoffMinutes && n < nMax; minutes += spacing, n++) {
int seconds = minutes * 60;
WTWD z0 = new WTWD();
z0.w = 1.0;
z0.wTime = seconds;
z0.d = offroadDistanceMeters;
IsochroneData isochrone = new IsochroneData(seconds, isolineBuilder.computeIsoline(z0));
isoData.add(isochrone);
}
long t1 = System.currentTimeMillis();
ResultSet resultSet = new ResultSet();
resultSet.isochrones = new IsochroneData[isoData.size()];
isoData.toArray(resultSet.isochrones);
LOG.debug("Computed {} isochrones in {} msec", isoData.size(), (int) (t1 - t0));
return resultSet;
}
use of org.opentripplanner.analyst.ResultSet in project OpenTripPlanner by opentripplanner.
the class PropagatedTimesStore method makeResults.
/**
* Make a ResultEnvelope directly from a given SampleSet.
* The RaptorWorkerData must have been constructed from the same SampleSet.
*/
public ResultEnvelope makeResults(SampleSet ss, boolean includeTimes, boolean includeHistograms, boolean includeIsochrones) {
ResultEnvelope envelope = new ResultEnvelope();
// max times == worst case accessibility
envelope.worstCase = new ResultSet(maxs, ss.pset, includeTimes, includeHistograms, includeIsochrones);
envelope.avgCase = new ResultSet(avgs, ss.pset, includeTimes, includeHistograms, includeIsochrones);
envelope.bestCase = new ResultSet(mins, ss.pset, includeTimes, includeHistograms, includeIsochrones);
return envelope;
}
Aggregations