Search in sources :

Example 6 with ShapePointsFactory

use of org.onebusaway.transit_data_federation.model.ShapePointsFactory in project onebusaway-application-modules by camsys.

the class DistanceAlongShapeLibraryTest method readShapePoints.

private ShapePoints readShapePoints(String key) throws IOException {
    BufferedReader reader = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("DistancesAlongShapeLibraryTest-" + key)));
    String line = null;
    ShapePointsFactory factory = new ShapePointsFactory();
    while ((line = reader.readLine()) != null) {
        String[] tokens = line.split(" ");
        double lat = Double.parseDouble(tokens[0]);
        double lon = Double.parseDouble(tokens[1]);
        factory.addPoint(lat, lon);
    }
    reader.close();
    return factory.create();
}
Also used : ShapePointsFactory(org.onebusaway.transit_data_federation.model.ShapePointsFactory) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader)

Example 7 with ShapePointsFactory

use of org.onebusaway.transit_data_federation.model.ShapePointsFactory in project onebusaway-application-modules by camsys.

the class StopTimeEntriesFactoryTest method testThreeInARowDuplicateRemoval.

@Test
public void testThreeInARowDuplicateRemoval() {
    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));
    Stop stopD = new Stop();
    stopD.setId(aid("stopD"));
    graph.putStopEntry(stop("stopD", 47.66947942216854, -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(9, 00));
    stC.setDepartureTime(time(9, 05));
    stC.setStopSequence(102);
    stC.setStop(stopC);
    stC.setTrip(trip);
    StopTime stD = new StopTime();
    stD.setId(103);
    stD.setArrivalTime(time(11, 00));
    stD.setDepartureTime(time(11, 05));
    stD.setStopSequence(103);
    stD.setStop(stopD);
    stD.setTrip(trip);
    StopTimeEntriesFactory factory = new StopTimeEntriesFactory();
    factory.setDistanceAlongShapeLibrary(new DistanceAlongShapeLibrary());
    List<StopTime> stopTimes = Arrays.asList(stA, stB, stC, stD);
    ShapePointsFactory shapePointsFactory = new ShapePointsFactory();
    shapePointsFactory.addPoint(47.673840100841396, -122.38756621771239);
    shapePointsFactory.addPoint(47.668667271970484, -122.38756621771239);
    shapePointsFactory.addPoint(47.66868172192725, -122.3661729186096);
    shapePointsFactory.addPoint(47.66947942216854, -122.37545336180114);
    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, 45), entry.getArrivalTime());
    assertEquals(time(9, 28, 45), 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, 34), entry.getArrivalTime());
    assertEquals(time(10, 00, 34), entry.getDepartureTime());
    assertEquals(2, entry.getSequence());
    assertEquals(1484.5, entry.getShapeDistTraveled(), 0.1);
    assertEquals(0, entry.getSlackTime());
    entry = entries.get(3);
    assertEquals(5 * 60, entry.getAccumulatedSlackTime());
    assertEquals(time(11, 00), entry.getArrivalTime());
    assertEquals(time(11, 05), entry.getDepartureTime());
    assertEquals(3, entry.getSequence());
    assertEquals(2877.69, entry.getShapeDistTraveled(), 0.1);
    assertEquals(60 * 5, 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)

Example 8 with ShapePointsFactory

use of org.onebusaway.transit_data_federation.model.ShapePointsFactory in project onebusaway-application-modules by camsys.

the class TripEntriesFactoryTest method test.

@Test
public void test() {
    GtfsRelationalDao gtfsDao = Mockito.mock(GtfsRelationalDao.class);
    Agency agency = new Agency();
    agency.setId("1");
    agency.setTimezone("America/Los_Angeles");
    // gtfsDao.saveEntity(agency);
    Route route = new Route();
    route.setId(new AgencyAndId("1", "routeA"));
    route.setAgency(agency);
    Mockito.when(gtfsDao.getAllRoutes()).thenReturn(Arrays.asList(route));
    AgencyAndId shapeId = new AgencyAndId("1", "shapeId");
    Trip trip = new Trip();
    trip.setId(new AgencyAndId("1", "tripA"));
    trip.setRoute(route);
    trip.setServiceId(new AgencyAndId("1", "serviceId"));
    trip.setShapeId(shapeId);
    Mockito.when(gtfsDao.getTripsForRoute(route)).thenReturn(Arrays.asList(trip));
    Stop stopA = new Stop();
    stopA.setId(aid("stopA"));
    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);
    Stop stopB = new Stop();
    stopB.setId(aid("stopB"));
    StopTime stB = new StopTime();
    stB.setId(101);
    stB.setArrivalTime(time(10, 00));
    stB.setDepartureTime(time(10, 05));
    stB.setStopSequence(102);
    stB.setStop(stopB);
    stB.setTrip(trip);
    Mockito.when(gtfsDao.getStopTimesForTrip(trip)).thenReturn(Arrays.asList(stA, stB));
    TransitGraphImpl graph = new TransitGraphImpl();
    graph.putStopEntry(stop("stopA", 47.672207391799056, -122.387855896286));
    graph.putStopEntry(stop("stopB", 47.66852277218285, -122.3853882639923));
    RouteEntryImpl routeEntry = route("routeA");
    graph.putRouteEntry(routeEntry);
    graph.initialize();
    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();
    ShapePointHelper shapePointHelper = Mockito.mock(ShapePointHelper.class);
    Mockito.when(shapePointHelper.getShapePointsForShapeId(shapeId)).thenReturn(shapePoints);
    TripEntriesFactory factory = new TripEntriesFactory();
    factory.setGtfsDao(gtfsDao);
    factory.setShapePointHelper(shapePointHelper);
    factory.setUniqueService(new UniqueServiceImpl());
    StopTimeEntriesFactory stopTimeEntriesFactory = new StopTimeEntriesFactory();
    stopTimeEntriesFactory.setDistanceAlongShapeLibrary(new DistanceAlongShapeLibrary());
    factory.setStopTimeEntriesFactory(stopTimeEntriesFactory);
    factory.processTrips(graph);
    TripEntryImpl entry = graph.getTripEntryForId(trip.getId());
    assertEquals(trip.getId(), entry.getId());
    assertEquals(route.getId(), entry.getRoute().getId());
    assertEquals(lsid("serviceId"), entry.getServiceId());
    assertEquals(trip.getShapeId(), entry.getShapeId());
    assertEquals(2177.1, entry.getTotalTripDistance(), 0.1);
    List<StopTimeEntry> stopTimes = entry.getStopTimes();
    assertEquals(2, stopTimes.size());
    for (StopTimeEntry stopTime : stopTimes) {
        assertSame(entry, stopTime.getTrip());
    }
}
Also used : UniqueServiceImpl(org.onebusaway.transit_data_federation.bundle.tasks.UniqueServiceImpl) GtfsRelationalDao(org.onebusaway.gtfs.services.GtfsRelationalDao) Trip(org.onebusaway.gtfs.model.Trip) Agency(org.onebusaway.gtfs.model.Agency) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Stop(org.onebusaway.gtfs.model.Stop) ShapePointHelper(org.onebusaway.transit_data_federation.bundle.tasks.ShapePointHelper) RouteEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.RouteEntryImpl) 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) StopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry) TransitGraphImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TransitGraphImpl) Route(org.onebusaway.gtfs.model.Route) StopTime(org.onebusaway.gtfs.model.StopTime) Test(org.junit.Test)

Example 9 with ShapePointsFactory

use of org.onebusaway.transit_data_federation.model.ShapePointsFactory in project onebusaway-application-modules by camsys.

the class ShapePointServiceImpl method getShapePointsForShapeIds.

@Cacheable
@Override
public ShapePoints getShapePointsForShapeIds(List<AgencyAndId> shapeIds) {
    ShapePointsFactory factory = new ShapePointsFactory();
    for (AgencyAndId shapeId : shapeIds) {
        ShapePoints shapePoints = getShapePointsForShapeId(shapeId);
        factory.addPoints(shapePoints);
    }
    return factory.create();
}
Also used : ShapePoints(org.onebusaway.transit_data_federation.model.ShapePoints) ShapePointsFactory(org.onebusaway.transit_data_federation.model.ShapePointsFactory) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Cacheable(org.onebusaway.container.cache.Cacheable)

Example 10 with ShapePointsFactory

use of org.onebusaway.transit_data_federation.model.ShapePointsFactory 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

ShapePointsFactory (org.onebusaway.transit_data_federation.model.ShapePointsFactory)13 ShapePoints (org.onebusaway.transit_data_federation.model.ShapePoints)9 Test (org.junit.Test)8 TripEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl)8 Stop (org.onebusaway.gtfs.model.Stop)6 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)5 StopTimeEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.StopTimeEntryImpl)5 Agency (org.onebusaway.gtfs.model.Agency)4 Route (org.onebusaway.gtfs.model.Route)4 StopTime (org.onebusaway.gtfs.model.StopTime)4 Trip (org.onebusaway.gtfs.model.Trip)4 TransitGraphImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TransitGraphImpl)4 DistanceAlongShapeLibrary (org.onebusaway.transit_data_federation.bundle.tasks.transit_graph.DistanceAlongShapeLibrary)3 StopTimeEntriesFactory (org.onebusaway.transit_data_federation.bundle.tasks.transit_graph.StopTimeEntriesFactory)3 BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)3 StopEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopEntry)3 BufferedReader (java.io.BufferedReader)2 Before (org.junit.Before)2 ShapePointHelper (org.onebusaway.transit_data_federation.bundle.tasks.ShapePointHelper)2 StopEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl)2