Search in sources :

Example 1 with BlockStopSequenceIndex

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

the class StopTimeServiceImpl method getNextBlockSequenceDeparturesForStop.

@Override
public List<StopTimeInstance> getNextBlockSequenceDeparturesForStop(StopEntry stopEntry, long time, boolean includePrivateSerivce) {
    List<StopTimeInstance> stopTimeInstances = new ArrayList<StopTimeInstance>();
    List<BlockStopSequenceIndex> blockStopTripIndices = _blockIndexService.getStopSequenceIndicesForStop(stopEntry);
    for (BlockStopSequenceIndex index : blockStopTripIndices) {
        List<Date> serviceDates = _calendarService.getNextServiceDatesForDepartureInterval(index.getServiceIds(), index.getServiceInterval(), time);
        for (Date serviceDate : serviceDates) {
            int relativeFrom = effectiveTime(serviceDate.getTime(), time);
            int fromIndex = GenericBinarySearch.search(index, index.size(), relativeFrom, IndexAdapters.BLOCK_STOP_TIME_DEPARTURE_INSTANCE);
            if (fromIndex < index.size()) {
                BlockStopTimeEntry blockStopTime = index.getBlockStopTimeForIndex(fromIndex);
                InstanceState state = new InstanceState(serviceDate.getTime());
                StopTimeInstance sti = new StopTimeInstance(blockStopTime, state);
                stopTimeInstances.add(sti);
            }
        }
    }
    List<FrequencyBlockStopTimeIndex> frequencyIndices = _blockIndexService.getFrequencyStopTimeIndicesForStop(stopEntry);
    for (FrequencyBlockStopTimeIndex index : frequencyIndices) {
        List<Date> serviceDates = _calendarService.getNextServiceDatesForDepartureInterval(index.getServiceIds(), index.getServiceInterval(), time);
        for (Date serviceDate : serviceDates) {
            int relativeFrom = effectiveTime(serviceDate.getTime(), time);
            int fromIndex = GenericBinarySearch.search(index, index.size(), relativeFrom, IndexAdapters.FREQUENCY_END_TIME_INSTANCE);
            List<FrequencyBlockStopTimeEntry> frequencyStopTimes = index.getFrequencyStopTimes();
            if (fromIndex < index.size()) {
                FrequencyBlockStopTimeEntry entry = frequencyStopTimes.get(fromIndex);
                BlockStopTimeEntry bst = entry.getStopTime();
                FrequencyEntry frequency = entry.getFrequency();
                InstanceState state = new InstanceState(serviceDate.getTime(), frequency);
                int stopTimeOffset = entry.getStopTimeOffset();
                int frequencyOffset = computeFrequencyOffset(relativeFrom, bst, frequency, stopTimeOffset, true);
                StopTimeInstance sti = new StopTimeInstance(bst, state, frequencyOffset);
                stopTimeInstances.add(sti);
            }
        }
    }
    return stopTimeInstances;
}
Also used : StopTimeInstance(org.onebusaway.transit_data_federation.model.StopTimeInstance) FrequencyBlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockStopTimeIndex) ArrayList(java.util.ArrayList) FrequencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry) Date(java.util.Date) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) FrequencyBlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyBlockStopTimeEntry) BlockStopSequenceIndex(org.onebusaway.transit_data_federation.services.blocks.BlockStopSequenceIndex) InstanceState(org.onebusaway.transit_data_federation.services.blocks.InstanceState) FrequencyBlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyBlockStopTimeEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)

Example 2 with BlockStopSequenceIndex

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

Aggregations

BlockStopSequenceIndex (org.onebusaway.transit_data_federation.services.blocks.BlockStopSequenceIndex)2 BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)1 StopEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl)1 StopTimeInstance (org.onebusaway.transit_data_federation.model.StopTimeInstance)1 BlockSequenceIndex (org.onebusaway.transit_data_federation.services.blocks.BlockSequenceIndex)1 FrequencyBlockStopTimeIndex (org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockStopTimeIndex)1 FrequencyBlockTripIndex (org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockTripIndex)1 FrequencyStopTripIndex (org.onebusaway.transit_data_federation.services.blocks.FrequencyStopTripIndex)1 InstanceState (org.onebusaway.transit_data_federation.services.blocks.InstanceState)1 BlockTripEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry)1 FrequencyBlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.FrequencyBlockStopTimeEntry)1 FrequencyEntry (org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry)1 StopEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopEntry)1 StopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry)1