Search in sources :

Example 1 with BlockLayoverIndex

use of org.onebusaway.transit_data_federation.services.blocks.BlockLayoverIndex in project onebusaway-application-modules by camsys.

the class BlockIndexFactoryServiceImpl method createLayoverData.

public List<BlockLayoverIndexData> createLayoverData(Iterable<BlockEntry> blocks) {
    List<BlockLayoverIndex> indices = createLayoverIndices(blocks);
    List<BlockLayoverIndexData> allData = new ArrayList<BlockLayoverIndexData>();
    for (BlockLayoverIndex index : indices) {
        List<BlockTripReference> references = new ArrayList<BlockTripReference>();
        for (BlockTripEntry trip : index.getTrips()) {
            BlockTripReference ref = ReferencesLibrary.getTripAsReference(trip);
            references.add(ref);
        }
        LayoverIntervalBlock layoverIntervalBlock = index.getLayoverIntervalBlock();
        BlockLayoverIndexData data = new BlockLayoverIndexData(references, layoverIntervalBlock);
        allData.add(data);
    }
    return allData;
}
Also used : BlockTripReference(org.onebusaway.transit_data_federation.services.blocks.BlockTripReference) LayoverIntervalBlock(org.onebusaway.transit_data_federation.services.blocks.LayoverIntervalBlock) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) ArrayList(java.util.ArrayList) BlockLayoverIndexData(org.onebusaway.transit_data_federation.services.blocks.BlockLayoverIndexData) BlockLayoverIndex(org.onebusaway.transit_data_federation.services.blocks.BlockLayoverIndex)

Example 2 with BlockLayoverIndex

use of org.onebusaway.transit_data_federation.services.blocks.BlockLayoverIndex 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());
}
Also used : Date(java.util.Date) 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) FrequencyBlockTripIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockTripIndex) BlockInstance(org.onebusaway.transit_data_federation.services.blocks.BlockInstance) ServiceIdActivation(org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation) BlockEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry) BlockTripIndex(org.onebusaway.transit_data_federation.services.blocks.BlockTripIndex) FrequencyBlockTripIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockTripIndex) Test(org.junit.Test)

Example 3 with BlockLayoverIndex

use of org.onebusaway.transit_data_federation.services.blocks.BlockLayoverIndex 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 4 with BlockLayoverIndex

use of org.onebusaway.transit_data_federation.services.blocks.BlockLayoverIndex 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);
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) BlockLayoverIndex(org.onebusaway.transit_data_federation.services.blocks.BlockLayoverIndex) FrequencyBlockTripIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockTripIndex) BlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.BlockStopTimeIndex) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) List(java.util.List) ArrayList(java.util.ArrayList) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry) FrequencyBlockTripIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockTripIndex) BlockTripIndex(org.onebusaway.transit_data_federation.services.blocks.BlockTripIndex) HashSet(java.util.HashSet)

Example 5 with BlockLayoverIndex

use of org.onebusaway.transit_data_federation.services.blocks.BlockLayoverIndex in project onebusaway-application-modules by camsys.

the class BlockIndexFactoryServiceImpl method createLayoverIndices.

public List<BlockLayoverIndex> createLayoverIndices(Iterable<BlockEntry> blocks) {
    List<BlockLayoverIndex> allIndices = new ArrayList<BlockLayoverIndex>();
    int logInterval = LoggingIntervalUtil.getAppropriateLoggingInterval(allIndices.size());
    Map<BlockLayoverSequenceKey, List<BlockTripEntry>> blockTripsByServiceIds = new FactoryMap<BlockLayoverSequenceKey, List<BlockTripEntry>>(new ArrayList<BlockTripEntry>());
    if (_verbose)
        _log.info("grouping block layovers by sequence key");
    int tripCount = 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()) {
            BlockTripEntry prevTrip = null;
            for (BlockTripEntry blockTrip : blockConfiguration.getTrips()) {
                if (prevTrip != null) {
                    BlockLayoverSequenceKey key = getBlockTripAsLayoverSequenceKey(blockTrip);
                    blockTripsByServiceIds.get(key).add(blockTrip);
                    tripCount++;
                }
                prevTrip = blockTrip;
            }
        }
    }
    if (_verbose)
        _log.info("groups found: " + blockTripsByServiceIds.size() + " out of trips: " + tripCount);
    int count = 0;
    for (List<BlockTripEntry> tripsWithSameSequence : blockTripsByServiceIds.values()) {
        if (_verbose && count % logInterval == 0)
            _log.info("groups processed: " + count + "/" + blockTripsByServiceIds.size());
        count++;
        List<List<BlockTripEntry>> groupedBlocks = ensureLayoverGroups(tripsWithSameSequence);
        for (List<BlockTripEntry> group : groupedBlocks) {
            BlockLayoverIndex index = createLayoverIndexForGroupOfBlockTrips(group);
            allIndices.add(index);
        }
    }
    return allIndices;
}
Also used : FactoryMap(org.onebusaway.collections.FactoryMap) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) ArrayList(java.util.ArrayList) BlockLayoverIndex(org.onebusaway.transit_data_federation.services.blocks.BlockLayoverIndex) BlockEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry) ArrayList(java.util.ArrayList) List(java.util.List) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)

Aggregations

BlockLayoverIndex (org.onebusaway.transit_data_federation.services.blocks.BlockLayoverIndex)7 ArrayList (java.util.ArrayList)4 BlockTripIndex (org.onebusaway.transit_data_federation.services.blocks.BlockTripIndex)4 FrequencyBlockTripIndex (org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockTripIndex)4 List (java.util.List)3 BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)3 BlockEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry)3 BlockTripEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry)3 Test (org.junit.Test)2 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)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 BlockLayoverIndexData (org.onebusaway.transit_data_federation.services.blocks.BlockLayoverIndexData)2 LayoverIntervalBlock (org.onebusaway.transit_data_federation.services.blocks.LayoverIntervalBlock)2 ServiceIdActivation (org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation)2 File (java.io.File)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 FactoryMap (org.onebusaway.collections.FactoryMap)1