Search in sources :

Example 56 with Trip

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

the class StopTimesMapperTest method testMapStopTimes.

@Test
public void testMapStopTimes() {
    NetexTestDataSample sample = new NetexTestDataSample();
    StopTimesMapper stopTimesMapper = new StopTimesMapper(MappingSupport.ID_FACTORY, sample.getStopsById(), sample.getDestinationDisplayById(), sample.getQuayIdByStopPointRef());
    StopTimesMapper.MappedStopTimes result = stopTimesMapper.mapToStopTimes(sample.getJourneyPattern(), new Trip(), sample.getTimetabledPassingTimes());
    List<StopTime> stopTimes = result.stopTimes;
    assertEquals(4, stopTimes.size());
    assertStop(stopTimes.get(0), "NSR:Quay:1", 18000, "Bergen");
    assertStop(stopTimes.get(1), "NSR:Quay:2", 18240, "Bergen");
    assertStop(stopTimes.get(2), "NSR:Quay:3", 18600, "Stavanger");
    assertStop(stopTimes.get(3), "NSR:Quay:4", 18900, "Stavanger");
    Map<String, StopTime> map = result.stopTimeByNetexId;
    assertEquals(stopTimes.get(0), map.get("TTPT-1"));
    assertEquals(stopTimes.get(1), map.get("TTPT-2"));
    assertEquals(stopTimes.get(2), map.get("TTPT-3"));
    assertEquals(stopTimes.get(3), map.get("TTPT-4"));
}
Also used : Trip(org.opentripplanner.model.Trip) StopTime(org.opentripplanner.model.StopTime) Test(org.junit.Test)

Example 57 with Trip

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

the class JourneyWhiteListed method isTripTimeShortAcceptable.

private static boolean isTripTimeShortAcceptable(TripTimeShort tts, Collection<FeedScopedId> authorityIds, Collection<FeedScopedId> lineIds, RoutingService routingService) {
    Trip trip = routingService.getTripForId().get(tts.tripId);
    if (trip == null || trip.getRoute() == null) {
        return true;
    }
    Route route = trip.getRoute();
    boolean okForAuthority = authorityIds.contains(route.getAgency().getId());
    boolean okForLine = lineIds.contains(route.getId());
    return okForAuthority || okForLine;
}
Also used : Trip(org.opentripplanner.model.Trip) Route(org.opentripplanner.model.Route)

Example 58 with Trip

use of org.opentripplanner.model.Trip 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;
}
Also used : Trip(org.opentripplanner.model.Trip) TransitAlert(org.opentripplanner.routing.alertpatch.TransitAlert) TransitAlertService(org.opentripplanner.routing.services.TransitAlertService) Stop(org.opentripplanner.model.Stop) FeedScopedId(org.opentripplanner.model.FeedScopedId) Date(java.util.Date) HashSet(java.util.HashSet)

Example 59 with Trip

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

the class TripPatternMapper method mapTripPattern.

Result mapTripPattern(JourneyPattern journeyPattern) {
    // Make sure the result is clean, by creating a new object.
    result = new Result();
    Collection<ServiceJourney> serviceJourneys = serviceJourneyByPatternId.lookup(journeyPattern.getId());
    if (serviceJourneys == null || serviceJourneys.isEmpty()) {
        LOG.warn("ServiceJourneyPattern " + journeyPattern.getId() + " does not contain any serviceJourneys.");
        return null;
    }
    List<Trip> trips = new ArrayList<>();
    for (ServiceJourney serviceJourney : serviceJourneys) {
        Trip trip = tripMapper.mapServiceJourney(serviceJourney);
        // Unable to map ServiceJourney, problem logged by the mapper above
        if (trip == null)
            continue;
        StopTimesMapper.MappedStopTimes stopTimes = stopTimesMapper.mapToStopTimes(journeyPattern, trip, serviceJourney.getPassingTimes().getTimetabledPassingTime());
        // Unable to map StopTimes, problem logged by the mapper above
        if (stopTimes == null)
            continue;
        result.tripStopTimes.put(trip, stopTimes.stopTimes);
        result.stopTimeByNetexId.putAll(stopTimes.stopTimeByNetexId);
        trip.setTripHeadsign(getHeadsign(stopTimes.stopTimes));
        trips.add(trip);
    }
    // No trips successfully mapped
    if (trips.isEmpty())
        return result;
    // Create StopPattern from any trip (since they are part of the same JourneyPattern)
    StopPattern stopPattern = new StopPattern(result.tripStopTimes.get(trips.get(0)));
    TripPattern tripPattern = new TripPattern(lookupRoute(journeyPattern), stopPattern);
    tripPattern.setId(idFactory.createId(journeyPattern.getId()));
    tripPattern.name = journeyPattern.getName() == null ? "" : journeyPattern.getName().getValue();
    createTripTimes(trips, tripPattern);
    result.tripPatterns.add(tripPattern);
    return result;
}
Also used : StopPattern(org.opentripplanner.model.StopPattern) ServiceJourney(org.rutebanken.netex.model.ServiceJourney) Trip(org.opentripplanner.model.Trip) ArrayList(java.util.ArrayList) TripPattern(org.opentripplanner.model.TripPattern)

Example 60 with Trip

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

the class SeattleFareServiceFactory method processGtfs.

@Override
public void processGtfs(OtpTransitService transitService) {
    // Add custom extension: trips may have a fare ID specified in KCM GTFS.
    // Need to ensure that we are scoped to feed when adding trips to FareRuleSet,
    // since fare IDs may not be unique across feeds and trip agency IDsqq
    // may not match fare attribute agency IDs (which are feed IDs).
    Map<FeedScopedId, FareRuleSet> feedFareRules = new HashMap<>();
    fillFareRules(transitService.getAllFareAttributes(), transitService.getAllFareRules(), feedFareRules);
    regularFareRules.putAll(feedFareRules);
    Map<String, FareRuleSet> feedFareRulesById = new HashMap<>();
    for (FareRuleSet rule : regularFareRules.values()) {
        String id = rule.getFareAttribute().getId().getId();
        feedFareRulesById.put(id, rule);
    }
    for (Trip trip : transitService.getAllTrips()) {
        String fareId = trip.getFareId();
        FareRuleSet rule = feedFareRulesById.get(fareId);
        if (rule != null)
            rule.addTrip(trip.getId());
    }
}
Also used : Trip(org.opentripplanner.model.Trip) HashMap(java.util.HashMap) FeedScopedId(org.opentripplanner.model.FeedScopedId) FareRuleSet(org.opentripplanner.routing.core.FareRuleSet)

Aggregations

Trip (org.opentripplanner.model.Trip)88 FeedScopedId (org.opentripplanner.model.FeedScopedId)42 TripPattern (org.opentripplanner.model.TripPattern)39 Test (org.junit.Test)24 Route (org.opentripplanner.model.Route)24 ArrayList (java.util.ArrayList)23 List (java.util.List)19 ServiceDate (org.opentripplanner.model.calendar.ServiceDate)19 TripTimes (org.opentripplanner.routing.trippattern.TripTimes)18 Stop (org.opentripplanner.model.Stop)15 StopTime (org.opentripplanner.model.StopTime)15 HashSet (java.util.HashSet)13 Collectors (java.util.stream.Collectors)13 Map (java.util.Map)12 Agency (org.opentripplanner.model.Agency)12 HashMap (java.util.HashMap)11 Deduplicator (org.opentripplanner.routing.trippattern.Deduplicator)11 Collection (java.util.Collection)10 Station (org.opentripplanner.model.Station)10 Set (java.util.Set)8