Search in sources :

Example 46 with Stop

use of org.opentripplanner.model.Stop in project OpenTripPlanner by opentripplanner.

the class SiriFuzzyTripMatcher method getStop.

public FeedScopedId getStop(String siriStopId) {
    if (nonExistingStops.contains(siriStopId)) {
        return null;
    }
    // TODO OTP2 #2838 - Guessing on the feedId is not a deterministic way to find a stop.
    // First, assume same agency
    Stop firstStop = routingService.getAllStops().stream().findFirst().get();
    FeedScopedId id = new FeedScopedId(firstStop.getId().getFeedId(), siriStopId);
    if (routingService.getStopForId(id) != null) {
        return id;
    } else if (routingService.getStationById(id) != null) {
        return id;
    }
    // Not same agency - loop through all stops/Stations
    Collection<Stop> stops = routingService.getAllStops();
    for (Stop stop : stops) {
        if (stop.getId().getId().equals(siriStopId)) {
            return stop.getId();
        }
    }
    // No match found in quays - check parent-stops (stopplace)
    for (Station station : routingService.getStations()) {
        if (station.getId().getId().equals(siriStopId)) {
            return station.getId();
        }
    }
    nonExistingStops.add(siriStopId);
    return null;
}
Also used : Station(org.opentripplanner.model.Station) Stop(org.opentripplanner.model.Stop) FeedScopedId(org.opentripplanner.model.FeedScopedId)

Example 47 with Stop

use of org.opentripplanner.model.Stop in project OpenTripPlanner by opentripplanner.

the class LegacyGraphQLStopImpl method stopTimesForPattern.

@Override
public DataFetcher<Iterable<TripTimeShort>> stopTimesForPattern() {
    return environment -> getValue(environment, stop -> {
        RoutingService routingService = getRoutingService(environment);
        LegacyGraphQLTypes.LegacyGraphQLStopStopTimesForPatternArgs args = new LegacyGraphQLTypes.LegacyGraphQLStopStopTimesForPatternArgs(environment.getArguments());
        TripPattern pattern = routingService.getTripPatternForId(FeedScopedId.parseId(args.getLegacyGraphQLId()));
        if (pattern == null) {
            return null;
        }
        ;
        return routingService.stopTimesForPatternAtStop(stop, pattern, args.getLegacyGraphQLStartTime(), args.getLegacyGraphQLTimeRange(), args.getLegacyGraphQLNumberOfDepartures(), args.getLegacyGraphQLOmitNonPickups());
    }, station -> null);
}
Also used : DataFetchingEnvironment(graphql.schema.DataFetchingEnvironment) StopAtDistance(org.opentripplanner.routing.graphfinder.StopAtDistance) RoutingService(org.opentripplanner.routing.RoutingService) StopTimesInPattern(org.opentripplanner.model.StopTimesInPattern) Function(java.util.function.Function) LegacyGraphQLTypes(org.opentripplanner.ext.legacygraphqlapi.generated.LegacyGraphQLTypes) ServiceDate(org.opentripplanner.model.calendar.ServiceDate) LegacyGraphQLRequestContext(org.opentripplanner.ext.legacygraphqlapi.LegacyGraphQLRequestContext) ArrayList(java.util.ArrayList) TripTimeShort(org.opentripplanner.model.TripTimeShort) Map(java.util.Map) DataFetcher(graphql.schema.DataFetcher) ParseException(java.text.ParseException) FeedScopedId(org.opentripplanner.model.FeedScopedId) Station(org.opentripplanner.model.Station) TripPattern(org.opentripplanner.model.TripPattern) Stop(org.opentripplanner.model.Stop) Collection(java.util.Collection) Collectors(java.util.stream.Collectors) GeometryUtils(org.opentripplanner.common.geometry.GeometryUtils) TransitAlert(org.opentripplanner.routing.alertpatch.TransitAlert) List(java.util.List) Route(org.opentripplanner.model.Route) Stream(java.util.stream.Stream) SimpleTransfer(org.opentripplanner.model.SimpleTransfer) LegacyGraphQLDataFetchers(org.opentripplanner.ext.legacygraphqlapi.generated.LegacyGraphQLDataFetchers) Relay(graphql.relay.Relay) Comparator(java.util.Comparator) Edge(org.opentripplanner.routing.graph.Edge) RoutingService(org.opentripplanner.routing.RoutingService) TripPattern(org.opentripplanner.model.TripPattern) LegacyGraphQLTypes(org.opentripplanner.ext.legacygraphqlapi.generated.LegacyGraphQLTypes)

Example 48 with Stop

use of org.opentripplanner.model.Stop 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 49 with Stop

use of org.opentripplanner.model.Stop 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 50 with Stop

use of org.opentripplanner.model.Stop in project OpenTripPlanner by opentripplanner.

the class EstimatedCallType method getAllRelevantAlerts.

/**
 * Resolves all AlertPatches that are relevant for the supplied TripTimeShort.
 */
private static Collection<TransitAlert> getAllRelevantAlerts(TripTimeShort tripTimeShort, RoutingService routingService) {
    FeedScopedId tripId = tripTimeShort.tripId;
    Trip trip = routingService.getTripForId().get(tripId);
    FeedScopedId routeId = trip.getRoute().getId();
    FeedScopedId stopId = tripTimeShort.stopId;
    Stop stop = routingService.getStopForId(stopId);
    FeedScopedId parentStopId = stop.getParentStation().getId();
    Collection<TransitAlert> allAlerts = new HashSet<>();
    TransitAlertService alertPatchService = routingService.getTransitAlertService();
    // Quay
    allAlerts.addAll(alertPatchService.getStopAlerts(stopId));
    allAlerts.addAll(alertPatchService.getStopAndTripAlerts(stopId, tripId));
    allAlerts.addAll(alertPatchService.getStopAndRouteAlerts(stopId, routeId));
    // StopPlace
    allAlerts.addAll(alertPatchService.getStopAlerts(parentStopId));
    allAlerts.addAll(alertPatchService.getStopAndTripAlerts(parentStopId, tripId));
    allAlerts.addAll(alertPatchService.getStopAndRouteAlerts(parentStopId, routeId));
    // Trip
    allAlerts.addAll(alertPatchService.getTripAlerts(tripId));
    // Route
    allAlerts.addAll(alertPatchService.getRouteAlerts(routeId));
    // Agency
    // TODO OTP2 This should probably have a FeedScopeId argument instead of string
    allAlerts.addAll(alertPatchService.getAgencyAlerts(trip.getRoute().getAgency().getId()));
    // TripPattern
    allAlerts.addAll(alertPatchService.getTripPatternAlerts(routingService.getPatternForTrip().get(trip).getId()));
    long serviceDayMillis = 1000 * tripTimeShort.serviceDay;
    long arrivalMillis = 1000 * tripTimeShort.realtimeArrival;
    long departureMillis = 1000 * tripTimeShort.realtimeDeparture;
    filterSituationsByDateAndStopConditions(allAlerts, new Date(serviceDayMillis + arrivalMillis), new Date(serviceDayMillis + departureMillis), Arrays.asList(StopCondition.STOP, StopCondition.START_POINT, StopCondition.EXCEPTIONAL_STOP));
    return allAlerts;
}
Also used : Trip(org.opentripplanner.model.Trip) TransitAlert(org.opentripplanner.routing.alertpatch.TransitAlert) TransitAlertService(org.opentripplanner.routing.services.TransitAlertService) Stop(org.opentripplanner.model.Stop) FeedScopedId(org.opentripplanner.model.FeedScopedId) Date(java.util.Date) HashSet(java.util.HashSet)

Aggregations

Stop (org.opentripplanner.model.Stop)73 FeedScopedId (org.opentripplanner.model.FeedScopedId)25 ArrayList (java.util.ArrayList)24 TripPattern (org.opentripplanner.model.TripPattern)24 Trip (org.opentripplanner.model.Trip)21 ServiceDate (org.opentripplanner.model.calendar.ServiceDate)13 RoutingService (org.opentripplanner.routing.RoutingService)13 TransitStopVertex (org.opentripplanner.routing.vertextype.TransitStopVertex)13 HashSet (java.util.HashSet)12 Station (org.opentripplanner.model.Station)12 TripTimes (org.opentripplanner.routing.trippattern.TripTimes)11 List (java.util.List)10 Test (org.junit.Test)8 Route (org.opentripplanner.model.Route)8 StopTime (org.opentripplanner.model.StopTime)8 Collectors (java.util.stream.Collectors)7 GET (javax.ws.rs.GET)7 Path (javax.ws.rs.Path)7 ApiStop (org.opentripplanner.api.model.ApiStop)7 TripTimeShort (org.opentripplanner.model.TripTimeShort)7