Skip to content

Commit

Permalink
Report only used transit modes
Browse files Browse the repository at this point in the history
Revert parts of #4443
  • Loading branch information
hannesj committed Nov 14, 2022
1 parent f3639c2 commit 972180e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.util.stream.Collectors;
import org.opentripplanner.api.parameter.QualifiedModeSet;
import org.opentripplanner.model.GenericLocation;
import org.opentripplanner.routing.core.TraverseMode;
import org.opentripplanner.transit.model.basic.TransitMode;
import org.opentripplanner.transit.model.framework.FeedScopedId;
import org.opentripplanner.util.time.DurationUtils;
Expand Down Expand Up @@ -87,7 +86,7 @@ public void writeResultsToFile(List<TestCase> testCases) {
return;
}

try (PrintWriter out = new PrintWriter(expectedResultsOutputFile, CHARSET_UTF_8.name())) {
try (PrintWriter out = new PrintWriter(expectedResultsOutputFile, CHARSET_UTF_8)) {
out.println(
"tcId,nTransfers,duration,cost,walkDistance,startTime,endTime,agencies,modes,routes,stops,details"
);
Expand Down Expand Up @@ -260,7 +259,7 @@ private Result readExpectedResult(CsvReader csvReader) throws IOException {
parseTime(csvReader.get("startTime")),
parseTime(csvReader.get("endTime")),
str2Col(csvReader.get("agencies")),
str2Col(csvReader.get("modes"), CsvFileIO::parseMode),
str2Col(csvReader.get("modes"), TransitMode::valueOf),
str2Col(csvReader.get("routes")),
str2Col(csvReader.get("stops")),
csvReader.get("details")
Expand All @@ -276,12 +275,4 @@ private Result readExpectedResult(CsvReader csvReader) throws IOException {
private boolean isCommentOrEmpty(String line) {
return line.startsWith("#") || line.matches("[\\s,;|]*");
}

private static Enum<?> parseMode(String mode) {
try {
return TransitMode.valueOf(mode);
} catch (IllegalArgumentException ignore) {
return TraverseMode.valueOf(mode);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import java.util.stream.Collectors;
import org.opentripplanner.model.plan.Itinerary;
import org.opentripplanner.model.plan.Leg;
import org.opentripplanner.model.plan.StreetLeg;
import org.opentripplanner.model.plan.TransitLeg;
import org.opentripplanner.transit.model.basic.TransitMode;
import org.opentripplanner.transit.model.organization.Agency;
import org.opentripplanner.transit.model.site.StopLocation;
import org.opentripplanner.transit.raptor.api.path.PathStringBuilder;
Expand Down Expand Up @@ -111,16 +111,14 @@ private static String agencyShortName(Agency agency) {
private Result map(Itinerary itinerary) {
List<String> agencies = new ArrayList<>();
List<String> routes = new ArrayList<>();
Set<Enum<?>> modes = new HashSet<>();
Set<TransitMode> modes = new HashSet<>();
List<String> stops = new ArrayList<>();

for (Leg it : itinerary.getLegs()) {
if (it instanceof TransitLeg trLeg) {
agencies.add(agencyShortName(it.getAgency()));
routes.add(it.getRoute().getName());
modes.add(trLeg.getMode());
} else if (it instanceof StreetLeg streetLeg) {
modes.add(streetLeg.getMode());
}
if (it.getTo().stop != null) {
stops.add(it.getTo().stop.getId().toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import org.opentripplanner.transit.model.basic.TransitMode;
import org.opentripplanner.util.CompositeComparator;
import org.opentripplanner.util.time.DurationUtils;
import org.opentripplanner.util.time.TimeUtils;
Expand Down Expand Up @@ -52,7 +53,7 @@ class Result {
Integer startTime,
Integer endTime,
Collection<String> agencies,
Collection<Enum<?>> modes,
Collection<TransitMode> modes,
Collection<String> routes,
Collection<String> stops,
String details
Expand Down Expand Up @@ -130,7 +131,7 @@ private static <T> List<T> sortedList(Collection<T> values) {
return values.stream().sorted().distinct().toList();
}

private static <T extends Enum<?>> List<T> sortedModes(Collection<T> modes) {
return modes.stream().sorted(Comparator.comparing(l -> l.name())).distinct().toList();
private static List<TransitMode> sortedModes(Collection<TransitMode> modes) {
return modes.stream().sorted(Comparator.comparing(Enum::name)).distinct().toList();
}
}

0 comments on commit 972180e

Please sign in to comment.