use of org.onebusaway.transit_data_federation.services.transit_graph.TripEntry in project onebusaway-application-modules by camsys.
the class TripEntriesFactory method processTrips.
public void processTrips(TransitGraphImpl graph) {
Collection<Route> routes = _gtfsDao.getAllRoutes();
int routeIndex = 0;
for (Route route : routes) {
_log.info("route processed: " + routeIndex + "/" + routes.size());
routeIndex++;
List<Trip> tripsForRoute = _gtfsDao.getTripsForRoute(route);
int tripCount = tripsForRoute.size();
int logInterval = LoggingIntervalUtil.getAppropriateLoggingInterval(tripCount);
_log.info("trips to process: " + tripCount);
int tripIndex = 0;
RouteEntryImpl routeEntry = graph.getRouteForId(route.getId());
ArrayList<TripEntry> tripEntries = new ArrayList<TripEntry>();
for (Trip trip : tripsForRoute) {
tripIndex++;
if (tripIndex % logInterval == 0)
_log.info("trips processed: " + tripIndex + "/" + tripsForRoute.size());
TripEntryImpl tripEntry = processTrip(graph, trip);
if (tripEntry != null) {
tripEntry.setRoute(routeEntry);
tripEntries.add(tripEntry);
}
}
tripEntries.trimToSize();
routeEntry.setTrips(tripEntries);
}
if (_stopTimeEntriesFactory.getInvalidStopToShapeMappingExceptionCount() > 0 && _throwExceptionOnInvalidStopToShapeMappingException) {
throw new IllegalStateException("Multiple instances of InvalidStopToShapeMappingException thrown: count=" + _stopTimeEntriesFactory.getInvalidStopToShapeMappingExceptionCount() + ". For more information on errors of this kind, see:\n" + " https://github.com/OneBusAway/onebusaway-application-modules/wiki/Stop-to-Shape-Matching");
}
graph.refreshTripMapping();
}
use of org.onebusaway.transit_data_federation.services.transit_graph.TripEntry in project onebusaway-application-modules by camsys.
the class AgencyServiceImpl method getAgencyIdsAndCenterPoints.
@Cacheable
public Map<String, CoordinatePoint> getAgencyIdsAndCenterPoints() {
Map<String, CoordinatePoint> centersByAgencyId = new HashMap<String, CoordinatePoint>();
for (AgencyEntry agency : _graph.getAllAgencies()) {
StopsCenterOfMass centerOfMass = new StopsCenterOfMass();
for (RouteCollectionEntry routeCollection : agency.getRouteCollections()) {
for (RouteEntry route : routeCollection.getChildren()) {
for (TripEntry trip : route.getTrips()) {
for (StopTimeEntry stopTime : trip.getStopTimes()) {
StopEntry stop = stopTime.getStop();
centerOfMass.lats += stop.getStopLat();
centerOfMass.lons += stop.getStopLon();
centerOfMass.count++;
}
}
}
}
if (centerOfMass.count == 0) {
_log.warn("Agency has no service: " + agency);
} else {
double lat = centerOfMass.lats / centerOfMass.count;
double lon = centerOfMass.lons / centerOfMass.count;
centersByAgencyId.put(agency.getId(), new CoordinatePoint(lat, lon));
}
}
return centersByAgencyId;
}
use of org.onebusaway.transit_data_federation.services.transit_graph.TripEntry in project onebusaway-application-modules by camsys.
the class StopScheduleBeanServiceImpl method getScheduledArrivalsForStopAndDate.
@Cacheable
public List<StopRouteScheduleBean> getScheduledArrivalsForStopAndDate(AgencyAndId stopId, ServiceDate date) {
StopEntry stopEntry = _graph.getStopEntryForId(stopId);
Map<AgencyAndId, List<StopTimeInstance>> stopTimesByRouteCollectionId = new FactoryMap<AgencyAndId, List<StopTimeInstance>>(new ArrayList<StopTimeInstance>());
Map<AgencyAndId, List<StopTimeInstance>> frequenciesByRouteCollectionId = new FactoryMap<AgencyAndId, List<StopTimeInstance>>(new ArrayList<StopTimeInstance>());
groupStopTimeInstancesByRouteCollectionId(stopEntry, date, stopTimesByRouteCollectionId, frequenciesByRouteCollectionId);
groupFrequencyInstancesByRouteCollectionId(stopEntry, date, frequenciesByRouteCollectionId);
Set<AgencyAndId> routeIds = new HashSet<AgencyAndId>();
routeIds.addAll(stopTimesByRouteCollectionId.keySet());
routeIds.addAll(frequenciesByRouteCollectionId.keySet());
List<StopRouteScheduleBean> beans = new ArrayList<StopRouteScheduleBean>();
for (AgencyAndId routeId : routeIds) {
StopRouteScheduleBean routeScheduleBean = new StopRouteScheduleBean();
beans.add(routeScheduleBean);
RouteBean route = _routeBeanService.getRouteForId(routeId);
routeScheduleBean.setRoute(route);
Map<String, StopTimeByDirectionEntry> stopTimesByDirection = new FactoryMap<String, StopTimeByDirectionEntry>(new StopTimeByDirectionEntry());
List<StopTimeInstance> stopTimesForRoute = stopTimesByRouteCollectionId.get(routeId);
for (StopTimeInstance sti : stopTimesForRoute) {
BlockStopTimeEntry bst = sti.getStopTime();
BlockTripEntry blockTrip = sti.getTrip();
BlockConfigurationEntry blockConfig = blockTrip.getBlockConfiguration();
TripEntry trip = blockTrip.getTrip();
AgencyAndId tripId = trip.getId();
AgencyAndId serviceId = trip.getServiceId().getId();
TripNarrative narrative = _narrativeService.getTripForId(tripId);
StopTimeInstanceBean stiBean = new StopTimeInstanceBean();
stiBean.setTripId(AgencyAndIdLibrary.convertToString(tripId));
stiBean.setServiceDate(sti.getServiceDate());
stiBean.setArrivalTime(sti.getArrivalTime());
stiBean.setDepartureTime(sti.getDepartureTime());
stiBean.setServiceId(AgencyAndIdLibrary.convertToString(serviceId));
stiBean.setArrivalEnabled(bst.getBlockSequence() > 0);
stiBean.setDepartureEnabled(bst.getBlockSequence() + 1 < blockConfig.getStopTimes().size());
String directionId = trip.getDirectionId();
if (directionId == null)
directionId = "0";
String tripHeadsign = narrative.getTripHeadsign();
TripHeadsignStopTimeGroupKey groupKey = new TripHeadsignStopTimeGroupKey(tripHeadsign);
ContinuesAsStopTimeGroupKey continuesAsGroupKey = getContinuesAsGroupKeyForStopTimeInstance(sti);
StopTimeByDirectionEntry stopTimesForDirection = stopTimesByDirection.get(directionId);
stopTimesForDirection.addEntry(stiBean, tripHeadsign, groupKey, continuesAsGroupKey);
}
List<StopTimeInstance> frequenciesForRoute = frequenciesByRouteCollectionId.get(routeId);
for (StopTimeInstance sti : frequenciesForRoute) {
BlockStopTimeEntry blockStopTime = sti.getStopTime();
BlockTripEntry blockTrip = blockStopTime.getTrip();
TripEntry trip = blockTrip.getTrip();
BlockConfigurationEntry blockConfig = blockTrip.getBlockConfiguration();
AgencyAndId tripId = trip.getId();
AgencyAndId serviceId = trip.getServiceId().getId();
TripNarrative narrative = _narrativeService.getTripForId(tripId);
FrequencyInstanceBean bean = new FrequencyInstanceBean();
bean.setTripId(AgencyAndIdLibrary.convertToString(tripId));
bean.setServiceDate(sti.getServiceDate());
bean.setStartTime(sti.getServiceDate() + sti.getFrequency().getStartTime() * 1000);
bean.setEndTime(sti.getServiceDate() + sti.getFrequency().getEndTime() * 1000);
bean.setHeadwaySecs(sti.getFrequency().getHeadwaySecs());
bean.setServiceId(AgencyAndIdLibrary.convertToString(serviceId));
bean.setArrivalEnabled(blockStopTime.getBlockSequence() > 0);
bean.setDepartureEnabled(blockStopTime.getBlockSequence() + 1 < blockConfig.getStopTimes().size());
String directionId = trip.getDirectionId();
if (directionId == null)
directionId = "0";
StopTimeByDirectionEntry stopTimesForDirection = stopTimesByDirection.get(directionId);
stopTimesForDirection.addEntry(bean, narrative.getTripHeadsign());
}
for (StopTimeByDirectionEntry stopTimesForDirection : stopTimesByDirection.values()) {
StopRouteDirectionScheduleBean directionBean = new StopRouteDirectionScheduleBean();
directionBean.getStopTimes().addAll(stopTimesForDirection.getStopTimes());
directionBean.getFrequencies().addAll(stopTimesForDirection.getFrequencies());
String headsign = stopTimesForDirection.getBestHeadsign();
directionBean.setTripHeadsign(headsign);
Collections.sort(directionBean.getStopTimes(), _stopTimeComparator);
Collections.sort(directionBean.getFrequencies(), _frequencyComparator);
List<StopTimeGroupBean> groups = new ArrayList<StopTimeGroupBean>();
applyTripHeadsignStopTimeGroups(stopTimesForDirection, groups);
applyContinuesAsStopTimeGroups(stopTimesForDirection, groups);
directionBean.setGroups(groups);
routeScheduleBean.getDirections().add(directionBean);
}
Collections.sort(routeScheduleBean.getDirections(), _directionComparator);
}
Collections.sort(beans, _stopRouteScheduleComparator);
return beans;
}
use of org.onebusaway.transit_data_federation.services.transit_graph.TripEntry in project onebusaway-application-modules by camsys.
the class StopScheduleBeanServiceImpl method groupFrequencyInstancesByRouteCollectionId.
private void groupFrequencyInstancesByRouteCollectionId(StopEntry stopEntry, ServiceDate date, Map<AgencyAndId, List<StopTimeInstance>> frequenciesByRouteCollectionId) {
for (FrequencyBlockStopTimeIndex index : _blockIndexService.getFrequencyStopTimeIndicesForStop(stopEntry)) {
ServiceIdActivation serviceIds = index.getServiceIds();
Set<ServiceDate> serviceDates = _calendarService.getServiceDatesForServiceIds(serviceIds);
if (!serviceDates.contains(date))
continue;
Date serviceDate = date.getAsDate(serviceIds.getTimeZone());
for (FrequencyBlockStopTimeEntry entry : index.getFrequencyStopTimes()) {
BlockStopTimeEntry stopTime = entry.getStopTime();
BlockTripEntry blockTrip = stopTime.getTrip();
TripEntry trip = blockTrip.getTrip();
AgencyAndId routeCollectionId = trip.getRouteCollection().getId();
InstanceState state = new InstanceState(serviceDate.getTime(), entry.getFrequency());
StopTimeInstance sti = new StopTimeInstance(stopTime, state);
frequenciesByRouteCollectionId.get(routeCollectionId).add(sti);
}
}
}
use of org.onebusaway.transit_data_federation.services.transit_graph.TripEntry in project onebusaway-application-modules by camsys.
the class StopScheduleBeanServiceImpl method getContinuesAsLineId.
private AgencyAndId getContinuesAsLineId(BlockTripEntry blockTrip) {
BlockTripEntry nextTrip = blockTrip.getNextTrip();
if (nextTrip == null)
return null;
TripEntry prevTrip = blockTrip.getTrip();
AgencyAndId prevLineId = prevTrip.getRouteCollection().getId();
AgencyAndId nextLineId = nextTrip.getTrip().getRouteCollection().getId();
if (prevLineId.equals(nextLineId))
return null;
List<BlockStopTimeEntry> stopTimes = blockTrip.getStopTimes();
BlockStopTimeEntry prevStopTime = stopTimes.get(stopTimes.size() - 1);
List<BlockStopTimeEntry> nextStopTimes = nextTrip.getStopTimes();
BlockStopTimeEntry nextStopTime = nextStopTimes.get(0);
int prevTime = prevStopTime.getStopTime().getDepartureTime();
int nextTime = nextStopTime.getStopTime().getArrivalTime();
if (nextTime - prevTime > _continuesAsThreshold)
return null;
return nextLineId;
}
Aggregations