use of org.onebusaway.transit_data_federation.services.blocks.FrequencyServiceIntervalBlock in project onebusaway-application-modules by camsys.
the class BlockIndexFactoryServiceImpl method getBlockTripsAsFrequencyBlockInterval.
private FrequencyServiceIntervalBlock getBlockTripsAsFrequencyBlockInterval(List<BlockTripEntry> trips, List<FrequencyEntry> frequencies) {
int n = trips.size();
int[] startTimes = new int[n];
int[] endTimes = new int[n];
for (int index = 0; index < n; index++) {
FrequencyEntry freq = frequencies.get(index);
startTimes[index] = freq.getStartTime();
endTimes[index] = freq.getEndTime();
}
return new FrequencyServiceIntervalBlock(startTimes, endTimes);
}
use of org.onebusaway.transit_data_federation.services.blocks.FrequencyServiceIntervalBlock 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.FrequencyServiceIntervalBlock 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.FrequencyServiceIntervalBlock 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.FrequencyServiceIntervalBlock in project onebusaway-application-modules by camsys.
the class BlockCalendarServiceImpl method handleFrequencyBlockIndex.
private Collection<BlockInstance> handleFrequencyBlockIndex(FrequencyBlockTripIndex index, Date timeFrom, Date timeTo, Collection<BlockInstance> instances) {
List<BlockTripEntry> trips = index.getTrips();
List<FrequencyEntry> frequencies = index.getFrequencies();
FrequencyServiceIntervalBlock serviceIntervalBlock = index.getServiceIntervalBlock();
ServiceInterval serviceInterval = serviceIntervalBlock.getRange();
Collection<Date> serviceDates = _calendarService.getServiceDatesWithinRange(index.getServiceIds(), serviceInterval, timeFrom, timeTo);
for (Date serviceDate : serviceDates) {
findFrequencyBlockTripsInRange(serviceIntervalBlock, serviceDate, timeFrom, timeTo, trips, frequencies, instances);
}
return instances;
}
Aggregations