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;
}
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;
}
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);
}
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;
}
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));
}
Aggregations