-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add option to include stations in nearest
search
#5390
Changes from 33 commits
c2d17db
b3ce4df
327067d
a2a3bb4
94ea8c3
e860a68
699bb47
895085f
d367d1a
1dc5cf8
a18d52d
128e738
681ab33
8176433
0ed2305
1b0c379
925008c
a54231b
c0a9df3
0b57c58
b2f04a0
a5fa1f4
e5892a2
b373fc8
3f51bb6
b4dff93
a08b8e4
bd20cba
7092574
8627c7e
1bc6785
57d064c
fb202d8
fd1973d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -29,6 +29,7 @@ public class PlaceFinderTraverseVisitor implements TraverseVisitor<State, Edge> | |||||||||
private final TransitService transitService; | ||||||||||
private final Set<TransitMode> filterByModes; | ||||||||||
private final Set<FeedScopedId> filterByStops; | ||||||||||
private final Set<FeedScopedId> filterByStations; | ||||||||||
private final Set<FeedScopedId> filterByRoutes; | ||||||||||
private final Set<String> filterByVehicleRental; | ||||||||||
private final Set<String> seenPatternAtStops = new HashSet<>(); | ||||||||||
|
@@ -40,6 +41,7 @@ public class PlaceFinderTraverseVisitor implements TraverseVisitor<State, Edge> | |||||||||
private final boolean includeVehicleRentals; | ||||||||||
private final boolean includeCarParking; | ||||||||||
private final boolean includeBikeParking; | ||||||||||
private final boolean includeStations; | ||||||||||
private final int maxResults; | ||||||||||
private final double radiusMeters; | ||||||||||
|
||||||||||
|
@@ -64,23 +66,31 @@ public PlaceFinderTraverseVisitor( | |||||||||
List<TransitMode> filterByModes, | ||||||||||
List<PlaceType> filterByPlaceTypes, | ||||||||||
List<FeedScopedId> filterByStops, | ||||||||||
List<FeedScopedId> filterByStations, | ||||||||||
List<FeedScopedId> filterByRoutes, | ||||||||||
List<String> filterByBikeRentalStations, | ||||||||||
int maxResults, | ||||||||||
double radiusMeters | ||||||||||
) { | ||||||||||
if (filterByPlaceTypes == null || filterByPlaceTypes.isEmpty()) { | ||||||||||
throw new IllegalArgumentException("No place type filter was included in request"); | ||||||||||
} | ||||||||||
this.transitService = transitService; | ||||||||||
|
||||||||||
this.filterByModes = toSet(filterByModes); | ||||||||||
this.filterByStops = toSet(filterByStops); | ||||||||||
this.filterByStations = toSet(filterByStations); | ||||||||||
this.filterByRoutes = toSet(filterByRoutes); | ||||||||||
this.filterByVehicleRental = toSet(filterByBikeRentalStations); | ||||||||||
|
||||||||||
includeStops = shouldInclude(filterByPlaceTypes, PlaceType.STOP); | ||||||||||
|
||||||||||
includePatternAtStops = shouldInclude(filterByPlaceTypes, PlaceType.PATTERN_AT_STOP); | ||||||||||
includeVehicleRentals = shouldInclude(filterByPlaceTypes, PlaceType.VEHICLE_RENT); | ||||||||||
includeCarParking = shouldInclude(filterByPlaceTypes, PlaceType.CAR_PARK); | ||||||||||
includeBikeParking = shouldInclude(filterByPlaceTypes, PlaceType.BIKE_PARK); | ||||||||||
includeStations = shouldInclude(filterByPlaceTypes, PlaceType.STATION); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need special handling for this as we don't want to return stations by default. This fact needs to also documented in the query docs. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there some better way to do so than to simply add a check for whether There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, that's fine. The docs to mentioned this are here: OpenTripPlanner/src/main/resources/org/opentripplanner/apis/gtfs/schema.graphqls Lines 2503 to 2506 in 7b48c4d
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please also add a test for this slightly strange behaviour. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please make sure that stations are only included if you explicitly enable them. |
||||||||||
this.maxResults = maxResults; | ||||||||||
|
||||||||||
this.radiusMeters = radiusMeters; | ||||||||||
} | ||||||||||
|
||||||||||
|
@@ -134,7 +144,7 @@ public SkipEdgeStrategy<State, Edge> getSkipEdgeStrategy() { | |||||||||
|
||||||||||
private static <T> Set<T> toSet(List<T> list) { | ||||||||||
if (list == null) { | ||||||||||
return null; | ||||||||||
return Set.of(); | ||||||||||
} | ||||||||||
return Set.copyOf(list); | ||||||||||
} | ||||||||||
|
@@ -156,7 +166,7 @@ private void handleParking(VehicleParking parking, double distance) { | |||||||||
} | ||||||||||
|
||||||||||
private boolean shouldInclude(List<PlaceType> filterByPlaceTypes, PlaceType type) { | ||||||||||
return filterByPlaceTypes == null || filterByPlaceTypes.contains(type); | ||||||||||
return filterByPlaceTypes.contains(type); | ||||||||||
} | ||||||||||
|
||||||||||
private boolean stopHasPatternsWithMode(RegularStop stop, Set<TransitMode> modes) { | ||||||||||
|
@@ -167,17 +177,54 @@ private boolean stopHasPatternsWithMode(RegularStop stop, Set<TransitMode> modes | |||||||||
.anyMatch(modes::contains); | ||||||||||
} | ||||||||||
|
||||||||||
private boolean stopIsIncludedByStopFilter(RegularStop stop) { | ||||||||||
return filterByStops.isEmpty() || filterByStops.contains(stop.getId()); | ||||||||||
} | ||||||||||
|
||||||||||
private boolean stopIsIncludedByStationFilter(RegularStop stop) { | ||||||||||
return ( | ||||||||||
((filterByStations.isEmpty() || filterByStations.contains(stop.getParentStation().getId()))) | ||||||||||
); | ||||||||||
} | ||||||||||
|
||||||||||
private boolean stopIsIncludedByModeFilter(RegularStop stop) { | ||||||||||
return filterByModes.isEmpty() || stopHasPatternsWithMode(stop, filterByModes); | ||||||||||
} | ||||||||||
|
||||||||||
/* Checks whether the stop is included in the stop filter and whether the stop should be considered | ||||||||||
* a stop or a station in the search.*/ | ||||||||||
private boolean stopShouldNotBeIncludedAsStop(RegularStop stop) { | ||||||||||
return ( | ||||||||||
(includeStations && !stop.isPartOfStation() && !stopIsIncludedByStopFilter(stop)) || | ||||||||||
(!includeStations && !stopIsIncludedByStopFilter(stop)) | ||||||||||
); | ||||||||||
} | ||||||||||
|
||||||||||
/* Checks if the stop is a part of a station and whether that station is | ||||||||||
* included in the station filter */ | ||||||||||
private boolean stopShouldNotBeIncludedAsStation(RegularStop stop) { | ||||||||||
return stop.isPartOfStation() && !stopIsIncludedByStationFilter(stop); | ||||||||||
} | ||||||||||
|
||||||||||
private void handleStop(RegularStop stop, double distance) { | ||||||||||
if (filterByStops != null && !filterByStops.contains(stop.getId())) { | ||||||||||
return; | ||||||||||
} | ||||||||||
// Do not consider stop if it is not included in the stop or mode filter | ||||||||||
// or if it or its parent station has already been seen. | ||||||||||
if ( | ||||||||||
includeStops && | ||||||||||
!seenStops.contains(stop.getId()) && | ||||||||||
(filterByModes == null || stopHasPatternsWithMode(stop, filterByModes)) | ||||||||||
stopShouldNotBeIncludedAsStop(stop) || | ||||||||||
stopShouldNotBeIncludedAsStation(stop) || | ||||||||||
seenStops.contains(stop.getId()) || | ||||||||||
seenStops.contains(stop.getStationOrStopId()) || | ||||||||||
!stopIsIncludedByModeFilter(stop) | ||||||||||
) { | ||||||||||
placesFound.add(new PlaceAtDistance(stop, distance)); | ||||||||||
return; | ||||||||||
} | ||||||||||
|
||||||||||
if (includeStations && stop.getParentStation() != null) { | ||||||||||
seenStops.add(stop.getParentStation().getId()); | ||||||||||
placesFound.add(new PlaceAtDistance(stop.getParentStation(), distance)); | ||||||||||
} else if (includeStops) { | ||||||||||
seenStops.add(stop.getId()); | ||||||||||
placesFound.add(new PlaceAtDistance(stop, distance)); | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
|
@@ -186,9 +233,9 @@ private void handlePatternsAtStop(RegularStop stop, double distance) { | |||||||||
List<TripPattern> patterns = transitService | ||||||||||
.getPatternsForStop(stop) | ||||||||||
.stream() | ||||||||||
.filter(pattern -> filterByModes == null || filterByModes.contains(pattern.getMode())) | ||||||||||
.filter(pattern -> filterByModes.isEmpty() || filterByModes.contains(pattern.getMode())) | ||||||||||
.filter(pattern -> | ||||||||||
filterByRoutes == null || filterByRoutes.contains(pattern.getRoute().getId()) | ||||||||||
filterByRoutes.isEmpty() || filterByRoutes.contains(pattern.getRoute().getId()) | ||||||||||
) | ||||||||||
.filter(pattern -> pattern.canBoard(stop)) | ||||||||||
.toList(); | ||||||||||
|
@@ -209,7 +256,9 @@ private void handleVehicleRental(VehicleRentalPlace station, double distance) { | |||||||||
if (!includeVehicleRentals) { | ||||||||||
return; | ||||||||||
} | ||||||||||
if (filterByVehicleRental != null && !filterByVehicleRental.contains(station.getStationId())) { | ||||||||||
if ( | ||||||||||
!filterByVehicleRental.isEmpty() && !filterByVehicleRental.contains(station.getStationId()) | ||||||||||
) { | ||||||||||
return; | ||||||||||
} | ||||||||||
if (seenVehicleRentalPlaces.contains(station.getId())) { | ||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,5 @@ public enum PlaceType { | |
VEHICLE_RENT, | ||
BIKE_PARK, | ||
CAR_PARK, | ||
STATION, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here