Search in sources :

Example 21 with BlockEntryImpl

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

the class UnitTestingSupport method block.

public static BlockEntryImpl block(String id) {
    BlockEntryImpl block = new BlockEntryImpl();
    block.setId(aid(id));
    return block;
}
Also used : BlockEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl)

Example 22 with BlockEntryImpl

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

the class BlockEntriesFactory method processBlockTrips.

/**
 * We loop over blocks of trips, removing any trip that has no stop times,
 * sorting the remaining trips into the proper order, setting the 'nextTrip'
 * property for trips in the block, and setting the 'nextStop' property for
 * stops in the block.
 *
 * @return
 */
private void processBlockTrips(TransitGraphImpl graph, Map<AgencyAndId, List<TripEntryImpl>> tripsByBlockId) {
    int blockIndex = 0;
    int logInterval = LoggingIntervalUtil.getAppropriateLoggingInterval(tripsByBlockId.keySet().size());
    for (Map.Entry<AgencyAndId, List<TripEntryImpl>> entry : tripsByBlockId.entrySet()) {
        if (blockIndex % logInterval == 0)
            _log.info("block: " + blockIndex + "/" + tripsByBlockId.size());
        blockIndex++;
        AgencyAndId blockId = entry.getKey();
        List<TripEntryImpl> tripsInBlock = entry.getValue();
        if (tripsInBlock.isEmpty()) {
            _log.warn("no trips for block=" + blockId);
            continue;
        }
        BlockEntryImpl blockEntry = new BlockEntryImpl();
        blockEntry.setId(blockId);
        _blockConfigurationEntriesFactory.processBlockConfigurations(blockEntry, tripsInBlock);
        graph.putBlockEntry(blockEntry);
        // Wire up the trip to block link
        for (TripEntryImpl trip : tripsInBlock) trip.setBlock(blockEntry);
    }
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ArrayList(java.util.ArrayList) List(java.util.List) BlockEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl) Map(java.util.Map) FactoryMap(org.onebusaway.collections.FactoryMap) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl)

Example 23 with BlockEntryImpl

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

the class FrequencyEntriesFactory method applyFrequenciesToBlockTrips.

private void applyFrequenciesToBlockTrips(List<TripEntryImpl> tripsInBlock, Map<AgencyAndId, List<FrequencyEntry>> frequenciesAlongBlockByTripId) {
    BlockEntryImpl blockEntry = tripsInBlock.get(0).getBlock();
    List<BlockConfigurationEntry> configurations = blockEntry.getConfigurations();
    for (int i = 0; i < configurations.size(); i++) {
        BlockConfigurationEntryImpl blockConfig = (BlockConfigurationEntryImpl) configurations.get(i);
        List<FrequencyEntry> frequencies = computeBlockFrequencies(blockEntry, blockConfig.getTrips(), frequenciesAlongBlockByTripId);
        blockConfig.setFrequencies(frequencies);
    }
}
Also used : BlockConfigurationEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.BlockConfigurationEntryImpl) 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)

Example 24 with BlockEntryImpl

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

the class BlockConfigurationEntriesFactoryTest method test.

@Test
public void test() {
    StopEntryImpl stopA = stop("stopA", 47.0, -122.0);
    StopEntryImpl stopB = stop("stopB", 47.1, -122.1);
    TripEntryImpl tripA = trip("tripA", "sA", 300.0);
    StopTimeEntryImpl st0 = stopTime(0, stopA, tripA, time(9, 00), time(9, 05), 100.0);
    StopTimeEntryImpl st1 = stopTime(1, stopB, tripA, time(9, 30), time(9, 35), 200.0);
    TripEntryImpl tripB = trip("tripB", "sA", 300.0);
    StopTimeEntryImpl st2 = stopTime(2, stopA, tripB, time(10, 00), time(10, 05), 100.0);
    StopTimeEntryImpl st3 = stopTime(3, stopB, tripB, time(10, 30), time(10, 35), 200.0);
    TripEntryImpl tripC = trip("tripC", "sB", 300.0);
    StopTimeEntryImpl st4 = stopTime(4, stopA, tripC, time(11, 00), time(11, 05), 100.0);
    StopTimeEntryImpl st5 = stopTime(5, stopB, tripC, time(11, 30), time(11, 35), 200.0);
    TripEntryImpl tripD = trip("tripD", "sB", 300.0);
    StopTimeEntryImpl st6 = stopTime(6, stopA, tripD, time(12, 00), time(12, 05), 100.0);
    StopTimeEntryImpl st7 = stopTime(7, stopB, tripD, time(12, 30), time(12, 35), 200.0);
    /**
     **
     * Actual Test
     ***
     */
    BlockEntryImpl block = new BlockEntryImpl();
    List<TripEntryImpl> tripsInBlock = Arrays.asList(tripA, tripB, tripC, tripD);
    _factory.processBlockConfigurations(block, tripsInBlock);
    List<BlockConfigurationEntry> configurations = block.getConfigurations();
    assertEquals(3, configurations.size());
    /**
     **
     * Order of the configurations matter. See
     * {@link BlockEntry#getConfigurations()} for details.
     ***
     */
    /**
     **
     * Configuration A & B
     ***
     */
    BlockConfigurationEntry entry = configurations.get(0);
    assertSame(block, entry.getBlock());
    assertEquals(serviceIds(lsids("sA", "sB"), lsids()), entry.getServiceIds());
    assertEquals(1200.0, entry.getTotalBlockDistance(), 0.0);
    assertNull(entry.getFrequencies());
    List<BlockTripEntry> trips = entry.getTrips();
    assertEquals(4, trips.size());
    BlockTripEntry trip = trips.get(0);
    assertEquals(0, trip.getAccumulatedStopTimeIndex());
    assertEquals(0, trip.getAccumulatedSlackTime());
    assertEquals(0.0, trip.getDistanceAlongBlock(), 0.0);
    assertSame(tripA, trip.getTrip());
    assertNull(trip.getPreviousTrip());
    assertSame(trips.get(1), trip.getNextTrip());
    trip = trips.get(1);
    assertEquals(2, trip.getAccumulatedStopTimeIndex());
    assertEquals(10 * 60, trip.getAccumulatedSlackTime());
    assertEquals(300.0, trip.getDistanceAlongBlock(), 0.0);
    assertSame(tripB, trip.getTrip());
    assertSame(trips.get(0), trip.getPreviousTrip());
    assertSame(trips.get(2), trip.getNextTrip());
    trip = trips.get(2);
    assertEquals(4, trip.getAccumulatedStopTimeIndex());
    assertEquals(20 * 60, trip.getAccumulatedSlackTime());
    assertEquals(600.0, trip.getDistanceAlongBlock(), 0.0);
    assertSame(tripC, trip.getTrip());
    assertSame(trips.get(1), trip.getPreviousTrip());
    assertSame(trips.get(3), trip.getNextTrip());
    trip = trips.get(3);
    assertEquals(6, trip.getAccumulatedStopTimeIndex());
    assertEquals(30 * 60, trip.getAccumulatedSlackTime());
    assertEquals(900.0, trip.getDistanceAlongBlock(), 0.0);
    assertSame(tripD, trip.getTrip());
    assertSame(trips.get(2), trip.getPreviousTrip());
    assertNull(trip.getNextTrip());
    List<BlockStopTimeEntry> stopTimes = entry.getStopTimes();
    assertEquals(8, stopTimes.size());
    BlockStopTimeEntry bst = stopTimes.get(0);
    assertEquals(0, bst.getAccumulatedSlackTime());
    assertEquals(0, bst.getBlockSequence());
    assertEquals(100.0, bst.getDistanceAlongBlock(), 0.0);
    assertSame(st0, bst.getStopTime());
    assertSame(trips.get(0), bst.getTrip());
    bst = stopTimes.get(1);
    assertEquals(5 * 60, bst.getAccumulatedSlackTime());
    assertEquals(1, bst.getBlockSequence());
    assertEquals(200.0, bst.getDistanceAlongBlock(), 0.0);
    assertSame(st1, bst.getStopTime());
    assertSame(trips.get(0), bst.getTrip());
    bst = stopTimes.get(2);
    assertEquals(10 * 60, bst.getAccumulatedSlackTime());
    assertEquals(2, bst.getBlockSequence());
    assertEquals(400.0, bst.getDistanceAlongBlock(), 0.0);
    assertSame(st2, bst.getStopTime());
    assertSame(trips.get(1), bst.getTrip());
    bst = stopTimes.get(3);
    assertEquals(15 * 60, bst.getAccumulatedSlackTime());
    assertEquals(3, bst.getBlockSequence());
    assertEquals(500.0, bst.getDistanceAlongBlock(), 0.0);
    assertSame(st3, bst.getStopTime());
    assertSame(trips.get(1), bst.getTrip());
    bst = stopTimes.get(4);
    assertEquals(20 * 60, bst.getAccumulatedSlackTime());
    assertEquals(4, bst.getBlockSequence());
    assertEquals(700.0, bst.getDistanceAlongBlock(), 0.0);
    assertSame(st4, bst.getStopTime());
    assertSame(trips.get(2), bst.getTrip());
    bst = stopTimes.get(5);
    assertEquals(25 * 60, bst.getAccumulatedSlackTime());
    assertEquals(5, bst.getBlockSequence());
    assertEquals(800.0, bst.getDistanceAlongBlock(), 0.0);
    assertSame(st5, bst.getStopTime());
    assertSame(trips.get(2), bst.getTrip());
    bst = stopTimes.get(6);
    assertEquals(30 * 60, bst.getAccumulatedSlackTime());
    assertEquals(6, bst.getBlockSequence());
    assertEquals(1000.0, bst.getDistanceAlongBlock(), 0.0);
    assertSame(st6, bst.getStopTime());
    assertSame(trips.get(3), bst.getTrip());
    bst = stopTimes.get(7);
    assertEquals(35 * 60, bst.getAccumulatedSlackTime());
    assertEquals(7, bst.getBlockSequence());
    assertEquals(1100.0, bst.getDistanceAlongBlock(), 0.0);
    assertSame(st7, bst.getStopTime());
    assertSame(trips.get(3), bst.getTrip());
    /**
     **
     * Configuration A
     ***
     */
    entry = configurations.get(1);
    assertSame(block, entry.getBlock());
    assertEquals(serviceIds(lsids("sA"), lsids("sB")), entry.getServiceIds());
    assertEquals(600.0, entry.getTotalBlockDistance(), 0.0);
    assertNull(entry.getFrequencies());
    trips = entry.getTrips();
    assertEquals(2, trips.size());
    trip = trips.get(0);
    assertEquals(0, trip.getAccumulatedStopTimeIndex());
    assertEquals(0, trip.getAccumulatedSlackTime());
    assertEquals(0.0, trip.getDistanceAlongBlock(), 0.0);
    assertSame(tripA, trip.getTrip());
    assertNull(trip.getPreviousTrip());
    assertSame(trips.get(1), trip.getNextTrip());
    trip = trips.get(1);
    assertEquals(2, trip.getAccumulatedStopTimeIndex());
    assertEquals(10 * 60, trip.getAccumulatedSlackTime());
    assertEquals(300.0, trip.getDistanceAlongBlock(), 0.0);
    assertSame(tripB, trip.getTrip());
    assertSame(trips.get(0), trip.getPreviousTrip());
    assertNull(trip.getNextTrip());
    stopTimes = entry.getStopTimes();
    assertEquals(4, stopTimes.size());
    bst = stopTimes.get(0);
    assertEquals(0, bst.getAccumulatedSlackTime());
    assertEquals(0, bst.getBlockSequence());
    assertEquals(100.0, bst.getDistanceAlongBlock(), 0.0);
    assertSame(st0, bst.getStopTime());
    assertSame(trips.get(0), bst.getTrip());
    bst = stopTimes.get(1);
    assertEquals(5 * 60, bst.getAccumulatedSlackTime());
    assertEquals(1, bst.getBlockSequence());
    assertEquals(200.0, bst.getDistanceAlongBlock(), 0.0);
    assertSame(st1, bst.getStopTime());
    assertSame(trips.get(0), bst.getTrip());
    bst = stopTimes.get(2);
    assertEquals(10 * 60, bst.getAccumulatedSlackTime());
    assertEquals(2, bst.getBlockSequence());
    assertEquals(400.0, bst.getDistanceAlongBlock(), 0.0);
    assertSame(st2, bst.getStopTime());
    assertSame(trips.get(1), bst.getTrip());
    bst = stopTimes.get(3);
    assertEquals(15 * 60, bst.getAccumulatedSlackTime());
    assertEquals(3, bst.getBlockSequence());
    assertEquals(500.0, bst.getDistanceAlongBlock(), 0.0);
    assertSame(st3, bst.getStopTime());
    assertSame(trips.get(1), bst.getTrip());
    /**
     **
     * Configuration B
     ***
     */
    entry = configurations.get(2);
    assertSame(block, entry.getBlock());
    assertEquals(serviceIds(lsids("sB"), lsids("sA")), entry.getServiceIds());
    assertEquals(600.0, entry.getTotalBlockDistance(), 0.0);
    assertNull(entry.getFrequencies());
    trips = entry.getTrips();
    assertEquals(2, trips.size());
    trip = trips.get(0);
    assertEquals(0, trip.getAccumulatedStopTimeIndex());
    assertEquals(0, trip.getAccumulatedSlackTime());
    assertEquals(0.0, trip.getDistanceAlongBlock(), 0.0);
    assertSame(tripC, trip.getTrip());
    assertNull(trip.getPreviousTrip());
    assertSame(trips.get(1), trip.getNextTrip());
    trip = trips.get(1);
    assertEquals(2, trip.getAccumulatedStopTimeIndex());
    assertEquals(10 * 60, trip.getAccumulatedSlackTime());
    assertEquals(300.0, trip.getDistanceAlongBlock(), 0.0);
    assertSame(tripD, trip.getTrip());
    assertSame(trips.get(0), trip.getPreviousTrip());
    assertNull(trip.getNextTrip());
    stopTimes = entry.getStopTimes();
    assertEquals(4, stopTimes.size());
    bst = stopTimes.get(0);
    assertEquals(0, bst.getAccumulatedSlackTime());
    assertEquals(0, bst.getBlockSequence());
    assertEquals(100.0, bst.getDistanceAlongBlock(), 0.0);
    assertSame(st4, bst.getStopTime());
    assertSame(trips.get(0), bst.getTrip());
    bst = stopTimes.get(1);
    assertEquals(5 * 60, bst.getAccumulatedSlackTime());
    assertEquals(1, bst.getBlockSequence());
    assertEquals(200.0, bst.getDistanceAlongBlock(), 0.0);
    assertSame(st5, bst.getStopTime());
    assertSame(trips.get(0), bst.getTrip());
    bst = stopTimes.get(2);
    assertEquals(10 * 60, bst.getAccumulatedSlackTime());
    assertEquals(2, bst.getBlockSequence());
    assertEquals(400.0, bst.getDistanceAlongBlock(), 0.0);
    assertSame(st6, bst.getStopTime());
    assertSame(trips.get(1), bst.getTrip());
    bst = stopTimes.get(3);
    assertEquals(15 * 60, bst.getAccumulatedSlackTime());
    assertEquals(3, bst.getBlockSequence());
    assertEquals(500.0, bst.getDistanceAlongBlock(), 0.0);
    assertSame(st7, bst.getStopTime());
    assertSame(trips.get(1), bst.getTrip());
}
Also used : StopTimeEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopTimeEntryImpl) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) 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) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry) StopEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl) Test(org.junit.Test)

Example 25 with BlockEntryImpl

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

the class BlockEntriesFactoryTest method testFixedScheduleBlocks.

@Test
public void testFixedScheduleBlocks() {
    LocalizedServiceId lsid = lsid("serviceId");
    StopEntryImpl stop = stop("stop");
    Trip tripA = new Trip();
    tripA.setId(aid("tripA"));
    tripA.setRoute(_route);
    tripA.setBlockId("blockA");
    TripEntryImpl tripEntryA = trip("tripA").setRoute(_routeEntry).setServiceId(lsid);
    _graph.putTripEntry(tripEntryA);
    addStopTime(tripEntryA, stopTime().setStop(stop));
    Trip tripB = new Trip();
    tripB.setId(aid("tripB"));
    tripB.setRoute(_route);
    tripB.setBlockId("blockA");
    TripEntryImpl tripEntryB = trip("tripB").setRoute(_routeEntry).setServiceId(lsid);
    _graph.putTripEntry(tripEntryB);
    addStopTime(tripEntryB, stopTime().setStop(stop));
    Trip tripC = new Trip();
    tripC.setId(aid("tripC"));
    tripC.setRoute(_route);
    tripC.setBlockId("blockB");
    TripEntryImpl tripEntryC = trip("tripC").setRoute(_routeEntry).setServiceId(lsid);
    _graph.putTripEntry(tripEntryC);
    addStopTime(tripEntryC, stopTime().setStop(stop));
    Mockito.when(_dao.getTripsForRoute(_route)).thenReturn(Arrays.asList(tripA, tripB, tripC));
    _graph.initialize();
    _factory.processBlocks(_graph);
    List<BlockEntryImpl> blocks = _graph.getBlocks();
    assertEquals(2, blocks.size());
    // jre8 changes this ordering so explicity search
    BlockEntryImpl block = find(blocks, "blockB");
    assertEquals(aid("blockB"), block.getId());
    assertSame(block, tripEntryC.getBlock());
    Mockito.verify(_blockConfigFactory).processBlockConfigurations(block, Arrays.asList(tripEntryC));
    // jre8 changes this ordering so explicity search
    block = find(blocks, "blockA");
    assertEquals(aid("blockA"), block.getId());
    assertSame(block, tripEntryA.getBlock());
    assertSame(block, tripEntryB.getBlock());
    Mockito.verify(_blockConfigFactory).processBlockConfigurations(block, Arrays.asList(tripEntryA, tripEntryB));
    Mockito.verifyNoMoreInteractions(_blockConfigFactory);
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) LocalizedServiceId(org.onebusaway.gtfs.model.calendar.LocalizedServiceId) BlockEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl) StopEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl) Test(org.junit.Test)

Aggregations

BlockEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl)43 TripEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl)34 BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)34 Test (org.junit.Test)33 BlockInstance (org.onebusaway.transit_data_federation.services.blocks.BlockInstance)25 StopEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl)16 VehicleLocationRecord (org.onebusaway.realtime.api.VehicleLocationRecord)15 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)11 TripUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate)9 BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)8 StopTimeUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeUpdate)7 TargetTime (org.onebusaway.transit_data_federation.model.TargetTime)7 BlockLocation (org.onebusaway.transit_data_federation.services.realtime.BlockLocation)7 Date (java.util.Date)6 StopTimeInstance (org.onebusaway.transit_data_federation.model.StopTimeInstance)6 ArrivalAndDepartureInstance (org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureInstance)6 ServiceIdActivation (org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation)6 ScheduledBlockLocation (org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation)5 BlockEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry)5 BlockTripEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry)5