use of org.onebusaway.transit_data_federation.services.blocks.BlockTripIndex in project onebusaway-application-modules by camsys.
the class BlockGeospatialServiceImpl method getActiveScheduledBlocksPassingThroughBounds.
@Override
public List<BlockInstance> getActiveScheduledBlocksPassingThroughBounds(CoordinateBounds bounds, long timeFrom, long timeTo) {
List<StopEntry> stops = _transitGraphDao.getStopsByLocation(bounds);
Set<AgencyAndId> blockIds = new HashSet<AgencyAndId>();
for (StopEntry stop : stops) {
List<BlockStopTimeIndex> stopTimeIndices = _blockIndexService.getStopTimeIndicesForStop(stop);
Set<BlockConfigurationEntry> blockConfigs = new HashSet<BlockConfigurationEntry>();
List<List<BlockConfigurationEntry>> blockConfigsList = MappingLibrary.map(stopTimeIndices, "blockConfigs");
for (List<BlockConfigurationEntry> l : blockConfigsList) {
blockConfigs.addAll(l);
}
List<AgencyAndId> stopBlockIds = MappingLibrary.map(blockConfigs, "block.id");
blockIds.addAll(stopBlockIds);
}
Set<BlockTripIndex> blockIndices = new HashSet<BlockTripIndex>();
for (AgencyAndId blockId : blockIds) {
blockIndices.addAll(_blockIndexService.getBlockTripIndicesForBlock(blockId));
}
List<BlockLayoverIndex> layoverIndices = Collections.emptyList();
List<FrequencyBlockTripIndex> frequencyIndices = Collections.emptyList();
return _blockCalendarService.getActiveBlocksInTimeRange(blockIndices, layoverIndices, frequencyIndices, timeFrom, timeTo);
}
use of org.onebusaway.transit_data_federation.services.blocks.BlockTripIndex in project onebusaway-application-modules by camsys.
the class RouteBeanServiceImpl method getStopsForRouteCollectionAndNarrative.
private StopsForRouteBean getStopsForRouteCollectionAndNarrative(RouteCollectionEntry routeCollection, RouteCollectionNarrative narrative) {
StopsForRouteBean result = new StopsForRouteBean();
AgencyAndId routeCollectionId = routeCollection.getId();
result.setRoute(getRouteBeanForRouteCollection(routeCollectionId, narrative));
result.setStops(getStopBeansForRoute(routeCollectionId));
result.setPolylines(getEncodedPolylinesForRoute(routeCollection));
StopGroupingBean directionGrouping = new StopGroupingBean();
directionGrouping.setType(TransitDataConstants.STOP_GROUPING_TYPE_DIRECTION);
List<StopGroupBean> directionGroups = new ArrayList<StopGroupBean>();
directionGrouping.setStopGroups(directionGroups);
directionGrouping.setOrdered(true);
result.addGrouping(directionGrouping);
List<BlockTripIndex> blockIndices = _blockIndexService.getBlockTripIndicesForRouteCollectionId(routeCollectionId);
List<FrequencyBlockTripIndex> frequencyBlockIndices = _blockIndexService.getFrequencyBlockTripIndicesForRouteCollectionId(routeCollectionId);
List<BlockTripEntry> blockTrips = new ArrayList<BlockTripEntry>();
getBlockTripsForIndicesMatchingRouteCollection(blockIndices, routeCollectionId, blockTrips);
getBlockTripsForIndicesMatchingRouteCollection(frequencyBlockIndices, routeCollectionId, blockTrips);
List<StopSequence> sequences = _stopSequencesService.getStopSequencesForTrips(blockTrips);
List<StopSequenceCollection> blocks = _stopSequenceBlocksService.getStopSequencesAsCollections(sequences);
for (StopSequenceCollection block : blocks) {
NameBean name = new NameBean(NameBeanTypes.DESTINATION, block.getDescription());
List<StopEntry> stops = getStopsInOrder(block);
List<String> groupStopIds = new ArrayList<String>();
for (StopEntry stop : stops) groupStopIds.add(ApplicationBeanLibrary.getId(stop.getId()));
Set<AgencyAndId> shapeIds = getShapeIdsForStopSequenceBlock(block);
List<EncodedPolylineBean> polylines = _shapeBeanService.getMergedPolylinesForShapeIds(shapeIds);
StopGroupBean group = new StopGroupBean();
group.setId(block.getPublicId());
group.setName(name);
group.setStopIds(groupStopIds);
group.setPolylines(polylines);
directionGroups.add(group);
}
sortResult(result);
return result;
}
use of org.onebusaway.transit_data_federation.services.blocks.BlockTripIndex in project onebusaway-application-modules by camsys.
the class BlockIndexFactoryServiceImpl method createTripIndices.
/**
**
*
***
*/
public List<BlockTripIndex> createTripIndices(Iterable<BlockEntry> blocks) {
List<BlockTripIndex> allIndices = new ArrayList<BlockTripIndex>();
int logInterval = LoggingIntervalUtil.getAppropriateLoggingInterval(allIndices.size());
Map<BlockSequenceKey, List<BlockTripEntry>> blockTripsByKey = new FactoryMap<BlockSequenceKey, List<BlockTripEntry>>(new ArrayList<BlockTripEntry>());
if (_verbose)
_log.info("grouping block trips by sequence key");
int tripCount = 0;
for (BlockEntry block : blocks) {
if (block.getConfigurations().isEmpty()) {
_log.warn("block has no active configurations: " + block.getId());
continue;
}
if (BlockLibrary.isFrequencyBased(block))
continue;
for (BlockConfigurationEntry blockConfiguration : block.getConfigurations()) {
for (BlockTripEntry blockTrip : blockConfiguration.getTrips()) {
BlockSequenceKey key = getBlockTripAsTripSequenceKey(blockTrip);
blockTripsByKey.get(key).add(blockTrip);
tripCount++;
}
}
}
if (_verbose)
_log.info("groups found: " + blockTripsByKey.size() + " out of trips: " + tripCount);
int count = 0;
for (List<BlockTripEntry> tripsWithSameSequence : blockTripsByKey.values()) {
if (_verbose && count % logInterval == 0)
_log.info("groups processed: " + count + "/" + blockTripsByKey.size());
count++;
List<List<BlockTripEntry>> groupedBlocks = BlockLibrary.createStrictlyOrderedGroups(tripsWithSameSequence, _blockTripLooseComparator, _blockTripStrictComparator);
for (List<BlockTripEntry> group : groupedBlocks) {
BlockTripIndex index = createTripIndexForGroupOfBlockTrips(group);
allIndices.add(index);
}
}
return allIndices;
}
use of org.onebusaway.transit_data_federation.services.blocks.BlockTripIndex in project onebusaway-application-modules by camsys.
the class BlockIndexServiceImpl method loadBlockTripIndicesByBlockId.
/**
**
*
***
*/
private void loadBlockTripIndicesByBlockId() {
_log.info("calculating block trip indices by blockId...");
long t1 = SystemTime.currentTimeMillis();
_blockTripIndicesByBlockId = new HashMap<AgencyAndId, List<BlockTripIndex>>();
_blockLayoverIndicesByBlockId = new HashMap<AgencyAndId, List<BlockLayoverIndex>>();
_frequencyBlockTripIndicesByBlockId = new HashMap<AgencyAndId, List<FrequencyBlockTripIndex>>();
for (BlockEntry block : _graphDao.getAllBlocks()) {
List<BlockEntry> list = Arrays.asList(block);
List<BlockTripIndex> indices = _factory.createTripIndices(list);
List<BlockLayoverIndex> layoverIndices = _factory.createLayoverIndices(list);
List<FrequencyBlockTripIndex> frequencyIndices = _factory.createFrequencyTripIndices(list);
if (!indices.isEmpty())
_blockTripIndicesByBlockId.put(block.getId(), indices);
if (!layoverIndices.isEmpty())
_blockLayoverIndicesByBlockId.put(block.getId(), layoverIndices);
if (!frequencyIndices.isEmpty())
_frequencyBlockTripIndicesByBlockId.put(block.getId(), frequencyIndices);
}
long t2 = SystemTime.currentTimeMillis();
_log.info("completed calculating block trip indices by blockId: t=" + (t2 - t1));
}
use of org.onebusaway.transit_data_federation.services.blocks.BlockTripIndex in project onebusaway-application-modules by camsys.
the class BlockIndexServiceImpl method loadBlockTripIndices.
/**
**
*
***
*/
private void loadBlockTripIndices() throws IOException, ClassNotFoundException {
File path = _bundle.getBlockTripIndicesPath();
if (path.exists()) {
_log.info("loading block trip indices data");
List<BlockTripIndexData> datas = ObjectSerializationLibrary.readObject(path);
_blockTripIndices = new ArrayList<BlockTripIndex>(datas.size());
for (BlockTripIndexData data : datas) _blockTripIndices.add(data.createIndex(_graphDao));
_blockTripIndicesByAgencyId = getBlockTripIndicesByAgencyId(_blockTripIndices);
_blockTripIndicesByRouteId = getBlockTripsByRouteId(_blockTripIndices);
_log.info("block indices data loaded");
} else {
_blockTripIndices = Collections.emptyList();
_blockTripIndicesByAgencyId = Collections.emptyMap();
_blockTripIndicesByRouteId = Collections.emptyMap();
}
}
Aggregations