use of org.onebusaway.transit_data_federation.services.blocks.BlockSequenceIndex in project onebusaway-application-modules by camsys.
the class BlockGeospatialServiceImpl method getBlockSequenceIndexPassingThroughBounds.
@Override
public Set<BlockSequenceIndex> getBlockSequenceIndexPassingThroughBounds(CoordinateBounds bounds) {
Envelope env = new Envelope(bounds.getMinLon(), bounds.getMaxLon(), bounds.getMinLat(), bounds.getMaxLat());
@SuppressWarnings("unchecked") List<List<AgencyAndId>> results = _tree.query(env);
Set<AgencyAndId> visitedShapeIds = new HashSet<AgencyAndId>();
Set<BlockSequenceIndex> allIndices = new HashSet<BlockSequenceIndex>();
for (List<AgencyAndId> shapeIds : results) {
for (AgencyAndId shapeId : shapeIds) {
if (visitedShapeIds.add(shapeId)) {
List<BlockSequenceIndex> indices = _blockSequenceIndicesByShapeId.get(shapeId);
if (!CollectionsLibrary.isEmpty(indices)) {
allIndices.addAll(indices);
}
}
}
}
return allIndices;
}
use of org.onebusaway.transit_data_federation.services.blocks.BlockSequenceIndex in project onebusaway-application-modules by camsys.
the class BlockGeospatialServiceImpl method groupBlockSequenceIndicesByShapeIds.
/**
**
* Private Methods
***
*/
private void groupBlockSequenceIndicesByShapeIds() {
List<BlockSequenceIndex> indices = _blockIndexService.getAllBlockSequenceIndices();
for (BlockSequenceIndex index : indices) {
Set<AgencyAndId> shapeIdsForIndex = new HashSet<AgencyAndId>();
for (BlockSequence sequence : index.getSequences()) {
for (BlockStopTimeEntry bst : sequence.getStopTimes()) {
BlockTripEntry blockTrip = bst.getTrip();
TripEntry trip = blockTrip.getTrip();
AgencyAndId shapeId = trip.getShapeId();
if (shapeId != null)
shapeIdsForIndex.add(shapeId);
}
}
for (AgencyAndId shapeId : shapeIdsForIndex) {
List<BlockSequenceIndex> list = _blockSequenceIndicesByShapeId.get(shapeId);
if (list == null) {
list = new ArrayList<BlockSequenceIndex>();
_blockSequenceIndicesByShapeId.put(shapeId, list);
}
list.add(index);
}
}
}
use of org.onebusaway.transit_data_federation.services.blocks.BlockSequenceIndex in project onebusaway-application-modules by camsys.
the class BlockIndexFactoryServiceImpl method createSequenceIndices.
public List<BlockSequenceIndex> createSequenceIndices(Iterable<BlockEntry> blocks) {
List<BlockSequenceIndex> allIndices = new ArrayList<BlockSequenceIndex>();
Map<BlockSequenceKey, List<BlockSequence>> blockSequencesByKey = new FactoryMap<BlockSequenceKey, List<BlockSequence>>(new ArrayList<BlockSequence>());
if (_verbose)
_log.info("grouping block trips into sequence indices");
int sequenceCount = 0;
int blockTripCount = 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()) {
blockTripCount += blockConfiguration.getTrips().size();
List<BlockSequence> sequences = groupTrips(blockConfiguration);
for (BlockSequence sequence : sequences) {
BlockSequenceKey key = getBlockSequenceAsSequenceKey(sequence);
blockSequencesByKey.get(key).add(sequence);
sequenceCount++;
}
}
}
if (_verbose)
_log.info("groups found: " + blockSequencesByKey.size() + " out of sequences: " + sequenceCount + " and trips: " + blockTripCount);
for (List<BlockSequence> sequences : blockSequencesByKey.values()) {
List<List<BlockSequence>> groupedBlocks = BlockLibrary.createStrictlyOrderedGroups(sequences, _blockSequenceLooseComparator, _blockSequenceStrictComparator);
for (List<BlockSequence> group : groupedBlocks) {
BlockSequenceIndex index = createSequenceIndexForGroupOfBlockSequences(group);
allIndices.add(index);
}
}
return allIndices;
}
use of org.onebusaway.transit_data_federation.services.blocks.BlockSequenceIndex in project onebusaway-application-modules by camsys.
the class CurrentVehicleEstimationServiceImpl method getCurrentVehicleEstimates.
@Override
public ListBean<CurrentVehicleEstimateBean> getCurrentVehicleEstimates(CurrentVehicleEstimateQueryBean query) {
long minT = SystemTime.currentTimeMillis() - _maxWindow * 60 * 1000;
minT = 0;
List<Record> records = getRecords(query.getRecords(), minT);
if (records.isEmpty())
return new ListBean<CurrentVehicleEstimateBean>();
List<CurrentVehicleEstimateBean> beans = new ArrayList<CurrentVehicleEstimateBean>();
if (tryDirectMatchAgainstVehicleId(query, records, beans))
return new ListBean<CurrentVehicleEstimateBean>(beans, true);
Map<Date, Record> recordsByTime = getRecordsByTimestamp(records);
List<Date> timestamps = new ArrayList<Date>(recordsByTime.keySet());
Collections.sort(timestamps);
if (tryDirectMatchAgainstBlockId(query, records, recordsByTime, timestamps, query.getMinProbability(), beans))
return new ListBean<CurrentVehicleEstimateBean>(beans, true);
Set<BlockSequenceIndex> allIndices = getBlockSequenceIndicesForRecords(recordsByTime);
for (BlockSequenceIndex index : allIndices) {
Map<BlockInstance, List<List<BlockLocation>>> allLocations = _blockStatusService.getBlocksForIndex(index, timestamps);
for (Map.Entry<BlockInstance, List<List<BlockLocation>>> entry : allLocations.entrySet()) {
BlockInstance blockInstance = entry.getKey();
List<List<BlockLocation>> realTimeLocations = entry.getValue();
computeEstimatesForBlockInstance(records, recordsByTime, blockInstance, realTimeLocations, query.getMinProbability(), beans);
}
}
Collections.sort(beans);
return new ListBean<CurrentVehicleEstimateBean>(beans, false);
}
use of org.onebusaway.transit_data_federation.services.blocks.BlockSequenceIndex in project onebusaway-application-modules by camsys.
the class CurrentVehicleEstimationServiceImpl method getBlockSequenceIndicesForRecords.
private Set<BlockSequenceIndex> getBlockSequenceIndicesForRecords(Map<Date, Record> recordsByTime) {
Set<BlockSequenceIndex> allIndices = null;
for (Record record : recordsByTime.values()) {
CoordinateBounds bounds = SphericalGeometryLibrary.bounds(record.getLocation(), record.getAccuracy());
Set<BlockSequenceIndex> indices = _blockGeospatialService.getBlockSequenceIndexPassingThroughBounds(bounds);
if (allIndices == null)
allIndices = indices;
else
allIndices.retainAll(indices);
}
return allIndices;
}
Aggregations