Search in sources :

Example 6 with RouteEntryImpl

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

the class RouteEntriesFactory method processRoute.

private RouteEntryImpl processRoute(TransitGraphImpl graph, Route route) {
    RouteEntryImpl routeEntry = new RouteEntryImpl();
    routeEntry.setId(unique(route.getId()));
    routeEntry.setType(route.getType());
    graph.putRouteEntry(routeEntry);
    return routeEntry;
}
Also used : RouteEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.RouteEntryImpl)

Example 7 with RouteEntryImpl

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

the class RouteCollectionEntriesFactoryTest method testProcessRouteCollections.

@Test
public void testProcessRouteCollections() {
    TransitGraphImpl graph = new TransitGraphImpl();
    AgencyEntryImpl agency = new AgencyEntryImpl();
    agency.setId("A");
    graph.putAgencyEntry(agency);
    graph.refreshAgencyMapping();
    RouteEntryImpl routeA = new RouteEntryImpl();
    routeA.setId(new AgencyAndId("A", "routeA"));
    graph.putRouteEntry(routeA);
    RouteEntryImpl routeB = new RouteEntryImpl();
    routeB.setId(new AgencyAndId("A", "routeB"));
    graph.putRouteEntry(routeB);
    RouteCollectionEntriesFactory factory = new RouteCollectionEntriesFactory();
    GtfsRelationalDao gtfsDao = Mockito.mock(GtfsRelationalDao.class);
    factory.setGtfsDao(gtfsDao);
    factory.setUniqueService(new UniqueServiceImpl());
    factory.processRouteCollections(graph);
    RouteCollectionEntry routeEntryA = graph.getRouteCollectionForId(routeA.getId());
    assertEquals(routeA.getId(), routeEntryA.getId());
    List<RouteEntry> routes = routeEntryA.getChildren();
    assertEquals(1, routes.size());
    assertTrue(routes.contains(routeA));
    RouteCollectionEntry routeEntryB = graph.getRouteCollectionForId(routeB.getId());
    assertEquals(routeB.getId(), routeEntryB.getId());
    routes = routeEntryB.getChildren();
    assertEquals(1, routes.size());
    assertTrue(routes.contains(routeB));
    List<RouteCollectionEntry> routeCollections = graph.getAllRouteCollections();
    assertEquals(2, routeCollections.size());
    assertTrue(routeCollections.contains(routeEntryA));
    assertTrue(routeCollections.contains(routeEntryB));
    routeCollections = agency.getRouteCollections();
    assertEquals(2, routeCollections.size());
    assertTrue(routeCollections.contains(routeEntryA));
    assertTrue(routeCollections.contains(routeEntryB));
}
Also used : UniqueServiceImpl(org.onebusaway.transit_data_federation.bundle.tasks.UniqueServiceImpl) GtfsRelationalDao(org.onebusaway.gtfs.services.GtfsRelationalDao) RouteEntry(org.onebusaway.transit_data_federation.services.transit_graph.RouteEntry) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) AgencyEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.AgencyEntryImpl) TransitGraphImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TransitGraphImpl) RouteEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.RouteEntryImpl) RouteCollectionEntry(org.onebusaway.transit_data_federation.services.transit_graph.RouteCollectionEntry) Test(org.junit.Test)

Example 8 with RouteEntryImpl

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

the class RouteCollectionEntriesFactoryTest method testGroupRoutesByShortName.

@Test
public void testGroupRoutesByShortName() {
    TransitGraphImpl graph = new TransitGraphImpl();
    AgencyEntryImpl agency = new AgencyEntryImpl();
    agency.setId("A");
    graph.putAgencyEntry(agency);
    graph.refreshAgencyMapping();
    RouteEntryImpl routeA = new RouteEntryImpl();
    routeA.setId(new AgencyAndId("A", "routeA"));
    graph.putRouteEntry(routeA);
    RouteEntryImpl routeB = new RouteEntryImpl();
    routeB.setId(new AgencyAndId("A", "routeB"));
    graph.putRouteEntry(routeB);
    GtfsRelationalDao gtfsDao = Mockito.mock(GtfsRelationalDao.class);
    Route rA = new Route();
    rA.setId(routeA.getId());
    rA.setShortName("10");
    Mockito.when(gtfsDao.getRouteForId(routeA.getId())).thenReturn(rA);
    Route rB = new Route();
    rB.setId(routeB.getId());
    rB.setShortName("10");
    Mockito.when(gtfsDao.getRouteForId(routeB.getId())).thenReturn(rB);
    RouteCollectionEntriesFactory factory = new RouteCollectionEntriesFactory();
    factory.setGroupRoutesByShortName(true);
    factory.setGtfsDao(gtfsDao);
    factory.setUniqueService(new UniqueServiceImpl());
    factory.processRouteCollections(graph);
    AgencyAndId id = new AgencyAndId("A", "10");
    RouteCollectionEntry routeCollectionEntry = graph.getRouteCollectionForId(id);
    assertEquals(id, routeCollectionEntry.getId());
    List<RouteEntry> routes = routeCollectionEntry.getChildren();
    assertEquals(2, routes.size());
    assertTrue(routes.contains(routeA));
    assertTrue(routes.contains(routeB));
    List<RouteCollectionEntry> routeCollections = graph.getAllRouteCollections();
    assertEquals(1, routeCollections.size());
    assertTrue(routeCollections.contains(routeCollectionEntry));
    routeCollections = agency.getRouteCollections();
    assertEquals(1, routeCollections.size());
    assertTrue(routeCollections.contains(routeCollectionEntry));
}
Also used : UniqueServiceImpl(org.onebusaway.transit_data_federation.bundle.tasks.UniqueServiceImpl) GtfsRelationalDao(org.onebusaway.gtfs.services.GtfsRelationalDao) RouteEntry(org.onebusaway.transit_data_federation.services.transit_graph.RouteEntry) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) AgencyEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.AgencyEntryImpl) TransitGraphImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TransitGraphImpl) RouteEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.RouteEntryImpl) RouteCollectionEntry(org.onebusaway.transit_data_federation.services.transit_graph.RouteCollectionEntry) Route(org.onebusaway.gtfs.model.Route) Test(org.junit.Test)

Example 9 with RouteEntryImpl

use of org.onebusaway.transit_data_federation.impl.transit_graph.RouteEntryImpl 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 10 with RouteEntryImpl

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

the class GtfsRealtimeEntitySourceTest method testGetRouteId.

@Test
public void testGetRouteId() {
    RouteCollectionEntryImpl routeCollection = new RouteCollectionEntryImpl();
    routeCollection.setId(new AgencyAndId("2", "R10C"));
    RouteEntryImpl route = new RouteEntryImpl();
    route.setId(new AgencyAndId("2", "R10"));
    route.setParent(routeCollection);
    Mockito.when(_dao.getRouteForId(route.getId())).thenReturn(route);
    Id routeId = _source.getRouteId("R10");
    assertEquals("2", routeId.getAgencyId());
    assertEquals("R10C", routeId.getId());
    routeId = _source.getRouteId("R11");
    assertEquals("1", routeId.getAgencyId());
    assertEquals("R11", routeId.getId());
}
Also used : RouteCollectionEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.RouteCollectionEntryImpl) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) RouteEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.RouteEntryImpl) Id(org.onebusaway.transit_data_federation.services.service_alerts.ServiceAlerts.Id) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Test(org.junit.Test)

Aggregations

RouteEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.RouteEntryImpl)15 Test (org.junit.Test)9 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)9 RouteEntry (org.onebusaway.transit_data_federation.services.transit_graph.RouteEntry)7 Route (org.onebusaway.gtfs.model.Route)6 RouteCollectionEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.RouteCollectionEntryImpl)6 TripEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl)5 GtfsRelationalDao (org.onebusaway.gtfs.services.GtfsRelationalDao)4 UniqueServiceImpl (org.onebusaway.transit_data_federation.bundle.tasks.UniqueServiceImpl)4 TransitGraphImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TransitGraphImpl)4 ArrayList (java.util.ArrayList)3 BlockEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl)3 StopEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl)3 RouteCollectionEntry (org.onebusaway.transit_data_federation.services.transit_graph.RouteCollectionEntry)3 TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)3 Agency (org.onebusaway.gtfs.model.Agency)2 Trip (org.onebusaway.gtfs.model.Trip)2 AgencyEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.AgencyEntryImpl)2 RouteCollectionNarrative (org.onebusaway.transit_data_federation.model.narrative.RouteCollectionNarrative)2 BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)2