Search in sources :

Example 1 with TripTimeShort

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

the class TripTimeShortHelper method getIntermediateTripTimeShortsForLeg.

/**
 * Find trip time shorts for all intermediate stops for a leg.
 */
public List<TripTimeShort> getIntermediateTripTimeShortsForLeg(Leg leg, RoutingService routingService) {
    if (!leg.isTransitLeg()) {
        return List.of();
    }
    ServiceDate serviceDate = leg.serviceDate;
    List<TripTimeShort> tripTimes = routingService.getTripTimesShort(leg.getTrip(), serviceDate);
    List<TripTimeShort> filteredTripTimes = new ArrayList<>();
    long startTimeSeconds = (leg.startTime.toInstant().toEpochMilli() - serviceDate.getAsDate().getTime()) / 1000;
    long endTimeSeconds = (leg.endTime.toInstant().toEpochMilli() - serviceDate.getAsDate().getTime()) / 1000;
    boolean boardingStopFound = false;
    for (TripTimeShort tripTime : tripTimes) {
        long boardingTime = leg.realTime ? tripTime.realtimeDeparture : tripTime.scheduledDeparture;
        if (!boardingStopFound) {
            boardingStopFound = boardingTime == startTimeSeconds && matchesQuayOrSiblingQuay(leg.from.stopId, tripTime.stopId, routingService);
            continue;
        }
        long arrivalTime = leg.realTime ? tripTime.realtimeArrival : tripTime.scheduledArrival;
        if (arrivalTime == endTimeSeconds && matchesQuayOrSiblingQuay(leg.to.stopId, tripTime.stopId, routingService)) {
            break;
        }
        filteredTripTimes.add(tripTime);
    }
    return filteredTripTimes;
}
Also used : TripTimeShort(org.opentripplanner.model.TripTimeShort) ServiceDate(org.opentripplanner.model.calendar.ServiceDate) ArrayList(java.util.ArrayList)

Example 2 with TripTimeShort

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

the class TripTimeShortHelper method getTripTimeShortForToPlace.

/**
 * Find trip time short for the to place in transit leg, or null.
 */
public TripTimeShort getTripTimeShortForToPlace(Leg leg, RoutingService routingService) {
    if (!leg.isTransitLeg()) {
        return null;
    }
    ServiceDate serviceDate = leg.serviceDate;
    List<TripTimeShort> tripTimes = routingService.getTripTimesShort(leg.getTrip(), serviceDate);
    long endTimeSeconds = (leg.endTime.toInstant().toEpochMilli() - serviceDate.getAsDate().getTime()) / 1000;
    if (leg.realTime) {
        return tripTimes.stream().filter(tripTime -> tripTime.realtimeArrival == endTimeSeconds && matchesQuayOrSiblingQuay(leg.to.stopId, tripTime.stopId, routingService)).findFirst().orElse(null);
    }
    return tripTimes.stream().filter(tripTime -> tripTime.scheduledArrival == endTimeSeconds && matchesQuayOrSiblingQuay(leg.to.stopId, tripTime.stopId, routingService)).findFirst().orElse(null);
}
Also used : TripTimeShort(org.opentripplanner.model.TripTimeShort) ServiceDate(org.opentripplanner.model.calendar.ServiceDate)

Example 3 with TripTimeShort

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

the class LegacyGraphQLNodeTypeResolver method getType.

@Override
public GraphQLObjectType getType(TypeResolutionEnvironment environment) {
    Object o = environment.getObject();
    GraphQLSchema schema = environment.getSchema();
    if (o instanceof Agency)
        return schema.getObjectType("Agency");
    if (o instanceof TransitAlert)
        return schema.getObjectType("Alert");
    if (o instanceof BikePark)
        return schema.getObjectType("BikePark");
    if (o instanceof BikeRentalStation)
        return schema.getObjectType("BikeRentalStation");
    // if (o instanceof Cluster) return schema.getObjectType("Cluster");
    if (o instanceof PatternAtStop)
        return schema.getObjectType("DepartureRow");
    if (o instanceof TripPattern)
        return schema.getObjectType("Pattern");
    if (o instanceof PlaceAtDistance)
        return schema.getObjectType("placeAtDistance");
    if (o instanceof Route)
        return schema.getObjectType("Route");
    if (o instanceof Stop)
        return schema.getObjectType("Stop");
    if (o instanceof Station)
        return schema.getObjectType("Stop");
    if (o instanceof TripTimeShort)
        return schema.getObjectType("Stoptime");
    if (o instanceof StopAtDistance)
        return schema.getObjectType("stopAtDistance");
    if (o instanceof FareRuleSet)
        return schema.getObjectType("TicketType");
    if (o instanceof Trip)
        return schema.getObjectType("Trip");
    return null;
}
Also used : TransitAlert(org.opentripplanner.routing.alertpatch.TransitAlert) Trip(org.opentripplanner.model.Trip) Agency(org.opentripplanner.model.Agency) Stop(org.opentripplanner.model.Stop) PatternAtStop(org.opentripplanner.routing.graphfinder.PatternAtStop) PlaceAtDistance(org.opentripplanner.routing.graphfinder.PlaceAtDistance) FareRuleSet(org.opentripplanner.routing.core.FareRuleSet) BikePark(org.opentripplanner.routing.bike_park.BikePark) GraphQLSchema(graphql.schema.GraphQLSchema) BikeRentalStation(org.opentripplanner.routing.bike_rental.BikeRentalStation) TripPattern(org.opentripplanner.model.TripPattern) Station(org.opentripplanner.model.Station) BikeRentalStation(org.opentripplanner.routing.bike_rental.BikeRentalStation) TripTimeShort(org.opentripplanner.model.TripTimeShort) PatternAtStop(org.opentripplanner.routing.graphfinder.PatternAtStop) StopAtDistance(org.opentripplanner.routing.graphfinder.StopAtDistance) Route(org.opentripplanner.model.Route)

Example 4 with TripTimeShort

use of org.opentripplanner.model.TripTimeShort 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 5 with TripTimeShort

use of org.opentripplanner.model.TripTimeShort 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)

Aggregations

TripTimeShort (org.opentripplanner.model.TripTimeShort)10 ServiceDate (org.opentripplanner.model.calendar.ServiceDate)7 ArrayList (java.util.ArrayList)5 Stop (org.opentripplanner.model.Stop)5 StopTimesInPattern (org.opentripplanner.model.StopTimesInPattern)4 TripPattern (org.opentripplanner.model.TripPattern)4 Station (org.opentripplanner.model.Station)3 DataFetchingEnvironment (graphql.schema.DataFetchingEnvironment)2 Collection (java.util.Collection)2 Date (java.util.Date)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Stream (java.util.stream.Stream)2 FeedScopedId (org.opentripplanner.model.FeedScopedId)2 Timetable (org.opentripplanner.model.Timetable)2 RoutingService (org.opentripplanner.routing.RoutingService)2 ServiceDay (org.opentripplanner.routing.core.ServiceDay)2 TripTimes (org.opentripplanner.routing.trippattern.TripTimes)2 Scalars (graphql.Scalars)1 Relay (graphql.relay.Relay)1