-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allow enabling and recording new results
- Enable opportunity temporal density, nearest n opportunities, and dual accessibility in AnalysisRequest and AnalysisWorkerTask - CSVResultWriter recording opportunity density and dual accessibility
- Loading branch information
Showing
9 changed files
with
134 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
src/main/java/com/conveyal/analysis/results/OpportunityCsvResultWriter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package com.conveyal.analysis.results; | ||
|
||
import com.conveyal.file.FileStorage; | ||
import com.conveyal.r5.analyst.cluster.RegionalTask; | ||
import com.conveyal.r5.analyst.cluster.RegionalWorkResult; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
/** | ||
* This handles collating regional results into CSV files containing temporal opportunity density | ||
* (number of opportunities reached in each one-minute interval, the derivative of step-function accessibility) | ||
* as well as "dual" accessibility (the amount of time needed to reach n opportunities). | ||
* And maybe the N closest opportunities to each origin? | ||
*/ | ||
public class OpportunityCsvResultWriter extends CsvResultWriter { | ||
|
||
private final int dualOpportunityCount; | ||
|
||
public OpportunityCsvResultWriter(RegionalTask task, FileStorage fileStorage) throws IOException { | ||
super(task, fileStorage); | ||
dualOpportunityCount = task.dualAccessibilityOpportunityThreshold; | ||
} | ||
|
||
@Override | ||
public CsvResultType resultType () { | ||
return CsvResultType.OPPORTUNITIES; | ||
} | ||
|
||
@Override | ||
public String[] columnHeaders () { | ||
List<String> headers = new ArrayList<>(); | ||
// The ids of the freeform origin point and destination set | ||
headers.add("originId"); | ||
headers.add("destId"); | ||
headers.add("percentile"); | ||
for (int m = 0; m < 120; m += 1) { | ||
// The opportunity density over travel minute m | ||
headers.add(Integer.toString(m)); | ||
} | ||
// The number of minutes needed to reach d destination opportunities | ||
headers.add("D" + dualOpportunityCount); | ||
return headers.toArray(new String[0]); | ||
} | ||
|
||
@Override | ||
protected void checkDimension (RegionalWorkResult workResult) { | ||
checkDimension(workResult, "destination pointsets", workResult.opportunitiesPerMinute.length, task.destinationPointSetKeys.length); | ||
for (double[][] percentilesForPointset : workResult.opportunitiesPerMinute) { | ||
checkDimension(workResult, "percentiles", percentilesForPointset.length, task.percentiles.length); | ||
for (double[] minutesForPercentile : percentilesForPointset) { | ||
checkDimension(workResult, "minutes", minutesForPercentile.length, 120); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public Iterable<String[]> rowValues (RegionalWorkResult workResult) { | ||
List<String> row = new ArrayList<>(125); | ||
String originId = task.originPointSet.getId(workResult.taskId); | ||
for (int d = 0; d < task.destinationPointSetKeys.length; d++) { | ||
int[][] percentilesForDestPointset = workResult.accessibilityValues[d]; | ||
for (int p = 0; p < task.percentiles.length; p++) { | ||
row.add(originId); | ||
row.add(task.destinationPointSets[d].name); | ||
row.add(Integer.toString(p)); | ||
int[] 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 < dualOpportunityCount) { | ||
sum += densitiesPerMinute[m]; | ||
m += 1; | ||
} | ||
row.add(Integer.toString(m >= 120 ? -1 : m)); | ||
} | ||
} | ||
} | ||
// 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])); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters