Skip to content

Commit

Permalink
return systemUrl, filter neareast by network, hide unwanted networks …
Browse files Browse the repository at this point in the history
…in maplayer, handle empty name
  • Loading branch information
sharhio committed Jun 14, 2024
1 parent b1a7c53 commit 01df869
Show file tree
Hide file tree
Showing 17 changed files with 82 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
abstract class VehicleRentalLayerBuilder<T extends VehicleRentalPlace> extends LayerBuilder<T> {

private final VehicleRentalService service;
private final List<String> hideNetworks;

public VehicleRentalLayerBuilder(
VehicleRentalService service,
Expand All @@ -30,6 +31,7 @@ public VehicleRentalLayerBuilder(
layerParameters.expansionFactor()
);
this.service = service;
this.hideNetworks = layerParameters.hideNetworks();
}

@Override
Expand All @@ -39,6 +41,7 @@ protected List<Geometry> getGeometries(Envelope query) {
}
return getVehicleRentalPlaces(service)
.stream()
.filter(rental -> !hideNetworks.contains(rental.getNetwork()))
.map(rental -> {
Coordinate coordinate = new Coordinate(rental.getLongitude(), rental.getLatitude());
Point point = GeometryUtils.getGeometryFactory().createPoint(coordinate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ public DataFetcher<Connection<PlaceAtDistance>> nearest() {
List<PlaceType> filterByPlaceTypes = args.getGraphQLFilterByPlaceTypes() != null
? args.getGraphQLFilterByPlaceTypes().stream().map(GraphQLUtils::toModel).toList()
: DEFAULT_PLACE_TYPES;
List<String> filterByNetworkNames = args.getGraphQLFilterByNetworkNames();

List<PlaceAtDistance> places;
try {
Expand All @@ -347,6 +348,7 @@ public DataFetcher<Connection<PlaceAtDistance>> nearest() {
filterByStations,
filterByRoutes,
filterByBikeRentalStations,
filterByNetworkNames,
getTransitService(environment)
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ public DataFetcher<RentalVehicleType> vehicleType() {
return environment -> getSource(environment).vehicleType;
}

@Override
public DataFetcher<String> systemUrl() {
return environment -> getSource(environment).system.url;
}

private VehicleRentalVehicle getSource(DataFetchingEnvironment environment) {
return environment.getSource();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,8 @@ public interface GraphQLRentalVehicle {
public DataFetcher<String> vehicleId();

public DataFetcher<RentalVehicleType> vehicleType();

DataFetcher<String> systemUrl();
}

public interface GraphQLRentalVehicleEntityCounts {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2416,6 +2416,7 @@ public static class GraphQLQueryTypeNearestArgs {
private Double lon;
private Integer maxDistance;
private Integer maxResults;
private List<String> filterByNetworkNames;

public GraphQLQueryTypeNearestArgs(Map<String, Object> args) {
if (args != null) {
Expand Down Expand Up @@ -2447,6 +2448,7 @@ public GraphQLQueryTypeNearestArgs(Map<String, Object> args) {
this.lon = (Double) args.get("lon");
this.maxDistance = (Integer) args.get("maxDistance");
this.maxResults = (Integer) args.get("maxResults");
this.filterByNetworkNames = (List<String>) args.get("filterByNetworkNames");
}
}

Expand Down Expand Up @@ -2537,6 +2539,14 @@ public void setGraphQLMaxDistance(Integer maxDistance) {
public void setGraphQLMaxResults(Integer maxResults) {
this.maxResults = maxResults;
}

public List<String> getGraphQLFilterByNetworkNames() {
return this.filterByNetworkNames;
}

public void setGraphQLFilterByNetworkNames(List<String> networkNames) {
this.filterByNetworkNames = networkNames;
}
}

public static class GraphQLQueryTypeNodeArgs {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,14 @@ private GraphQLSchema create() {
.type(Scalars.GraphQLInt)
.build()
)
.argument(
GraphQLArgument
.newArgument()
.name("filterByNetworkNames")
.description("Only include places that match one of the given network names.")
.type(new GraphQLList(Scalars.GraphQLString))
.build()
)
.argument(
GraphQLArgument
.newArgument()
Expand Down Expand Up @@ -937,6 +945,7 @@ private GraphQLSchema create() {
if (placeTypes.contains(TransmodelPlaceType.STOP_PLACE)) {
maxResults *= 5;
}
List<String> filterByNetworkNames = environment.getArgument("filterByNetworkNames");

List<PlaceAtDistance> places;
places =
Expand All @@ -953,6 +962,7 @@ private GraphQLSchema create() {
filterByStations,
filterByRoutes,
filterByBikeRentalStations,
filterByNetworkNames,
GqlUtil.getTransitService(environment)
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.opentripplanner.inspector.vector;

import java.util.ArrayList;
import java.util.List;
import org.opentripplanner.apis.support.mapping.PropertyMapper;

/**
Expand All @@ -10,7 +12,7 @@ public interface LayerParameters<T extends Enum<T>> {
int MAX_ZOOM = 20;
int CACHE_MAX_SECONDS = -1;
double EXPANSION_FACTOR = 0.25d;

List<String> HIDE_NETWORKS = new ArrayList<>();
/**
* User-visible name of the layer
*/
Expand Down Expand Up @@ -54,4 +56,8 @@ default int cacheMaxSeconds() {
default double expansionFactor() {
return EXPANSION_FACTOR;
}

default List<String> hideNetworks() {
return HIDE_NETWORKS;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public List<PlaceAtDistance> findClosestPlaces(
List<FeedScopedId> filterByStations,
List<FeedScopedId> filterByRoutes,
List<String> filterByBikeRentalStations,
List<String> filterByNetworkNames,
TransitService transitService
) {
throw new UnsupportedOperationException("Not implemented");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ List<PlaceAtDistance> findClosestPlaces(
List<FeedScopedId> filterByStations,
List<FeedScopedId> filterByRoutes,
List<String> filterByBikeRentalStations,
List<String> filterByNetworkNames,
TransitService transitService
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class PlaceFinderTraverseVisitor implements TraverseVisitor<State, Edge>
private final boolean includeStations;
private final int maxResults;
private final double radiusMeters;
private final Set<String> filterByNetworkNames;

/**
* @param transitService A TransitService used in finding information about the
Expand All @@ -69,6 +70,7 @@ public PlaceFinderTraverseVisitor(
List<FeedScopedId> filterByStations,
List<FeedScopedId> filterByRoutes,
List<String> filterByBikeRentalStations,
List<String> filterByNetworkNames,
int maxResults,
double radiusMeters
) {
Expand All @@ -82,6 +84,7 @@ public PlaceFinderTraverseVisitor(
this.filterByStations = toSet(filterByStations);
this.filterByRoutes = toSet(filterByRoutes);
this.filterByVehicleRental = toSet(filterByBikeRentalStations);
this.filterByNetworkNames = toSet(filterByNetworkNames);
includeStops = shouldInclude(filterByPlaceTypes, PlaceType.STOP);

includePatternAtStops = shouldInclude(filterByPlaceTypes, PlaceType.PATTERN_AT_STOP);
Expand Down Expand Up @@ -264,6 +267,9 @@ private void handleVehicleRental(VehicleRentalPlace station, double distance) {
if (seenVehicleRentalPlaces.contains(station.getId())) {
return;
}
if (!filterByNetworkNames.isEmpty() && !filterByNetworkNames.contains(station.getNetwork())) {
return;
}
seenVehicleRentalPlaces.add(station.getId());
placesFound.add(new PlaceAtDistance(station, distance));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public List<PlaceAtDistance> findClosestPlaces(
List<FeedScopedId> filterByStations,
List<FeedScopedId> filterByRoutes,
List<String> filterByBikeRentalStations,
List<String> filterByNetworkNames,
TransitService transitService
) {
PlaceFinderTraverseVisitor visitor = new PlaceFinderTraverseVisitor(
Expand All @@ -66,6 +67,7 @@ public List<PlaceAtDistance> findClosestPlaces(
filterByStations,
filterByRoutes,
filterByBikeRentalStations,
filterByNetworkNames,
maxResults,
radiusMeters
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ private GeofencingZone toInternalModel(GBFSFeature f) {
LOG.error("Could not convert geofencing zone", e);
return null;
}
var name = Objects.requireNonNullElseGet(f.getProperties().getName(), () -> fallbackId(g));
var nameFromData = f.getProperties().getName().isEmpty() ? null : f.getProperties().getName();
var name = Objects.requireNonNullElseGet(nameFromData, () -> fallbackId(g));
var dropOffBanned = !f.getProperties().getRules().get(0).getRideAllowed();
var passThroughBanned = !f.getProperties().getRules().get(0).getRideThroughAllowed();
return new GeofencingZone(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,9 @@ type RentalVehicle implements Node & PlaceInterface {

"""The type of the rental vehicle (scooter, bicycle, car...)"""
vehicleType: RentalVehicleType

"""The rental vehicle operator's system URL."""
systemUrl: String!
}

type BikeRentalStationUris {
Expand Down Expand Up @@ -3543,6 +3546,9 @@ type QueryType {
"""
filterByModes: [Mode]

"""Only include places that match one of the given network names."""
filterByNetworkNames: [String]

"""Only include places that match one of the given GTFS ids."""
filterByIds: InputFilters @deprecated(reason: "Not actively maintained")
before: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,8 @@ type QueryType {
filterByInUse: Boolean = false,
"Only include places that include this mode. Only checked for places with mode i.e. quays, departures."
filterByModes: [TransportMode],
"""Only include places that match one of the given network names."""
filterByNetworkNames: [String],
"Only include places of given types if set. Default accepts all types"
filterByPlaceTypes: [FilterPlaceType] = [quay, stopPlace, bicycleRent, bikePark, carPark],
"fetching only the first certain number of nodes"
Expand Down Expand Up @@ -953,6 +955,7 @@ type RentalVehicle implements PlaceInterface {
longitude: Float!
network: String!
vehicleType: RentalVehicleType!
systemUrl: String!
}

type RentalVehicleType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ public List<PlaceAtDistance> findClosestPlaces(
List<FeedScopedId> filterByStations,
List<FeedScopedId> filterByRoutes,
List<String> filterByBikeRentalStations,
List<String> filterByNetworkNames,
TransitService transitService
) {
return List
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ void stopsOnly() {
null,
null,
null,
null,
1,
500
);
Expand Down Expand Up @@ -124,6 +125,7 @@ void stationsOnly() {
null,
null,
null,
null,
1,
500
);
Expand Down Expand Up @@ -152,6 +154,7 @@ void stopsAndStations() {
null,
null,
null,
null,
1,
500
);
Expand Down Expand Up @@ -183,6 +186,7 @@ void stopsAndStationsWithStationFilter() {
List.of(STATION1.getId()),
null,
null,
null,
1,
500
);
Expand Down Expand Up @@ -217,6 +221,7 @@ void stopsAndStationsWithStopFilter() {
null,
null,
null,
null,
1,
500
);
Expand Down Expand Up @@ -250,6 +255,7 @@ void stopsAndStationsWithStopAndStationFilter() {
List.of(STATION1.getId()),
null,
null,
null,
1,
500
);
Expand Down
Loading

0 comments on commit 01df869

Please sign in to comment.