Search in sources :

Example 1 with StopTimesInPattern

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

the class IndexAPI method getStoptimesForStopAndDate.

/**
 * Return upcoming vehicle arrival/departure times at the given stop.
 * @param date in YYYYMMDD or YYYY-MM-DD format
 */
@GET
@Path("/stops/{stopId}/stoptimes/{date}")
public List<ApiStopTimesInPattern> getStoptimesForStopAndDate(@PathParam("stopId") String stopId, @PathParam("date") String date, @QueryParam("omitNonPickups") boolean omitNonPickups) {
    RoutingService routingService = createRoutingService();
    Stop stop = getStop(routingService, stopId);
    ServiceDate serviceDate = parseServiceDate("date", date);
    List<StopTimesInPattern> stopTimes = routingService.getStopTimesForStop(stop, serviceDate, omitNonPickups);
    return StopTimesInPatternMapper.mapToApi(stopTimes);
}
Also used : ServiceDate(org.opentripplanner.model.calendar.ServiceDate) ApiStop(org.opentripplanner.api.model.ApiStop) Stop(org.opentripplanner.model.Stop) RoutingService(org.opentripplanner.routing.RoutingService) StopTimesInPattern(org.opentripplanner.model.StopTimesInPattern) ApiStopTimesInPattern(org.opentripplanner.api.model.ApiStopTimesInPattern) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 2 with StopTimesInPattern

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

the class StopTimesHelper method stopTimesForStop.

/**
 * Fetch upcoming vehicle departures from a stop.
 * It goes though all patterns passing the stop for the previous, current and next service date.
 * It uses a priority queue to keep track of the next departures. The queue is shared between all
 * dates, as services from the previous service date can visit the stop later than the current
 * service date's services. This happens eg. with sleeper trains.
 *
 * TODO: Add frequency based trips
 * @param stop Stop object to perform the search for
 * @param startTime Start time for the search. Seconds from UNIX epoch
 * @param timeRange Searches forward for timeRange seconds from startTime
 * @param numberOfDepartures Number of departures to fetch per pattern
 * @param omitNonPickups If true, do not include vehicles that will not pick up passengers.
 */
public static List<StopTimesInPattern> stopTimesForStop(RoutingService routingService, TimetableSnapshot timetableSnapshot, Stop stop, long startTime, int timeRange, int numberOfDepartures, boolean omitNonPickups) {
    if (startTime == 0) {
        startTime = System.currentTimeMillis() / 1000;
    }
    List<StopTimesInPattern> ret = new ArrayList<>();
    Date date = new Date(startTime * 1000);
    ServiceDate[] serviceDates = { new ServiceDate(date).previous(), new ServiceDate(date), new ServiceDate(date).next() };
    Collection<TripPattern> patternsForStop = routingService.getPatternsForStop(stop, true);
    for (TripPattern pattern : patternsForStop) {
        Queue<TripTimeShort> pq = listTripTimeShortsForPatternAtStop(routingService, timetableSnapshot, stop, pattern, startTime, timeRange, numberOfDepartures, omitNonPickups, serviceDates);
        if (pq.size() != 0) {
            StopTimesInPattern stopTimes = new StopTimesInPattern(pattern);
            while (pq.size() != 0) {
                stopTimes.times.add(0, pq.poll());
            }
            ret.add(stopTimes);
        }
    }
    return ret;
}
Also used : TripTimeShort(org.opentripplanner.model.TripTimeShort) ServiceDate(org.opentripplanner.model.calendar.ServiceDate) ArrayList(java.util.ArrayList) Date(java.util.Date) ServiceDate(org.opentripplanner.model.calendar.ServiceDate) TripPattern(org.opentripplanner.model.TripPattern) StopTimesInPattern(org.opentripplanner.model.StopTimesInPattern)

Example 3 with StopTimesInPattern

use of org.opentripplanner.model.StopTimesInPattern 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 4 with StopTimesInPattern

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

the class StopTimesHelper method stopTimesForStop.

/**
 * Get a list of all trips that pass through a stop during a single ServiceDate. Useful when creating complete stop
 * timetables for a single day.
 *
 * @param stop Stop object to perform the search for
 * @param serviceDate Return all departures for the specified date
 */
public static List<StopTimesInPattern> stopTimesForStop(RoutingService routingService, Stop stop, ServiceDate serviceDate, boolean omitNonPickups) {
    List<StopTimesInPattern> ret = new ArrayList<>();
    Collection<TripPattern> patternsForStop = routingService.getPatternsForStop(stop, true);
    for (TripPattern pattern : patternsForStop) {
        StopTimesInPattern stopTimes = new StopTimesInPattern(pattern);
        Timetable tt;
        TimetableSnapshot timetableSnapshot = routingService.getTimetableSnapshot();
        if (timetableSnapshot != null) {
            tt = timetableSnapshot.resolve(pattern, serviceDate);
        } else {
            tt = pattern.scheduledTimetable;
        }
        ServiceDay sd = new ServiceDay(routingService.getServiceCodes(), serviceDate, routingService.getCalendarService(), pattern.route.getAgency().getId());
        int sidx = 0;
        for (Stop currStop : pattern.stopPattern.stops) {
            if (currStop == stop) {
                if (omitNonPickups && pattern.stopPattern.pickups[sidx] == StopPattern.PICKDROP_NONE)
                    continue;
                for (TripTimes t : tt.tripTimes) {
                    if (!sd.serviceRunning(t.serviceCode))
                        continue;
                    stopTimes.times.add(new TripTimeShort(t, sidx, stop, sd));
                }
            }
            sidx++;
        }
        ret.add(stopTimes);
    }
    return ret;
}
Also used : Timetable(org.opentripplanner.model.Timetable) TripTimeShort(org.opentripplanner.model.TripTimeShort) ServiceDay(org.opentripplanner.routing.core.ServiceDay) Stop(org.opentripplanner.model.Stop) ArrayList(java.util.ArrayList) TripTimes(org.opentripplanner.routing.trippattern.TripTimes) TimetableSnapshot(org.opentripplanner.model.TimetableSnapshot) TripPattern(org.opentripplanner.model.TripPattern) StopTimesInPattern(org.opentripplanner.model.StopTimesInPattern)

Aggregations

StopTimesInPattern (org.opentripplanner.model.StopTimesInPattern)4 Stop (org.opentripplanner.model.Stop)3 TripTimeShort (org.opentripplanner.model.TripTimeShort)3 ArrayList (java.util.ArrayList)2 TripPattern (org.opentripplanner.model.TripPattern)2 ServiceDate (org.opentripplanner.model.calendar.ServiceDate)2 RoutingService (org.opentripplanner.routing.RoutingService)2 Scalars (graphql.Scalars)1 DataFetchingEnvironment (graphql.schema.DataFetchingEnvironment)1 GraphQLArgument (graphql.schema.GraphQLArgument)1 GraphQLFieldDefinition (graphql.schema.GraphQLFieldDefinition)1 GraphQLInterfaceType (graphql.schema.GraphQLInterfaceType)1 GraphQLList (graphql.schema.GraphQLList)1 GraphQLNonNull (graphql.schema.GraphQLNonNull)1 GraphQLObjectType (graphql.schema.GraphQLObjectType)1 GraphQLOutputType (graphql.schema.GraphQLOutputType)1 GraphQLTypeReference (graphql.schema.GraphQLTypeReference)1 TRUE (java.lang.Boolean.TRUE)1 Collection (java.util.Collection)1 Date (java.util.Date)1