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);
}
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;
}
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;
}
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());
}
}
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;
}
Aggregations