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