Search in sources :

Example 31 with TripEntryImpl

use of org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl 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 32 with TripEntryImpl

use of org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl 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 33 with TripEntryImpl

use of org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl in project onebusaway-application-modules by camsys.

the class BlockIndexFactoryServiceImplTest method test.

@Test
public void test() {
    BlockIndexFactoryServiceImpl factory = new BlockIndexFactoryServiceImpl();
    StopEntryImpl stopA = stop("a", 47.0, -122.0);
    StopEntryImpl stopB = stop("b", 47.1, -122.1);
    StopEntryImpl stopC = stop("c", 47.2, -122.2);
    /**
     **
     * Block A
     ***
     */
    BlockEntryImpl blockA = block("a");
    // 1
    TripEntryImpl tripA1 = trip("a1", "s1");
    TripEntryImpl tripA2 = trip("a2", "s1");
    TripEntryImpl tripA3 = trip("a3", "s1");
    stopTime(0, stopA, tripA1, 0, 10, 0);
    stopTime(0, stopB, tripA1, 20, 20, 0);
    stopTime(0, stopC, tripA2, 30, 30, 0);
    stopTime(0, stopA, tripA2, 40, 40, 0);
    stopTime(0, stopA, tripA3, 50, 50, 0);
    stopTime(0, stopB, tripA3, 60, 70, 0);
    linkBlockTrips(blockA, tripA1, tripA2, tripA3);
    /**
     **
     * Block B - Same trip/stop sequence as A
     ***
     */
    BlockEntryImpl blockB = block("b");
    TripEntryImpl tripB1 = trip("b1", "s1");
    TripEntryImpl tripB2 = trip("b2", "s1");
    TripEntryImpl tripB3 = trip("b3", "s1");
    stopTime(0, stopA, tripB1, 20, 30, 0);
    stopTime(0, stopB, tripB1, 50, 50, 0);
    stopTime(0, stopC, tripB2, 60, 60, 0);
    stopTime(0, stopA, tripB2, 70, 70, 0);
    stopTime(0, stopA, tripB3, 80, 80, 0);
    stopTime(0, stopB, tripB3, 90, 100, 0);
    linkBlockTrips(blockB, tripB1, tripB2, tripB3);
    /**
     **
     * Block C - Same stop sequence, but runs a little bit faster
     ***
     */
    BlockEntryImpl blockC = block("c");
    TripEntryImpl tripC1 = trip("c1", "s1");
    TripEntryImpl tripC2 = trip("c2", "s1");
    TripEntryImpl tripC3 = trip("c3", "s1");
    stopTime(0, stopA, tripC1, 40, 50, 0);
    stopTime(0, stopB, tripC1, 60, 60, 0);
    stopTime(0, stopC, tripC2, 70, 70, 0);
    stopTime(0, stopA, tripC2, 80, 80, 0);
    stopTime(0, stopA, tripC3, 85, 85, 0);
    stopTime(0, stopB, tripC3, 90, 95, 0);
    linkBlockTrips(blockC, tripC1, tripC2, tripC3);
    /**
     **
     * Block D - Same stop sequence, but with different service id
     ***
     */
    BlockEntryImpl blockD = block("d");
    TripEntryImpl tripD1 = trip("d1", "s1");
    TripEntryImpl tripD2 = trip("d2", "s1");
    TripEntryImpl tripD3 = trip("d3", "s2");
    stopTime(0, stopA, tripD1, 40, 50, 0);
    stopTime(0, stopB, tripD1, 70, 70, 0);
    stopTime(0, stopC, tripD2, 80, 80, 0);
    stopTime(0, stopA, tripD2, 90, 90, 0);
    stopTime(0, stopA, tripD3, 100, 100, 0);
    stopTime(0, stopB, tripD3, 110, 120, 0);
    linkBlockTrips(blockD, tripD1, tripD2, tripD3);
    /**
     **
     * Block E - One less stop
     ***
     */
    BlockEntryImpl blockE = block("e");
    TripEntryImpl tripE1 = trip("e1", "s1");
    TripEntryImpl tripE2 = trip("e2", "s1");
    TripEntryImpl tripE3 = trip("e3", "s1");
    stopTime(0, stopA, tripE1, 50, 60, 0);
    stopTime(0, stopB, tripE1, 80, 80, 0);
    stopTime(0, stopC, tripE2, 90, 90, 0);
    stopTime(0, stopA, tripE2, 100, 100, 0);
    stopTime(0, stopA, tripE3, 110, 110, 0);
    linkBlockTrips(blockE, tripE1, tripE2, tripE3);
    /**
     **
     * Block F - Another to group with E, but earlier
     ***
     */
    BlockEntryImpl blockF = block("f");
    TripEntryImpl tripF1 = trip("f1", "s1");
    TripEntryImpl tripF2 = trip("f2", "s1");
    TripEntryImpl tripF3 = trip("f3", "s1");
    stopTime(0, stopA, tripF1, 40, 50, 0);
    stopTime(0, stopB, tripF1, 70, 70, 0);
    stopTime(0, stopC, tripF2, 80, 80, 0);
    stopTime(0, stopA, tripF2, 90, 90, 0);
    stopTime(0, stopA, tripF3, 100, 100, 0);
    linkBlockTrips(blockF, tripF1, tripF2, tripF3);
    List<BlockTripIndex> allIndices = factory.createTripIndices(Arrays.asList((BlockEntry) blockF, blockE, blockD, blockC, blockB, blockA));
    assertEquals(6, allIndices.size());
    List<BlockTripIndex> indices = grep(allIndices, aid("a1"));
    assertEquals(1, indices.size());
    BlockTripIndex index = indices.get(0);
    List<TripEntry> trips = trips(index.getTrips());
    assertEquals(5, trips.size());
    assertEquals(tripA1, trips.get(0));
    assertEquals(tripB1, trips.get(1));
    assertEquals(tripF1, trips.get(2));
    assertEquals(tripE1, trips.get(3));
    assertEquals(tripB3, trips.get(4));
    ServiceIdActivation serviceIds = index.getServiceIds();
    assertEquals(1, serviceIds.getActiveServiceIds().size());
    assertTrue(serviceIds.getActiveServiceIds().contains(lsid("s1")));
    ServiceIntervalBlock intervalBlock = index.getServiceIntervalBlock();
    assertTrue(Arrays.equals(new int[] { 0, 20, 40, 50, 80 }, intervalBlock.getMinArrivals()));
    assertTrue(Arrays.equals(new int[] { 10, 30, 50, 60, 80 }, intervalBlock.getMinDepartures()));
    assertTrue(Arrays.equals(new int[] { 20, 50, 70, 80, 90 }, intervalBlock.getMaxArrivals()));
    assertTrue(Arrays.equals(new int[] { 20, 50, 70, 80, 100 }, intervalBlock.getMaxDepartures()));
    indices = grep(allIndices, aid("a2"));
    assertEquals(1, indices.size());
    index = indices.get(0);
    trips = trips(index.getTrips());
    assertEquals(5, trips.size());
    assertEquals(tripA2, trips.get(0));
    assertEquals(tripB2, trips.get(1));
    assertEquals(tripC2, trips.get(2));
    assertEquals(tripF2, trips.get(3));
    assertEquals(tripE2, trips.get(4));
    serviceIds = index.getServiceIds();
    assertEquals(1, serviceIds.getActiveServiceIds().size());
    assertTrue(serviceIds.getActiveServiceIds().contains(lsid("s1")));
    intervalBlock = index.getServiceIntervalBlock();
    assertTrue(Arrays.equals(new int[] { 30, 60, 70, 80, 90 }, intervalBlock.getMinArrivals()));
    assertTrue(Arrays.equals(new int[] { 30, 60, 70, 80, 90 }, intervalBlock.getMinDepartures()));
    assertTrue(Arrays.equals(new int[] { 40, 70, 80, 90, 100 }, intervalBlock.getMaxArrivals()));
    assertTrue(Arrays.equals(new int[] { 40, 70, 80, 90, 100 }, intervalBlock.getMaxDepartures()));
    indices = grep(allIndices, aid("c1"));
    assertEquals(1, indices.size());
    index = indices.get(0);
    trips = trips(index.getTrips());
    assertEquals(3, trips.size());
    assertEquals(tripC1, trips.get(0));
    assertEquals(tripA3, trips.get(1));
    assertEquals(tripC3, trips.get(2));
    serviceIds = index.getServiceIds();
    assertEquals(1, serviceIds.getActiveServiceIds().size());
    assertTrue(serviceIds.getActiveServiceIds().contains(lsid("s1")));
    intervalBlock = index.getServiceIntervalBlock();
    assertTrue(Arrays.equals(new int[] { 40, 50, 85 }, intervalBlock.getMinArrivals()));
    assertTrue(Arrays.equals(new int[] { 50, 50, 85 }, intervalBlock.getMinDepartures()));
    assertTrue(Arrays.equals(new int[] { 60, 60, 90 }, intervalBlock.getMaxArrivals()));
    assertTrue(Arrays.equals(new int[] { 60, 70, 95 }, intervalBlock.getMaxDepartures()));
    indices = grep(allIndices, aid("d1"));
    assertEquals(1, indices.size());
    index = indices.get(0);
    trips = trips(index.getTrips());
    assertEquals(2, trips.size());
    assertEquals(tripD1, trips.get(0));
    assertEquals(tripD3, trips.get(1));
    serviceIds = index.getServiceIds();
    assertEquals(2, serviceIds.getActiveServiceIds().size());
    assertTrue(serviceIds.getActiveServiceIds().contains(lsid("s1")));
    assertTrue(serviceIds.getActiveServiceIds().contains(lsid("s2")));
    intervalBlock = index.getServiceIntervalBlock();
    assertTrue(Arrays.equals(new int[] { 40, 100 }, intervalBlock.getMinArrivals()));
    assertTrue(Arrays.equals(new int[] { 50, 100 }, intervalBlock.getMinDepartures()));
    assertTrue(Arrays.equals(new int[] { 70, 110 }, intervalBlock.getMaxArrivals()));
    assertTrue(Arrays.equals(new int[] { 70, 120 }, intervalBlock.getMaxDepartures()));
    indices = grep(allIndices, aid("d2"));
    assertEquals(1, indices.size());
    index = indices.get(0);
    trips = trips(index.getTrips());
    assertEquals(1, trips.size());
    assertEquals(tripD2, trips.get(0));
    serviceIds = index.getServiceIds();
    assertEquals(2, serviceIds.getActiveServiceIds().size());
    assertTrue(serviceIds.getActiveServiceIds().contains(lsid("s1")));
    assertTrue(serviceIds.getActiveServiceIds().contains(lsid("s2")));
    intervalBlock = index.getServiceIntervalBlock();
    assertTrue(Arrays.equals(new int[] { 80 }, intervalBlock.getMinArrivals()));
    assertTrue(Arrays.equals(new int[] { 80 }, intervalBlock.getMinDepartures()));
    assertTrue(Arrays.equals(new int[] { 90 }, intervalBlock.getMaxArrivals()));
    assertTrue(Arrays.equals(new int[] { 90 }, intervalBlock.getMaxDepartures()));
    indices = grep(allIndices, aid("e3"));
    assertEquals(1, indices.size());
    index = indices.get(0);
    trips = trips(index.getTrips());
    assertEquals(2, trips.size());
    assertEquals(tripF3, trips.get(0));
    assertEquals(tripE3, trips.get(1));
    serviceIds = index.getServiceIds();
    assertEquals(1, serviceIds.getActiveServiceIds().size());
    assertTrue(serviceIds.getActiveServiceIds().contains(lsid("s1")));
    intervalBlock = index.getServiceIntervalBlock();
    assertTrue(Arrays.equals(new int[] { 100, 110 }, intervalBlock.getMinArrivals()));
    assertTrue(Arrays.equals(new int[] { 100, 110 }, intervalBlock.getMinDepartures()));
    assertTrue(Arrays.equals(new int[] { 100, 110 }, intervalBlock.getMaxArrivals()));
    assertTrue(Arrays.equals(new int[] { 100, 110 }, intervalBlock.getMaxDepartures()));
    /**
     **
     * Test Layover Indices
     ***
     */
    List<BlockLayoverIndex> allLayoverIndices = factory.createLayoverIndices(Arrays.asList((BlockEntry) blockF, blockE, blockD, blockC, blockB, blockA));
    List<BlockLayoverIndex> layoverIndices = grep(allLayoverIndices, aid("a2"));
    assertEquals(1, layoverIndices.size());
    BlockLayoverIndex layoverIndiex = layoverIndices.get(0);
    trips = trips(layoverIndiex.getTrips());
    assertEquals(5, trips.size());
    assertEquals(tripA2, trips.get(0));
    assertEquals(tripB2, trips.get(1));
    assertEquals(tripC2, trips.get(2));
    assertEquals(tripF2, trips.get(3));
    assertEquals(tripE2, trips.get(4));
    serviceIds = layoverIndiex.getServiceIds();
    assertEquals(1, serviceIds.getActiveServiceIds().size());
    assertTrue(serviceIds.getActiveServiceIds().contains(lsid("s1")));
    LayoverIntervalBlock layoverIntervalBlock = layoverIndiex.getLayoverIntervalBlock();
    assertTrue(Arrays.equals(new int[] { 20, 50, 60, 70, 80 }, layoverIntervalBlock.getStartTimes()));
    assertTrue(Arrays.equals(new int[] { 30, 60, 70, 80, 90 }, layoverIntervalBlock.getEndTimes()));
    layoverIndices = grep(allLayoverIndices, aid("a3"));
    assertEquals(1, layoverIndices.size());
    layoverIndiex = layoverIndices.get(0);
    trips = trips(layoverIndiex.getTrips());
    assertEquals(5, trips.size());
    assertEquals(tripA3, trips.get(0));
    assertEquals(tripB3, trips.get(1));
    assertEquals(tripC3, trips.get(2));
    assertEquals(tripF3, trips.get(3));
    assertEquals(tripE3, trips.get(4));
    serviceIds = layoverIndiex.getServiceIds();
    assertEquals(1, serviceIds.getActiveServiceIds().size());
    assertTrue(serviceIds.getActiveServiceIds().contains(lsid("s1")));
    layoverIntervalBlock = layoverIndiex.getLayoverIntervalBlock();
    assertTrue(Arrays.equals(new int[] { 40, 70, 80, 90, 100 }, layoverIntervalBlock.getStartTimes()));
    assertTrue(Arrays.equals(new int[] { 50, 80, 85, 100, 110 }, layoverIntervalBlock.getEndTimes()));
    layoverIndices = grep(allLayoverIndices, aid("d2"));
    assertEquals(1, layoverIndices.size());
    layoverIndiex = layoverIndices.get(0);
    trips = trips(layoverIndiex.getTrips());
    assertEquals(1, trips.size());
    assertEquals(tripD2, trips.get(0));
    serviceIds = layoverIndiex.getServiceIds();
    assertEquals(2, serviceIds.getActiveServiceIds().size());
    assertTrue(serviceIds.getActiveServiceIds().contains(lsid("s1")));
    assertTrue(serviceIds.getActiveServiceIds().contains(lsid("s2")));
    layoverIntervalBlock = layoverIndiex.getLayoverIntervalBlock();
    assertTrue(Arrays.equals(new int[] { 70 }, layoverIntervalBlock.getStartTimes()));
    assertTrue(Arrays.equals(new int[] { 80 }, layoverIntervalBlock.getEndTimes()));
    layoverIndices = grep(allLayoverIndices, aid("d3"));
    assertEquals(1, layoverIndices.size());
    layoverIndiex = layoverIndices.get(0);
    trips = trips(layoverIndiex.getTrips());
    assertEquals(1, trips.size());
    assertEquals(tripD3, trips.get(0));
    serviceIds = layoverIndiex.getServiceIds();
    assertEquals(2, serviceIds.getActiveServiceIds().size());
    assertTrue(serviceIds.getActiveServiceIds().contains(lsid("s1")));
    assertTrue(serviceIds.getActiveServiceIds().contains(lsid("s2")));
    layoverIntervalBlock = layoverIndiex.getLayoverIntervalBlock();
    assertTrue(Arrays.equals(new int[] { 90 }, layoverIntervalBlock.getStartTimes()));
    assertTrue(Arrays.equals(new int[] { 100 }, layoverIntervalBlock.getEndTimes()));
}
Also used : ServiceIntervalBlock(org.onebusaway.transit_data_federation.services.blocks.ServiceIntervalBlock) FrequencyServiceIntervalBlock(org.onebusaway.transit_data_federation.services.blocks.FrequencyServiceIntervalBlock) LayoverIntervalBlock(org.onebusaway.transit_data_federation.services.blocks.LayoverIntervalBlock) 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) BlockLayoverIndex(org.onebusaway.transit_data_federation.services.blocks.BlockLayoverIndex) 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) BlockTripIndex(org.onebusaway.transit_data_federation.services.blocks.BlockTripIndex) FrequencyBlockTripIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockTripIndex) Test(org.junit.Test)

Example 34 with TripEntryImpl

use of org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl in project onebusaway-application-modules by camsys.

the class BlockStopTimeIndicesFactoryTest method testFrequencies.

@Test
public void testFrequencies() {
    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);
    BlockConfigurationEntry bcA = 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);
    BlockConfigurationEntry bcB = linkBlockTrips(blockB, freqsB, tripB);
    BlockStopTimeIndicesFactory factory = new BlockStopTimeIndicesFactory();
    List<FrequencyBlockStopTimeIndex> allIndices = factory.createFrequencyIndices(Arrays.asList((BlockEntry) blockB, blockA));
    assertEquals(2, allIndices.size());
    List<FrequencyBlockStopTimeIndex> indices = grep(allIndices, aid("a"), serviceIds(lsids("s1"), lsids()));
    assertEquals(1, indices.size());
    FrequencyBlockStopTimeIndex index = indices.get(0);
    assertEquals(freqA1, index.getFrequencies().get(0));
    assertEquals(freqB1, index.getFrequencies().get(1));
    assertEquals(freqA2, index.getFrequencies().get(2));
    assertEquals(freqB2, index.getFrequencies().get(3));
    assertEquals(bcA, index.getBlockConfigs().get(0));
    assertEquals(bcB, index.getBlockConfigs().get(1));
    assertEquals(bcA, index.getBlockConfigs().get(2));
    assertEquals(bcB, index.getBlockConfigs().get(3));
}
Also used : BlockEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry) FrequencyBlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockStopTimeIndex) FrequencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry) BlockEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl) StopEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl) Test(org.junit.Test)

Example 35 with TripEntryImpl

use of org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl in project onebusaway-application-modules by camsys.

the class ScheduledBlockLocationServiceImplTest method before.

@Before
public void before() {
    _service = new ScheduledBlockLocationServiceImpl();
    _shapePointService = Mockito.mock(ShapePointService.class);
    _service.setShapePointService(_shapePointService);
    TripEntryImpl tripA = trip("A", "serviceId", 1000.0);
    TripEntryImpl tripB = trip("B", "serviceId", 1000.0);
    tripA.setShapeId(aid("shapeA"));
    tripB.setShapeId(aid("shapeB"));
    ShapePointsFactory m = new ShapePointsFactory();
    m.setShapeId(aid("shapeA"));
    m.addPoint(47.670170374084805, -122.3875880241394);
    m.addPoint(47.66871094987642, -122.38756656646729);
    m.addPoint(47.66862425012441, -122.38610744476318);
    m.addPoint(47.66869649992775, -122.38439083099365);
    m.addPoint(47.664852671516094, -122.3800778388977);
    m.addPoint(47.664467962697906, -122.37945087847474);
    Mockito.when(_shapePointService.getShapePointsForShapeId(aid("shapeA"))).thenReturn(m.create());
    m = new ShapePointsFactory();
    m.setShapeId(aid("shapeB"));
    m.addPoint(47.664467962697906, -122.37945087847474);
    m.addPoint(47.663667674849385, -122.37814664840698);
    m.addPoint(47.663667674849385, -122.37355470657349);
    Mockito.when(_shapePointService.getShapePointsForShapeId(aid("shapeB"))).thenReturn(m.create());
    _stopA = stop("stopA", 47.66868114116101, -122.3870648978625);
    _stopB = stop("stopB", 47.66583195331816, -122.38117664826683);
    _stopC = stop("stopC", 47.663667674849385, -122.37724035677341);
    stopTime(1, _stopA, tripA, time(10, 00), time(10, 00), 200, 1);
    stopTime(2, _stopB, tripA, time(10, 10), time(10, 15), 800, 3);
    stopTime(3, _stopC, tripB, time(10, 20), time(10, 20), 200, 1);
    _blockConfig = linkBlockTrips("blockA", tripA, tripB);
    List<BlockTripEntry> trips = _blockConfig.getTrips();
    _tripA = trips.get(0);
    _tripB = trips.get(1);
    List<BlockStopTimeEntry> stopTimes = _blockConfig.getStopTimes();
    _stopTimeA = stopTimes.get(0);
    _stopTimeB = stopTimes.get(1);
    _stopTimeC = stopTimes.get(2);
}
Also used : ShapePointsFactory(org.onebusaway.transit_data_federation.model.ShapePointsFactory) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) ShapePointService(org.onebusaway.transit_data_federation.services.shapes.ShapePointService) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry) Before(org.junit.Before)

Aggregations

TripEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl)58 Test (org.junit.Test)43 BlockEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl)34 BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)29 StopEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl)22 BlockInstance (org.onebusaway.transit_data_federation.services.blocks.BlockInstance)20 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)14 StopTimeEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.StopTimeEntryImpl)14 Trip (org.onebusaway.gtfs.model.Trip)10 VehicleLocationRecord (org.onebusaway.realtime.api.VehicleLocationRecord)10 TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)10 TripUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate)9 ArrayList (java.util.ArrayList)9 ShapePoints (org.onebusaway.transit_data_federation.model.ShapePoints)8 ShapePointsFactory (org.onebusaway.transit_data_federation.model.ShapePointsFactory)8 StopTimeUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeUpdate)7 ServiceIdActivation (org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation)7 Route (org.onebusaway.gtfs.model.Route)6 Stop (org.onebusaway.gtfs.model.Stop)6 StopTime (org.onebusaway.gtfs.model.StopTime)6