use of org.onebusaway.transit_data.model.StopTimeGroupBean in project onebusaway-application-modules by camsys.
the class StopScheduleBeanServiceImpl method applyContinuesAsStopTimeGroups.
private void applyContinuesAsStopTimeGroups(StopTimeByDirectionEntry stopTimesForDirection, List<StopTimeGroupBean> groups) {
Counter<ContinuesAsStopTimeGroupKey> keyCounts = stopTimesForDirection.getContinuesAsKeyCounts();
List<ContinuesAsStopTimeGroupKey> sortedKeys = keyCounts.getSortedKeys();
for (ContinuesAsStopTimeGroupKey key : sortedKeys) {
AgencyAndId lineId = key.getLineId();
if (lineId == null)
continue;
StopTimeGroupBean group = new StopTimeGroupBean();
String groupId = Integer.toString(groups.size());
group.setId(groupId);
RouteBean route = _routeBeanService.getRouteForId(lineId);
group.setContinuesAs(route);
applyGroupIdForGroupKey(stopTimesForDirection, key, groupId);
groups.add(group);
}
}
use of org.onebusaway.transit_data.model.StopTimeGroupBean 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.model.StopTimeGroupBean in project onebusaway-application-modules by camsys.
the class StopScheduleBeanServiceImpl method applyTripHeadsignStopTimeGroups.
private void applyTripHeadsignStopTimeGroups(StopTimeByDirectionEntry stopTimesForDirection, List<StopTimeGroupBean> groups) {
Counter<TripHeadsignStopTimeGroupKey> keyCounts = stopTimesForDirection.getTripHeadsignKeyCounts();
List<TripHeadsignStopTimeGroupKey> sortedKeys = keyCounts.getSortedKeys();
for (int i = 0; i < sortedKeys.size() - 1; i++) {
TripHeadsignStopTimeGroupKey key = sortedKeys.get(i);
StopTimeGroupBean group = new StopTimeGroupBean();
String groupId = Integer.toString(groups.size());
group.setId(groupId);
String tripHeadsign = key.getTripHeadsign();
group.setTripHeadsign(tripHeadsign);
applyGroupIdForGroupKey(stopTimesForDirection, key, groupId);
groups.add(group);
}
}
Aggregations