use of org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry in project onebusaway-application-modules by camsys.
the class BlockCalendarServiceImpl method findFrequencyBlockTripsInRange.
private void findFrequencyBlockTripsInRange(FrequencyServiceIntervalBlock serviceIntervalIndex, Date serviceDate, Date timeFrom, Date timeTo, List<BlockTripEntry> trips, List<FrequencyEntry> frequencies, Collection<BlockInstance> instances) {
int scheduledTimeFrom = (int) ((timeFrom.getTime() - serviceDate.getTime()) / 1000);
int scheduledTimeTo = (int) ((timeTo.getTime() - serviceDate.getTime()) / 1000);
int indexFrom = index(Arrays.binarySearch(serviceIntervalIndex.getEndTimes(), scheduledTimeFrom));
int indexTo = index(Arrays.binarySearch(serviceIntervalIndex.getStartTimes(), scheduledTimeTo));
for (int in = indexFrom; in < indexTo; in++) {
BlockTripEntry trip = trips.get(in);
BlockConfigurationEntry block = trip.getBlockConfiguration();
FrequencyEntry frequency = frequencies.get(in);
InstanceState state = new InstanceState(serviceDate.getTime(), frequency);
BlockInstance instance = new BlockInstance(block, state);
instances.add(instance);
}
}
use of org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry in project onebusaway-application-modules by camsys.
the class BlockCalendarServiceImpl method getClosestActiveBlocks.
@Override
public List<BlockInstance> getClosestActiveBlocks(AgencyAndId blockId, long time) {
Date timeAsDate = new Date(time);
Min<BlockInstance> m = new Min<BlockInstance>();
BlockEntry blockEntry = _transitGraphDao.getBlockEntryForId(blockId);
for (BlockConfigurationEntry blockConfig : blockEntry.getConfigurations()) {
List<Date> serviceDates = _calendarService.getDatesForServiceIdsAsOrderedList(blockConfig.getServiceIds());
int index = index(Collections.binarySearch(serviceDates, timeAsDate));
if (index > 0) {
BlockInstance instance = new BlockInstance(blockConfig, serviceDates.get(index - 1).getTime());
long delta = getTimeToBlockInstance(instance, time);
m.add(delta, instance);
}
if (index < serviceDates.size()) {
BlockInstance instance = new BlockInstance(blockConfig, serviceDates.get(index).getTime());
long delta = getTimeToBlockInstance(instance, time);
m.add(delta, instance);
}
}
return m.getMinElements();
}
use of org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry in project onebusaway-application-modules by camsys.
the class BlockCalendarServiceImpl method findBlockLayoversInRange.
private void findBlockLayoversInRange(LayoverIntervalBlock intervals, Date serviceDate, Date timeFrom, Date timeTo, List<BlockTripEntry> trips, Collection<BlockInstance> instances) {
int scheduledTimeFrom = (int) ((timeFrom.getTime() - serviceDate.getTime()) / 1000);
int scheduledTimeTo = (int) ((timeTo.getTime() - serviceDate.getTime()) / 1000);
int indexFrom = index(Arrays.binarySearch(intervals.getEndTimes(), scheduledTimeFrom));
int indexTo = index(Arrays.binarySearch(intervals.getStartTimes(), scheduledTimeTo));
InstanceState state = new InstanceState(serviceDate.getTime());
for (int in = indexFrom; in < indexTo; in++) {
BlockTripEntry trip = trips.get(in);
BlockConfigurationEntry block = trip.getBlockConfiguration();
BlockInstance instance = new BlockInstance(block, state);
instances.add(instance);
}
}
use of org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry in project onebusaway-application-modules by camsys.
the class BlockGeospatialServiceImpl method getActiveScheduledBlocksPassingThroughBounds.
@Override
public List<BlockInstance> getActiveScheduledBlocksPassingThroughBounds(CoordinateBounds bounds, long timeFrom, long timeTo) {
List<StopEntry> stops = _transitGraphDao.getStopsByLocation(bounds);
Set<AgencyAndId> blockIds = new HashSet<AgencyAndId>();
for (StopEntry stop : stops) {
List<BlockStopTimeIndex> stopTimeIndices = _blockIndexService.getStopTimeIndicesForStop(stop);
Set<BlockConfigurationEntry> blockConfigs = new HashSet<BlockConfigurationEntry>();
List<List<BlockConfigurationEntry>> blockConfigsList = MappingLibrary.map(stopTimeIndices, "blockConfigs");
for (List<BlockConfigurationEntry> l : blockConfigsList) {
blockConfigs.addAll(l);
}
List<AgencyAndId> stopBlockIds = MappingLibrary.map(blockConfigs, "block.id");
blockIds.addAll(stopBlockIds);
}
Set<BlockTripIndex> blockIndices = new HashSet<BlockTripIndex>();
for (AgencyAndId blockId : blockIds) {
blockIndices.addAll(_blockIndexService.getBlockTripIndicesForBlock(blockId));
}
List<BlockLayoverIndex> layoverIndices = Collections.emptyList();
List<FrequencyBlockTripIndex> frequencyIndices = Collections.emptyList();
return _blockCalendarService.getActiveBlocksInTimeRange(blockIndices, layoverIndices, frequencyIndices, timeFrom, timeTo);
}
use of org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry in project onebusaway-application-modules by camsys.
the class BlockLocationServiceImpl method getScheduledBlockLocationForBlockInstance.
private ScheduledBlockLocation getScheduledBlockLocationForBlockInstance(BlockInstance blockInstance, long targetTime) {
BlockConfigurationEntry blockConfig = blockInstance.getBlock();
long serviceDate = blockInstance.getServiceDate();
int scheduledTime = (int) ((targetTime - serviceDate) / 1000);
return _scheduledBlockLocationService.getScheduledBlockLocationFromScheduledTime(blockConfig, scheduledTime);
}
Aggregations