use of org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl in project onebusaway-application-modules by camsys.
the class UnitTestingSupport method trip.
public static TripEntryImpl trip(String id, String serviceId, double totalTripDistance) {
TripEntryImpl trip = trip(id, serviceId);
trip.setTotalTripDistance(totalTripDistance);
return trip;
}
use of org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl in project onebusaway-application-modules by camsys.
the class BlockConfigurationEntriesFactory method getTripsByServiceId.
/**
**
* Private Methods
***
*/
private Map<LocalizedServiceId, List<TripEntryImpl>> getTripsByServiceId(BlockEntryImpl block, List<TripEntryImpl> tripsInBlock) {
Map<LocalizedServiceId, List<TripEntryImpl>> tripsByServiceId = new FactoryMap<LocalizedServiceId, List<TripEntryImpl>>(new ArrayList<TripEntryImpl>());
TimeZone tz = null;
for (TripEntryImpl trip : tripsInBlock) {
LocalizedServiceId serviceId = trip.getServiceId();
if (tz == null) {
tz = serviceId.getTimeZone();
} else if (!tz.equals(serviceId.getTimeZone())) {
throw new IllegalStateException("trips in block must all have same timezone: block=" + block + " trip=" + trip + " execpted=" + tz + " actual=" + serviceId.getTimeZone());
}
tripsByServiceId.get(serviceId).add(trip);
}
return tripsByServiceId;
}
use of org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl in project onebusaway-application-modules by camsys.
the class BlockEntriesFactory method getTripsByBlockId.
private Map<AgencyAndId, List<TripEntryImpl>> getTripsByBlockId(TransitGraphImpl graph) {
Collection<Route> routes = _gtfsDao.getAllRoutes();
int routeIndex = 0;
Map<AgencyAndId, List<TripEntryImpl>> tripsByBlockId = new FactoryMap<AgencyAndId, List<TripEntryImpl>>(new ArrayList<TripEntryImpl>());
for (Route route : routes) {
_log.info("routes: " + (routeIndex++) + "/" + routes.size());
List<Trip> trips = _gtfsDao.getTripsForRoute(route);
for (Trip trip : trips) {
TripEntryImpl tripEntry = graph.getTripEntryForId(trip.getId());
// prune the trip
if (tripEntry == null)
continue;
/*
* here we default the blockId to the tripId
*/
AgencyAndId blockId = trip.getId();
if (trip.getBlockId() != null) {
/*
* he have a block so set it
*/
blockId = new AgencyAndId(trip.getId().getAgencyId(), trip.getBlockId());
}
tripsByBlockId.get(blockId).add(tripEntry);
}
}
return tripsByBlockId;
}
use of org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl in project onebusaway-application-modules by camsys.
the class DistanceAlongShapeLibrary method constructErrorForPotentialAssignmentCount.
private void constructErrorForPotentialAssignmentCount(ShapePoints shapePoints, List<StopTimeEntryImpl> stopTimes, long count) throws InvalidStopToShapeMappingException {
if (count == 0) {
_log.error("We were attempting to compute the distance along a particular trip for each stop time of that " + "trip by snapping them to the shape for that trip. However, we could not find an assignment for each " + "stop time of the trip, which usually indicates that there is something wrong with the underlying " + "shape data. For more information on errors of this kind, see:\n" + " https://github.com/OneBusAway/onebusaway-application-modules/wiki/Stop-to-Shape-Matching");
} else {
_log.error("We were attempting to compute the distance along a particular trip for each stop time of that " + "trip by snapping them to the shape for that trip. However, we found WAY TOO MANY potential " + "assignments, which usually indicates that there is something wrong with the underlying shape data. " + "For more information on errors of this kind, see:\n" + " https://github.com/OneBusAway/onebusaway-application-modules/wiki/Stop-to-Shape-Matching");
}
StopTimeEntryImpl first = stopTimes.get(0);
TripEntryImpl trip = first.getTrip();
StopTimeEntryImpl last = stopTimes.get(stopTimes.size() - 1);
_log.error("error constructing stop-time distances along shape for trip=" + trip.getId() + " shape=" + trip.getShapeId() + " firstStopTime=" + first.getId() + " lastStopTime=" + last.getId());
if (_shapeIdsWeHavePrinted.add(trip.getShapeId())) {
StringBuilder b = new StringBuilder();
for (int i = 0; i < shapePoints.getSize(); i++) {
b.append(shapePoints.getLatForIndex(i));
b.append(' ');
b.append(shapePoints.getLonForIndex(i));
b.append(' ');
b.append(shapePoints.getDistTraveledForIndex(i));
b.append('\n');
}
_log.error("shape points:\n" + b.toString());
}
throw new InvalidStopToShapeMappingException(first.getTrip());
}
use of org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl in project onebusaway-application-modules by camsys.
the class FrequencyEntriesFactory method processFrequencies.
public void processFrequencies(TransitGraphImpl graph) {
Map<AgencyAndId, List<FrequencyEntry>> frequenciesByTripId = new HashMap<AgencyAndId, List<FrequencyEntry>>();
Collection<Frequency> allFrequencies = _gtfsDao.getAllFrequencies();
int logInterval = LoggingIntervalUtil.getAppropriateLoggingInterval(allFrequencies.size());
int frequencyIndex = 0;
Map<AgencyAndId, Integer> exactTimesValueByTrip = new HashMap<AgencyAndId, Integer>();
for (Frequency frequency : allFrequencies) {
if (frequencyIndex % logInterval == 0)
_log.info("frequencies: " + (frequencyIndex++) + "/" + allFrequencies.size());
frequencyIndex++;
processRawFrequency(graph, frequency, frequenciesByTripId, exactTimesValueByTrip);
}
FrequencyComparator comparator = new FrequencyComparator();
for (List<FrequencyEntry> list : frequenciesByTripId.values()) {
Collections.sort(list, comparator);
}
int blockIndex = 0;
Map<AgencyAndId, List<TripEntryImpl>> tripsByBlockId = MappingLibrary.mapToValueList(graph.getTrips(), "block.id");
for (Map.Entry<AgencyAndId, List<TripEntryImpl>> entry : tripsByBlockId.entrySet()) {
if (blockIndex % 10 == 0)
_log.info("block: " + blockIndex + "/" + tripsByBlockId.size());
blockIndex++;
AgencyAndId blockId = entry.getKey();
List<TripEntryImpl> tripsInBlock = entry.getValue();
Map<AgencyAndId, List<FrequencyEntry>> frequenciesAlongBlockByTripId = new HashMap<AgencyAndId, List<FrequencyEntry>>();
for (TripEntryImpl trip : tripsInBlock) {
List<FrequencyEntry> frequencies = frequenciesByTripId.get(trip.getId());
if (frequencies != null) {
frequenciesAlongBlockByTripId.put(trip.getId(), frequencies);
}
}
checkForInvalidFrequencyConfigurations(blockId, tripsInBlock, frequenciesAlongBlockByTripId);
applyFrequenciesToBlockTrips(tripsInBlock, frequenciesAlongBlockByTripId);
}
}
Aggregations