Skip to content

Commit e42274e

Browse files
authored
Add feed id column to path results (sequel) (#936)
* Write feedIds as separate column feedIds are derived from boarding stops * Add "group" column in CSV path results For future use (see #924, for example)
1 parent 5aa45f5 commit e42274e

File tree

3 files changed

+41
-15
lines changed

3 files changed

+41
-15
lines changed

src/main/java/com/conveyal/r5/analyst/cluster/PathResult.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,15 @@ public class PathResult {
5757
"routes",
5858
"boardStops",
5959
"alightStops",
60+
"feedIds",
6061
"rideTimes",
6162
"accessTime",
6263
"egressTime",
6364
"transferTime",
6465
"waitTimes",
6566
"totalTime",
66-
"nIterations"
67+
"nIterations",
68+
"group"
6769
};
6870

6971
public PathResult(AnalysisWorkerTask task, TransitLayer transitLayer) {
@@ -140,7 +142,10 @@ public ArrayList<String[]>[] summarizeIterations(Stat stat) {
140142
score = thisScore;
141143
}
142144
}
143-
String[] row = ArrayUtils.addAll(path, transfer, waits, totalTime, String.valueOf(nIterations));
145+
String group = ""; // Reserved for future use
146+
String[] row = ArrayUtils.addAll(
147+
path, transfer, waits, totalTime, String.valueOf(nIterations), group
148+
);
144149
checkState(row.length == DATA_COLUMNS.length);
145150
summary[d].add(row);
146151
}

src/main/java/com/conveyal/r5/transit/TransitLayer.java

+7
Original file line numberDiff line numberDiff line change
@@ -873,4 +873,11 @@ public String stopString(int stopIndex, EntityRepresentation nameOrId) {
873873
default -> stopId;
874874
};
875875
}
876+
877+
/**
878+
* For a supplied stopIndex in the transit layer, return the feed id (which we prepend to the GTFS stop id).
879+
*/
880+
public String feedFromStop(int stopIndex) {
881+
return stopIdForIndex.get(stopIndex) == null ? "[new]" : stopIdForIndex.get(stopIndex).split(":")[0];
882+
}
876883
}

src/main/java/com/conveyal/r5/transit/path/RouteSequence.java

+27-13
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,39 @@ public RouteSequence(PatternSequence patternSequence, TransitLayer transitLayer)
3131
}
3232
}
3333

34-
/** Returns details summarizing this route sequence, using GTFS ids stored in the supplied transitLayer. */
34+
/**
35+
* Returns details summarizing this route sequence, using GTFS ids stored in the supplied transitLayer.
36+
* @param csvOptions indicates whether names or IDs should be returned for certain fields.
37+
* @return array of pipe-concatenated strings, with the route, board stop, alight stop, ride time, and feed for
38+
* each transit leg, as well as the access and egress time.
39+
*
40+
* If csvOptions.feedRepresentation is not null, the feed values will be R5-generated UUID for boarding stop of
41+
* each leg. We are grabbing the feed ID from the stop rather than the route (which might seem like a better
42+
* representative of the leg) because stops happen to have a readily available feed ID.
43+
*/
3544
public String[] detailsWithGtfsIds (TransitLayer transitLayer, CsvResultOptions csvOptions){
36-
StringJoiner routeIds = new StringJoiner("|");
37-
StringJoiner boardStopIds = new StringJoiner("|");
38-
StringJoiner alightStopIds = new StringJoiner("|");
39-
StringJoiner rideTimes = new StringJoiner("|");
45+
StringJoiner routeJoiner = new StringJoiner("|");
46+
StringJoiner boardStopJoiner = new StringJoiner("|");
47+
StringJoiner alightStopJoiner = new StringJoiner("|");
48+
StringJoiner feedJoiner = new StringJoiner("|");
49+
StringJoiner rideTimeJoiner = new StringJoiner("|");
4050
for (int i = 0; i < routes.size(); i++) {
41-
routeIds.add(transitLayer.routeString(routes.get(i), csvOptions.routeRepresentation));
42-
boardStopIds.add(transitLayer.stopString(stopSequence.boardStops.get(i), csvOptions.stopRepresentation));
43-
alightStopIds.add(transitLayer.stopString(stopSequence.alightStops.get(i), csvOptions.stopRepresentation));
44-
rideTimes.add(String.format("%.1f", stopSequence.rideTimesSeconds.get(i) / 60f));
51+
routeJoiner.add(transitLayer.routeString(routes.get(i), csvOptions.routeRepresentation));
52+
boardStopJoiner.add(transitLayer.stopString(stopSequence.boardStops.get(i), csvOptions.stopRepresentation));
53+
alightStopJoiner.add(transitLayer.stopString(stopSequence.alightStops.get(i), csvOptions.stopRepresentation));
54+
if (csvOptions.feedRepresentation != null) {
55+
feedJoiner.add(transitLayer.feedFromStop(stopSequence.boardStops.get(i)));
56+
}
57+
rideTimeJoiner.add(String.format("%.1f", stopSequence.rideTimesSeconds.get(i) / 60f));
4558
}
4659
String accessTime = stopSequence.access == null ? null : String.format("%.1f", stopSequence.access.time / 60f);
4760
String egressTime = stopSequence.egress == null ? null : String.format("%.1f", stopSequence.egress.time / 60f);
4861
return new String[]{
49-
routeIds.toString(),
50-
boardStopIds.toString(),
51-
alightStopIds.toString(),
52-
rideTimes.toString(),
62+
routeJoiner.toString(),
63+
boardStopJoiner.toString(),
64+
alightStopJoiner.toString(),
65+
rideTimeJoiner.toString(),
66+
feedJoiner.toString(),
5367
accessTime,
5468
egressTime
5569
};

0 commit comments

Comments
 (0)