Skip to content

Commit

Permalink
graphql: vehicles, cluster by bbox; parking updater
Browse files Browse the repository at this point in the history
  • Loading branch information
zabuTNT committed Jun 16, 2023
1 parent ce0c915 commit 199b8de
Show file tree
Hide file tree
Showing 9 changed files with 401 additions and 7 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "opentripplanner",
"version": "1.5.17",
"version": "1.5.20",
"description": "OpenTripPlanner (OTP) is an open source multi-modal trip planner. It depends on open data in open standard file formats (GTFS and OpenStreetMap), and includes a REST API for journey planning as well as a map-based Javascript client. OpenTripPlanner can also create travel time contour visualizations and compute accessibility indicators for planning and research applications.",
"main": "index.js",
"directories": {
Expand All @@ -18,7 +18,7 @@
"scripts": {
"deploy": "mvn deploy:deploy-file -s openmove-settings.xml -DgroupId=org.opentripplanner -DartifactId=otp -Dversion=${npm_package_version}-SNAPSHOT -Dclassifier=shaded -Dpackaging=jar -Dfile=target/otp-${npm_package_version}-SNAPSHOT-shaded.jar -Durl=https://maven.pkg.github.com/openmove/OpenTripPlanner -DrepositoryId=otp",
"build": "mvn clean package -DskipTests -s openmove-settings.xml",
"debug": "java -Xmx5G -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:32935,suspend=y,server=y -jar target/otp-${npm_package_version}-SNAPSHOT-shaded.jar --build ../otp/otp/debug/ --inMemory "
"debug": "java -Xmx5G -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:32935,suspend=y,server=y -jar target/otp-${npm_package_version}-SNAPSHOT-shaded.jar --build ../otp/otp/napoli-test/ --inMemory "
},
"homepage": "https://github.com/openmove/OpenTripPlanner#readme"
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<groupId>org.opentripplanner</groupId>
<artifactId>otp</artifactId>
<version>1.5.17-SNAPSHOT</version>
<version>1.5.20-SNAPSHOT</version>
<packaging>jar</packaging>

<licenses>
Expand Down
162 changes: 160 additions & 2 deletions src/main/java/org/opentripplanner/index/IndexGraphQLSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.opentripplanner.api.model.TripPlan;
import org.opentripplanner.api.model.VertexType;
import org.opentripplanner.api.model.WalkStep;
import org.opentripplanner.common.geometry.SphericalDistanceLibrary;
import org.opentripplanner.common.model.P2;
import org.opentripplanner.gtfs.GtfsLibrary;
import org.opentripplanner.index.model.DestinationType;
Expand Down Expand Up @@ -238,6 +239,28 @@ public String parseLiteral(Object input) {
.value("WARNING", GtfsRealtime.Alert.SeverityLevel.WARNING, "Warning alerts are used when a single stop or route has a disruption that can affect user's journey, for example: All trams on a specific route are running with irregular schedules.")
.value("SEVERE", GtfsRealtime.Alert.SeverityLevel.SEVERE, "Severe alerts are used when a significant part of public transport services is affected, for example: All train services are cancelled due to technical problems.")
.build();

public static GraphQLEnumType congestionLevelEnum = GraphQLEnumType.newEnum()
.name("CongestionLevelType")
.description("Congestion level of a vehicle")
.value("UNKNOWN_CONGESTION_LEVEL", GtfsRealtime.VehiclePosition.CongestionLevel.UNKNOWN_CONGESTION_LEVEL, "Congestion is unknown")
.value("RUNNING_SMOOTHLY", GtfsRealtime.VehiclePosition.CongestionLevel.RUNNING_SMOOTHLY, "No congestion")
.value("STOP_AND_GO", GtfsRealtime.VehiclePosition.CongestionLevel.STOP_AND_GO, "The vehicle stop and go")
.value("CONGESTION", GtfsRealtime.VehiclePosition.CongestionLevel.CONGESTION, "There is a significant congestion")
.value("SEVERE_CONGESTION", GtfsRealtime.VehiclePosition.CongestionLevel.SEVERE_CONGESTION, "People are leaving their cars!")
.build();

public static GraphQLEnumType occupancyStatusEnum = GraphQLEnumType.newEnum()
.name("OccupancyStatusType")
.description("Occupancy status of a vehicle")
.value("EMPTY", GtfsRealtime.VehiclePosition.OccupancyStatus.EMPTY, "The vehicle is considered empty by most measures, and has few or no passengers onboard, but is still accepting passengers.")
.value("MANY_SEATS_AVAILABLE", GtfsRealtime.VehiclePosition.OccupancyStatus.MANY_SEATS_AVAILABLE, "The vehicle has a relatively large percentage of seats available.")
.value("FEW_SEATS_AVAILABLE", GtfsRealtime.VehiclePosition.OccupancyStatus.FEW_SEATS_AVAILABLE, "The vehicle has a relatively small percentage of seats available.")
.value("STANDING_ROOM_ONLY", GtfsRealtime.VehiclePosition.OccupancyStatus.STANDING_ROOM_ONLY, "The vehicle can currently accommodate only standing passengers.")
.value("CRUSHED_STANDING_ROOM_ONLY", GtfsRealtime.VehiclePosition.OccupancyStatus.CRUSHED_STANDING_ROOM_ONLY, "The vehicle can currently accommodate only standing passengers and has limited space for them.")
.value("FULL", GtfsRealtime.VehiclePosition.OccupancyStatus.FULL, "The vehicle is considered full by most measures, but may still be allowing passengers to board.")
.value("NOT_ACCEPTING_PASSENGERS", GtfsRealtime.VehiclePosition.OccupancyStatus.NOT_ACCEPTING_PASSENGERS, "The vehicle is not accepting additional passengers.")
.build();

private final GtfsRealtimeFuzzyTripMatcher fuzzyTripMatcher;

Expand Down Expand Up @@ -1221,9 +1244,16 @@ public IndexGraphQLSchema(GraphIndex index) {
vehiclePositionType = GraphQLObjectType.newObject()
.name("VehiclePosition")
.withInterface(nodeInterface)
.field(GraphQLFieldDefinition.newFieldDefinition()
.name("id")
.type(new GraphQLNonNull(Scalars.GraphQLID))
.dataFetcher(environment -> relay.toGlobalId(
vehiclePositionType.getName(),
((RealtimeVehiclePosition) environment.getSource()).vehicleId))
.build())
.field(GraphQLFieldDefinition.newFieldDefinition()
.name("vehicleId")
.type(new GraphQLNonNull(Scalars.GraphQLString))
.type(Scalars.GraphQLString)
.dataFetcher(environment -> ((RealtimeVehiclePosition) environment.getSource()).vehicleId)
.build())
.field(GraphQLFieldDefinition.newFieldDefinition()
Expand Down Expand Up @@ -1256,6 +1286,35 @@ public IndexGraphQLSchema(GraphIndex index) {
.type(Scalars.GraphQLLong)
.dataFetcher(environment -> ((RealtimeVehiclePosition) environment.getSource()).seconds)
.build())
.field(GraphQLFieldDefinition.newFieldDefinition()
.name("trip")
.type(tripType)
.dataFetcher(environment -> {
FeedScopedId tripId = ((RealtimeVehiclePosition) environment.getSource()).tripId;
return index.tripForId.get(tripId);
})
.build())
.field(GraphQLFieldDefinition.newFieldDefinition()
.name("congestionLevel")
.type(congestionLevelEnum)
.dataFetcher(environment -> {
return ((RealtimeVehiclePosition) environment.getSource()).congestionLevel;
})
.build())
.field(GraphQLFieldDefinition.newFieldDefinition()
.name("occupancyStatus")
.type(occupancyStatusEnum)
.dataFetcher(environment -> {
return ((RealtimeVehiclePosition) environment.getSource()).occupancyStatus;
})
.build())
.field(GraphQLFieldDefinition.newFieldDefinition()
.name("occupancyPercentage")
.type(Scalars.GraphQLInt)
.dataFetcher(environment -> {
return ((RealtimeVehiclePosition) environment.getSource()).occupancyPercentage;
})
.build())
.field(GraphQLFieldDefinition.newFieldDefinition()
.name("stoptime")
.type(stoptimeType)
Expand Down Expand Up @@ -1357,11 +1416,15 @@ public IndexGraphQLSchema(GraphIndex index) {
.dataFetcher(
environment -> {
Trip trip = (Trip) environment.getSource();
return index.patternForTrip.get(trip)
List<RealtimeVehiclePosition> rtp = index.patternForTrip.get(trip)
.getVehiclePositions()
.stream()
.filter(vp -> vp.tripId.equals(trip.getId()))
.collect(Collectors.toList());
if(rtp.isEmpty()) {
return null;
}
return rtp.get(0);
}
)
.build())
Expand Down Expand Up @@ -1572,6 +1635,18 @@ public int compare(TripTimeShort tripTimeShort, TripTimeShort t1) {
.name("stops")
.type(new GraphQLList(new GraphQLNonNull(stopType)))
.build())
.field(GraphQLFieldDefinition.newFieldDefinition()
.name("realtimeVehiclePositions")
.type(new GraphQLList(vehiclePositionType))
.dataFetcher(
environment -> {
return ((TripPattern) environment.getSource())
.getVehiclePositions()
.stream()
.collect(Collectors.toList());
}
)
.build())
.field(GraphQLFieldDefinition.newFieldDefinition()
.name("geometry")
.type(Scalars.GraphQLString)
Expand Down Expand Up @@ -2868,6 +2943,57 @@ public int compare(TripTimeShort tripTimeShort, TripTimeShort t1) {
.collect(Collectors.toList())
))
.build())
.field(GraphQLFieldDefinition.newFieldDefinition()
.name("realtimeVehiclePositions")
.description("Get all vehicle positions for the specified graph")
.type(new GraphQLList(vehiclePositionType))
.argument(GraphQLArgument.newArgument()
.name("lat")
.description("Latitude of the location")
.type(Scalars.GraphQLFloat)
.build())
.argument(GraphQLArgument.newArgument()
.name("lon")
.description("Longitude of the location")
.type(Scalars.GraphQLFloat)
.build())
.argument(GraphQLArgument.newArgument()
.name("radius")
.description("Radius (in meters) to search for from the specidied location")
.type(Scalars.GraphQLInt)
.build())
.dataFetcher(environment -> {
return index.patternForId.values()
.stream()
.flatMap(p -> p.getVehiclePositions().stream().filter(
v -> {
Coordinate coord = null;
int radius = 0;
if(environment.getArgument("lon") != null && environment.getArgument("lat") != null && environment.getArgument("radius") != null) {

double lon = environment.getArgument("lon");
double lat = environment.getArgument("lat");
radius = Math.toIntExact(environment.getArgument("radius"));

coord = new Coordinate(lon, lat);
}
if(coord != null) {
double distance = SphericalDistanceLibrary.fastDistance(new Coordinate(v.lon, v.lat), coord);

if (distance < radius) {
return true;
} else {
return false;
}
}else {
return true;
}

}
))
.collect(Collectors.toList());
})
.build())
.field(GraphQLFieldDefinition.newFieldDefinition()
.name("trip")
.description("Get a single trip based on its id (format is Agency:TripId)")
Expand Down Expand Up @@ -2951,6 +3077,38 @@ public int compare(TripTimeShort tripTimeShort, TripTimeShort t1) {
)
)
.build())
.field(GraphQLFieldDefinition.newFieldDefinition()
.name("clustersByBbox")
.description("Get all clusters for the specified graph in a bounding box")
.type(new GraphQLList(clusterType))
.argument(GraphQLArgument.newArgument()
.name("minLat")
.type(Scalars.GraphQLFloat)
.build())
.argument(GraphQLArgument.newArgument()
.name("minLon")
.type(Scalars.GraphQLFloat)
.build())
.argument(GraphQLArgument.newArgument()
.name("maxLat")
.type(Scalars.GraphQLFloat)
.build())
.argument(GraphQLArgument.newArgument()
.name("maxLon")
.type(Scalars.GraphQLFloat)
.build())
.dataFetcher(environment -> {
Envelope envelope = new Envelope(
new Coordinate(environment.getArgument("minLon"), environment.getArgument("minLat")),
new Coordinate(environment.getArgument("maxLon"), environment.getArgument("maxLat")));
return new ArrayList<>(
index.stopClusterForId.values()
.stream()
.filter(c -> envelope.contains(new Coordinate(c.lon,c.lat)))
.collect(Collectors.toList())
);
})
.build())
.field(GraphQLFieldDefinition.newFieldDefinition()
.name("cluster")
.description("Get a single cluster based on its id")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.opentripplanner.index.model;

import com.google.transit.realtime.GtfsRealtime.VehiclePosition.CongestionLevel;
import com.google.transit.realtime.GtfsRealtime.VehiclePosition.OccupancyStatus;
import com.google.transit.realtime.GtfsRealtime.VehiclePosition.VehicleStopStatus;
import org.opentripplanner.model.FeedScopedId;

Expand Down Expand Up @@ -28,4 +29,8 @@ public class RealtimeVehiclePosition {
public int nextStopSequenceId;

public CongestionLevel congestionLevel;
public OccupancyStatus occupancyStatus;

public int occupancyPercentage;

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.opentripplanner.routing.vertextype.ParkAndRideVertex;

import org.locationtech.jts.geom.LineString;
import org.opentripplanner.updater.car_park.ODHCarParkDataSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class GraphPathFinder {

private static final Logger LOG = LoggerFactory.getLogger(GraphPathFinder.class);
private static final double DEFAULT_MAX_WALK = 2000;
private static final double CLAMP_MAX_WALK = 15000;
private static final double CLAMP_MAX_WALK = 150000;

Router router;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ protected void configurePolling(Graph graph, JsonNode config) throws Exception {
if (sourceType.equals("park-and-ride")) {
source = new ODHCarParkDataSource();
}
if (sourceType.equals("park-openmove")) {
source = new OMCarParkDataSource();
}
}

if (source == null) {
Expand Down
Loading

0 comments on commit 199b8de

Please sign in to comment.