Skip to content

Commit

Permalink
consistent naming, comments, fix csv writer
Browse files Browse the repository at this point in the history
  • Loading branch information
abyrd committed Aug 17, 2023
1 parent e8944ef commit e688365
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 25 deletions.
15 changes: 10 additions & 5 deletions src/main/java/com/conveyal/analysis/models/AnalysisRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,16 @@ public class AnalysisRequest {
/**
* Whether to include the number of opportunities reached during each minute of travel in results sent back
* to the broker. Requires both an origin and destination pointset to be specified, and in the case of regional
* analyses the origins must be non-gridded. (Should be possible to make a grid as well.)
* analyses the origins must be non-gridded, and results will be collated to CSV.
* It should be possible to enable regional results for gridded origins as well.
*/
public boolean opportunityTemporalDensity = false;
public boolean includeTemporalDensity = false;

public int dualAccessibilityOpportunityThreshold = 0;
/**
* If this is set to a value above zero, report the amount of time needed to reach the given number of
* opportunities from this origin (known technically as "dual accessibility").
*/
public int dualAccessibilityThreshold = 0;


/**
Expand Down Expand Up @@ -276,8 +281,8 @@ public void populateTask (AnalysisWorkerTask task, UserPermissions userPermissio
}
}

task.includeTemporalDensity = opportunityTemporalDensity;
task.dualAccessibilityThreshold = dualAccessibilityOpportunityThreshold;
task.includeTemporalDensity = includeTemporalDensity;
task.dualAccessibilityThreshold = dualAccessibilityThreshold;
}

private EnumSet<LegMode> getEnumSetFromString (String s) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
* do serve to enumerate the acceptable parameters coming over the HTTP API.
*/
public enum CsvResultType {
ACCESS, TIMES, PATHS, OPPORTUNITIES
ACCESS, TIMES, PATHS, TDENSITY
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,10 @@ public MultiOriginAssembler (RegionalAnalysis regionalAnalysis, Job job, FileSto

if (job.templateTask.recordAccessibility) {
if (job.templateTask.originPointSet != null) {
// Freeform origins - create CSV regional analysis results
resultWriters.add(new AccessCsvResultWriter(job.templateTask, fileStorage));
} else {
// Gridded origins - create gridded regional analysis results
resultWriters.add(new MultiGridResultWriter(regionalAnalysis, job.templateTask, fileStorage));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public TemporalDensityCsvResultWriter(RegionalTask task, FileStorage fileStorage

@Override
public CsvResultType resultType () {
return CsvResultType.OPPORTUNITIES;
return CsvResultType.TDENSITY;
}

@Override
Expand Down Expand Up @@ -59,33 +59,32 @@ protected void checkDimension (RegionalWorkResult workResult) {

@Override
public Iterable<String[]> rowValues (RegionalWorkResult workResult) {
List<String> row = new ArrayList<>(125);
List<String[]> rows = new ArrayList<>();
String originId = task.originPointSet.getId(workResult.taskId);
for (int d = 0; d < task.destinationPointSetKeys.length; d++) {
int[][] percentilesForDestPointset = workResult.accessibilityValues[d];
double[][] percentilesForDestPointset = workResult.opportunitiesPerMinute[d];
for (int p = 0; p < task.percentiles.length; p++) {
List<String> row = new ArrayList<>(125);
row.add(originId);
row.add(task.destinationPointSets[d].name);
row.add(task.destinationPointSetKeys[d]);
row.add(Integer.toString(p));
int[] densitiesPerMinute = percentilesForDestPointset[p];
// One density value for each of 120 minutes
double[] densitiesPerMinute = percentilesForDestPointset[p];
for (int m = 0; m < 120; m++) {
row.add(Double.toString(densitiesPerMinute[m]));
}
// Dual accessibility
{
int m = 0;
double sum = 0;
while (sum < dualThreshold) {
sum += densitiesPerMinute[m];
m += 1;
}
row.add(Integer.toString(m >= 120 ? -1 : m));
// One dual accessibility value
int m = 0;
double sum = 0;
while (sum < dualThreshold && m < 120) {
sum += densitiesPerMinute[m];
m += 1;
}
row.add(Integer.toString(m >= 120 ? -1 : m));
rows.add(row.toArray(new String[row.size()]));
}
}
// List.of() or Arrays.asList() don't work without explicitly specifying the generic type because
// they interpret the String[] as varargs in the method signature.
return List.<String[]>of(row.toArray(new String[0]));
return rows;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class TemporalDensityResult {

private final PointSet[] destinationPointSets;
private final int nPercentiles;
private final int opportunityThreshold;

// Externally visible fields for accumulating results

Expand All @@ -44,6 +45,7 @@ public TemporalDensityResult(AnalysisWorkerTask task) {
);
this.destinationPointSets = task.destinationPointSets;
this.nPercentiles = task.percentiles.length;
this.opportunityThreshold = task.dualAccessibilityThreshold;
this.opportunitiesPerMinute = new double[destinationPointSets.length][nPercentiles][120];
}

Expand All @@ -66,7 +68,8 @@ public void recordOneTarget (int target, int[] travelTimePercentilesSeconds) {
/**
* Calculate "dual" accessibility from the accumulated temporal opportunity density array.
* @param n the threshold quantity of opportunities
* @return the number of minutes it takes to reach n opportunities, for each destination set and percentile of travel time.
* @return the minimum whole number of minutes necessary to reach n opportunities,
* for each destination set and percentile of travel time.
*/
public int[][] minutesToReachOpportunities(int n) {
int[][] result = new int[destinationPointSets.length][nPercentiles];
Expand All @@ -86,4 +89,8 @@ public int[][] minutesToReachOpportunities(int n) {
return result;
}

public int[][] minutesToReachOpportunities() {
return minutesToReachOpportunities(opportunityThreshold);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,6 @@ public static void addJsonToGrid (
}
if (oneOriginResult.density != null) {
jsonBlock.opportunitiesPerMinute = oneOriginResult.density.opportunitiesPerMinute;
LOG.info("Opportunities per minute: {}", oneOriginResult.density.opportunitiesPerMinute);
}
}
LOG.debug("Travel time surface written, appending {}.", jsonBlock);
Expand Down

0 comments on commit e688365

Please sign in to comment.