use of org.opentripplanner.routing.RoutingService in project OpenTripPlanner by opentripplanner.
the class StopPlaceType method fetchStopPlaces.
public static Collection<MonoOrMultiModalStation> fetchStopPlaces(double minLat, double minLon, double maxLat, double maxLon, String authority, Boolean filterByInUse, String multiModalMode, DataFetchingEnvironment environment) {
final RoutingService routingService = GqlUtil.getRoutingService(environment);
Stream<Station> stations = routingService.getStopsByBoundingBox(minLat, minLon, maxLat, maxLon).stream().map(Stop::getParentStation).filter(Objects::nonNull).distinct();
if (authority != null) {
stations = stations.filter(s -> s.getId().getFeedId().equalsIgnoreCase(authority));
}
if (TRUE.equals(filterByInUse)) {
stations = stations.filter(s -> isStopPlaceInUse(s, routingService));
}
// "child" - Only mono modal children stop places, not their multi modal parent stop
if ("child".equals(multiModalMode)) {
return stations.map(s -> {
MultiModalStation parent = routingService.getMultiModalStationForStations().get(s);
return new MonoOrMultiModalStation(s, parent);
}).collect(Collectors.toList());
} else // "all" - Both multiModal parents and their mono modal child stop places
if ("all".equals(multiModalMode)) {
Set<MonoOrMultiModalStation> result = new HashSet<>();
stations.forEach(it -> {
MultiModalStation p = routingService.getMultiModalStationForStations().get(it);
result.add(new MonoOrMultiModalStation(it, p));
if (p != null) {
result.add(new MonoOrMultiModalStation(p));
}
});
return result;
} else // Default "parent" - Multi modal parent stop places without their mono modal children
if ("parent".equals(multiModalMode)) {
return stations.map(it -> routingService.getMultiModalStationForStations().get(it)).filter(Objects::nonNull).distinct().map(MonoOrMultiModalStation::new).collect(Collectors.toUnmodifiableList());
} else {
throw new IllegalArgumentException("Unexpected multiModalMode: " + multiModalMode);
}
}
use of org.opentripplanner.routing.RoutingService in project OpenTripPlanner by opentripplanner.
the class StopPlaceType method getTripTimesForStop.
public static Stream<TripTimeShort> getTripTimesForStop(Stop stop, Long startTimeSeconds, int timeRage, boolean omitNonBoarding, int numberOfDepartures, Integer departuresPerLineAndDestinationDisplay, Collection<FeedScopedId> authorityIdsWhiteListed, Collection<FeedScopedId> lineIdsWhiteListed, Collection<TransitMode> transitModes, DataFetchingEnvironment environment) {
RoutingService routingService = GqlUtil.getRoutingService(environment);
boolean limitOnDestinationDisplay = departuresPerLineAndDestinationDisplay != null && departuresPerLineAndDestinationDisplay > 0 && departuresPerLineAndDestinationDisplay < numberOfDepartures;
int departuresPerTripPattern = limitOnDestinationDisplay ? departuresPerLineAndDestinationDisplay : numberOfDepartures;
List<StopTimesInPattern> stopTimesInPatterns = routingService.stopTimesForStop(stop, startTimeSeconds, timeRage, departuresPerTripPattern, omitNonBoarding);
// TODO OTP2 - Applying filters here is not correct - the `departuresPerTripPattern` is used
// - to limit the result, and using filters after that point may result in
// - loosing valid results.
Stream<StopTimesInPattern> stopTimesStream = stopTimesInPatterns.stream();
if (transitModes != null && !transitModes.isEmpty()) {
stopTimesStream = stopTimesStream.filter(it -> transitModes.contains(it.pattern.getMode()));
}
Stream<TripTimeShort> tripTimesStream = stopTimesStream.flatMap(p -> p.times.stream());
tripTimesStream = JourneyWhiteListed.whiteListAuthoritiesAndOrLines(tripTimesStream, authorityIdsWhiteListed, lineIdsWhiteListed, routingService);
if (!limitOnDestinationDisplay) {
return tripTimesStream;
}
// Group by line and destination display, limit departures per group and merge
return tripTimesStream.collect(Collectors.groupingBy(t -> destinationDisplayPerLine(((TripTimeShort) t), routingService))).values().stream().flatMap(tripTimes -> tripTimes.stream().sorted(TripTimeShort.compareByDeparture()).distinct().limit(departuresPerLineAndDestinationDisplay));
}
use of org.opentripplanner.routing.RoutingService in project OpenTripPlanner by opentripplanner.
the class PtSituationElementType method create.
public static GraphQLObjectType create(GraphQLOutputType authorityType, GraphQLOutputType quayType, GraphQLOutputType lineType, GraphQLOutputType serviceJourneyType, GraphQLOutputType multilingualStringType, GraphQLObjectType validityPeriodType, GraphQLObjectType infoLinkType, Relay relay) {
return GraphQLObjectType.newObject().name(NAME).description("Simple public transport situation element").field(GraphQLFieldDefinition.newFieldDefinition().name("id").type(new GraphQLNonNull(Scalars.GraphQLID)).dataFetcher(environment -> relay.toGlobalId(NAME, ((TransitAlert) environment.getSource()).getId())).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("authority").type(authorityType).description("Get affected authority for this situation element").dataFetcher(environment -> {
return GqlUtil.getRoutingService(environment).getAgencyForId(((TransitAlert) environment.getSource()).getEntities().stream().filter(EntitySelector.Agency.class::isInstance).map(EntitySelector.Agency.class::cast).findAny().map(entitySelector -> entitySelector.agencyId).orElse(null));
}).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("lines").type(new GraphQLNonNull(new GraphQLList(lineType))).dataFetcher(environment -> {
RoutingService routingService = GqlUtil.getRoutingService(environment);
return ((TransitAlert) environment.getSource()).getEntities().stream().filter(EntitySelector.Route.class::isInstance).map(EntitySelector.Route.class::cast).map(entitySelector -> entitySelector.routeId).map(routeId -> routingService.getRouteForId(routeId)).collect(Collectors.toList());
}).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("serviceJourneys").type(new GraphQLNonNull(new GraphQLList(serviceJourneyType))).dataFetcher(environment -> {
RoutingService routingService = GqlUtil.getRoutingService(environment);
return ((TransitAlert) environment.getSource()).getEntities().stream().filter(EntitySelector.Trip.class::isInstance).map(EntitySelector.Trip.class::cast).map(entitySelector -> entitySelector.tripId).map(tripId -> routingService.getTripForId().get(tripId)).collect(Collectors.toList());
}).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("quays").type(new GraphQLNonNull(new GraphQLList(quayType))).dataFetcher(environment -> {
RoutingService routingService = GqlUtil.getRoutingService(environment);
return ((TransitAlert) environment.getSource()).getEntities().stream().filter(EntitySelector.Stop.class::isInstance).map(EntitySelector.Stop.class::cast).map(entitySelector -> entitySelector.stopId).map(stopId -> routingService.getStopForId(stopId)).collect(Collectors.toList());
}).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("summary").type(new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(multilingualStringType)))).description("Summary of situation in all different translations available").dataFetcher(environment -> {
TransitAlert alert = environment.getSource();
if (alert.alertHeaderText instanceof TranslatedString) {
return ((TranslatedString) alert.alertHeaderText).getTranslations();
} else if (alert.alertHeaderText != null) {
return List.of(new AbstractMap.SimpleEntry<>(null, alert.alertHeaderText.toString()));
} else {
return emptyList();
}
}).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("description").type(new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(multilingualStringType)))).description("Description of situation in all different translations available").dataFetcher(environment -> {
TransitAlert alert = environment.getSource();
if (alert.alertDescriptionText instanceof TranslatedString) {
return ((TranslatedString) alert.alertDescriptionText).getTranslations();
} else if (alert.alertDescriptionText != null) {
return List.of(new AbstractMap.SimpleEntry<>(null, alert.alertDescriptionText.toString()));
} else {
return emptyList();
}
}).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("advice").type(new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(multilingualStringType)))).description("Advice of situation in all different translations available").dataFetcher(environment -> {
TransitAlert alert = environment.getSource();
if (alert.alertAdviceText instanceof TranslatedString) {
return ((TranslatedString) alert.alertAdviceText).getTranslations();
} else if (alert.alertAdviceText != null) {
return List.of(new AbstractMap.SimpleEntry<>(null, alert.alertAdviceText.toString()));
} else {
return emptyList();
}
}).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("infoLinks").type(new GraphQLList(infoLinkType)).description("Optional links to more information.").dataFetcher(environment -> null).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("validityPeriod").type(validityPeriodType).description("Period this situation is in effect").dataFetcher(environment -> {
TransitAlert alert = environment.getSource();
Long startTime = alert.getEffectiveStartDate() != null ? alert.getEffectiveEndDate().getTime() : null;
Long endTime = alert.getEffectiveEndDate() != null ? alert.getEffectiveEndDate().getTime() : null;
return Pair.of(startTime, endTime);
}).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("reportType").type(EnumTypes.REPORT_TYPE).description("ReportType of this situation").dataFetcher(environment -> ((TransitAlert) environment.getSource()).alertType).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("situationNumber").type(Scalars.GraphQLString).description("Operator's internal id for this situation").dataFetcher(environment -> null).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("reportAuthority").type(authorityType).description("Authority that reported this situation").deprecate("Not yet officially supported. May be removed or renamed.").dataFetcher(environment -> {
return GqlUtil.getRoutingService(environment).getAgencyForId(((TransitAlert) environment.getSource()).getEntities().stream().filter(EntitySelector.Agency.class::isInstance).map(EntitySelector.Agency.class::cast).findAny().map(entitySelector -> entitySelector.agencyId).orElse(null));
}).build()).build();
}
use of org.opentripplanner.routing.RoutingService in project OpenTripPlanner by opentripplanner.
the class IndexAPI method getSemanticHashForTrip.
@GET
@Path("/trips/{tripId}/semanticHash")
public String getSemanticHashForTrip(@PathParam("tripId") String tripId) {
RoutingService routingService = createRoutingService();
Trip trip = getTrip(routingService, tripId);
TripPattern pattern = getTripPattern(routingService, trip);
return pattern.semanticHashString(trip);
}
use of org.opentripplanner.routing.RoutingService in project OpenTripPlanner by opentripplanner.
the class IndexAPI method getAlertsForRoute.
/**
* Return all alerts for a route
*/
@GET
@Path("/routes/{routeId}/alerts")
public Collection<ApiAlert> getAlertsForRoute(@PathParam("routeId") String routeId) {
RoutingService routingService = createRoutingService();
// TODO: Add locale
AlertMapper alertMapper = new AlertMapper(null);
FeedScopedId id = createId("routeId", routeId);
return alertMapper.mapToApi(routingService.getTransitAlertService().getRouteAlerts(id));
}
Aggregations