Search in sources :

Example 51 with TripPattern

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

the class IndexAPI method getPatternsForRoute.

/**
 * Return all stop patterns used by trips on the given route.
 */
@GET
@Path("/routes/{routeId}/patterns")
public List<ApiPatternShort> getPatternsForRoute(@PathParam("routeId") String routeId) {
    RoutingService routingService = createRoutingService();
    Collection<TripPattern> patterns = routingService.getPatternsForRoute().get(getRoute(routingService, routeId));
    return TripPatternMapper.mapToApiShort(patterns);
}
Also used : RoutingService(org.opentripplanner.routing.RoutingService) TripPattern(org.opentripplanner.model.TripPattern) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 52 with TripPattern

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

the class IndexAPI method getStoptimesForTrip.

@GET
@Path("/trips/{tripId}/stoptimes")
public List<TripTimeShort> getStoptimesForTrip(@PathParam("tripId") String tripId) {
    RoutingService routingService = createRoutingService();
    Trip trip = getTrip(routingService, tripId);
    TripPattern pattern = getTripPattern(routingService, trip);
    // Note, we need the updated timetable not the scheduled one (which contains no real-time updates).
    Timetable table = routingService.getTimetableForTripPattern(pattern);
    return TripTimeShort.fromTripTimes(table, trip);
}
Also used : Timetable(org.opentripplanner.model.Timetable) 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 53 with TripPattern

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

the class TripPatternMapper method mapTripPattern.

Result mapTripPattern(JourneyPattern journeyPattern) {
    // Make sure the result is clean, by creating a new object.
    result = new Result();
    Collection<ServiceJourney> serviceJourneys = serviceJourneyByPatternId.lookup(journeyPattern.getId());
    if (serviceJourneys == null || serviceJourneys.isEmpty()) {
        LOG.warn("ServiceJourneyPattern " + journeyPattern.getId() + " does not contain any serviceJourneys.");
        return null;
    }
    List<Trip> trips = new ArrayList<>();
    for (ServiceJourney serviceJourney : serviceJourneys) {
        Trip trip = tripMapper.mapServiceJourney(serviceJourney);
        // Unable to map ServiceJourney, problem logged by the mapper above
        if (trip == null)
            continue;
        StopTimesMapper.MappedStopTimes stopTimes = stopTimesMapper.mapToStopTimes(journeyPattern, trip, serviceJourney.getPassingTimes().getTimetabledPassingTime());
        // Unable to map StopTimes, problem logged by the mapper above
        if (stopTimes == null)
            continue;
        result.tripStopTimes.put(trip, stopTimes.stopTimes);
        result.stopTimeByNetexId.putAll(stopTimes.stopTimeByNetexId);
        trip.setTripHeadsign(getHeadsign(stopTimes.stopTimes));
        trips.add(trip);
    }
    // No trips successfully mapped
    if (trips.isEmpty())
        return result;
    // Create StopPattern from any trip (since they are part of the same JourneyPattern)
    StopPattern stopPattern = new StopPattern(result.tripStopTimes.get(trips.get(0)));
    TripPattern tripPattern = new TripPattern(lookupRoute(journeyPattern), stopPattern);
    tripPattern.setId(idFactory.createId(journeyPattern.getId()));
    tripPattern.name = journeyPattern.getName() == null ? "" : journeyPattern.getName().getValue();
    createTripTimes(trips, tripPattern);
    result.tripPatterns.add(tripPattern);
    return result;
}
Also used : StopPattern(org.opentripplanner.model.StopPattern) ServiceJourney(org.rutebanken.netex.model.ServiceJourney) Trip(org.opentripplanner.model.Trip) ArrayList(java.util.ArrayList) TripPattern(org.opentripplanner.model.TripPattern)

Example 54 with TripPattern

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

the class RaptorPathToItineraryMapper method extractIntermediateStops.

private List<StopArrival> extractIntermediateStops(TransitPathLeg<TripSchedule> pathLeg) {
    List<StopArrival> visits = new ArrayList<>();
    TripPattern tripPattern = pathLeg.trip().getOriginalTripPattern();
    TripSchedule tripSchedule = pathLeg.trip();
    boolean boarded = false;
    for (int j = 0; j < tripPattern.stopPattern.stops.length; j++) {
        if (boarded && tripSchedule.arrival(j) == pathLeg.toTime()) {
            break;
        }
        if (boarded) {
            Stop stop = tripPattern.stopPattern.stops[j];
            Place place = mapStopToPlace(stop, j);
            // TODO: fill out stopSequence
            StopArrival visit = new StopArrival(place, createCalendar(tripSchedule.arrival(j)), createCalendar(tripSchedule.departure(j)));
            visits.add(visit);
        }
        if (!boarded && tripSchedule.departure(j) == pathLeg.fromTime()) {
            boarded = true;
        }
    }
    return visits;
}
Also used : StopArrival(org.opentripplanner.model.plan.StopArrival) Stop(org.opentripplanner.model.Stop) ArrayList(java.util.ArrayList) TripPattern(org.opentripplanner.model.TripPattern) TripSchedule(org.opentripplanner.routing.algorithm.raptor.transit.TripSchedule) Place(org.opentripplanner.model.plan.Place)

Example 55 with TripPattern

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

TripPattern (org.opentripplanner.model.TripPattern)61 Trip (org.opentripplanner.model.Trip)26 FeedScopedId (org.opentripplanner.model.FeedScopedId)23 Stop (org.opentripplanner.model.Stop)23 ArrayList (java.util.ArrayList)19 TripTimes (org.opentripplanner.routing.trippattern.TripTimes)19 Timetable (org.opentripplanner.model.Timetable)13 ServiceDate (org.opentripplanner.model.calendar.ServiceDate)13 Route (org.opentripplanner.model.Route)12 Test (org.junit.Test)11 HashSet (java.util.HashSet)8 RoutingService (org.opentripplanner.routing.RoutingService)8 List (java.util.List)7 StopPattern (org.opentripplanner.model.StopPattern)7 TimetableSnapshot (org.opentripplanner.model.TimetableSnapshot)7 GET (javax.ws.rs.GET)6 Path (javax.ws.rs.Path)6 StopTime (org.opentripplanner.model.StopTime)5 TripUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate)4 StopTimeUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeUpdate)4