Search in sources :

Example 16 with Stop

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());
}
Also used : ApiStop(org.opentripplanner.api.model.ApiStop) Stop(org.opentripplanner.model.Stop) RoutingService(org.opentripplanner.routing.RoutingService) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 17 with Stop

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);
    }
}
Also used : Trip(org.opentripplanner.model.Trip) Stop(org.opentripplanner.model.Stop) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) RepeatedStops(org.opentripplanner.graph_builder.issues.RepeatedStops) TIntList(gnu.trove.list.TIntList) StopTime(org.opentripplanner.model.StopTime)

Example 18 with Stop

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());
}
Also used : Stop(org.opentripplanner.model.Stop)

Example 19 with Stop

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;
}
Also used : WgsCoordinate(org.opentripplanner.model.WgsCoordinate) Stop(org.opentripplanner.model.Stop) QuayWithoutCoordinates(org.opentripplanner.graph_builder.issues.QuayWithoutCoordinates)

Example 20 with 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;
}
Also used : Trip(org.opentripplanner.model.Trip) TripDescriptor(com.google.transit.realtime.GtfsRealtime.TripDescriptor) Stop(org.opentripplanner.model.Stop) FeedScopedId(org.opentripplanner.model.FeedScopedId)

Aggregations

Stop (org.opentripplanner.model.Stop)73 FeedScopedId (org.opentripplanner.model.FeedScopedId)25 ArrayList (java.util.ArrayList)24 TripPattern (org.opentripplanner.model.TripPattern)24 Trip (org.opentripplanner.model.Trip)21 ServiceDate (org.opentripplanner.model.calendar.ServiceDate)13 RoutingService (org.opentripplanner.routing.RoutingService)13 TransitStopVertex (org.opentripplanner.routing.vertextype.TransitStopVertex)13 HashSet (java.util.HashSet)12 Station (org.opentripplanner.model.Station)12 TripTimes (org.opentripplanner.routing.trippattern.TripTimes)11 List (java.util.List)10 Test (org.junit.Test)8 Route (org.opentripplanner.model.Route)8 StopTime (org.opentripplanner.model.StopTime)8 Collectors (java.util.stream.Collectors)7 GET (javax.ws.rs.GET)7 Path (javax.ws.rs.Path)7 ApiStop (org.opentripplanner.api.model.ApiStop)7 TripTimeShort (org.opentripplanner.model.TripTimeShort)7