Search in sources :

Example 1 with FrequencyServiceIntervalBlock

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);
}
Also used : FrequencyServiceIntervalBlock(org.onebusaway.transit_data_federation.services.blocks.FrequencyServiceIntervalBlock) FrequencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry)

Example 2 with FrequencyServiceIntervalBlock

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;
}
Also used : FrequencyBlockTripIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockTripIndex) BlockTripReference(org.onebusaway.transit_data_federation.services.blocks.BlockTripReference) FrequencyServiceIntervalBlock(org.onebusaway.transit_data_federation.services.blocks.FrequencyServiceIntervalBlock) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) ArrayList(java.util.ArrayList) FrequencyBlockTripIndexData(org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockTripIndexData)

Example 3 with FrequencyServiceIntervalBlock

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()));
}
Also used : FrequencyServiceIntervalBlock(org.onebusaway.transit_data_federation.services.blocks.FrequencyServiceIntervalBlock) FrequencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl) StopEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl) FrequencyBlockTripIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockTripIndex) BlockEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry) ServiceIdActivation(org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation) BlockEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl) Test(org.junit.Test)

Example 4 with FrequencyServiceIntervalBlock

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()));
}
Also used : FrequencyServiceIntervalBlock(org.onebusaway.transit_data_federation.services.blocks.FrequencyServiceIntervalBlock) FrequencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl) StopEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl) FrequencyBlockTripIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockTripIndex) BlockEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry) ServiceIdActivation(org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation) BlockEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl) Test(org.junit.Test)

Example 5 with FrequencyServiceIntervalBlock

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;
}
Also used : FrequencyServiceIntervalBlock(org.onebusaway.transit_data_federation.services.blocks.FrequencyServiceIntervalBlock) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) ServiceInterval(org.onebusaway.gtfs.model.calendar.ServiceInterval) FrequencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry) Date(java.util.Date)

Aggregations

FrequencyServiceIntervalBlock (org.onebusaway.transit_data_federation.services.blocks.FrequencyServiceIntervalBlock)5 BlockTripEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry)4 FrequencyEntry (org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry)4 FrequencyBlockTripIndex (org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockTripIndex)3 Test (org.junit.Test)2 BlockEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl)2 StopEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl)2 TripEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl)2 BlockEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry)2 ServiceIdActivation (org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation)2 TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 ServiceInterval (org.onebusaway.gtfs.model.calendar.ServiceInterval)1 BlockTripReference (org.onebusaway.transit_data_federation.services.blocks.BlockTripReference)1 FrequencyBlockTripIndexData (org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockTripIndexData)1