Search in sources :

Example 1 with FrequencyBlockStopTimeIndex

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

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

the class StopTimeServiceImpl method getDepartureForStopAndServiceDate.

@Override
public Range getDepartureForStopAndServiceDate(AgencyAndId stopId, ServiceDate serviceDate) {
    StopEntry stop = _graph.getStopEntryForId(stopId, true);
    List<BlockStopTimeIndex> indices = _blockIndexService.getStopTimeIndicesForStop(stop);
    Range interval = new Range();
    for (BlockStopTimeIndex index : indices) {
        extendIntervalWithIndex(serviceDate, interval, index);
    }
    List<FrequencyBlockStopTimeIndex> freqIndices = _blockIndexService.getFrequencyStopTimeIndicesForStop(stop);
    for (FrequencyBlockStopTimeIndex index : freqIndices) extendIntervalWithIndex(serviceDate, interval, index);
    return interval;
}
Also used : FrequencyBlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockStopTimeIndex) BlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.BlockStopTimeIndex) AbstractBlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.AbstractBlockStopTimeIndex) FrequencyBlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockStopTimeIndex) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) Range(org.onebusaway.collections.Range)

Example 3 with FrequencyBlockStopTimeIndex

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

Example 4 with FrequencyBlockStopTimeIndex

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

the class RouteServiceImpl method getRouteCollectionIdsForStop.

@Override
@Cacheable
public Set<AgencyAndId> getRouteCollectionIdsForStop(AgencyAndId stopId) {
    StopEntry stopEntry = _transitGraphDao.getStopEntryForId(stopId);
    if (stopEntry == null)
        throw new InternalErrorServiceException("no such stop: id=" + stopId);
    Set<AgencyAndId> routeCollectionIds = new HashSet<AgencyAndId>();
    List<BlockStopTimeIndex> indices = _blockIndexService.getStopTimeIndicesForStop(stopEntry);
    for (BlockStopTimeIndex blockStopTimeIndex : indices) {
        for (BlockTripEntry blockTrip : blockStopTimeIndex.getTrips()) {
            TripEntry trip = blockTrip.getTrip();
            routeCollectionIds.add(trip.getRouteCollection().getId());
        }
    }
    List<FrequencyBlockStopTimeIndex> frequencyIndices = _blockIndexService.getFrequencyStopTimeIndicesForStop(stopEntry);
    for (FrequencyBlockStopTimeIndex blockStopTimeIndex : frequencyIndices) {
        for (BlockTripEntry blockTrip : blockStopTimeIndex.getTrips()) {
            TripEntry trip = blockTrip.getTrip();
            routeCollectionIds.add(trip.getRouteCollection().getId());
        }
    }
    return routeCollectionIds;
}
Also used : InternalErrorServiceException(org.onebusaway.exceptions.InternalErrorServiceException) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) FrequencyBlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockStopTimeIndex) BlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.BlockStopTimeIndex) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) FrequencyBlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockStopTimeIndex) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) HashSet(java.util.HashSet) Cacheable(org.onebusaway.container.cache.Cacheable)

Example 5 with FrequencyBlockStopTimeIndex

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

the class BlockStopTimeIndicesFactoryTest method testFrequencies.

@Test
public void testFrequencies() {
    StopEntryImpl stopA = stop("a", 47.0, -122.0);
    StopEntryImpl stopB = stop("b", 47.1, -122.1);
    /**
     **
     * Block A
     ***
     */
    BlockEntryImpl blockA = block("a");
    TripEntryImpl tripA = trip("a", "s1");
    stopTime(0, stopA, tripA, 0, 10, 0);
    stopTime(0, stopB, tripA, 20, 20, 0);
    FrequencyEntry freqA1 = frequency(time(6, 00), time(9, 00), 10, 0);
    FrequencyEntry freqA2 = frequency(time(15, 00), time(18, 00), 10, 0);
    List<FrequencyEntry> freqsA = Arrays.asList(freqA1, freqA2);
    BlockConfigurationEntry bcA = linkBlockTrips(blockA, freqsA, tripA);
    /**
     **
     * Block B
     ***
     */
    BlockEntryImpl blockB = block("b");
    TripEntryImpl tripB = trip("b", "s1");
    stopTime(0, stopA, tripB, 20, 30, 0);
    stopTime(0, stopB, tripB, 50, 50, 0);
    FrequencyEntry freqB1 = frequency(time(9, 00), time(15, 00), 20, 0);
    FrequencyEntry freqB2 = frequency(time(18, 00), time(21, 00), 20, 0);
    List<FrequencyEntry> freqsB = Arrays.asList(freqB1, freqB2);
    BlockConfigurationEntry bcB = linkBlockTrips(blockB, freqsB, tripB);
    BlockStopTimeIndicesFactory factory = new BlockStopTimeIndicesFactory();
    List<FrequencyBlockStopTimeIndex> allIndices = factory.createFrequencyIndices(Arrays.asList((BlockEntry) blockB, blockA));
    assertEquals(2, allIndices.size());
    List<FrequencyBlockStopTimeIndex> indices = grep(allIndices, aid("a"), serviceIds(lsids("s1"), lsids()));
    assertEquals(1, indices.size());
    FrequencyBlockStopTimeIndex index = indices.get(0);
    assertEquals(freqA1, index.getFrequencies().get(0));
    assertEquals(freqB1, index.getFrequencies().get(1));
    assertEquals(freqA2, index.getFrequencies().get(2));
    assertEquals(freqB2, index.getFrequencies().get(3));
    assertEquals(bcA, index.getBlockConfigs().get(0));
    assertEquals(bcB, index.getBlockConfigs().get(1));
    assertEquals(bcA, index.getBlockConfigs().get(2));
    assertEquals(bcB, index.getBlockConfigs().get(3));
}
Also used : BlockEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry) FrequencyBlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockStopTimeIndex) FrequencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry) BlockEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl) StopEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl) Test(org.junit.Test)

Aggregations

FrequencyBlockStopTimeIndex (org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockStopTimeIndex)10 BlockStopTimeIndex (org.onebusaway.transit_data_federation.services.blocks.BlockStopTimeIndex)5 ArrayList (java.util.ArrayList)4 BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)4 FrequencyBlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.FrequencyBlockStopTimeEntry)4 StopEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopEntry)4 Date (java.util.Date)3 HashSet (java.util.HashSet)3 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)3 FrequencyEntry (org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry)3 ServiceIdActivation (org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation)3 Cacheable (org.onebusaway.container.cache.Cacheable)2 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)2 StopEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl)2 StopTimeInstance (org.onebusaway.transit_data_federation.model.StopTimeInstance)2 InstanceState (org.onebusaway.transit_data_federation.services.blocks.InstanceState)2 BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)2 BlockTripEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry)2 TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)2 HashMap (java.util.HashMap)1