use of org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockTripIndex in project onebusaway-application-modules by camsys.
the class BlockIndexFactoryServiceImpl method createFrequencyTripData.
public List<FrequencyBlockTripIndexData> createFrequencyTripData(Iterable<BlockEntry> blocks) {
List<FrequencyBlockTripIndex> indices = createFrequencyTripIndices(blocks);
List<FrequencyBlockTripIndexData> allData = new ArrayList<FrequencyBlockTripIndexData>();
for (FrequencyBlockTripIndex index : indices) {
List<BlockTripReference> tripReferences = new ArrayList<BlockTripReference>();
for (BlockTripEntry entry : index.getTrips()) {
BlockTripReference reference = ReferencesLibrary.getTripAsReference(entry);
tripReferences.add(reference);
}
FrequencyServiceIntervalBlock serviceIntervalBlock = index.getServiceIntervalBlock();
FrequencyBlockTripIndexData data = new FrequencyBlockTripIndexData(tripReferences, index.getFrequencies(), serviceIntervalBlock);
allData.add(data);
}
return allData;
}
use of org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockTripIndex in project onebusaway-application-modules by camsys.
the class BlockCalendarServiceImplTest method testGetActiveBlocksInTimeRange.
@Test
public void testGetActiveBlocksInTimeRange() {
Date serviceDateA = UnitTestingSupport.date("2010-09-07 00:00");
Date serviceDateB = UnitTestingSupport.date("2010-09-08 00:00");
Date serviceDateC = UnitTestingSupport.date("2010-09-09 00:00");
UnitTestingSupport.addDates(_calendarData, "sidA", serviceDateA, serviceDateB);
UnitTestingSupport.addDates(_calendarData, "sidB", serviceDateB, serviceDateC);
ServiceIdActivation ids_A_not_B = serviceIds(lsids("sidA"), lsids("sidB"));
ServiceIdActivation ids_B_not_A = serviceIds(lsids("sidB"), lsids("sidA"));
ServiceIdActivation ids_A_and_B = serviceIds(lsids("sidA", "sidB"), lsids());
StopEntryImpl stopA = stop("stopA", 0.0, 0.0);
StopEntryImpl stopB = stop("stopB", 0.0, 0.0);
BlockEntryImpl blockA = block("blockA");
TripEntryImpl tripA = trip("tripA", "sidA");
TripEntryImpl tripB = trip("tripB", "sidB");
stopTime(0, stopA, tripA, time(9, 00), time(9, 00), 0);
stopTime(1, stopB, tripA, time(9, 30), time(9, 30), 100);
stopTime(2, stopB, tripB, time(10, 00), time(10, 00), 200);
stopTime(3, stopA, tripB, time(10, 30), time(10, 30), 300);
linkBlockTrips(ids_A_not_B, blockA, tripA);
linkBlockTrips(ids_A_and_B, blockA, tripA, tripB);
linkBlockTrips(ids_B_not_A, blockA, tripB);
BlockConfigurationEntry bcA_A_B = findBlockConfig(blockA, ids_A_not_B);
BlockConfigurationEntry bcA_B_A = findBlockConfig(blockA, ids_B_not_A);
BlockConfigurationEntry bcA_AB = findBlockConfig(blockA, ids_A_and_B);
BlockEntryImpl blockB = block("blockB");
TripEntryImpl tripC = trip("tripC", "sidA");
TripEntryImpl tripD = trip("tripD", "sidB");
TripEntryImpl tripE = trip("tripE", "sidA");
stopTime(4, stopA, tripC, time(10, 00), time(10, 00), 0);
stopTime(5, stopB, tripC, time(10, 30), time(10, 30), 0);
stopTime(6, stopB, tripD, time(11, 00), time(11, 00), 0);
stopTime(7, stopA, tripD, time(11, 30), time(11, 30), 0);
stopTime(8, stopA, tripE, time(12, 00), time(12, 00), 0);
stopTime(9, stopB, tripE, time(12, 30), time(12, 30), 0);
linkBlockTrips(ids_A_not_B, blockB, tripC, tripE);
linkBlockTrips(ids_A_and_B, blockB, tripC, tripD, tripE);
linkBlockTrips(ids_B_not_A, blockB, tripD);
BlockConfigurationEntry bcB_A_B = findBlockConfig(blockB, ids_A_not_B);
BlockConfigurationEntry bcB_B_A = findBlockConfig(blockB, ids_B_not_A);
BlockConfigurationEntry bcB_AB = findBlockConfig(blockB, ids_A_and_B);
List<BlockTripIndex> blocks = blockTripIndices(blockA, blockB);
List<BlockLayoverIndex> layoverIndices = Collections.emptyList();
List<FrequencyBlockTripIndex> frequencyIndices = Collections.emptyList();
/**
**
*
***
*/
long time = timeFromString("2010-09-07 09:15");
List<BlockInstance> instances = _service.getActiveBlocksInTimeRange(blocks, layoverIndices, frequencyIndices, time, time);
assertEquals(1, instances.size());
BlockInstance instance = instances.get(0);
assertEquals(bcA_A_B, instance.getBlock());
assertEquals(serviceDateA.getTime(), instance.getServiceDate());
/**
**
*
***
*/
time = timeFromString("2010-09-07 010:15");
instances = _service.getActiveBlocksInTimeRange(blocks, layoverIndices, frequencyIndices, time, time);
assertEquals(1, instances.size());
instance = instances.get(0);
assertEquals(bcB_A_B, instance.getBlock());
assertEquals(serviceDateA.getTime(), instance.getServiceDate());
/**
**
*
***
*/
/*
* time = timeFromString("2010-09-07 011:15");
*
* instances = _service.getActiveBlocksInTimeRange(blocks, frequencyIndices,
* time, time);
*
* assertEquals(1, instances.size());
*
* instance = instances.get(0); assertEquals(bcB_A_B, instance.getBlock());
* assertEquals(serviceDateA.getTime(), instance.getServiceDate());
*/
/**
**
*
***
*/
time = timeFromString("2010-09-07 012:15");
instances = _service.getActiveBlocksInTimeRange(blocks, layoverIndices, frequencyIndices, time, time);
assertEquals(1, instances.size());
instance = instances.get(0);
assertEquals(bcB_A_B, instance.getBlock());
assertEquals(serviceDateA.getTime(), instance.getServiceDate());
/**
**
*
***
*/
time = timeFromString("2010-09-08 09:15");
instances = _service.getActiveBlocksInTimeRange(blocks, layoverIndices, frequencyIndices, time, time);
assertEquals(1, instances.size());
instance = instances.get(0);
assertEquals(bcA_AB, instance.getBlock());
assertEquals(serviceDateB.getTime(), instance.getServiceDate());
/**
**
*
***
*/
time = timeFromString("2010-09-08 10:15");
instances = _service.getActiveBlocksInTimeRange(blocks, layoverIndices, frequencyIndices, time, time);
Collections.sort(instances, new BlockInstanceComparator());
assertEquals(2, instances.size());
instance = instances.get(0);
assertEquals(bcA_AB, instance.getBlock());
assertEquals(serviceDateB.getTime(), instance.getServiceDate());
instance = instances.get(1);
assertEquals(bcB_AB, instance.getBlock());
assertEquals(serviceDateB.getTime(), instance.getServiceDate());
/**
**
*
***
*/
time = timeFromString("2010-09-08 11:15");
instances = _service.getActiveBlocksInTimeRange(blocks, layoverIndices, frequencyIndices, time, time);
assertEquals(1, instances.size());
instance = instances.get(0);
assertEquals(bcB_AB, instance.getBlock());
assertEquals(serviceDateB.getTime(), instance.getServiceDate());
/**
**
*
***
*/
time = timeFromString("2010-09-08 12:15");
instances = _service.getActiveBlocksInTimeRange(blocks, layoverIndices, frequencyIndices, time, time);
assertEquals(1, instances.size());
instance = instances.get(0);
assertEquals(bcB_AB, instance.getBlock());
assertEquals(serviceDateB.getTime(), instance.getServiceDate());
/**
**
*
***
*/
time = timeFromString("2010-09-09 09:15");
instances = _service.getActiveBlocksInTimeRange(blocks, layoverIndices, frequencyIndices, time, time);
assertEquals(0, instances.size());
/**
**
*
***
*/
time = timeFromString("2010-09-09 10:15");
instances = _service.getActiveBlocksInTimeRange(blocks, layoverIndices, frequencyIndices, time, time);
assertEquals(1, instances.size());
instance = instances.get(0);
assertEquals(bcA_B_A, instance.getBlock());
assertEquals(serviceDateC.getTime(), instance.getServiceDate());
/**
**
*
***
*/
time = timeFromString("2010-09-09 11:15");
instances = _service.getActiveBlocksInTimeRange(blocks, layoverIndices, frequencyIndices, time, time);
assertEquals(1, instances.size());
instance = instances.get(0);
assertEquals(bcB_B_A, instance.getBlock());
assertEquals(serviceDateC.getTime(), instance.getServiceDate());
}
use of org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockTripIndex in project onebusaway-application-modules by camsys.
the class BlockIndexFactoryServiceImplTest method testFrequencies.
@Test
public void testFrequencies() {
BlockIndexFactoryServiceImpl factory = new BlockIndexFactoryServiceImpl();
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);
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);
linkBlockTrips(blockB, freqsB, tripB);
List<FrequencyBlockTripIndex> allIndices = factory.createFrequencyTripIndices(Arrays.asList((BlockEntry) blockB, blockA));
assertEquals(1, allIndices.size());
List<FrequencyBlockTripIndex> indices = grep(allIndices, aid("a"));
assertEquals(1, indices.size());
FrequencyBlockTripIndex index = indices.get(0);
List<TripEntry> trips = trips(index.getTrips());
assertEquals(4, trips.size());
assertEquals(tripA, trips.get(0));
assertEquals(tripB, trips.get(1));
assertEquals(tripA, trips.get(2));
assertEquals(tripB, trips.get(3));
List<FrequencyEntry> freqs = index.getFrequencies();
assertEquals(Arrays.asList(freqA1, freqB1, freqA2, freqB2), freqs);
ServiceIdActivation serviceIds = index.getServiceIds();
assertEquals(1, serviceIds.getActiveServiceIds().size());
assertTrue(serviceIds.getActiveServiceIds().contains(lsid("s1")));
FrequencyServiceIntervalBlock intervalBlock = index.getServiceIntervalBlock();
assertTrue(Arrays.equals(new int[] { time(6, 0), time(9, 0), time(15, 0), time(18, 0) }, intervalBlock.getStartTimes()));
assertTrue(Arrays.equals(new int[] { time(9, 0), time(15, 0), time(18, 0), time(21, 0) }, intervalBlock.getEndTimes()));
}
use of org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockTripIndex in project onebusaway-application-modules by camsys.
the class BlockIndexFactoryServiceImplTest method testOverlappingFrequencies.
@Test
public void testOverlappingFrequencies() {
BlockIndexFactoryServiceImpl factory = new BlockIndexFactoryServiceImpl();
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);
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(8, 00), time(14, 00), 20, 0);
FrequencyEntry freqB2 = frequency(time(17, 00), time(20, 00), 20, 0);
List<FrequencyEntry> freqsB = Arrays.asList(freqB1, freqB2);
linkBlockTrips(blockB, freqsB, tripB);
List<FrequencyBlockTripIndex> allIndices = factory.createFrequencyTripIndices(Arrays.asList((BlockEntry) blockB, blockA));
assertEquals(2, allIndices.size());
List<FrequencyBlockTripIndex> indices = grep(allIndices, aid("a"));
assertEquals(1, indices.size());
FrequencyBlockTripIndex index = indices.get(0);
List<TripEntry> trips = trips(index.getTrips());
assertEquals(2, trips.size());
assertEquals(tripA, trips.get(0));
assertEquals(tripA, trips.get(1));
List<FrequencyEntry> freqs = index.getFrequencies();
assertEquals(Arrays.asList(freqA1, freqA2), freqs);
ServiceIdActivation serviceIds = index.getServiceIds();
assertEquals(1, serviceIds.getActiveServiceIds().size());
assertTrue(serviceIds.getActiveServiceIds().contains(lsid("s1")));
FrequencyServiceIntervalBlock intervalBlock = index.getServiceIntervalBlock();
assertTrue(Arrays.equals(new int[] { time(6, 0), time(15, 0) }, intervalBlock.getStartTimes()));
assertTrue(Arrays.equals(new int[] { time(9, 0), time(18, 0) }, intervalBlock.getEndTimes()));
/**
**
*
***
*/
indices = grep(allIndices, aid("b"));
assertEquals(1, indices.size());
index = indices.get(0);
trips = trips(index.getTrips());
assertEquals(2, trips.size());
assertEquals(tripB, trips.get(0));
assertEquals(tripB, trips.get(1));
freqs = index.getFrequencies();
assertEquals(Arrays.asList(freqB1, freqB2), freqs);
serviceIds = index.getServiceIds();
assertEquals(1, serviceIds.getActiveServiceIds().size());
assertTrue(serviceIds.getActiveServiceIds().contains(lsid("s1")));
intervalBlock = index.getServiceIntervalBlock();
assertTrue(Arrays.equals(new int[] { time(8, 0), time(17, 0) }, intervalBlock.getStartTimes()));
assertTrue(Arrays.equals(new int[] { time(14, 0), time(20, 0) }, intervalBlock.getEndTimes()));
}
use of org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockTripIndex 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);
}
Aggregations