Search in sources :

Example 96 with Trip

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

the class PatternInterlineDwell method traverse.

@Override
public State traverse(State state0) {
    RoutingRequest options = state0.getOptions();
    Trip oldTrip = state0.getBackTrip();
    Trip newTrip = options.arriveBy ? trips.inverse().get(oldTrip) : trips.get(oldTrip);
    if (newTrip == null)
        return null;
    TripPattern newPattern;
    TripTimes newTripTimes;
    TripTimes oldTripTimes = state0.getTripTimes();
    int arrivalTime;
    int departureTime;
    AgencyAndId tripId = state0.getTripId();
    if (options.arriveBy) {
        // traversing backward
        newPattern = ((OnboardVertex) fromv).getTripPattern();
        newTripTimes = newPattern.getResolvedTripTimes(newTrip, state0);
        // FIXME with getLastTime method
        arrivalTime = newTripTimes.getArrivalTime(newTripTimes.getNumStops() - 1);
        departureTime = oldTripTimes.getDepartureTime(0);
    } else {
        // traversing forward
        newPattern = ((OnboardVertex) tov).getTripPattern();
        newTripTimes = newPattern.getResolvedTripTimes(newTrip, state0);
        // FIXME with getLastTime method
        arrivalTime = oldTripTimes.getArrivalTime(oldTripTimes.getNumStops() - 1);
        departureTime = newTripTimes.getDepartureTime(0);
    }
    int boardStopIndex = options.arriveBy ? newPattern.stopPattern.size - 1 : 0;
    if (!newTripTimes.tripAcceptable(state0, boardStopIndex))
        return null;
    int dwellTime = departureTime - arrivalTime;
    if (dwellTime < 0)
        return null;
    StateEditor s1 = state0.edit(this);
    s1.incrementTimeInSeconds(dwellTime);
    // TODO check meaning
    s1.setTripId(newTrip.getId());
    // TODO check meaning
    s1.setPreviousTrip(oldTrip);
    s1.setTripTimes(newTripTimes);
    s1.incrementWeight(dwellTime);
    // Mode should not change.
    return s1.makeState();
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) StateEditor(org.opentripplanner.routing.core.StateEditor) TripTimes(org.opentripplanner.routing.trippattern.TripTimes) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest)

Example 97 with Trip

use of org.onebusaway.gtfs.model.Trip in project gtfs-realtime-validator by CUTR-at-USF.

the class TripDescriptorValidator method checkE035.

/**
 * Checks rule E035 - "GTFS-rt trip.trip_id does not belong to GTFS-rt trip.route_id in GTFS trips.txt", and adds any errors that are found to the provided error list
 *
 * @param entity       entity which contains the specified trip
 * @param trip         trip to examine to see if the trip_id belongs to the route_id
 * @param gtfsMetadata information about the GTFS dataset
 * @param errors       list to add any errors for E034 to
 */
private void checkE035(GtfsRealtime.FeedEntity entity, GtfsRealtime.TripDescriptor trip, GtfsMetadata gtfsMetadata, List<OccurrenceModel> errors) {
    if (trip.hasTripId() && trip.hasRouteId()) {
        if (!gtfsMetadata.getRouteIds().contains(trip.getRouteId())) {
            // route_id isn't in GTFS data (which will be caught by E004) - return;
            return;
        }
        Trip gtfsTrip = gtfsMetadata.getTrips().get(trip.getTripId());
        if (gtfsTrip == null) {
            // trip_id isn't in GTFS data (which will be caught by E003) - return;
            return;
        }
        String gtfsRouteId = gtfsTrip.getRoute().getId().getId();
        if (!gtfsRouteId.equals(trip.getRouteId())) {
            RuleUtils.addOccurrence(E035, "GTFS-rt entity ID " + entity.getId() + " trip_id " + trip.getTripId() + " has route_id " + trip.getRouteId() + " but belongs to GTFS route_id " + gtfsRouteId, errors, _log);
        }
    }
}
Also used : Trip(org.onebusaway.gtfs.model.Trip)

Example 98 with Trip

use of org.onebusaway.gtfs.model.Trip in project gtfs-realtime-validator by CUTR-at-USF.

the class TripDescriptorValidator method checkE030.

/**
 * Checks rule E030 - "GTFS-rt alert trip_id does not belong to GTFS-rt alert route_id in GTFS trips.txt" and adds
 * any errors that are found to the provided errors list
 *
 * @param entity         feed entity to examine that contains an alert
 * @param entitySelector EntitySelector that has both a routeId and a tripDescriptor
 * @param gtfsMetadata   metadata for the static GTFS data
 * @param errors         list to add any errors for E030 to
 */
private void checkE030(GtfsRealtime.FeedEntity entity, GtfsRealtime.EntitySelector entitySelector, GtfsMetadata gtfsMetadata, List<OccurrenceModel> errors) {
    String routeId = entitySelector.getRouteId();
    GtfsRealtime.TripDescriptor tripDescriptor = entitySelector.getTrip();
    if (tripDescriptor.hasTripId()) {
        Trip gtfsTrip = gtfsMetadata.getTrips().get(tripDescriptor.getTripId());
        if (gtfsTrip != null && !routeId.equals(gtfsTrip.getRoute().getId().getId())) {
            String prefix = "alert ID " + entity.getId() + " informed_entity.trip.trip_id " + tripDescriptor.getTripId() + " does not belong to informed_entity.route_id " + routeId + " (GTFS says it belongs to route_id " + gtfsTrip.getRoute().getId().getId() + ")";
            RuleUtils.addOccurrence(E030, prefix, errors, _log);
        }
    }
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) GtfsRealtime(com.google.transit.realtime.GtfsRealtime)

Example 99 with Trip

use of org.onebusaway.gtfs.model.Trip in project gtfs-realtime-validator by CUTR-at-USF.

the class CrossFeedDescriptorValidator method checkE047VehiclePositions.

/**
 * Checks E047 - "VehiclePosition and TripUpdate ID pairing mismatch" for VehiclePositions, and adds a found error to the provided error list.
 *
 * @param vehicle            A map entry of a vehicle_id to a trip_id that represents a vehicle in VehiclePositions and the trip_id that the vehicle contains
 * @param tripUpdatesInverse An inverse map of a TripUpdates feed, with keys that represent the vehicle_ids that each TripUpdate contains, and the value being the TripUpdate trip_id that contains the vehicle.id
 * @param errors             the list to add the errors to
 */
private void checkE047VehiclePositions(Map.Entry<String, String> vehicle, HashMap<String, String> tripUpdatesInverse, GtfsMetadata gtfsMetadata, List<OccurrenceModel> errors) {
    String tripUpdatesTripId = tripUpdatesInverse.get(vehicle.getKey());
    String vehiclePositionsTripId = vehicle.getValue();
    if (!StringUtils.isEmpty(tripUpdatesTripId)) {
        if (!vehiclePositionsTripId.equals(tripUpdatesTripId)) {
            // Log E047 if either trip_id is missing from GTFS, if the block_id is missing for either trip (block_id is an optional field) or if the two trips aren't in the same block
            Trip tripA = gtfsMetadata.getTrips().get(vehiclePositionsTripId);
            Trip tripB = gtfsMetadata.getTrips().get(tripUpdatesTripId);
            if (tripA == null || tripB == null || StringUtils.isEmpty(tripA.getBlockId()) || StringUtils.isEmpty(tripB.getBlockId()) || !tripA.getBlockId().equals(tripB.getBlockId())) {
                // E047 - "VehiclePosition and TripUpdate ID pairing mismatch" for VehiclePositions
                RuleUtils.addOccurrence(E047, "trip_id " + vehicle.getValue() + " and vehicle_id " + vehicle.getKey() + " pairing in VehiclePositions does not match trip_id " + tripUpdatesTripId + " and vehicle_id " + vehicle.getKey() + " pairing in TripUpdates feed and trip block_ids aren't the same", errors, _log);
            }
        }
    }
}
Also used : Trip(org.onebusaway.gtfs.model.Trip)

Example 100 with Trip

use of org.onebusaway.gtfs.model.Trip in project onebusaway-application-modules by camsys.

the class GenerateNarrativesTask method generateTripNarratives.

public void generateTripNarratives(NarrativeProviderImpl provider) {
    int tripIndex = 0;
    Collection<Trip> trips = _gtfsDao.getAllTrips();
    int logInterval = LoggingIntervalUtil.getAppropriateLoggingInterval(trips.size());
    for (Trip trip : trips) {
        if (tripIndex % logInterval == 0) {
            _log.info("trips=" + tripIndex + " of " + trips.size());
        }
        tripIndex++;
        TripNarrative tripNarrative = getTripNarrative(trip);
        provider.setNarrativeForTripId(trip.getId(), tripNarrative);
        List<StopTime> stopTimes = _gtfsDao.getStopTimesForTrip(trip);
        int stopTimeIndex = 0;
        for (StopTime stopTime : stopTimes) {
            StopTimeNarrative stopTimeNarrative = getStopTimeNarrative(stopTime);
            provider.setNarrativeForStopTimeEntry(trip.getId(), stopTimeIndex++, stopTimeNarrative);
        }
    }
}
Also used : StopTimeNarrative(org.onebusaway.transit_data_federation.model.narrative.StopTimeNarrative) Trip(org.onebusaway.gtfs.model.Trip) TripNarrative(org.onebusaway.transit_data_federation.model.narrative.TripNarrative) ProjectedPoint(org.onebusaway.transit_data_federation.model.ProjectedPoint) StopTime(org.onebusaway.gtfs.model.StopTime)

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