Search in sources :

Example 81 with BlockConfigurationEntry

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

the class BlockBeanServiceImpl method getBlockForId.

@Cacheable
public BlockBean getBlockForId(AgencyAndId blockId) {
    BlockEntry blockEntry = _graph.getBlockEntryForId(blockId);
    if (blockEntry == null)
        return null;
    BlockBean bean = new BlockBean();
    bean.setId(AgencyAndIdLibrary.convertToString(blockEntry.getId()));
    List<BlockConfigurationBean> configBeans = new ArrayList<BlockConfigurationBean>();
    for (BlockConfigurationEntry blockConfiguration : blockEntry.getConfigurations()) {
        BlockConfigurationBean configBean = getBlockConfigurationAsBean(blockConfiguration);
        configBeans.add(configBean);
    }
    bean.setConfigurations(configBeans);
    return bean;
}
Also used : BlockEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry) BlockBean(org.onebusaway.transit_data.model.blocks.BlockBean) ArrayList(java.util.ArrayList) BlockConfigurationBean(org.onebusaway.transit_data.model.blocks.BlockConfigurationBean) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry) Cacheable(org.onebusaway.container.cache.Cacheable)

Example 82 with BlockConfigurationEntry

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

the class BlockStatusBeanServiceImpl method bean.

private BlockStatusBean bean(BlockLocation blockLocation) {
    if (blockLocation == null)
        return null;
    BlockInstance instance = blockLocation.getBlockInstance();
    BlockConfigurationEntry block = instance.getBlock();
    long serviceDate = instance.getServiceDate();
    BlockStatusBean bean = new BlockStatusBean();
    bean.setBlock(_blockBeanService.getBlockForId(block.getBlock().getId()));
    bean.setStatus("default");
    bean.setServiceDate(serviceDate);
    bean.setTotalDistanceAlongBlock(block.getTotalBlockDistance());
    bean.setInService(blockLocation.isInService());
    CoordinatePoint location = blockLocation.getLocation();
    bean.setLocation(location);
    bean.setScheduledDistanceAlongBlock(blockLocation.getScheduledDistanceAlongBlock());
    bean.setDistanceAlongBlock(blockLocation.getDistanceAlongBlock());
    BlockTripEntry activeTrip = blockLocation.getActiveTrip();
    if (activeTrip != null) {
        BlockTripBean activeTripBean = _blockBeanService.getBlockTripAsBean(activeTrip);
        bean.setActiveTrip(activeTripBean);
    }
    BlockStopTimeEntry stop = blockLocation.getClosestStop();
    if (stop != null) {
        StopBean stopBean = _stopBeanService.getStopForId(stop.getStopTime().getStop().getId());
        bean.setClosestStop(stopBean);
        bean.setClosestStopTimeOffset(blockLocation.getClosestStopTimeOffset());
    }
    bean.setPredicted(blockLocation.isPredicted());
    bean.setLastUpdateTime(blockLocation.getLastUpdateTime());
    bean.setScheduleDeviation(blockLocation.getScheduleDeviation());
    AgencyAndId vid = blockLocation.getVehicleId();
    if (vid != null)
        bean.setVehicleId(ApplicationBeanLibrary.getId(vid));
    return bean;
}
Also used : CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) BlockTripBean(org.onebusaway.transit_data.model.blocks.BlockTripBean) BlockStatusBean(org.onebusaway.transit_data.model.blocks.BlockStatusBean) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) BlockInstance(org.onebusaway.transit_data_federation.services.blocks.BlockInstance) StopBean(org.onebusaway.transit_data.model.StopBean) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)

Example 83 with BlockConfigurationEntry

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

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

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

BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)89 BlockInstance (org.onebusaway.transit_data_federation.services.blocks.BlockInstance)36 BlockEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl)34 Test (org.junit.Test)30 TripEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl)29 BlockTripEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry)27 ArrayList (java.util.ArrayList)23 BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)23 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)18 VehicleLocationRecord (org.onebusaway.realtime.api.VehicleLocationRecord)17 CoordinatePoint (org.onebusaway.geospatial.model.CoordinatePoint)14 StopTimeInstance (org.onebusaway.transit_data_federation.model.StopTimeInstance)13 BlockEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry)13 Date (java.util.Date)12 List (java.util.List)11 StopEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl)11 TripUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate)10 ScheduledBlockLocation (org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation)10 StopTimeUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeUpdate)8 FactoryMap (org.onebusaway.collections.FactoryMap)8