Skip to content

Commit

Permalink
Add feed id column to path results (sequel) (#936)
Browse files Browse the repository at this point in the history
* 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)
  • Loading branch information
ansoncfit authored Mar 21, 2024
1 parent 5aa45f5 commit e42274e
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 15 deletions.
9 changes: 7 additions & 2 deletions src/main/java/com/conveyal/r5/analyst/cluster/PathResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,15 @@ public class PathResult {
"routes",
"boardStops",
"alightStops",
"feedIds",
"rideTimes",
"accessTime",
"egressTime",
"transferTime",
"waitTimes",
"totalTime",
"nIterations"
"nIterations",
"group"
};

public PathResult(AnalysisWorkerTask task, TransitLayer transitLayer) {
Expand Down Expand Up @@ -140,7 +142,10 @@ public ArrayList<String[]>[] summarizeIterations(Stat stat) {
score = thisScore;
}
}
String[] row = ArrayUtils.addAll(path, transfer, waits, totalTime, String.valueOf(nIterations));
String group = ""; // Reserved for future use
String[] row = ArrayUtils.addAll(
path, transfer, waits, totalTime, String.valueOf(nIterations), group
);
checkState(row.length == DATA_COLUMNS.length);
summary[d].add(row);
}
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/conveyal/r5/transit/TransitLayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -873,4 +873,11 @@ public String stopString(int stopIndex, EntityRepresentation nameOrId) {
default -> stopId;
};
}

/**
* For a supplied stopIndex in the transit layer, return the feed id (which we prepend to the GTFS stop id).
*/
public String feedFromStop(int stopIndex) {
return stopIdForIndex.get(stopIndex) == null ? "[new]" : stopIdForIndex.get(stopIndex).split(":")[0];
}
}
40 changes: 27 additions & 13 deletions src/main/java/com/conveyal/r5/transit/path/RouteSequence.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,39 @@ public RouteSequence(PatternSequence patternSequence, TransitLayer transitLayer)
}
}

/** Returns details summarizing this route sequence, using GTFS ids stored in the supplied transitLayer. */
/**
* Returns details summarizing this route sequence, using GTFS ids stored in the supplied transitLayer.
* @param csvOptions indicates whether names or IDs should be returned for certain fields.
* @return array of pipe-concatenated strings, with the route, board stop, alight stop, ride time, and feed for
* each transit leg, as well as the access and egress time.
*
* If csvOptions.feedRepresentation is not null, the feed values will be R5-generated UUID for boarding stop of
* each leg. We are grabbing the feed ID from the stop rather than the route (which might seem like a better
* representative of the leg) because stops happen to have a readily available feed ID.
*/
public String[] detailsWithGtfsIds (TransitLayer transitLayer, CsvResultOptions csvOptions){
StringJoiner routeIds = new StringJoiner("|");
StringJoiner boardStopIds = new StringJoiner("|");
StringJoiner alightStopIds = new StringJoiner("|");
StringJoiner rideTimes = new StringJoiner("|");
StringJoiner routeJoiner = new StringJoiner("|");
StringJoiner boardStopJoiner = new StringJoiner("|");
StringJoiner alightStopJoiner = new StringJoiner("|");
StringJoiner feedJoiner = new StringJoiner("|");
StringJoiner rideTimeJoiner = new StringJoiner("|");
for (int i = 0; i < routes.size(); i++) {
routeIds.add(transitLayer.routeString(routes.get(i), csvOptions.routeRepresentation));
boardStopIds.add(transitLayer.stopString(stopSequence.boardStops.get(i), csvOptions.stopRepresentation));
alightStopIds.add(transitLayer.stopString(stopSequence.alightStops.get(i), csvOptions.stopRepresentation));
rideTimes.add(String.format("%.1f", stopSequence.rideTimesSeconds.get(i) / 60f));
routeJoiner.add(transitLayer.routeString(routes.get(i), csvOptions.routeRepresentation));
boardStopJoiner.add(transitLayer.stopString(stopSequence.boardStops.get(i), csvOptions.stopRepresentation));
alightStopJoiner.add(transitLayer.stopString(stopSequence.alightStops.get(i), csvOptions.stopRepresentation));
if (csvOptions.feedRepresentation != null) {
feedJoiner.add(transitLayer.feedFromStop(stopSequence.boardStops.get(i)));
}
rideTimeJoiner.add(String.format("%.1f", stopSequence.rideTimesSeconds.get(i) / 60f));
}
String accessTime = stopSequence.access == null ? null : String.format("%.1f", stopSequence.access.time / 60f);
String egressTime = stopSequence.egress == null ? null : String.format("%.1f", stopSequence.egress.time / 60f);
return new String[]{
routeIds.toString(),
boardStopIds.toString(),
alightStopIds.toString(),
rideTimes.toString(),
routeJoiner.toString(),
boardStopJoiner.toString(),
alightStopJoiner.toString(),
rideTimeJoiner.toString(),
feedJoiner.toString(),
accessTime,
egressTime
};
Expand Down

0 comments on commit e42274e

Please sign in to comment.