use of org.opentripplanner.model.Stop in project OpenTripPlanner by opentripplanner.
the class IndexAPI method getRoutesForStop.
@GET
@Path("/stops/{stopId}/routes")
public List<ApiRouteShort> getRoutesForStop(@PathParam("stopId") String stopId) {
RoutingService routingService = createRoutingService();
Stop stop = getStop(routingService, stopId);
return routingService.getPatternsForStop(stop).stream().map(it -> it.route).map(RouteMapper::mapToApiShort).collect(Collectors.toList());
}
use of org.opentripplanner.model.Stop in project OpenTripPlanner by opentripplanner.
the class RepairStopTimesForEachTripOperation method run.
public void run() {
final int tripSize = stopTimesByTrip.size();
int tripCount = 0;
for (Trip trip : stopTimesByTrip.keys()) {
if (++tripCount % 100000 == 0) {
LOG.debug("Repair StopTimes for trips {}/{}", tripCount, tripSize);
}
/* Fetch the stop times for this trip. Copy the list since it's immutable. */
List<StopTime> stopTimes = new ArrayList<>(stopTimesByTrip.get(trip));
/* Remove stoptimes without stops */
stopTimes.removeIf(st -> !(st.getStop() instanceof Stop));
/* Stop times frequently contain duplicate, missing, or incorrect entries. Repair them. */
TIntList removedStopSequences = removeRepeatedStops(stopTimes);
if (!removedStopSequences.isEmpty()) {
issueStore.add(new RepeatedStops(trip, removedStopSequences));
}
filterStopTimes(stopTimes);
interpolateStopTimes(stopTimes);
stopTimesByTrip.replace(trip, stopTimes);
}
}
use of org.opentripplanner.model.Stop in project OpenTripPlanner by opentripplanner.
the class StopAndStationMapper method addNewStopToParentIfNotPresent.
private void addNewStopToParentIfNotPresent(Quay quay, Station station, List<FareZone> fareZones) {
// Continue if this is not newest version of quay
if (!quayIndex.isNewerOrSameVersionComparedWithExistingValues(quay)) {
return;
}
if (quaysAlreadyProcessed.contains(quay.getId())) {
return;
}
Stop stop = stopMapper.mapQuayToStop(quay, station, fareZones);
if (stop == null)
return;
station.addChildStop(stop);
resultStops.add(stop);
quaysAlreadyProcessed.add(quay.getId());
}
use of org.opentripplanner.model.Stop in project OpenTripPlanner by opentripplanner.
the class StopMapper method mapQuayToStop.
/**
* Map Netex Quay to OTP Stop
*/
Stop mapQuayToStop(Quay quay, Station parentStation, List<FareZone> fareZones) {
WgsCoordinate coordinate = WgsCoordinateMapper.mapToDomain(quay.getCentroid());
if (coordinate == null) {
issueStore.add(new QuayWithoutCoordinates(quay.getId()));
return null;
}
Stop stop = new Stop(idFactory.createId(quay.getId()), parentStation.getName(), quay.getPublicCode(), null, WgsCoordinateMapper.mapToDomain(quay.getCentroid()), null, null, null, fareZones, null, null, null);
stop.setParentStation(parentStation);
return stop;
}
use of org.opentripplanner.model.Stop in project OpenTripPlanner by opentripplanner.
the class TimetableSnapshotSource method validateAndHandleModifiedTrip.
/**
* Validate and handle GTFS-RT TripUpdate message containing a MODIFIED trip.
*
* @param graph graph to update
* @param tripUpdate GTFS-RT TripUpdate message
* @param feedId
* @param serviceDate
* @return true iff successful
*/
private boolean validateAndHandleModifiedTrip(final Graph graph, final TripUpdate tripUpdate, final String feedId, final ServiceDate serviceDate) {
// Preconditions
Preconditions.checkNotNull(graph);
Preconditions.checkNotNull(tripUpdate);
Preconditions.checkNotNull(serviceDate);
//
// Validate modified trip
//
// Check whether trip id of MODIFIED trip is available
final TripDescriptor tripDescriptor = tripUpdate.getTrip();
if (!tripDescriptor.hasTripId()) {
LOG.warn("No trip id found for MODIFIED trip, skipping.");
return false;
}
// Check whether trip id already exists in graph
String tripId = tripDescriptor.getTripId();
Trip trip = getTripForTripId(feedId, tripId);
if (trip == null) {
// TODO: should we support this and consider it an ADDED trip?
LOG.warn("Graph does not contain trip id of MODIFIED trip, skipping.");
return false;
}
// Check whether a start date exists
if (!tripDescriptor.hasStartDate()) {
// TODO: should we support this and apply update to all days?
LOG.warn("MODIFIED trip doesn't have a start date in TripDescriptor, skipping.");
return false;
} else {
// Check whether service date is served by trip
final Set<FeedScopedId> serviceIds = graph.getCalendarService().getServiceIdsOnDate(serviceDate);
if (!serviceIds.contains(trip.getServiceId())) {
// TODO: should we support this and change service id of trip?
LOG.warn("MODIFIED trip has a service date that is not served by trip, skipping.");
return false;
}
}
// Check whether at least two stop updates exist
if (tripUpdate.getStopTimeUpdateCount() < 2) {
LOG.warn("MODIFIED trip has less then two stops, skipping.");
return false;
}
// Check whether all stop times are available and all stops exist
List<Stop> stops = checkNewStopTimeUpdatesAndFindStops(feedId, tripUpdate);
if (stops == null) {
return false;
}
//
// Handle modified trip
//
final boolean success = handleModifiedTrip(graph, trip, tripUpdate, stops, feedId, serviceDate);
return success;
}
Aggregations