Search in sources :

Example 61 with BlockTripEntry

use of org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry 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 62 with BlockTripEntry

use of org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry in project onebusaway-application-modules by camsys.

the class BlockIndexFactoryServiceImpl method groupTrips.

private List<BlockSequence> groupTrips(BlockConfigurationEntry blockConfig) {
    List<BlockTripEntry> trips = blockConfig.getTrips();
    if (trips.isEmpty())
        return Collections.emptyList();
    List<List<BlockTripEntry>> groups = new ArrayList<List<BlockTripEntry>>();
    List<BlockTripEntry> group = new ArrayList<BlockTripEntry>();
    groups.add(group);
    BlockTripEntry prev = null;
    for (BlockTripEntry trip : trips) {
        if (prev != null) {
            if (!areBlockTripsContinuous(prev, trip)) {
                group = new ArrayList<BlockTripEntry>();
                groups.add(group);
            }
        }
        group.add(trip);
        prev = trip;
    }
    List<BlockSequence> sequences = new ArrayList<BlockSequence>();
    for (List<BlockTripEntry> g : groups) {
        BlockTripEntry firstTrip = g.get(0);
        BlockTripEntry lastTrip = g.get(g.size() - 1);
        int from = firstTrip.getAccumulatedStopTimeIndex();
        int to = blockConfig.getStopTimes().size();
        if (lastTrip.getNextTrip() != null) {
            BlockTripEntry next = lastTrip.getNextTrip();
            to = next.getAccumulatedStopTimeIndex();
        }
        BlockSequence sequence = new BlockSequence(blockConfig, from, to);
        sequences.add(sequence);
    }
    return sequences;
}
Also used : BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 63 with BlockTripEntry

use of org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry in project onebusaway-application-modules by camsys.

the class BlockIndexFactoryServiceImpl method createLayoverIndices.

public List<BlockLayoverIndex> createLayoverIndices(Iterable<BlockEntry> blocks) {
    List<BlockLayoverIndex> allIndices = new ArrayList<BlockLayoverIndex>();
    int logInterval = LoggingIntervalUtil.getAppropriateLoggingInterval(allIndices.size());
    Map<BlockLayoverSequenceKey, List<BlockTripEntry>> blockTripsByServiceIds = new FactoryMap<BlockLayoverSequenceKey, List<BlockTripEntry>>(new ArrayList<BlockTripEntry>());
    if (_verbose)
        _log.info("grouping block layovers 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()) {
            BlockTripEntry prevTrip = null;
            for (BlockTripEntry blockTrip : blockConfiguration.getTrips()) {
                if (prevTrip != null) {
                    BlockLayoverSequenceKey key = getBlockTripAsLayoverSequenceKey(blockTrip);
                    blockTripsByServiceIds.get(key).add(blockTrip);
                    tripCount++;
                }
                prevTrip = blockTrip;
            }
        }
    }
    if (_verbose)
        _log.info("groups found: " + blockTripsByServiceIds.size() + " out of trips: " + tripCount);
    int count = 0;
    for (List<BlockTripEntry> tripsWithSameSequence : blockTripsByServiceIds.values()) {
        if (_verbose && count % logInterval == 0)
            _log.info("groups processed: " + count + "/" + blockTripsByServiceIds.size());
        count++;
        List<List<BlockTripEntry>> groupedBlocks = ensureLayoverGroups(tripsWithSameSequence);
        for (List<BlockTripEntry> group : groupedBlocks) {
            BlockLayoverIndex index = createLayoverIndexForGroupOfBlockTrips(group);
            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) BlockLayoverIndex(org.onebusaway.transit_data_federation.services.blocks.BlockLayoverIndex) 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 64 with BlockTripEntry

use of org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry 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;
}
Also used : FactoryMap(org.onebusaway.collections.FactoryMap) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) 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) BlockTripIndex(org.onebusaway.transit_data_federation.services.blocks.BlockTripIndex) FrequencyBlockTripIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockTripIndex)

Example 65 with BlockTripEntry

use of org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry 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)

Aggregations

BlockTripEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry)72 BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)30 TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)27 ArrayList (java.util.ArrayList)26 BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)25 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)23 StopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry)15 List (java.util.List)11 FrequencyEntry (org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry)10 StopEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopEntry)10 FactoryMap (org.onebusaway.collections.FactoryMap)9 BlockInstance (org.onebusaway.transit_data_federation.services.blocks.BlockInstance)8 HashSet (java.util.HashSet)7 CoordinatePoint (org.onebusaway.geospatial.model.CoordinatePoint)7 StopTimeInstance (org.onebusaway.transit_data_federation.model.StopTimeInstance)7 InstanceState (org.onebusaway.transit_data_federation.services.blocks.InstanceState)7 Date (java.util.Date)6 FrequencyBlockTripIndex (org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockTripIndex)6 ServiceInterval (org.onebusaway.gtfs.model.calendar.ServiceInterval)5 StopSequence (org.onebusaway.transit_data_federation.model.StopSequence)5