use of org.onebusaway.transit_data_federation.services.transit_graph.FrequencyBlockStopTimeEntry 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.transit_graph.FrequencyBlockStopTimeEntry 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.transit_graph.FrequencyBlockStopTimeEntry in project onebusaway-application-modules by camsys.
the class StopTimeServiceImpl method getFrequenciesForStopAndServiceIdsAndTimeRange.
private List<Integer> getFrequenciesForStopAndServiceIdsAndTimeRange(FrequencyStopTripIndex index, Date serviceDate, Date from, Date to, List<StopTimeInstance> stopTimeInstances, EFrequencyStopTimeBehavior frequencyBehavior) {
int relativeFrom = effectiveTime(serviceDate, from);
int relativeTo = effectiveTime(serviceDate, to);
int fromIndex = GenericBinarySearch.search(index, index.size(), relativeFrom, IndexAdapters.FREQUENCY_END_TIME_INSTANCE);
int toIndex = GenericBinarySearch.search(index, index.size(), relativeTo, IndexAdapters.FREQUENCY_START_TIME_INSTANCE);
List<FrequencyBlockStopTimeEntry> frequencyStopTimes = index.getFrequencyStopTimes();
List<Integer> offsetsIntoIndex = new ArrayList<Integer>();
for (int in = fromIndex; in < toIndex; in++) {
FrequencyBlockStopTimeEntry entry = frequencyStopTimes.get(in);
BlockStopTimeEntry bst = entry.getStopTime();
FrequencyEntry frequency = entry.getFrequency();
InstanceState state = new InstanceState(serviceDate.getTime(), frequency);
switch(frequencyBehavior) {
case INCLUDE_UNSPECIFIED:
{
stopTimeInstances.add(new StopTimeInstance(bst, state));
offsetsIntoIndex.add(in);
break;
}
case INCLUDE_INTERPOLATED:
{
int stopTimeOffset = entry.getStopTimeOffset();
int tFrom = Math.max(relativeFrom, frequency.getStartTime());
int tTo = Math.min(relativeTo, frequency.getEndTime());
tFrom = snapToFrequencyStopTime(frequency, tFrom, stopTimeOffset, true);
tTo = snapToFrequencyStopTime(frequency, tTo, stopTimeOffset, false);
for (int t = tFrom; t <= tTo; t += frequency.getHeadwaySecs()) {
int frequencyOffset = t - bst.getStopTime().getDepartureTime();
stopTimeInstances.add(new StopTimeInstance(bst, state, frequencyOffset));
offsetsIntoIndex.add(in);
}
break;
}
}
}
return offsetsIntoIndex;
}
use of org.onebusaway.transit_data_federation.services.transit_graph.FrequencyBlockStopTimeEntry in project onebusaway-application-modules by camsys.
the class StopScheduleBeanServiceImpl method groupFrequencyInstancesByRouteCollectionId.
private void groupFrequencyInstancesByRouteCollectionId(StopEntry stopEntry, ServiceDate date, Map<AgencyAndId, List<StopTimeInstance>> frequenciesByRouteCollectionId) {
for (FrequencyBlockStopTimeIndex index : _blockIndexService.getFrequencyStopTimeIndicesForStop(stopEntry)) {
ServiceIdActivation serviceIds = index.getServiceIds();
Set<ServiceDate> serviceDates = _calendarService.getServiceDatesForServiceIds(serviceIds);
if (!serviceDates.contains(date))
continue;
Date serviceDate = date.getAsDate(serviceIds.getTimeZone());
for (FrequencyBlockStopTimeEntry entry : index.getFrequencyStopTimes()) {
BlockStopTimeEntry stopTime = entry.getStopTime();
BlockTripEntry blockTrip = stopTime.getTrip();
TripEntry trip = blockTrip.getTrip();
AgencyAndId routeCollectionId = trip.getRouteCollection().getId();
InstanceState state = new InstanceState(serviceDate.getTime(), entry.getFrequency());
StopTimeInstance sti = new StopTimeInstance(stopTime, state);
frequenciesByRouteCollectionId.get(routeCollectionId).add(sti);
}
}
}
use of org.onebusaway.transit_data_federation.services.transit_graph.FrequencyBlockStopTimeEntry in project onebusaway-application-modules by camsys.
the class BlockStopTimeIndicesFactory method getStopTimesAsFrequencyStopTimes.
private List<FrequencyBlockStopTimeEntry> getStopTimesAsFrequencyStopTimes(List<BlockStopTimeEntry> stopTimes) {
List<FrequencyBlockStopTimeEntry> frequencyStopTimes = new ArrayList<FrequencyBlockStopTimeEntry>();
for (BlockStopTimeEntry blockStopTime : stopTimes) {
BlockTripEntry trip = blockStopTime.getTrip();
BlockConfigurationEntry blockConfig = trip.getBlockConfiguration();
for (FrequencyEntry frequency : blockConfig.getFrequencies()) {
FrequencyBlockStopTimeEntry frequencyStopTime = new FrequencyBlockStopTimeEntryImpl(blockStopTime, frequency);
frequencyStopTimes.add(frequencyStopTime);
}
}
return frequencyStopTimes;
}
Aggregations