Search in sources :

Example 51 with TripEntryImpl

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

the class ShapeGeospatialIndexTaskTest method test.

@Test
public void test() throws IOException, ClassNotFoundException {
    ShapeGeospatialIndexTask task = new ShapeGeospatialIndexTask();
    File path = File.createTempFile(ShapeGeospatialIndexTaskTest.class.getName(), ".tmp");
    path.delete();
    path.deleteOnExit();
    FederatedTransitDataBundle bundle = Mockito.mock(FederatedTransitDataBundle.class);
    Mockito.when(bundle.getShapeGeospatialIndexDataPath()).thenReturn(path);
    task.setBundle(bundle);
    RefreshService refreshService = Mockito.mock(RefreshService.class);
    task.setRefreshService(refreshService);
    ShapePointHelper shapePointHelper = Mockito.mock(ShapePointHelper.class);
    task.setShapePointHelper(shapePointHelper);
    TransitGraphDao transitGraphDao = Mockito.mock(TransitGraphDao.class);
    task.setTransitGraphDao(transitGraphDao);
    StopEntry stopA = stop("stopA", 47.65, -122.32);
    StopEntry stopB = stop("stopB", 47.67, -122.30);
    Mockito.when(transitGraphDao.getAllStops()).thenReturn(Arrays.asList(stopA, stopB));
    TripEntryImpl tripA = trip("tripA");
    AgencyAndId shapeIdA = aid("shapeA");
    tripA.setShapeId(shapeIdA);
    TripEntryImpl tripB = trip("tripB");
    AgencyAndId shapeIdB = aid("shapeB");
    tripB.setShapeId(shapeIdB);
    Mockito.when(transitGraphDao.getAllTrips()).thenReturn(Arrays.asList((TripEntry) tripA, tripB));
    ShapePointsFactory factory = new ShapePointsFactory();
    factory.addPoint(47.652300128129454, -122.30622018270873);
    factory.addPoint(47.653181844549394, -122.30523312979125);
    factory.addPoint(47.654265901710744, -122.30511511259459);
    ShapePoints shapeA = factory.create();
    factory = new ShapePointsFactory();
    factory.addPoint(47.661275594717026, -122.31189573698424);
    factory.addPoint(47.661347854692465, -122.3240622370758);
    factory.addPoint(47.661368177792546, -122.32508885257624);
    factory.addPoint(47.66496659665593, -122.32501375072383);
    ShapePoints shapeB = factory.create();
    Mockito.when(shapePointHelper.getShapePointsForShapeId(shapeIdA)).thenReturn(shapeA);
    Mockito.when(shapePointHelper.getShapePointsForShapeId(shapeIdB)).thenReturn(shapeB);
    task.run();
    Mockito.verify(refreshService).refresh(RefreshableResources.SHAPE_GEOSPATIAL_INDEX);
    Map<CoordinateBounds, List<AgencyAndId>> shapeIdsByBounds = ObjectSerializationLibrary.readObject(path);
    assertEquals(5, shapeIdsByBounds.size());
    CoordinateBounds b = new CoordinateBounds(47.65048049686506, -122.30767397879845, 47.654977097836735, -122.300997795721);
    assertEquals(Arrays.asList(shapeIdA), shapeIdsByBounds.get(b));
    b = new CoordinateBounds(47.65947369880841, -122.32102634495334, 47.66397029978009, -122.3143501618759);
    assertEquals(Arrays.asList(shapeIdB), shapeIdsByBounds.get(b));
    b = new CoordinateBounds(47.66397029978009, -122.32770252803078, 47.66846690075177, -122.32102634495334);
    assertEquals(Arrays.asList(shapeIdB), shapeIdsByBounds.get(b));
    b = new CoordinateBounds(47.65947369880841, -122.3143501618759, 47.66397029978009, -122.30767397879845);
    assertEquals(Arrays.asList(shapeIdB), shapeIdsByBounds.get(b));
    b = new CoordinateBounds(47.65947369880841, -122.32770252803078, 47.66397029978009, -122.32102634495334);
    assertEquals(Arrays.asList(shapeIdB), shapeIdsByBounds.get(b));
}
Also used : TransitGraphDao(org.onebusaway.transit_data_federation.services.transit_graph.TransitGraphDao) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl) ShapePoints(org.onebusaway.transit_data_federation.model.ShapePoints) ShapePointsFactory(org.onebusaway.transit_data_federation.model.ShapePointsFactory) FederatedTransitDataBundle(org.onebusaway.transit_data_federation.services.FederatedTransitDataBundle) RefreshService(org.onebusaway.container.refresh.RefreshService) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) List(java.util.List) File(java.io.File) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds) Test(org.junit.Test)

Example 52 with TripEntryImpl

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

the class BlockConfigurationEntryImplTest method test.

@Test
public void test() {
    ServiceIdActivation serviceIds = serviceIds(lsids("sA"), lsids("sB"));
    StopEntryImpl stopA = stop("stopA", 47.0, -122.0);
    StopEntryImpl stopB = stop("stopB", 47.1, -122.0);
    BlockEntryImpl block = block("blockA");
    TripEntryImpl tripA = trip("tripA", 1000);
    TripEntryImpl tripB = trip("tripB", 2000);
    TripEntryImpl tripC = trip("tripB", 1500);
    List<TripEntry> trips = Arrays.asList((TripEntry) tripA, tripB, tripC);
    StopTimeEntryImpl st1 = stopTime(1, stopA, tripA, time(6, 30), time(6, 35), 200);
    StopTimeEntryImpl st2 = stopTime(2, stopB, tripA, time(7, 00), time(7, 10), 800);
    StopTimeEntryImpl st3 = stopTime(3, stopB, tripB, time(7, 30), time(7, 35), 400);
    StopTimeEntryImpl st4 = stopTime(4, stopA, tripB, time(8, 00), time(8, 07), 1600);
    StopTimeEntryImpl st5 = stopTime(5, stopA, tripC, time(8, 30), time(8, 35), 300);
    StopTimeEntryImpl st6 = stopTime(6, stopB, tripC, time(9, 00), time(9, 02), 1200);
    Builder builder = BlockConfigurationEntryImpl.builder();
    builder.setBlock(block);
    builder.setTrips(trips);
    builder.setServiceIds(serviceIds);
    builder.setTripGapDistances(new double[] { 10.0, 20.0, 0.0 });
    BlockConfigurationEntry entry = builder.create();
    assertSame(block, entry.getBlock());
    assertSame(serviceIds, entry.getServiceIds());
    assertEquals(4530.0, entry.getTotalBlockDistance(), 0.0);
    /**
     **
     * Trips
     ***
     */
    List<BlockTripEntry> blockTrips = entry.getTrips();
    assertEquals(3, blockTrips.size());
    BlockTripEntry blockTrip = blockTrips.get(0);
    assertEquals(0, blockTrip.getSequence());
    assertEquals(0, blockTrip.getAccumulatedStopTimeIndex());
    assertEquals(0, blockTrip.getAccumulatedSlackTime());
    assertEquals(0.0, blockTrip.getDistanceAlongBlock(), 0.0);
    assertSame(blockTrips.get(1), blockTrip.getNextTrip());
    assertNull(blockTrip.getPreviousTrip());
    blockTrip = blockTrips.get(1);
    assertEquals(1, blockTrip.getSequence());
    assertEquals(2, blockTrip.getAccumulatedStopTimeIndex());
    assertEquals(15 * 60, blockTrip.getAccumulatedSlackTime());
    assertEquals(1010.0, blockTrip.getDistanceAlongBlock(), 0.0);
    assertSame(blockTrips.get(2), blockTrip.getNextTrip());
    assertSame(blockTrips.get(0), blockTrip.getPreviousTrip());
    blockTrip = blockTrips.get(2);
    assertEquals(2, blockTrip.getSequence());
    assertEquals(4, blockTrip.getAccumulatedStopTimeIndex());
    assertEquals(35 * 60, blockTrip.getAccumulatedSlackTime());
    assertEquals(3030.0, blockTrip.getDistanceAlongBlock(), 0.0);
    assertNull(blockTrip.getNextTrip());
    assertSame(blockTrips.get(1), blockTrip.getPreviousTrip());
    /**
     **
     * Stop Times
     ***
     */
    List<BlockStopTimeEntry> stopTimes = entry.getStopTimes();
    assertEquals(6, stopTimes.size());
    BlockStopTimeEntry bst = stopTimes.get(0);
    assertEquals(0, bst.getAccumulatedSlackTime());
    assertEquals(0, bst.getBlockSequence());
    assertEquals(200, bst.getDistanceAlongBlock(), 0.0);
    assertSame(st1, bst.getStopTime());
    assertSame(blockTrips.get(0), bst.getTrip());
    bst = stopTimes.get(1);
    assertEquals(300, bst.getAccumulatedSlackTime());
    assertEquals(1, bst.getBlockSequence());
    assertEquals(800, bst.getDistanceAlongBlock(), 0.0);
    assertSame(st2, bst.getStopTime());
    assertSame(blockTrips.get(0), bst.getTrip());
    bst = stopTimes.get(2);
    assertEquals(15 * 60, bst.getAccumulatedSlackTime());
    assertEquals(2, bst.getBlockSequence());
    assertEquals(1410, bst.getDistanceAlongBlock(), 0.0);
    assertSame(st3, bst.getStopTime());
    assertSame(blockTrips.get(1), bst.getTrip());
    bst = stopTimes.get(3);
    assertEquals(20 * 60, bst.getAccumulatedSlackTime());
    assertEquals(3, bst.getBlockSequence());
    assertEquals(2610, bst.getDistanceAlongBlock(), 0.0);
    assertSame(st4, bst.getStopTime());
    assertSame(blockTrips.get(1), bst.getTrip());
    bst = stopTimes.get(4);
    assertEquals(35 * 60, bst.getAccumulatedSlackTime());
    assertEquals(4, bst.getBlockSequence());
    assertEquals(3330, bst.getDistanceAlongBlock(), 0.0);
    assertSame(st5, bst.getStopTime());
    assertSame(blockTrips.get(2), bst.getTrip());
    bst = stopTimes.get(5);
    assertEquals(40 * 60, bst.getAccumulatedSlackTime());
    assertEquals(5, bst.getBlockSequence());
    assertEquals(4230, bst.getDistanceAlongBlock(), 0.0);
    assertSame(st6, bst.getStopTime());
    assertSame(blockTrips.get(2), bst.getTrip());
}
Also used : StopTimeEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopTimeEntryImpl) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) Builder(org.onebusaway.transit_data_federation.impl.transit_graph.BlockConfigurationEntryImpl.Builder) 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) 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) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry) Test(org.junit.Test)

Example 53 with TripEntryImpl

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

the class FrequenciesEntriesFactoryTest method testTripsWithMismatchedFrequencies.

@Test
public void testTripsWithMismatchedFrequencies() {
    BlockEntryImpl block = block("block");
    TripEntryImpl tripEntryA = trip("trip").setRoute(_routeEntry).setServiceId(_lsid).setBlock(block);
    _graph.putTripEntry(tripEntryA);
    addStopTime(tripEntryA, stopTime().setStop(_stopA).setTime(time(7, 00)));
    Trip trip = new Trip();
    trip.setId(tripEntryA.getId());
    Frequency freqA = new Frequency();
    freqA.setTrip(trip);
    freqA.setStartTime(time(8, 00));
    freqA.setEndTime(time(10, 00));
    freqA.setHeadwaySecs(10 * 60);
    freqA.setExactTimes(0);
    Frequency freqB = new Frequency();
    freqB.setTrip(trip);
    freqB.setStartTime(time(10, 00));
    freqB.setEndTime(time(12, 00));
    freqB.setHeadwaySecs(10 * 60);
    /**
     * We don't allow a mix of trips with exactTimes=0 and exactTimes=1
     */
    freqB.setExactTimes(1);
    Mockito.when(_dao.getAllFrequencies()).thenReturn(Arrays.asList(freqA, freqB));
    _graph.initialize();
    try {
        _factory.processFrequencies(_graph);
        fail();
    } catch (IllegalStateException ex) {
    }
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) Frequency(org.onebusaway.gtfs.model.Frequency) BlockEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl) Test(org.junit.Test)

Example 54 with TripEntryImpl

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

the class FrequenciesEntriesFactoryTest method testSingleTripWithFrequencies.

@Test
public void testSingleTripWithFrequencies() {
    BlockEntryImpl block = block("block");
    TripEntryImpl tripEntryA = trip("trip").setRoute(_routeEntry).setServiceId(_lsid).setBlock(block);
    _graph.putTripEntry(tripEntryA);
    addStopTime(tripEntryA, stopTime().setStop(_stopA).setTime(time(7, 00)));
    BlockConfigurationEntry blockConfig = blockConfiguration(block, serviceIds("serviceId"), tripEntryA);
    Trip trip = new Trip();
    trip.setId(tripEntryA.getId());
    Frequency freqA = new Frequency();
    freqA.setTrip(trip);
    freqA.setStartTime(time(8, 00));
    freqA.setEndTime(time(10, 00));
    freqA.setHeadwaySecs(10 * 60);
    freqA.setExactTimes(0);
    Frequency freqB = new Frequency();
    freqB.setTrip(trip);
    freqB.setStartTime(time(10, 00));
    freqB.setEndTime(time(12, 00));
    freqB.setHeadwaySecs(10 * 60);
    freqB.setExactTimes(0);
    Mockito.when(_dao.getAllFrequencies()).thenReturn(Arrays.asList(freqA, freqB));
    _graph.initialize();
    _factory.processFrequencies(_graph);
    blockConfig = block.getConfigurations().get(0);
    List<FrequencyEntry> frequencies = blockConfig.getFrequencies();
    assertEquals(2, frequencies.size());
    FrequencyEntry frequency = frequencies.get(0);
    assertEquals(freqA.getStartTime(), frequency.getStartTime());
    assertEquals(freqA.getEndTime(), frequency.getEndTime());
    assertEquals(freqA.getHeadwaySecs(), frequency.getHeadwaySecs());
    assertEquals(freqA.getExactTimes(), frequency.getExactTimes());
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) Frequency(org.onebusaway.gtfs.model.Frequency) 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) Test(org.junit.Test)

Example 55 with TripEntryImpl

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

the class StopTimeEntriesFactoryTest method testDuplicateRemoval.

@Test
public void testDuplicateRemoval() {
    TransitGraphImpl graph = new TransitGraphImpl();
    Stop stopA = new Stop();
    stopA.setId(aid("stopA"));
    graph.putStopEntry(stop("stopA", 47.672207391799056, -122.387855896286));
    Stop stopB = new Stop();
    stopB.setId(aid("stopB"));
    graph.putStopEntry(stop("stopB", 47.66852277218285, -122.3853882639923));
    Stop stopC = new Stop();
    stopC.setId(aid("stopC"));
    graph.putStopEntry(stop("stopC", 47.66847942216854, -122.37545336180114));
    graph.refreshStopMapping();
    Agency agency = new Agency();
    agency.setId("1");
    agency.setTimezone("America/Los_Angeles");
    Route route = new Route();
    route.setAgency(agency);
    Trip trip = new Trip();
    trip.setRoute(route);
    trip.setServiceId(aid("serviceId"));
    TripEntryImpl tripEntry = trip("trip");
    StopTime stA = new StopTime();
    stA.setId(100);
    stA.setArrivalTime(time(9, 00));
    stA.setDepartureTime(time(9, 05));
    stA.setStopSequence(100);
    stA.setStop(stopA);
    stA.setTrip(trip);
    StopTime stB = new StopTime();
    stB.setId(101);
    stB.setArrivalTime(time(9, 00));
    stB.setDepartureTime(time(9, 05));
    stB.setStopSequence(101);
    stB.setStop(stopB);
    stB.setTrip(trip);
    StopTime stC = new StopTime();
    stC.setId(102);
    stC.setArrivalTime(time(10, 00));
    stC.setDepartureTime(time(10, 05));
    stC.setStopSequence(102);
    stC.setStop(stopC);
    stC.setTrip(trip);
    StopTimeEntriesFactory factory = new StopTimeEntriesFactory();
    factory.setDistanceAlongShapeLibrary(new DistanceAlongShapeLibrary());
    List<StopTime> stopTimes = Arrays.asList(stA, stB, stC);
    ShapePointsFactory shapePointsFactory = new ShapePointsFactory();
    shapePointsFactory.addPoint(47.673840100841396, -122.38756621771239);
    shapePointsFactory.addPoint(47.668667271970484, -122.38756621771239);
    shapePointsFactory.addPoint(47.66868172192725, -122.3661729186096);
    ShapePoints shapePoints = shapePointsFactory.create();
    List<StopTimeEntryImpl> entries = factory.processStopTimes(graph, stopTimes, tripEntry, shapePoints);
    assertEquals(stopTimes.size(), entries.size());
    StopTimeEntryImpl entry = entries.get(0);
    assertEquals(0, entry.getAccumulatedSlackTime());
    assertEquals(time(9, 00), entry.getArrivalTime());
    assertEquals(time(9, 05), entry.getDepartureTime());
    assertEquals(0, entry.getSequence());
    assertEquals(181.5, entry.getShapeDistTraveled(), 0.1);
    assertEquals(5 * 60, entry.getSlackTime());
    entry = entries.get(1);
    assertEquals(5 * 60, entry.getAccumulatedSlackTime());
    assertEquals(time(9, 28, 31), entry.getArrivalTime());
    assertEquals(time(9, 28, 31), entry.getDepartureTime());
    assertEquals(1, entry.getSequence());
    assertEquals(738.7, entry.getShapeDistTraveled(), 0.1);
    assertEquals(0, entry.getSlackTime());
    entry = entries.get(2);
    assertEquals(5 * 60, entry.getAccumulatedSlackTime());
    assertEquals(time(10, 00), entry.getArrivalTime());
    assertEquals(time(10, 05), entry.getDepartureTime());
    assertEquals(2, entry.getSequence());
    assertEquals(1484.5, entry.getShapeDistTraveled(), 0.1);
    assertEquals(5 * 60, entry.getSlackTime());
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) Agency(org.onebusaway.gtfs.model.Agency) Stop(org.onebusaway.gtfs.model.Stop) StopTimeEntriesFactory(org.onebusaway.transit_data_federation.bundle.tasks.transit_graph.StopTimeEntriesFactory) StopTimeEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopTimeEntryImpl) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl) ShapePoints(org.onebusaway.transit_data_federation.model.ShapePoints) ShapePointsFactory(org.onebusaway.transit_data_federation.model.ShapePointsFactory) TransitGraphImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TransitGraphImpl) DistanceAlongShapeLibrary(org.onebusaway.transit_data_federation.bundle.tasks.transit_graph.DistanceAlongShapeLibrary) Route(org.onebusaway.gtfs.model.Route) StopTime(org.onebusaway.gtfs.model.StopTime) Test(org.junit.Test)

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