use of org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry in project onebusaway-application-modules by camsys.
the class ScheduledBlockLocationServiceImpl method getScheduledBlockLocationFromScheduledTime.
@Override
public ScheduledBlockLocation getScheduledBlockLocationFromScheduledTime(ScheduledBlockLocation previousLocation, int scheduleTime) {
if (previousLocation.getScheduledTime() > scheduleTime)
throw new IllegalStateException("previousLocation's scheduledTime must be before the requested scheduleTime");
BlockTripEntry trip = previousLocation.getActiveTrip();
BlockConfigurationEntry blockConfig = trip.getBlockConfiguration();
List<BlockStopTimeEntry> stopTimes = blockConfig.getStopTimes();
int index = previousLocation.getStopTimeIndex();
while (index < stopTimes.size()) {
int t = blockConfig.getDepartureTimeForIndex(index);
if (scheduleTime <= t)
break;
index++;
}
return getScheduledBlockLocationFromScheduleTimeAndStopTimeIndex(stopTimes, scheduleTime, index);
}
use of org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry in project onebusaway-application-modules by camsys.
the class BlockIndexFactoryServiceImpl method ensureFrequencyTripGroups.
private List<FrequencyTripGroup> ensureFrequencyTripGroups(List<BlockTripEntry> tripsWithSameSequence) {
List<BlockTripWithFrequency> btwfs = new ArrayList<BlockTripWithFrequency>();
for (BlockTripEntry trip : tripsWithSameSequence) {
BlockConfigurationEntry blockConfig = trip.getBlockConfiguration();
for (FrequencyEntry frequency : blockConfig.getFrequencies()) btwfs.add(new BlockTripWithFrequency(trip, frequency));
}
Collections.sort(btwfs);
List<FrequencyTripGroup> lists = new ArrayList<FrequencyTripGroup>();
for (BlockTripWithFrequency btwf : btwfs) {
FrequencyTripGroup group = getBestFrequencyTripGroup(lists, btwf);
if (group == null) {
group = new FrequencyTripGroup();
lists.add(group);
}
group.addEntry(btwf);
}
return lists;
}
use of org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry in project onebusaway-application-modules by camsys.
the class BlockIndexFactoryServiceImpl method createSequenceIndices.
public List<BlockSequenceIndex> createSequenceIndices(Iterable<BlockEntry> blocks) {
List<BlockSequenceIndex> allIndices = new ArrayList<BlockSequenceIndex>();
Map<BlockSequenceKey, List<BlockSequence>> blockSequencesByKey = new FactoryMap<BlockSequenceKey, List<BlockSequence>>(new ArrayList<BlockSequence>());
if (_verbose)
_log.info("grouping block trips into sequence indices");
int sequenceCount = 0;
int blockTripCount = 0;
for (BlockEntry block : blocks) {
if (block.getConfigurations().isEmpty()) {
_log.warn("block has no active configurations: " + block.getId());
continue;
}
if (BlockLibrary.isFrequencyBased(block))
continue;
for (BlockConfigurationEntry blockConfiguration : block.getConfigurations()) {
blockTripCount += blockConfiguration.getTrips().size();
List<BlockSequence> sequences = groupTrips(blockConfiguration);
for (BlockSequence sequence : sequences) {
BlockSequenceKey key = getBlockSequenceAsSequenceKey(sequence);
blockSequencesByKey.get(key).add(sequence);
sequenceCount++;
}
}
}
if (_verbose)
_log.info("groups found: " + blockSequencesByKey.size() + " out of sequences: " + sequenceCount + " and trips: " + blockTripCount);
for (List<BlockSequence> sequences : blockSequencesByKey.values()) {
List<List<BlockSequence>> groupedBlocks = BlockLibrary.createStrictlyOrderedGroups(sequences, _blockSequenceLooseComparator, _blockSequenceStrictComparator);
for (List<BlockSequence> group : groupedBlocks) {
BlockSequenceIndex index = createSequenceIndexForGroupOfBlockSequences(group);
allIndices.add(index);
}
}
return allIndices;
}
use of org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry in project onebusaway-application-modules by camsys.
the class BlockStatusServiceImpl method getBlockInstances.
/**
**
* Private Methods
***
*/
private List<BlockInstance> getBlockInstances(AgencyAndId blockId, long serviceDate, long time) {
if (serviceDate != 0) {
BlockInstance blockInstance = _blockCalendarService.getBlockInstance(blockId, serviceDate);
if (blockInstance == null)
return Collections.emptyList();
BlockConfigurationEntry blockConfig = blockInstance.getBlock();
if (blockConfig.getFrequencies() == null)
return Arrays.asList(blockInstance);
List<BlockInstance> instances = new ArrayList<BlockInstance>();
for (FrequencyEntry frequency : blockConfig.getFrequencies()) instances.add(new BlockInstance(blockConfig, blockInstance.getServiceDate(), frequency));
return instances;
} else {
List<BlockInstance> instances = _blockCalendarService.getActiveBlocks(blockId, time, time);
if (instances.isEmpty()) {
instances = _blockCalendarService.getClosestActiveBlocks(blockId, time);
}
return instances;
}
}
use of org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry 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);
}
Aggregations