Search in sources :

Example 6 with BlockConfigurationEntry

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

the class ScheduledBlockLocationServiceImpl method getScheduledBlockLocationFromScheduledTime.

@Override
public ScheduledBlockLocation getScheduledBlockLocationFromScheduledTime(ScheduledBlockLocation previousLocation, int scheduleTime) {
    if (previousLocation.getScheduledTime() > scheduleTime)
        throw new IllegalStateException("previousLocation's scheduledTime must be before the requested scheduleTime");
    BlockTripEntry trip = previousLocation.getActiveTrip();
    BlockConfigurationEntry blockConfig = trip.getBlockConfiguration();
    List<BlockStopTimeEntry> stopTimes = blockConfig.getStopTimes();
    int index = previousLocation.getStopTimeIndex();
    while (index < stopTimes.size()) {
        int t = blockConfig.getDepartureTimeForIndex(index);
        if (scheduleTime <= t)
            break;
        index++;
    }
    return getScheduledBlockLocationFromScheduleTimeAndStopTimeIndex(stopTimes, scheduleTime, index);
}
Also used : BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint)

Example 7 with BlockConfigurationEntry

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

the class BlockIndexFactoryServiceImpl method ensureFrequencyTripGroups.

private List<FrequencyTripGroup> ensureFrequencyTripGroups(List<BlockTripEntry> tripsWithSameSequence) {
    List<BlockTripWithFrequency> btwfs = new ArrayList<BlockTripWithFrequency>();
    for (BlockTripEntry trip : tripsWithSameSequence) {
        BlockConfigurationEntry blockConfig = trip.getBlockConfiguration();
        for (FrequencyEntry frequency : blockConfig.getFrequencies()) btwfs.add(new BlockTripWithFrequency(trip, frequency));
    }
    Collections.sort(btwfs);
    List<FrequencyTripGroup> lists = new ArrayList<FrequencyTripGroup>();
    for (BlockTripWithFrequency btwf : btwfs) {
        FrequencyTripGroup group = getBestFrequencyTripGroup(lists, btwf);
        if (group == null) {
            group = new FrequencyTripGroup();
            lists.add(group);
        }
        group.addEntry(btwf);
    }
    return lists;
}
Also used : BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) ArrayList(java.util.ArrayList) FrequencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)

Example 8 with BlockConfigurationEntry

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

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

the class BlockStatusServiceImpl method getBlockInstances.

/**
 **
 * Private Methods
 ***
 */
private List<BlockInstance> getBlockInstances(AgencyAndId blockId, long serviceDate, long time) {
    if (serviceDate != 0) {
        BlockInstance blockInstance = _blockCalendarService.getBlockInstance(blockId, serviceDate);
        if (blockInstance == null)
            return Collections.emptyList();
        BlockConfigurationEntry blockConfig = blockInstance.getBlock();
        if (blockConfig.getFrequencies() == null)
            return Arrays.asList(blockInstance);
        List<BlockInstance> instances = new ArrayList<BlockInstance>();
        for (FrequencyEntry frequency : blockConfig.getFrequencies()) instances.add(new BlockInstance(blockConfig, blockInstance.getServiceDate(), frequency));
        return instances;
    } else {
        List<BlockInstance> instances = _blockCalendarService.getActiveBlocks(blockId, time, time);
        if (instances.isEmpty()) {
            instances = _blockCalendarService.getClosestActiveBlocks(blockId, time);
        }
        return instances;
    }
}
Also used : BlockInstance(org.onebusaway.transit_data_federation.services.blocks.BlockInstance) ArrayList(java.util.ArrayList) FrequencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)

Example 10 with BlockConfigurationEntry

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

the class BlockStopTimeIndicesFactory method createFrequencyBlockStopTimeIndexForGroup.

private FrequencyBlockStopTimeIndex createFrequencyBlockStopTimeIndexForGroup(List<FrequencyBlockStopTimeEntry> group) {
    int n = group.size();
    List<FrequencyEntry> frequencies = new ArrayList<FrequencyEntry>(n);
    List<BlockConfigurationEntry> blockConfigs = new ArrayList<BlockConfigurationEntry>(n);
    int[] stopIndices = new int[n];
    ServiceInterval interval = null;
    for (int i = 0; i < n; i++) {
        FrequencyBlockStopTimeEntry frequencyBlockStopTime = group.get(i);
        FrequencyEntry frequency = frequencyBlockStopTime.getFrequency();
        frequencies.add(frequency);
        BlockStopTimeEntry blockStopTime = frequencyBlockStopTime.getStopTime();
        blockConfigs.add(blockStopTime.getTrip().getBlockConfiguration());
        stopIndices[i] = blockStopTime.getBlockSequence();
        interval = ServiceInterval.extend(interval, frequency.getStartTime(), frequency.getStartTime());
        interval = ServiceInterval.extend(interval, frequency.getEndTime(), frequency.getEndTime());
    }
    return new FrequencyBlockStopTimeIndex(frequencies, blockConfigs, stopIndices, interval);
}
Also used : ServiceInterval(org.onebusaway.gtfs.model.calendar.ServiceInterval) FrequencyBlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockStopTimeIndex) ArrayList(java.util.ArrayList) FrequencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry) FrequencyBlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyBlockStopTimeEntry) FrequencyBlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyBlockStopTimeEntry)

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