use of org.opentripplanner.model.Stop in project OpenTripPlanner by opentripplanner.
the class SiriFuzzyTripMatcher method getStop.
public FeedScopedId getStop(String siriStopId) {
if (nonExistingStops.contains(siriStopId)) {
return null;
}
// TODO OTP2 #2838 - Guessing on the feedId is not a deterministic way to find a stop.
// First, assume same agency
Stop firstStop = routingService.getAllStops().stream().findFirst().get();
FeedScopedId id = new FeedScopedId(firstStop.getId().getFeedId(), siriStopId);
if (routingService.getStopForId(id) != null) {
return id;
} else if (routingService.getStationById(id) != null) {
return id;
}
// Not same agency - loop through all stops/Stations
Collection<Stop> stops = routingService.getAllStops();
for (Stop stop : stops) {
if (stop.getId().getId().equals(siriStopId)) {
return stop.getId();
}
}
// No match found in quays - check parent-stops (stopplace)
for (Station station : routingService.getStations()) {
if (station.getId().getId().equals(siriStopId)) {
return station.getId();
}
}
nonExistingStops.add(siriStopId);
return null;
}
use of org.opentripplanner.model.Stop 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);
}
use of org.opentripplanner.model.Stop in project OpenTripPlanner by opentripplanner.
the class StopPlaceType method fetchStopPlaces.
public static Collection<MonoOrMultiModalStation> fetchStopPlaces(double minLat, double minLon, double maxLat, double maxLon, String authority, Boolean filterByInUse, String multiModalMode, DataFetchingEnvironment environment) {
final RoutingService routingService = GqlUtil.getRoutingService(environment);
Stream<Station> stations = routingService.getStopsByBoundingBox(minLat, minLon, maxLat, maxLon).stream().map(Stop::getParentStation).filter(Objects::nonNull).distinct();
if (authority != null) {
stations = stations.filter(s -> s.getId().getFeedId().equalsIgnoreCase(authority));
}
if (TRUE.equals(filterByInUse)) {
stations = stations.filter(s -> isStopPlaceInUse(s, routingService));
}
// "child" - Only mono modal children stop places, not their multi modal parent stop
if ("child".equals(multiModalMode)) {
return stations.map(s -> {
MultiModalStation parent = routingService.getMultiModalStationForStations().get(s);
return new MonoOrMultiModalStation(s, parent);
}).collect(Collectors.toList());
} else // "all" - Both multiModal parents and their mono modal child stop places
if ("all".equals(multiModalMode)) {
Set<MonoOrMultiModalStation> result = new HashSet<>();
stations.forEach(it -> {
MultiModalStation p = routingService.getMultiModalStationForStations().get(it);
result.add(new MonoOrMultiModalStation(it, p));
if (p != null) {
result.add(new MonoOrMultiModalStation(p));
}
});
return result;
} else // Default "parent" - Multi modal parent stop places without their mono modal children
if ("parent".equals(multiModalMode)) {
return stations.map(it -> routingService.getMultiModalStationForStations().get(it)).filter(Objects::nonNull).distinct().map(MonoOrMultiModalStation::new).collect(Collectors.toUnmodifiableList());
} else {
throw new IllegalArgumentException("Unexpected multiModalMode: " + multiModalMode);
}
}
use of org.opentripplanner.model.Stop 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.Stop in project OpenTripPlanner by opentripplanner.
the class EstimatedCallType method getAllRelevantAlerts.
/**
* Resolves all AlertPatches that are relevant for the supplied TripTimeShort.
*/
private static Collection<TransitAlert> getAllRelevantAlerts(TripTimeShort tripTimeShort, RoutingService routingService) {
FeedScopedId tripId = tripTimeShort.tripId;
Trip trip = routingService.getTripForId().get(tripId);
FeedScopedId routeId = trip.getRoute().getId();
FeedScopedId stopId = tripTimeShort.stopId;
Stop stop = routingService.getStopForId(stopId);
FeedScopedId parentStopId = stop.getParentStation().getId();
Collection<TransitAlert> allAlerts = new HashSet<>();
TransitAlertService alertPatchService = routingService.getTransitAlertService();
// Quay
allAlerts.addAll(alertPatchService.getStopAlerts(stopId));
allAlerts.addAll(alertPatchService.getStopAndTripAlerts(stopId, tripId));
allAlerts.addAll(alertPatchService.getStopAndRouteAlerts(stopId, routeId));
// StopPlace
allAlerts.addAll(alertPatchService.getStopAlerts(parentStopId));
allAlerts.addAll(alertPatchService.getStopAndTripAlerts(parentStopId, tripId));
allAlerts.addAll(alertPatchService.getStopAndRouteAlerts(parentStopId, routeId));
// Trip
allAlerts.addAll(alertPatchService.getTripAlerts(tripId));
// Route
allAlerts.addAll(alertPatchService.getRouteAlerts(routeId));
// Agency
// TODO OTP2 This should probably have a FeedScopeId argument instead of string
allAlerts.addAll(alertPatchService.getAgencyAlerts(trip.getRoute().getAgency().getId()));
// TripPattern
allAlerts.addAll(alertPatchService.getTripPatternAlerts(routingService.getPatternForTrip().get(trip).getId()));
long serviceDayMillis = 1000 * tripTimeShort.serviceDay;
long arrivalMillis = 1000 * tripTimeShort.realtimeArrival;
long departureMillis = 1000 * tripTimeShort.realtimeDeparture;
filterSituationsByDateAndStopConditions(allAlerts, new Date(serviceDayMillis + arrivalMillis), new Date(serviceDayMillis + departureMillis), Arrays.asList(StopCondition.STOP, StopCondition.START_POINT, StopCondition.EXCEPTIONAL_STOP));
return allAlerts;
}
Aggregations