Search in sources :

Example 11 with Trip

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

the class TripPattern method setServiceCodes.

/**
 * A bit of a strange place to set service codes all at once when TripTimes are already added,
 * but we need a reference to the Graph or at least the codes map. This could also be
 * placed in the hop factory itself.
 */
public void setServiceCodes(Map<AgencyAndId, Integer> serviceCodes) {
    services = new BitSet();
    for (Trip trip : trips) {
        services.set(serviceCodes.get(trip.getServiceId()));
    }
    scheduledTimetable.setServiceCodes(serviceCodes);
}
Also used : Trip(org.onebusaway.gtfs.model.Trip)

Example 12 with Trip

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

the class TimetableSnapshotSource method getPatternForTripId.

/**
 * Retrieve a trip pattern given a feed id and trid id.
 *
 * @param feedId feed id for the trip id
 * @param tripId trip id without agency
 * @return trip pattern or null if no trip pattern was found
 */
private TripPattern getPatternForTripId(String feedId, String tripId) {
    Trip trip = graphIndex.tripForId.get(new AgencyAndId(feedId, tripId));
    TripPattern pattern = graphIndex.patternForTrip.get(trip);
    return pattern;
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TripPattern(org.opentripplanner.routing.edgetype.TripPattern)

Example 13 with Trip

use of org.onebusaway.gtfs.model.Trip 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<AgencyAndId> 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.onebusaway.gtfs.model.Trip) TripDescriptor(com.google.transit.realtime.GtfsRealtime.TripDescriptor) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Stop(org.onebusaway.gtfs.model.Stop)

Example 14 with Trip

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

the class SeattleFareServiceFactory method processGtfs.

@Override
public void processGtfs(GtfsRelationalDao dao) {
    // 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<AgencyAndId, FareRuleSet> feedFareRules = new HashMap<>();
    fillFareRules(null, dao.getAllFareAttributes(), dao.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 : dao.getAllTrips()) {
        String fareId = trip.getFareId();
        FareRuleSet rule = feedFareRulesById.get(fareId);
        if (rule != null)
            rule.addTrip(trip.getId());
    }
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) HashMap(java.util.HashMap) FareRuleSet(org.opentripplanner.routing.core.FareRuleSet)

Example 15 with Trip

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

the class GraphPath method getTrips.

/**
 * @return A list containing one AgencyAndId (trip_id) for each vehicle boarded in this path,
 * in the chronological order they are boarded.
 */
public List<AgencyAndId> getTrips() {
    List<AgencyAndId> ret = new LinkedList<AgencyAndId>();
    Trip lastTrip = null;
    for (State s : states) {
        if (s.getBackEdge() != null) {
            Trip trip = s.getBackTrip();
            if (trip != null && trip != lastTrip) {
                ret.add(trip.getId());
                lastTrip = trip;
            }
        }
    }
    return ret;
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) State(org.opentripplanner.routing.core.State) LinkedList(java.util.LinkedList)

Aggregations

Trip (org.onebusaway.gtfs.model.Trip)166 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)89 Test (org.junit.Test)56 StopTime (org.onebusaway.gtfs.model.StopTime)52 Route (org.onebusaway.gtfs.model.Route)51 Stop (org.onebusaway.gtfs.model.Stop)40 ArrayList (java.util.ArrayList)34 List (java.util.List)23 GtfsMutableRelationalDao (org.onebusaway.gtfs.services.GtfsMutableRelationalDao)21 TripPattern (org.opentripplanner.routing.edgetype.TripPattern)20 Agency (org.onebusaway.gtfs.model.Agency)19 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)19 HashMap (java.util.HashMap)14 ServiceCalendar (org.onebusaway.gtfs.model.ServiceCalendar)13 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)13 HashSet (java.util.HashSet)12 Vertex (org.opentripplanner.routing.graph.Vertex)12 FactoryMap (org.onebusaway.collections.FactoryMap)10 ServiceCalendarDate (org.onebusaway.gtfs.model.ServiceCalendarDate)10 ShapePoint (org.onebusaway.gtfs.model.ShapePoint)10