use of org.opentripplanner.routing.RoutingService in project OpenTripPlanner by opentripplanner.
the class IndexAPI method getTripsForRoute.
/**
* Return all trips in any pattern on the given route.
*/
@GET
@Path("/routes/{routeId}/trips")
public List<ApiTripShort> getTripsForRoute(@PathParam("routeId") String routeId) {
RoutingService routingService = createRoutingService();
Route route = getRoute(routingService, routeId);
List<Trip> trips = new ArrayList<>();
Collection<TripPattern> patterns = routingService.getPatternsForRoute().get(route);
for (TripPattern pattern : patterns) {
trips.addAll(pattern.getTrips());
}
return TripMapper.mapToApiShort(trips);
}
use of org.opentripplanner.routing.RoutingService in project OpenTripPlanner by opentripplanner.
the class IndexAPI method getRoutesForStop.
@GET
@Path("/stops/{stopId}/routes")
public List<ApiRouteShort> getRoutesForStop(@PathParam("stopId") String stopId) {
RoutingService routingService = createRoutingService();
Stop stop = getStop(routingService, stopId);
return routingService.getPatternsForStop(stop).stream().map(it -> it.route).map(RouteMapper::mapToApiShort).collect(Collectors.toList());
}
use of org.opentripplanner.routing.RoutingService in project OpenTripPlanner by opentripplanner.
the class PlannerResource method plan.
// We inject info about the incoming request so we can include the incoming query
// parameters in the outgoing response. This is a TriMet requirement.
// Jersey uses @Context to inject internal types and @InjectParam or @Resource for DI objects.
@GET
@Produces(MediaType.APPLICATION_JSON)
public TripPlannerResponse plan(@Context UriInfo uriInfo, @Context Request grizzlyRequest) {
/*
* TODO: add Lang / Locale parameter, and thus get localized content (Messages & more...)
* TODO: from/to inputs should be converted / geocoded / etc... here, and maybe send coords
* or vertex ids to planner (or error back to user)
* TODO: org.opentripplanner.routing.module.PathServiceImpl has COOORD parsing. Abstract that
* out so it's used here too...
*/
// Create response object, containing a copy of all request parameters. Maybe they should be in the debug section of the response.
TripPlannerResponse response = new TripPlannerResponse(uriInfo);
RoutingRequest request = null;
Router router = null;
RoutingResponse res = null;
try {
/* Fill in request fields from query parameters via shared superclass method, catching any errors. */
request = super.buildRequest();
router = otpServer.getRouter();
// Route
RoutingService routingService = new RoutingService(router.graph);
res = routingService.route(request, router);
// Map to API
TripPlanMapper tripPlanMapper = new TripPlanMapper(request.locale);
response.setPlan(tripPlanMapper.mapTripPlan(res.getTripPlan()));
response.setMetadata(TripSearchMetadataMapper.mapTripSearchMetadata(res.getMetadata()));
if (!res.getRoutingErrors().isEmpty()) {
// The api can only return one error message, so the first one is mapped
response.setError(PlannerErrorMapper.mapMessage(res.getRoutingErrors().get(0)));
}
/* Populate up the elevation metadata */
response.elevationMetadata = new ElevationMetadata();
response.elevationMetadata.ellipsoidToGeoidDifference = router.graph.ellipsoidToGeoidDifference;
response.elevationMetadata.geoidElevation = request.geoidElevation;
response.debugOutput = res.getDebugAggregator().finishedRendering();
} catch (Exception e) {
LOG.error("System error", e);
PlannerError error = new PlannerError();
error.setMsg(Message.SYSTEM_ERROR);
response.setError(error);
}
/* Log this request if such logging is enabled. */
if (request != null && router != null && router.requestLogger != null) {
StringBuilder sb = new StringBuilder();
String clientIpAddress = grizzlyRequest.getRemoteAddr();
// sb.append(LocalDateTime.now().format(DateTimeFormatter.ISO_DATE_TIME));
sb.append(clientIpAddress);
sb.append(' ');
sb.append(request.arriveBy ? "ARRIVE" : "DEPART");
sb.append(' ');
sb.append(LocalDateTime.ofInstant(Instant.ofEpochSecond(request.dateTime), ZoneId.systemDefault()));
sb.append(' ');
sb.append(request.streetSubRequestModes.getAsStr());
sb.append(' ');
sb.append(request.from.lat);
sb.append(' ');
sb.append(request.from.lng);
sb.append(' ');
sb.append(request.to.lat);
sb.append(' ');
sb.append(request.to.lng);
sb.append(' ');
if (res != null) {
for (Itinerary it : res.getTripPlan().itineraries) {
sb.append(it.durationSeconds);
sb.append(' ');
}
}
router.requestLogger.info(sb.toString());
}
return response;
}
use of org.opentripplanner.routing.RoutingService in project OpenTripPlanner by opentripplanner.
the class StreetGraphFinder method findClosestPlaces.
@Override
public List<PlaceAtDistance> findClosestPlaces(double lat, double lon, double radiusMeters, int maxResults, List<TransitMode> filterByModes, List<PlaceType> filterByPlaceTypes, List<FeedScopedId> filterByStops, List<FeedScopedId> filterByRoutes, List<String> filterByBikeRentalStations, List<String> filterByBikeParks, List<String> filterByCarParks, RoutingService routingService) {
PlaceFinderTraverseVisitor visitor = new PlaceFinderTraverseVisitor(routingService, filterByModes, filterByPlaceTypes, filterByStops, filterByRoutes, filterByBikeRentalStations, maxResults);
SearchTerminationStrategy terminationStrategy = visitor.getSearchTerminationStrategy();
findClosestUsingStreets(lat, lon, radiusMeters, visitor, terminationStrategy);
List<PlaceAtDistance> results = visitor.placesFound;
results.sort(Comparator.comparingDouble(pad -> pad.distance));
return results.subList(0, min(results.size(), maxResults));
}
use of org.opentripplanner.routing.RoutingService in project OpenTripPlanner by opentripplanner.
the class GtfsRealtimeFuzzyTripMatcherTest method testMatch.
public void testMatch() throws Exception {
String feedId = graph.getFeedIds().iterator().next();
GtfsRealtimeFuzzyTripMatcher matcher = new GtfsRealtimeFuzzyTripMatcher(new RoutingService(graph));
TripDescriptor trip1 = TripDescriptor.newBuilder().setRouteId("1").setDirectionId(0).setStartTime("06:47:00").setStartDate("20090915").build();
assertEquals("10W1020", matcher.match(feedId, trip1).getTripId());
trip1 = TripDescriptor.newBuilder().setRouteId("4").setDirectionId(0).setStartTime("00:02:00").setStartDate("20090915").build();
assertEquals("40W1890", matcher.match(feedId, trip1).getTripId());
// Test matching with "real time", when schedule uses time grater than 24:00
trip1 = TripDescriptor.newBuilder().setRouteId("4").setDirectionId(0).setStartTime("12:00:00").setStartDate("20090915").build();
// No departure at this time
assertFalse(trip1.hasTripId());
trip1 = TripDescriptor.newBuilder().setRouteId("1").setStartTime("06:47:00").setStartDate("20090915").build();
// Missing direction id
assertFalse(trip1.hasTripId());
}
Aggregations