Search in sources :

Example 11 with TripPattern

use of org.opentripplanner.model.TripPattern in project OpenTripPlanner by opentripplanner.

the class IndexAPI method getStopsForRoute.

/**
 * Return all stops in any pattern on a given route.
 */
@GET
@Path("/routes/{routeId}/stops")
public List<ApiStopShort> getStopsForRoute(@PathParam("routeId") String routeId) {
    RoutingService routingService = createRoutingService();
    Route route = getRoute(routingService, routeId);
    Set<Stop> stops = new HashSet<>();
    Collection<TripPattern> patterns = routingService.getPatternsForRoute().get(route);
    for (TripPattern pattern : patterns) {
        stops.addAll(pattern.getStops());
    }
    return StopMapper.mapToApiShort(stops);
}
Also used : ApiStop(org.opentripplanner.api.model.ApiStop) Stop(org.opentripplanner.model.Stop) RoutingService(org.opentripplanner.routing.RoutingService) ApiRoute(org.opentripplanner.api.model.ApiRoute) Route(org.opentripplanner.model.Route) TripPattern(org.opentripplanner.model.TripPattern) HashSet(java.util.HashSet) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 12 with TripPattern

use of org.opentripplanner.model.TripPattern in project OpenTripPlanner by opentripplanner.

the class IndexAPI method getTripsForRoute.

/**
 * Return all trips in any pattern on the given route.
 */
@GET
@Path("/routes/{routeId}/trips")
public List<ApiTripShort> getTripsForRoute(@PathParam("routeId") String routeId) {
    RoutingService routingService = createRoutingService();
    Route route = getRoute(routingService, routeId);
    List<Trip> trips = new ArrayList<>();
    Collection<TripPattern> patterns = routingService.getPatternsForRoute().get(route);
    for (TripPattern pattern : patterns) {
        trips.addAll(pattern.getTrips());
    }
    return TripMapper.mapToApiShort(trips);
}
Also used : Trip(org.opentripplanner.model.Trip) ApiTrip(org.opentripplanner.api.model.ApiTrip) RoutingService(org.opentripplanner.routing.RoutingService) ArrayList(java.util.ArrayList) ApiRoute(org.opentripplanner.api.model.ApiRoute) Route(org.opentripplanner.model.Route) TripPattern(org.opentripplanner.model.TripPattern) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 13 with TripPattern

use of org.opentripplanner.model.TripPattern in project OpenTripPlanner by opentripplanner.

the class GenerateTripPatternsOperation method buildTripPatternForTrip.

private void buildTripPatternForTrip(Trip trip) {
    // Check that the mode is supported
    if (trip.getRoute().getMode() == null) {
        issueStore.add(new GTFSModeNotSupported(trip, Integer.toString(trip.getRoute().getType())));
        return;
    }
    // TODO: move to a validator module
    if (!calendarServiceIds.contains(trip.getServiceId())) {
        issueStore.add(new TripUndefinedService(trip));
        // Invalid trip, skip it, it will break later
        return;
    }
    int directionId = getDirectionId(trip);
    Collection<StopTime> stopTimes = transitDaoBuilder.getStopTimesSortedByTrip().get(trip);
    // If after filtering this trip does not contain at least 2 stoptimes, it does not serve any purpose.
    if (stopTimes.size() < 2) {
        issueStore.add(new TripDegenerate(trip));
        return;
    }
    // Get the existing TripPattern for this filtered StopPattern, or create one.
    StopPattern stopPattern = new StopPattern(stopTimes);
    TripPattern tripPattern = findOrCreateTripPattern(stopPattern, trip.getRoute(), directionId);
    // Create a TripTimes object for this list of stoptimes, which form one trip.
    TripTimes tripTimes = new TripTimes(trip, stopTimes, deduplicator);
    // If this trip is referenced by one or more lines in frequencies.txt, wrap it in a FrequencyEntry.
    List<Frequency> frequencies = frequenciesForTrip.get(trip);
    if (frequencies != null && !(frequencies.isEmpty())) {
        for (Frequency freq : frequencies) {
            tripPattern.add(new FrequencyEntry(freq, tripTimes));
            freqCount++;
        }
    // TODO replace: createGeometry(graph, trip, stopTimes, hops);
    } else // This trip was not frequency-based. Add the TripTimes directly to the TripPattern's scheduled timetable.
    {
        tripPattern.add(tripTimes);
        scheduledCount++;
    }
}
Also used : StopPattern(org.opentripplanner.model.StopPattern) GTFSModeNotSupported(org.opentripplanner.graph_builder.issues.GTFSModeNotSupported) TripTimes(org.opentripplanner.routing.trippattern.TripTimes) Frequency(org.opentripplanner.model.Frequency) TripUndefinedService(org.opentripplanner.graph_builder.issues.TripUndefinedService) FrequencyEntry(org.opentripplanner.routing.trippattern.FrequencyEntry) TripPattern(org.opentripplanner.model.TripPattern) StopTime(org.opentripplanner.model.StopTime) TripDegenerate(org.opentripplanner.graph_builder.issues.TripDegenerate)

Example 14 with TripPattern

use of org.opentripplanner.model.TripPattern in project OpenTripPlanner by opentripplanner.

the class NetexMapper method mapTripPatterns.

private void mapTripPatterns(NetexImportDataIndexReadOnlyView netexIndex) {
    TripPatternMapper tripPatternMapper = new TripPatternMapper(idFactory, transitBuilder.getStops(), transitBuilder.getRoutes(), transitBuilder.getShapePoints().keySet(), netexIndex.getRouteById(), netexIndex.getJourneyPatternsById(), netexIndex.getQuayIdByStopPointRef(), netexIndex.getDestinationDisplayById(), netexIndex.getServiceJourneyByPatternId(), deduplicator);
    for (JourneyPattern journeyPattern : netexIndex.getJourneyPatternsById().localValues()) {
        TripPatternMapper.Result result = tripPatternMapper.mapTripPattern(journeyPattern);
        for (Map.Entry<Trip, List<StopTime>> it : result.tripStopTimes.entrySet()) {
            transitBuilder.getStopTimesSortedByTrip().put(it.getKey(), it.getValue());
            transitBuilder.getTripsById().add(it.getKey());
        }
        for (TripPattern it : result.tripPatterns) {
            transitBuilder.getTripPatterns().put(it.stopPattern, it);
        }
        stopTimesByNetexId.putAll(result.stopTimeByNetexId);
    }
}
Also used : JourneyPattern(org.rutebanken.netex.model.JourneyPattern) Trip(org.opentripplanner.model.Trip) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) TripPattern(org.opentripplanner.model.TripPattern)

Example 15 with TripPattern

use of org.opentripplanner.model.TripPattern in project OpenTripPlanner by opentripplanner.

the class OtpTransitServiceBuilder method fixOrRemovePatternsWhichReferenceNoneExistingTrips.

/**
 * Remove none existing trips from patterns and then remove empty patterns
 */
private void fixOrRemovePatternsWhichReferenceNoneExistingTrips() {
    int orgSize = tripPatterns.size();
    List<Map.Entry<StopPattern, TripPattern>> removePatterns = new ArrayList<>();
    for (Map.Entry<StopPattern, TripPattern> e : tripPatterns.entries()) {
        TripPattern ptn = e.getValue();
        ptn.removeTrips(t -> !tripsById.containsKey(t.getId()));
        if (ptn.getTrips().isEmpty()) {
            removePatterns.add(e);
        }
    }
    for (Map.Entry<StopPattern, TripPattern> it : removePatterns) {
        tripPatterns.remove(it.getKey(), it.getValue());
    }
    logRemove("TripPattern", orgSize, tripPatterns.size(), "No trips for pattern exist.");
}
Also used : StopPattern(org.opentripplanner.model.StopPattern) ArrayList(java.util.ArrayList) Map(java.util.Map) ShapePoint(org.opentripplanner.model.ShapePoint) TripPattern(org.opentripplanner.model.TripPattern)

Aggregations

TripPattern (org.opentripplanner.model.TripPattern)61 Trip (org.opentripplanner.model.Trip)26 FeedScopedId (org.opentripplanner.model.FeedScopedId)23 Stop (org.opentripplanner.model.Stop)23 ArrayList (java.util.ArrayList)19 TripTimes (org.opentripplanner.routing.trippattern.TripTimes)19 Timetable (org.opentripplanner.model.Timetable)13 ServiceDate (org.opentripplanner.model.calendar.ServiceDate)13 Route (org.opentripplanner.model.Route)12 Test (org.junit.Test)11 HashSet (java.util.HashSet)8 RoutingService (org.opentripplanner.routing.RoutingService)8 List (java.util.List)7 StopPattern (org.opentripplanner.model.StopPattern)7 TimetableSnapshot (org.opentripplanner.model.TimetableSnapshot)7 GET (javax.ws.rs.GET)6 Path (javax.ws.rs.Path)6 StopTime (org.opentripplanner.model.StopTime)5 TripUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate)4 StopTimeUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeUpdate)4