use of org.opentripplanner.model.Route in project OpenTripPlanner by opentripplanner.
the class JourneyWhiteListed method isTripTimeShortAcceptable.
private static boolean isTripTimeShortAcceptable(TripTimeShort tts, Collection<FeedScopedId> authorityIds, Collection<FeedScopedId> lineIds, RoutingService routingService) {
Trip trip = routingService.getTripForId().get(tts.tripId);
if (trip == null || trip.getRoute() == null) {
return true;
}
Route route = trip.getRoute();
boolean okForAuthority = authorityIds.contains(route.getAgency().getId());
boolean okForLine = lineIds.contains(route.getId());
return okForAuthority || okForLine;
}
use of org.opentripplanner.model.Route 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);
}
use of org.opentripplanner.model.Route in project OpenTripPlanner by opentripplanner.
the class NetexMapper method mapRoute.
private void mapRoute(NetexImportDataIndexReadOnlyView netexIndex) {
RouteMapper routeMapper = new RouteMapper(idFactory, transitBuilder.getAgenciesById(), transitBuilder.getOperatorsById(), netexIndex, netexIndex.getTimeZone());
for (Line line : netexIndex.getLineById().localValues()) {
Route route = routeMapper.mapRoute(line);
transitBuilder.getRoutes().add(route);
}
}
use of org.opentripplanner.model.Route in project OpenTripPlanner by opentripplanner.
the class DefaultFareServiceFactory method fillFareRules.
protected void fillFareRules(Collection<FareAttribute> fareAttributes, Collection<FareRule> fareRules, Map<FeedScopedId, FareRuleSet> fareRuleSet) {
/*
* Create an empty FareRuleSet for each FareAttribute, as some FareAttribute may have no
* rules attached to them.
*/
for (FareAttribute fare : fareAttributes) {
FeedScopedId id = fare.getId();
FareRuleSet fareRule = fareRuleSet.get(id);
if (fareRule == null) {
fareRule = new FareRuleSet(fare);
fareRuleSet.put(id, fareRule);
}
}
/*
* For each fare rule, add it to the FareRuleSet of the fare.
*/
for (FareRule rule : fareRules) {
FareAttribute fare = rule.getFare();
FeedScopedId id = fare.getId();
FareRuleSet fareRule = fareRuleSet.get(id);
if (fareRule == null) {
// Should never happen by design
LOG.error("Inexistant fare ID in fare rule: " + id);
continue;
}
String contains = rule.getContainsId();
if (contains != null) {
fareRule.addContains(contains);
}
String origin = rule.getOriginId();
String destination = rule.getDestinationId();
if (origin != null || destination != null) {
fareRule.addOriginDestination(origin, destination);
}
Route route = rule.getRoute();
if (route != null) {
FeedScopedId routeId = route.getId();
fareRule.addRoute(routeId);
}
}
}
use of org.opentripplanner.model.Route in project OpenTripPlanner by opentripplanner.
the class TimetableSnapshotSource method handleAddedTrip.
/**
* Handle GTFS-RT TripUpdate message containing an ADDED trip.
*
* @param graph graph to update
* @param tripUpdate GTFS-RT TripUpdate message
* @param stops the stops of each StopTimeUpdate in the TripUpdate message
* @param feedId
* @param serviceDate service date for added trip
* @return true iff successful
*/
private boolean handleAddedTrip(final Graph graph, final TripUpdate tripUpdate, final List<Stop> stops, final String feedId, final ServiceDate serviceDate) {
// Preconditions
Preconditions.checkNotNull(stops);
Preconditions.checkArgument(tripUpdate.getStopTimeUpdateCount() == stops.size(), "number of stop should match the number of stop time updates");
// Check whether trip id has been used for previously ADDED trip message and cancel
// previously created trip
final String tripId = tripUpdate.getTrip().getTripId();
cancelPreviouslyAddedTrip(new FeedScopedId(feedId, tripId), serviceDate);
//
// Create added trip
//
Route route = null;
if (tripUpdate.getTrip().hasRouteId()) {
// Try to find route
route = getRouteForRouteId(feedId, tripUpdate.getTrip().getRouteId());
}
if (route == null) {
// Create new Route
route = new Route();
// Use route id of trip descriptor if available
if (tripUpdate.getTrip().hasRouteId()) {
route.setId(new FeedScopedId(feedId, tripUpdate.getTrip().getRouteId()));
} else {
route.setId(new FeedScopedId(feedId, tripId));
}
// Create dummy agency for added trips
Agency dummyAgency = new Agency(new FeedScopedId(feedId, "Dummy"), "Dummy", "Europe/Paris");
route.setAgency(dummyAgency);
// Guess the route type as it doesn't exist yet in the specifications
// Bus. Used for short- and long-distance bus routes.
route.setType(3);
route.setMode(TransitMode.BUS);
// Create route name
route.setLongName(tripId);
}
// Create new Trip
final Trip trip = new Trip();
// TODO: which Agency ID to use? Currently use feed id.
trip.setId(new FeedScopedId(feedId, tripUpdate.getTrip().getTripId()));
trip.setRoute(route);
// Find service ID running on this service date
final Set<FeedScopedId> serviceIds = graph.getCalendarService().getServiceIdsOnDate(serviceDate);
if (serviceIds.isEmpty()) {
// No service id exists: return error for now
LOG.warn("ADDED trip has service date for which no service id is available, skipping.");
return false;
} else {
// Just use first service id of set
trip.setServiceId(serviceIds.iterator().next());
}
final boolean success = addTripToGraphAndBuffer(feedId, graph, trip, tripUpdate, stops, serviceDate, RealTimeState.ADDED);
return success;
}
Aggregations