Search in sources :

Example 6 with FrequencyBlockTripIndex

use of org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockTripIndex 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;
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) StopGroupBean(org.onebusaway.transit_data.model.StopGroupBean) ArrayList(java.util.ArrayList) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) StopSequence(org.onebusaway.transit_data_federation.model.StopSequence) FrequencyBlockTripIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockTripIndex) StopGroupingBean(org.onebusaway.transit_data.model.StopGroupingBean) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) NameBean(org.onebusaway.transit_data.model.NameBean) EncodedPolylineBean(org.onebusaway.geospatial.model.EncodedPolylineBean) BlockTripIndex(org.onebusaway.transit_data_federation.services.blocks.BlockTripIndex) FrequencyBlockTripIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockTripIndex) AbstractBlockTripIndex(org.onebusaway.transit_data_federation.services.blocks.AbstractBlockTripIndex) StopSequenceCollection(org.onebusaway.transit_data_federation.model.StopSequenceCollection)

Example 7 with FrequencyBlockTripIndex

use of org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockTripIndex in project onebusaway-application-modules by camsys.

the class BlockIndexFactoryServiceImpl method createFrequencyTripIndices.

public List<FrequencyBlockTripIndex> createFrequencyTripIndices(Iterable<BlockEntry> blocks) {
    List<FrequencyBlockTripIndex> allIndices = new ArrayList<FrequencyBlockTripIndex>();
    int logInterval = LoggingIntervalUtil.getAppropriateLoggingInterval(allIndices.size());
    Map<BlockSequenceKey, List<BlockTripEntry>> blockTripsByKey = new FactoryMap<BlockSequenceKey, List<BlockTripEntry>>(new ArrayList<BlockTripEntry>());
    if (_verbose)
        _log.info("grouping frequency blocks by sequence key");
    int tripCount = 0;
    for (BlockEntry block : blocks) {
        if (block.getConfigurations().isEmpty()) {
            _log.warn("block has no 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("frequency groups found: " + blockTripsByKey.size() + " out of trips: " + tripCount);
    int count = 0;
    for (List<BlockTripEntry> tripsWithSameSequence : blockTripsByKey.values()) {
        if (_verbose && count % logInterval == 0)
            _log.info("frequency groups processed: " + count + "/" + blockTripsByKey.size());
        count++;
        List<FrequencyTripGroup> groupedTrips = ensureFrequencyTripGroups(tripsWithSameSequence);
        for (FrequencyTripGroup group : groupedTrips) {
            group.trimToSize();
            FrequencyBlockTripIndex index = createFrequencyIndexForTrips(group.getTrips(), group.getFrequencies());
            allIndices.add(index);
        }
    }
    return allIndices;
}
Also used : FactoryMap(org.onebusaway.collections.FactoryMap) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) ArrayList(java.util.ArrayList) FrequencyBlockTripIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockTripIndex) 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 8 with FrequencyBlockTripIndex

use of org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockTripIndex in project onebusaway-application-modules by camsys.

the class BlockIndexServiceImpl method loadStopTripIndices.

private void loadStopTripIndices() {
    // Clear any existing indices
    for (StopEntry stop : _graphDao.getAllStops()) {
        StopEntryImpl stopImpl = (StopEntryImpl) stop;
        stopImpl.getStopTripIndices().clear();
        stopImpl.getFrequencyStopTripIndices().clear();
    }
    for (BlockSequenceIndex index : _blockSequenceIndices) {
        BlockSequence sequence = index.getSequences().get(0);
        int offset = 0;
        for (BlockStopTimeEntry bst : sequence.getStopTimes()) {
            StopTimeEntry stopTime = bst.getStopTime();
            StopEntryImpl stop = (StopEntryImpl) stopTime.getStop();
            BlockStopSequenceIndex blockStopTripIndex = new BlockStopSequenceIndex(index, offset);
            stop.addBlockStopTripIndex(blockStopTripIndex);
            offset++;
        }
    }
    for (FrequencyBlockTripIndex index : _frequencyBlockTripIndices) {
        BlockTripEntry trip = index.getTrips().get(0);
        int offset = 0;
        for (BlockStopTimeEntry bst : trip.getStopTimes()) {
            StopTimeEntry stopTime = bst.getStopTime();
            StopEntryImpl stop = (StopEntryImpl) stopTime.getStop();
            FrequencyStopTripIndex stopTripIndex = new FrequencyStopTripIndex(index, offset);
            stop.addFrequencyStopTripIndex(stopTripIndex);
            offset++;
        }
    }
}
Also used : BlockStopSequenceIndex(org.onebusaway.transit_data_federation.services.blocks.BlockStopSequenceIndex) FrequencyBlockTripIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockTripIndex) FrequencyStopTripIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyStopTripIndex) StopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) BlockSequenceIndex(org.onebusaway.transit_data_federation.services.blocks.BlockSequenceIndex) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry) StopEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl)

Example 9 with FrequencyBlockTripIndex

use of org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockTripIndex 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));
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) BlockLayoverIndex(org.onebusaway.transit_data_federation.services.blocks.BlockLayoverIndex) FrequencyBlockTripIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockTripIndex) BlockEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry) ArrayList(java.util.ArrayList) List(java.util.List) BlockTripIndex(org.onebusaway.transit_data_federation.services.blocks.BlockTripIndex) FrequencyBlockTripIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockTripIndex)

Example 10 with FrequencyBlockTripIndex

use of org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockTripIndex in project onebusaway-application-modules by camsys.

the class BlockIndexServiceImpl method loadFrequencyBlockTripIndices.

private void loadFrequencyBlockTripIndices() throws IOException, ClassNotFoundException {
    File path = _bundle.getFrequencyBlockTripIndicesPath();
    if (path.exists()) {
        _log.info("loading frequency block trip indices data");
        List<FrequencyBlockTripIndexData> datas = ObjectSerializationLibrary.readObject(path);
        _frequencyBlockTripIndices = new ArrayList<FrequencyBlockTripIndex>(datas.size());
        for (FrequencyBlockTripIndexData data : datas) _frequencyBlockTripIndices.add(data.createIndex(_graphDao));
        _frequencyBlockTripIndicesByAgencyId = getBlockTripIndicesByAgencyId(_frequencyBlockTripIndices);
        _frequencyBlockTripIndicesByRouteId = getBlockTripsByRouteId(_frequencyBlockTripIndices);
        _log.info("block frequency trip indices data loaded");
    } else {
        _frequencyBlockTripIndices = Collections.emptyList();
        _frequencyBlockTripIndicesByAgencyId = Collections.emptyMap();
        _frequencyBlockTripIndicesByRouteId = Collections.emptyMap();
    }
}
Also used : FrequencyBlockTripIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockTripIndex) File(java.io.File) FrequencyBlockTripIndexData(org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockTripIndexData)

Aggregations

FrequencyBlockTripIndex (org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockTripIndex)10 BlockTripEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry)6 ArrayList (java.util.ArrayList)5 StopEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl)4 BlockTripIndex (org.onebusaway.transit_data_federation.services.blocks.BlockTripIndex)4 BlockEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry)4 List (java.util.List)3 Test (org.junit.Test)3 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)3 BlockEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl)3 TripEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl)3 BlockLayoverIndex (org.onebusaway.transit_data_federation.services.blocks.BlockLayoverIndex)3 FrequencyServiceIntervalBlock (org.onebusaway.transit_data_federation.services.blocks.FrequencyServiceIntervalBlock)3 BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)3 ServiceIdActivation (org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation)3 StopEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopEntry)3 FrequencyBlockTripIndexData (org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockTripIndexData)2 FrequencyEntry (org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry)2 TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)2 File (java.io.File)1