use of org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockStopTimeIndex in project onebusaway-application-modules by camsys.
the class StopScheduleServiceImpl method getAllServiceIdsForStop.
private Set<ServiceIdActivation> getAllServiceIdsForStop(StopEntry stop, boolean includePrivateService) {
Set<ServiceIdActivation> allServiceIds = new HashSet<ServiceIdActivation>();
List<BlockStopTimeIndex> indices = _blockIndexService.getStopTimeIndicesForStop(stop);
for (BlockStopTimeIndex index : indices) allServiceIds.add(index.getServiceIds());
List<FrequencyBlockStopTimeIndex> frequencyIndices = _blockIndexService.getFrequencyStopTimeIndicesForStop(stop);
for (FrequencyBlockStopTimeIndex index : frequencyIndices) allServiceIds.add(index.getServiceIds());
for (Iterator<ServiceIdActivation> it = allServiceIds.iterator(); it.hasNext(); ) {
ServiceIdActivation activation = it.next();
LocalizedServiceId lsid = activation.getActiveServiceIds().get(0);
String agencyId = lsid.getId().getAgencyId();
AgencyBean bean = _agencyBeanService.getAgencyForId(agencyId);
if (bean.isPrivateService() && !includePrivateService)
it.remove();
}
return allServiceIds;
}
use of org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockStopTimeIndex in project onebusaway-application-modules by camsys.
the class StopScheduleBeanServiceImpl method getCalendarForStop.
@Cacheable
public StopCalendarDaysBean getCalendarForStop(AgencyAndId stopId) {
TimeZone timeZone = _agencyService.getTimeZoneForAgencyId(stopId.getAgencyId());
StopEntry stopEntry = _graph.getStopEntryForId(stopId);
Set<ServiceIdActivation> serviceIds = new HashSet<ServiceIdActivation>();
for (BlockStopTimeIndex index : _blockIndexService.getStopTimeIndicesForStop(stopEntry)) serviceIds.add(index.getServiceIds());
for (FrequencyBlockStopTimeIndex index : _blockIndexService.getFrequencyStopTimeIndicesForStop(stopEntry)) serviceIds.add(index.getServiceIds());
SortedMap<ServiceDate, Set<ServiceIdActivation>> serviceIdsByDate = getServiceIdsByDate(serviceIds);
Counter<Set<ServiceIdActivation>> counts = new Counter<Set<ServiceIdActivation>>();
for (Set<ServiceIdActivation> ids : serviceIdsByDate.values()) counts.increment(ids);
int total = counts.size();
Map<Set<ServiceIdActivation>, Integer> idsToGroup = new HashMap<Set<ServiceIdActivation>, Integer>();
for (Set<ServiceIdActivation> ids : counts.getSortedKeys()) idsToGroup.put(ids, total--);
List<StopCalendarDayBean> beans = new ArrayList<StopCalendarDayBean>(serviceIdsByDate.size());
for (Map.Entry<ServiceDate, Set<ServiceIdActivation>> entry : serviceIdsByDate.entrySet()) {
StopCalendarDayBean bean = new StopCalendarDayBean();
ServiceDate serviceDate = entry.getKey();
Date date = serviceDate.getAsDate(timeZone);
bean.setDate(date);
Integer indexId = idsToGroup.get(entry.getValue());
bean.setGroup(indexId);
beans.add(bean);
}
return new StopCalendarDaysBean(timeZone.getID(), beans);
}
use of org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockStopTimeIndex 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.blocks.FrequencyBlockStopTimeIndex in project onebusaway-application-modules by camsys.
the class BlockIndexServiceImpl method loadStopTimeIndices.
private void loadStopTimeIndices() {
// Clear any existing indices
for (StopEntry stop : _graphDao.getAllStops()) {
StopEntryImpl stopImpl = (StopEntryImpl) stop;
stopImpl.getStopTimeIndices().clear();
stopImpl.getFrequencyStopTimeIndices().clear();
}
BlockStopTimeIndicesFactory factory = new BlockStopTimeIndicesFactory();
factory.setVerbose(true);
List<BlockStopTimeIndex> indices = factory.createIndices(_graphDao.getAllBlocks());
for (BlockStopTimeIndex index : indices) {
StopEntryImpl stop = (StopEntryImpl) index.getStop();
stop.addStopTimeIndex(index);
}
List<FrequencyBlockStopTimeIndex> frequencyIndices = factory.createFrequencyIndices(_graphDao.getAllBlocks());
for (FrequencyBlockStopTimeIndex index : frequencyIndices) {
StopEntryImpl stop = (StopEntryImpl) index.getStop();
stop.addFrequencyStopTimeIndex(index);
}
}
use of org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockStopTimeIndex in project onebusaway-application-modules by camsys.
the class BlockStopTimeIndicesFactory method createFrequencyIndicesFromGroups.
/**
**
*
***
*/
private List<FrequencyBlockStopTimeIndex> createFrequencyIndicesFromGroups(Map<BlockStopTimeKey, List<BlockStopTimeEntry>> stopTimesByKey) {
List<FrequencyBlockStopTimeIndex> allIndices = new ArrayList<FrequencyBlockStopTimeIndex>();
int count = 0;
for (List<BlockStopTimeEntry> stopTimes : stopTimesByKey.values()) {
if (_verbose && count % 100 == 0)
_log.info("groups processed: " + count + "/" + stopTimesByKey.size());
count++;
List<FrequencyBlockStopTimeEntry> frequencyStopTimes = getStopTimesAsFrequencyStopTimes(stopTimes);
List<List<FrequencyBlockStopTimeEntry>> groupedStopTimes = BlockLibrary.createStrictlyOrderedGroups(frequencyStopTimes, _frequencyBlockStopTimeLooseComparator, _frequencyBlockStopTimeStrictComparator);
for (List<FrequencyBlockStopTimeEntry> group : groupedStopTimes) {
FrequencyBlockStopTimeIndex index = createFrequencyBlockStopTimeIndexForGroup(group);
allIndices.add(index);
}
}
return allIndices;
}
Aggregations