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