Search in sources :

Example 21 with RoutingService

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);
    }
}
Also used : MultiModalStation(org.opentripplanner.model.MultiModalStation) Station(org.opentripplanner.model.Station) DataFetchingEnvironment(graphql.schema.DataFetchingEnvironment) RoutingService(org.opentripplanner.routing.RoutingService) Trip(org.opentripplanner.model.Trip) MultiModalStation(org.opentripplanner.model.MultiModalStation) StopTimesInPattern(org.opentripplanner.model.StopTimesInPattern) GraphQLFieldDefinition(graphql.schema.GraphQLFieldDefinition) GraphQLInterfaceType(graphql.schema.GraphQLInterfaceType) TRANSPORT_MODE(org.opentripplanner.ext.transmodelapi.model.EnumTypes.TRANSPORT_MODE) HashSet(java.util.HashSet) Scalars(graphql.Scalars) TripTimeShort(org.opentripplanner.model.TripTimeShort) TransitMode(org.opentripplanner.model.TransitMode) GraphQLObjectType(graphql.schema.GraphQLObjectType) FeedScopedId(org.opentripplanner.model.FeedScopedId) Station(org.opentripplanner.model.Station) TRANSPORT_SUBMODE(org.opentripplanner.ext.transmodelapi.model.EnumTypes.TRANSPORT_SUBMODE) EnumTypes(org.opentripplanner.ext.transmodelapi.model.EnumTypes) GqlUtil(org.opentripplanner.ext.transmodelapi.support.GqlUtil) GraphQLNonNull(graphql.schema.GraphQLNonNull) Stop(org.opentripplanner.model.Stop) StopCollection(org.opentripplanner.model.StopCollection) Collection(java.util.Collection) Set(java.util.Set) GraphQLOutputType(graphql.schema.GraphQLOutputType) GraphQLArgument(graphql.schema.GraphQLArgument) TransmodelTransportSubmode(org.opentripplanner.ext.transmodelapi.model.TransmodelTransportSubmode) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) GraphQLList(graphql.schema.GraphQLList) Stream(java.util.stream.Stream) GraphQLTypeReference(graphql.schema.GraphQLTypeReference) JourneyWhiteListed(org.opentripplanner.ext.transmodelapi.model.route.JourneyWhiteListed) TRUE(java.lang.Boolean.TRUE) HashSet(java.util.HashSet) Set(java.util.Set) Stop(org.opentripplanner.model.Stop) RoutingService(org.opentripplanner.routing.RoutingService) MultiModalStation(org.opentripplanner.model.MultiModalStation)

Example 22 with RoutingService

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));
}
Also used : DataFetchingEnvironment(graphql.schema.DataFetchingEnvironment) RoutingService(org.opentripplanner.routing.RoutingService) Trip(org.opentripplanner.model.Trip) MultiModalStation(org.opentripplanner.model.MultiModalStation) StopTimesInPattern(org.opentripplanner.model.StopTimesInPattern) GraphQLFieldDefinition(graphql.schema.GraphQLFieldDefinition) GraphQLInterfaceType(graphql.schema.GraphQLInterfaceType) TRANSPORT_MODE(org.opentripplanner.ext.transmodelapi.model.EnumTypes.TRANSPORT_MODE) HashSet(java.util.HashSet) Scalars(graphql.Scalars) TripTimeShort(org.opentripplanner.model.TripTimeShort) TransitMode(org.opentripplanner.model.TransitMode) GraphQLObjectType(graphql.schema.GraphQLObjectType) FeedScopedId(org.opentripplanner.model.FeedScopedId) Station(org.opentripplanner.model.Station) TRANSPORT_SUBMODE(org.opentripplanner.ext.transmodelapi.model.EnumTypes.TRANSPORT_SUBMODE) EnumTypes(org.opentripplanner.ext.transmodelapi.model.EnumTypes) GqlUtil(org.opentripplanner.ext.transmodelapi.support.GqlUtil) GraphQLNonNull(graphql.schema.GraphQLNonNull) Stop(org.opentripplanner.model.Stop) StopCollection(org.opentripplanner.model.StopCollection) Collection(java.util.Collection) Set(java.util.Set) GraphQLOutputType(graphql.schema.GraphQLOutputType) GraphQLArgument(graphql.schema.GraphQLArgument) TransmodelTransportSubmode(org.opentripplanner.ext.transmodelapi.model.TransmodelTransportSubmode) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) GraphQLList(graphql.schema.GraphQLList) Stream(java.util.stream.Stream) GraphQLTypeReference(graphql.schema.GraphQLTypeReference) JourneyWhiteListed(org.opentripplanner.ext.transmodelapi.model.route.JourneyWhiteListed) TRUE(java.lang.Boolean.TRUE) TripTimeShort(org.opentripplanner.model.TripTimeShort) RoutingService(org.opentripplanner.routing.RoutingService) StopTimesInPattern(org.opentripplanner.model.StopTimesInPattern)

Example 23 with RoutingService

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();
}
Also used : GraphQLObjectType(graphql.schema.GraphQLObjectType) EnumTypes(org.opentripplanner.ext.transmodelapi.model.EnumTypes) RoutingService(org.opentripplanner.routing.RoutingService) GqlUtil(org.opentripplanner.ext.transmodelapi.support.GqlUtil) Collections.emptyList(java.util.Collections.emptyList) GraphQLNonNull(graphql.schema.GraphQLNonNull) GraphQLFieldDefinition(graphql.schema.GraphQLFieldDefinition) EntitySelector(org.opentripplanner.routing.alertpatch.EntitySelector) GraphQLOutputType(graphql.schema.GraphQLOutputType) Collectors(java.util.stream.Collectors) TranslatedString(org.opentripplanner.util.TranslatedString) TransitAlert(org.opentripplanner.routing.alertpatch.TransitAlert) Scalars(graphql.Scalars) AbstractMap(java.util.AbstractMap) List(java.util.List) GraphQLList(graphql.schema.GraphQLList) GraphQLTypeReference(graphql.schema.GraphQLTypeReference) Pair(org.apache.commons.lang3.tuple.Pair) Relay(graphql.relay.Relay) GraphQLList(graphql.schema.GraphQLList) TranslatedString(org.opentripplanner.util.TranslatedString) EntitySelector(org.opentripplanner.routing.alertpatch.EntitySelector) TransitAlert(org.opentripplanner.routing.alertpatch.TransitAlert) RoutingService(org.opentripplanner.routing.RoutingService) AbstractMap(java.util.AbstractMap) GraphQLNonNull(graphql.schema.GraphQLNonNull)

Example 24 with RoutingService

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);
}
Also used : Trip(org.opentripplanner.model.Trip) ApiTrip(org.opentripplanner.api.model.ApiTrip) RoutingService(org.opentripplanner.routing.RoutingService) TripPattern(org.opentripplanner.model.TripPattern) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 25 with RoutingService

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));
}
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)

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