Search in sources :

Example 1 with BlockSequenceIndex

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;
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) BlockSequenceIndex(org.onebusaway.transit_data_federation.services.blocks.BlockSequenceIndex) List(java.util.List) ArrayList(java.util.ArrayList) Envelope(com.vividsolutions.jts.geom.Envelope) HashSet(java.util.HashSet)

Example 2 with BlockSequenceIndex

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);
        }
    }
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) BlockSequenceIndex(org.onebusaway.transit_data_federation.services.blocks.BlockSequenceIndex) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry) HashSet(java.util.HashSet)

Example 3 with BlockSequenceIndex

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;
}
Also used : FactoryMap(org.onebusaway.collections.FactoryMap) BlockSequenceIndex(org.onebusaway.transit_data_federation.services.blocks.BlockSequenceIndex) ArrayList(java.util.ArrayList) BlockEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry) ArrayList(java.util.ArrayList) List(java.util.List) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)

Example 4 with BlockSequenceIndex

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);
}
Also used : BlockSequenceIndex(org.onebusaway.transit_data_federation.services.blocks.BlockSequenceIndex) DoubleArrayList(cern.colt.list.DoubleArrayList) ArrayList(java.util.ArrayList) ListBean(org.onebusaway.transit_data.model.ListBean) ScheduledBlockLocation(org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation) BlockLocation(org.onebusaway.transit_data_federation.services.realtime.BlockLocation) Date(java.util.Date) CurrentVehicleEstimateBean(org.onebusaway.transit_data.model.realtime.CurrentVehicleEstimateBean) BlockInstance(org.onebusaway.transit_data_federation.services.blocks.BlockInstance) Record(org.onebusaway.transit_data.model.realtime.CurrentVehicleEstimateQueryBean.Record) DoubleArrayList(cern.colt.list.DoubleArrayList) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with BlockSequenceIndex

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;
}
Also used : BlockSequenceIndex(org.onebusaway.transit_data_federation.services.blocks.BlockSequenceIndex) Record(org.onebusaway.transit_data.model.realtime.CurrentVehicleEstimateQueryBean.Record) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds)

Aggregations

BlockSequenceIndex (org.onebusaway.transit_data_federation.services.blocks.BlockSequenceIndex)7 ArrayList (java.util.ArrayList)3 List (java.util.List)3 HashSet (java.util.HashSet)2 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)2 Record (org.onebusaway.transit_data.model.realtime.CurrentVehicleEstimateQueryBean.Record)2 BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)2 BlockTripEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry)2 DoubleArrayList (cern.colt.list.DoubleArrayList)1 Envelope (com.vividsolutions.jts.geom.Envelope)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 FactoryMap (org.onebusaway.collections.FactoryMap)1 CoordinateBounds (org.onebusaway.geospatial.model.CoordinateBounds)1 ListBean (org.onebusaway.transit_data.model.ListBean)1 CurrentVehicleEstimateBean (org.onebusaway.transit_data.model.realtime.CurrentVehicleEstimateBean)1 StopEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl)1 BlockInstance (org.onebusaway.transit_data_federation.services.blocks.BlockInstance)1 BlockStopSequenceIndex (org.onebusaway.transit_data_federation.services.blocks.BlockStopSequenceIndex)1