Search in sources :

Example 26 with RoutingService

use of org.opentripplanner.routing.RoutingService in project OpenTripPlanner by opentripplanner.

the class IndexAPI method getStopTimesForStop.

/**
 * Return upcoming vehicle arrival/departure times at the given stop.
 *
 * @param stopIdString       Stop ID in Agency:Stop ID format
 * @param startTime          Start time for the search. Seconds from UNIX epoch
 * @param timeRange          Searches forward for timeRange seconds from startTime
 * @param numberOfDepartures Number of departures to fetch per pattern
 */
@GET
@Path("/stops/{stopId}/stoptimes")
public Collection<ApiStopTimesInPattern> getStopTimesForStop(@PathParam("stopId") String stopIdString, @QueryParam("startTime") long startTime, @QueryParam("timeRange") @DefaultValue("86400") int timeRange, @QueryParam("numberOfDepartures") @DefaultValue("2") int numberOfDepartures, @QueryParam("omitNonPickups") boolean omitNonPickups) {
    RoutingService routingService = createRoutingService();
    Stop stop = getStop(routingService, stopIdString);
    return routingService.stopTimesForStop(stop, startTime, timeRange, numberOfDepartures, omitNonPickups).stream().map(StopTimesInPatternMapper::mapToApi).collect(Collectors.toList());
}
Also used : ApiStop(org.opentripplanner.api.model.ApiStop) Stop(org.opentripplanner.model.Stop) RoutingService(org.opentripplanner.routing.RoutingService) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 27 with RoutingService

use of org.opentripplanner.routing.RoutingService in project OpenTripPlanner by opentripplanner.

the class IndexAPI method getAlertsForStop.

/**
 * Return all alerts for a stop
 */
@GET
@Path("/stops/{stopId}/alerts")
public Collection<ApiAlert> getAlertsForStop(@PathParam("stopId") String stopId) {
    RoutingService routingService = createRoutingService();
    // TODO: Add locale
    AlertMapper alertMapper = new AlertMapper(null);
    FeedScopedId id = createId("stopId", stopId);
    return alertMapper.mapToApi(routingService.getTransitAlertService().getStopAlerts(id));
}
Also used : RoutingService(org.opentripplanner.routing.RoutingService) FeedScopedId(org.opentripplanner.model.FeedScopedId) AlertMapper(org.opentripplanner.api.mapping.AlertMapper) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 28 with RoutingService

use of org.opentripplanner.routing.RoutingService in project OpenTripPlanner by opentripplanner.

the class IndexAPI method getAlertsForPattern.

/**
 * Return all alerts for a pattern
 */
@GET
@Path("/patterns/{patternId}/alerts")
public Collection<ApiAlert> getAlertsForPattern(@PathParam("patternId") String patternId) {
    RoutingService routingService = createRoutingService();
    // TODO: Add locale
    AlertMapper alertMapper = new AlertMapper(null);
    FeedScopedId id = createId("patternId", patternId);
    return alertMapper.mapToApi(routingService.getTransitAlertService().getTripPatternAlerts(id));
}
Also used : RoutingService(org.opentripplanner.routing.RoutingService) FeedScopedId(org.opentripplanner.model.FeedScopedId) AlertMapper(org.opentripplanner.api.mapping.AlertMapper) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 29 with RoutingService

use of org.opentripplanner.routing.RoutingService in project OpenTripPlanner by opentripplanner.

the class IndexAPI method getRoutes.

/**
 * Return a list of all routes in the graph.
 */
// with repeated hasStop parameters, replaces old routesBetweenStops
@GET
@Path("/routes")
public List<ApiRouteShort> getRoutes(@QueryParam("hasStop") List<String> stopIds) {
    RoutingService routingService = createRoutingService();
    Collection<Route> routes = routingService.getAllRoutes();
    // Filter routes to include only those that pass through all given stops
    if (stopIds != null) {
        // Protective copy, we are going to calculate the intersection destructively
        routes = new ArrayList<>(routes);
        for (String stopId : stopIds) {
            Stop stop = getStop(routingService, stopId);
            Set<Route> routesHere = new HashSet<>();
            for (TripPattern pattern : routingService.getPatternsForStop(stop)) {
                routesHere.add(pattern.route);
            }
            routes.retainAll(routesHere);
        }
    }
    return RouteMapper.mapToApiShort(routes);
}
Also used : ApiStop(org.opentripplanner.api.model.ApiStop) Stop(org.opentripplanner.model.Stop) RoutingService(org.opentripplanner.routing.RoutingService) LineString(org.locationtech.jts.geom.LineString) ApiRoute(org.opentripplanner.api.model.ApiRoute) Route(org.opentripplanner.model.Route) TripPattern(org.opentripplanner.model.TripPattern) HashSet(java.util.HashSet) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 30 with RoutingService

use of org.opentripplanner.routing.RoutingService in project OpenTripPlanner by opentripplanner.

the class IndexAPI method getPatternsForRoute.

/**
 * Return all stop patterns used by trips on the given route.
 */
@GET
@Path("/routes/{routeId}/patterns")
public List<ApiPatternShort> getPatternsForRoute(@PathParam("routeId") String routeId) {
    RoutingService routingService = createRoutingService();
    Collection<TripPattern> patterns = routingService.getPatternsForRoute().get(getRoute(routingService, routeId));
    return TripPatternMapper.mapToApiShort(patterns);
}
Also used : RoutingService(org.opentripplanner.routing.RoutingService) TripPattern(org.opentripplanner.model.TripPattern) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Aggregations

RoutingService (org.opentripplanner.routing.RoutingService)32 GET (javax.ws.rs.GET)17 Path (javax.ws.rs.Path)16 Stop (org.opentripplanner.model.Stop)13 FeedScopedId (org.opentripplanner.model.FeedScopedId)12 TripPattern (org.opentripplanner.model.TripPattern)9 List (java.util.List)8 ApiStop (org.opentripplanner.api.model.ApiStop)8 Trip (org.opentripplanner.model.Trip)8 HashSet (java.util.HashSet)7 Collectors (java.util.stream.Collectors)7 Collection (java.util.Collection)5 Stream (java.util.stream.Stream)5 AlertMapper (org.opentripplanner.api.mapping.AlertMapper)5 Route (org.opentripplanner.model.Route)5 StopTimesInPattern (org.opentripplanner.model.StopTimesInPattern)5 TripTimeShort (org.opentripplanner.model.TripTimeShort)5 Relay (graphql.relay.Relay)4 ArrayList (java.util.ArrayList)4 Objects (java.util.Objects)4