Search in sources :

Example 31 with BlockConfigurationEntry

use of org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry in project onebusaway-application-modules by camsys.

the class BlockCalendarServiceImplTest method linkBlockTrips.

private static void linkBlockTrips(ServiceIdActivation serviceIds, BlockEntryImpl block, TripEntryImpl... trips) {
    List<TripEntry> tripsInBlock = new ArrayList<TripEntry>();
    for (TripEntryImpl trip : trips) tripsInBlock.add(trip);
    Builder builder = BlockConfigurationEntryImpl.builder();
    builder.setBlock(block);
    builder.setTripGapDistances(new double[tripsInBlock.size()]);
    builder.setServiceIds(serviceIds);
    builder.setTrips(tripsInBlock);
    BlockConfigurationEntry config = builder.create();
    List<BlockConfigurationEntry> configs = block.getConfigurations();
    if (configs == null) {
        configs = new ArrayList<BlockConfigurationEntry>();
        block.setConfigurations(configs);
    }
    configs.add(config);
}
Also used : Builder(org.onebusaway.transit_data_federation.impl.transit_graph.BlockConfigurationEntryImpl.Builder) ArrayList(java.util.ArrayList) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl)

Example 32 with BlockConfigurationEntry

use of org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry in project onebusaway-application-modules by camsys.

the class BlockInstanceComparator method compare.

@Override
public int compare(BlockInstance o1, BlockInstance o2) {
    BlockConfigurationEntry bc1 = o1.getBlock();
    BlockConfigurationEntry bc2 = o2.getBlock();
    BlockEntry b1 = bc1.getBlock();
    BlockEntry b2 = bc2.getBlock();
    AgencyAndId bId1 = b1.getId();
    AgencyAndId bId2 = b2.getId();
    int rc = bId1.compareTo(bId2);
    if (rc != 0)
        return rc;
    rc = bc1.getServiceIds().compareTo(bc2.getServiceIds());
    if (rc != 0)
        return rc;
    return Double.compare(o1.getServiceDate(), o2.getServiceDate());
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) BlockEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)

Example 33 with BlockConfigurationEntry

use of org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry in project onebusaway-application-modules by camsys.

the class BlockStopTimeIndicesFactoryTest method test.

@Test
public void test() {
    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);
    BlockConfigurationEntry bcA = 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);
    BlockConfigurationEntry bcB = 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);
    BlockConfigurationEntry bcC = 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);
    BlockConfigurationEntry bcD = 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);
    BlockConfigurationEntry bcE = 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);
    BlockConfigurationEntry bcF = linkBlockTrips(blockF, tripF1, tripF2, tripF3);
    BlockStopTimeIndicesFactory factory = new BlockStopTimeIndicesFactory();
    List<BlockStopTimeIndex> allIndices = factory.createIndices(Arrays.asList((BlockEntry) blockF, blockE, blockD, blockC, blockB, blockA));
    assertEquals(6, allIndices.size());
    List<BlockStopTimeIndex> indices = grep(allIndices, aid("a"), serviceIds(lsids("s1"), lsids()));
    assertEquals(1, indices.size());
    BlockStopTimeIndex index = indices.get(0);
    assertEquals(15, index.getStopTimes().size());
    assertEquals(bcA.getStopTimes().get(0), index.getStopTimes().get(0));
    assertEquals(bcB.getStopTimes().get(0), index.getStopTimes().get(1));
    assertEquals(bcA.getStopTimes().get(3), index.getStopTimes().get(2));
    assertEquals(bcF.getStopTimes().get(0), index.getStopTimes().get(3));
    assertEquals(bcC.getStopTimes().get(0), index.getStopTimes().get(4));
    assertEquals(bcA.getStopTimes().get(4), index.getStopTimes().get(5));
    assertEquals(bcE.getStopTimes().get(0), index.getStopTimes().get(6));
    assertEquals(bcB.getStopTimes().get(3), index.getStopTimes().get(7));
    assertEquals(bcC.getStopTimes().get(3), index.getStopTimes().get(8));
    assertEquals(bcB.getStopTimes().get(4), index.getStopTimes().get(9));
    assertEquals(bcC.getStopTimes().get(4), index.getStopTimes().get(10));
    assertEquals(bcF.getStopTimes().get(3), index.getStopTimes().get(11));
    assertEquals(bcF.getStopTimes().get(4), index.getStopTimes().get(12));
    assertEquals(bcE.getStopTimes().get(3), index.getStopTimes().get(13));
    assertEquals(bcE.getStopTimes().get(4), index.getStopTimes().get(14));
    indices = grep(allIndices, aid("a"), serviceIds(lsids("s1", "s2"), lsids()));
    assertEquals(1, indices.size());
    index = indices.get(0);
    assertEquals(3, index.getStopTimes().size());
    assertEquals(bcD.getStopTimes().get(0), index.getStopTimes().get(0));
    assertEquals(bcD.getStopTimes().get(3), index.getStopTimes().get(1));
    assertEquals(bcD.getStopTimes().get(4), index.getStopTimes().get(2));
    indices = grep(allIndices, aid("b"), serviceIds(lsids("s1"), lsids()));
    assertEquals(1, indices.size());
    index = indices.get(0);
    assertEquals(8, index.getStopTimes().size());
    assertEquals(bcA.getStopTimes().get(1), index.getStopTimes().get(0));
    assertEquals(bcB.getStopTimes().get(1), index.getStopTimes().get(1));
    assertEquals(bcC.getStopTimes().get(1), index.getStopTimes().get(2));
    assertEquals(bcA.getStopTimes().get(5), index.getStopTimes().get(3));
    assertEquals(bcF.getStopTimes().get(1), index.getStopTimes().get(4));
    assertEquals(bcE.getStopTimes().get(1), index.getStopTimes().get(5));
    assertEquals(bcC.getStopTimes().get(5), index.getStopTimes().get(6));
    assertEquals(bcB.getStopTimes().get(5), index.getStopTimes().get(7));
    indices = grep(allIndices, aid("b"), serviceIds(lsids("s1", "s2"), lsids()));
    assertEquals(1, indices.size());
    index = indices.get(0);
    assertEquals(2, index.getStopTimes().size());
    assertEquals(bcD.getStopTimes().get(1), index.getStopTimes().get(0));
    assertEquals(bcD.getStopTimes().get(5), index.getStopTimes().get(1));
    indices = grep(allIndices, aid("c"), serviceIds(lsids("s1"), lsids()));
    assertEquals(1, indices.size());
    index = indices.get(0);
    assertEquals(5, index.getStopTimes().size());
    assertEquals(bcA.getStopTimes().get(2), index.getStopTimes().get(0));
    assertEquals(bcB.getStopTimes().get(2), index.getStopTimes().get(1));
    assertEquals(bcC.getStopTimes().get(2), index.getStopTimes().get(2));
    assertEquals(bcF.getStopTimes().get(2), index.getStopTimes().get(3));
    assertEquals(bcE.getStopTimes().get(2), index.getStopTimes().get(4));
    indices = grep(allIndices, aid("c"), serviceIds(lsids("s1", "s2"), lsids()));
    assertEquals(1, indices.size());
    index = indices.get(0);
    assertEquals(1, index.getStopTimes().size());
    assertEquals(bcD.getStopTimes().get(2), index.getStopTimes().get(0));
}
Also used : BlockEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry) FrequencyBlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockStopTimeIndex) BlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.BlockStopTimeIndex) AbstractBlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.AbstractBlockStopTimeIndex) 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 34 with BlockConfigurationEntry

use of org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry in project onebusaway-application-modules by camsys.

the class BlockLocationRecordCacheImplTest method testSimpleOperations.

@Test
public void testSimpleOperations() {
    long serviceDate = System.currentTimeMillis();
    BlockEntryImpl block = block("blockA");
    TripEntryImpl trip = trip("tripA", "serviceId");
    stopTime(0, null, trip, time(9, 00), 0);
    BlockConfigurationEntry blockConfig = linkBlockTrips(block, trip);
    BlockInstance blockInstance = new BlockInstance(blockConfig, serviceDate);
    BlockLocationRecordCacheImpl cache = new BlockLocationRecordCacheImpl();
    cache.setBlockLocationRecordCacheWindowSize(20);
    List<BlockLocationRecordCollection> records = cache.getRecordsForBlockInstance(blockInstance);
    assertEquals(0, records.size());
    records = cache.getRecordsForVehicleId(aid("vehicleA"));
    assertEquals(0, records.size());
    cache.addRecord(blockInstance, record(20, "blockA", serviceDate, "vehicleA", 10.0));
    records = cache.getRecordsForBlockInstance(blockInstance);
    assertEquals(1, records.size());
    BlockLocationRecordCollection collection = records.get(0);
    assertEquals(20, collection.getFromTime());
    assertEquals(20, collection.getToTime());
    assertEquals(blockInstance, collection.getBlockInstance());
    assertEquals(aid("vehicleA"), collection.getVehicleId());
    records = cache.getRecordsForVehicleId(aid("vehicleA"));
    assertEquals(1, records.size());
    cache.addRecord(blockInstance, record(30, "blockA", serviceDate, "vehicleA", 20.0));
    records = cache.getRecordsForBlockInstance(blockInstance);
    assertEquals(1, records.size());
    collection = records.get(0);
    assertEquals(20, collection.getFromTime());
    assertEquals(30, collection.getToTime());
    assertEquals(blockInstance, collection.getBlockInstance());
    assertEquals(aid("vehicleA"), collection.getVehicleId());
    records = cache.getRecordsForVehicleId(aid("vehicleA"));
    assertEquals(1, records.size());
    cache.addRecord(blockInstance, record(40, "blockA", serviceDate, "vehicleB", 5.0));
    records = cache.getRecordsForBlockInstance(blockInstance);
    assertEquals(2, records.size());
    records = cache.getRecordsForVehicleId(aid("vehicleA"));
    assertEquals(1, records.size());
    collection = records.get(0);
    assertEquals(20, collection.getFromTime());
    assertEquals(30, collection.getToTime());
    assertEquals(blockInstance, collection.getBlockInstance());
    assertEquals(aid("vehicleA"), collection.getVehicleId());
    records = cache.getRecordsForVehicleId(aid("vehicleB"));
    assertEquals(1, records.size());
    collection = records.get(0);
    assertEquals(40, collection.getFromTime());
    assertEquals(40, collection.getToTime());
    assertEquals(blockInstance, collection.getBlockInstance());
    assertEquals(aid("vehicleB"), collection.getVehicleId());
    cache.clearRecordsForVehicleId(aid("vehicleA"));
    records = cache.getRecordsForBlockInstance(blockInstance);
    assertEquals(1, records.size());
    records = cache.getRecordsForVehicleId(aid("vehicleA"));
    assertEquals(0, records.size());
    records = cache.getRecordsForVehicleId(aid("vehicleB"));
    assertEquals(1, records.size());
}
Also used : BlockInstance(org.onebusaway.transit_data_federation.services.blocks.BlockInstance) 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) Test(org.junit.Test)

Example 35 with BlockConfigurationEntry

use of org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry in project onebusaway-application-modules by camsys.

the class BlockLocationRecordCacheImplTest method testClearCache.

@Test
public void testClearCache() throws InterruptedException {
    long serviceDate = System.currentTimeMillis();
    BlockEntryImpl blockA = block("blockA");
    TripEntryImpl tripA = trip("tripA", "serviceId");
    stopTime(0, null, tripA, time(9, 00), 0);
    BlockConfigurationEntry blockConfigA = linkBlockTrips(blockA, tripA);
    BlockInstance instanceA = new BlockInstance(blockConfigA, serviceDate);
    BlockEntryImpl blockB = block("blockB");
    TripEntryImpl tripB = trip("tripB", "serviceId");
    stopTime(0, null, tripB, time(9, 00), 0);
    BlockConfigurationEntry blockConfigB = linkBlockTrips(blockB, tripB);
    BlockInstance instanceB = new BlockInstance(blockConfigB, serviceDate);
    BlockLocationRecordCacheImpl cache = new BlockLocationRecordCacheImpl();
    cache.setBlockLocationRecordCacheWindowSize(20);
    cache.addRecord(instanceA, record(20, "blockA", serviceDate, "vehicleA", 10.0));
    Thread.sleep(100);
    cache.addRecord(instanceB, record(30, "blockB", serviceDate, "vehicleB", 20.0));
    Thread.sleep(100);
    cache.addRecord(instanceA, record(40, "blockA", serviceDate, "vehicleC", 20.0));
    Thread.sleep(100);
    cache.addRecord(instanceB, record(50, "blockB", serviceDate, "vehicleD", 20.0));
    cache.clearStaleRecords(System.currentTimeMillis() - 150);
    List<BlockLocationRecordCollection> records = cache.getRecordsForVehicleId(aid("vehicleA"));
    assertEquals(0, records.size());
    records = cache.getRecordsForVehicleId(aid("vehicleB"));
    assertEquals(0, records.size());
    records = cache.getRecordsForVehicleId(aid("vehicleC"));
    assertEquals(1, records.size());
    records = cache.getRecordsForVehicleId(aid("vehicleD"));
    assertEquals(1, records.size());
    records = cache.getRecordsForBlockInstance(instanceA);
    assertEquals(1, records.size());
    records = cache.getRecordsForBlockInstance(instanceB);
    assertEquals(1, records.size());
}
Also used : BlockInstance(org.onebusaway.transit_data_federation.services.blocks.BlockInstance) 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) Test(org.junit.Test)

Aggregations

BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)89 BlockInstance (org.onebusaway.transit_data_federation.services.blocks.BlockInstance)36 BlockEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl)34 Test (org.junit.Test)30 TripEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl)29 BlockTripEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry)27 ArrayList (java.util.ArrayList)23 BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)23 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)18 VehicleLocationRecord (org.onebusaway.realtime.api.VehicleLocationRecord)17 CoordinatePoint (org.onebusaway.geospatial.model.CoordinatePoint)14 StopTimeInstance (org.onebusaway.transit_data_federation.model.StopTimeInstance)13 BlockEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry)13 Date (java.util.Date)12 List (java.util.List)11 StopEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl)11 TripUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate)10 ScheduledBlockLocation (org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation)10 StopTimeUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeUpdate)8 FactoryMap (org.onebusaway.collections.FactoryMap)8