Search in sources :

Example 61 with Route

use of org.onebusaway.gtfs.model.Route in project onebusaway-application-modules by camsys.

the class BlockEntriesFactory method getTripsByBlockId.

private Map<AgencyAndId, List<TripEntryImpl>> getTripsByBlockId(TransitGraphImpl graph) {
    Collection<Route> routes = _gtfsDao.getAllRoutes();
    int routeIndex = 0;
    Map<AgencyAndId, List<TripEntryImpl>> tripsByBlockId = new FactoryMap<AgencyAndId, List<TripEntryImpl>>(new ArrayList<TripEntryImpl>());
    for (Route route : routes) {
        _log.info("routes: " + (routeIndex++) + "/" + routes.size());
        List<Trip> trips = _gtfsDao.getTripsForRoute(route);
        for (Trip trip : trips) {
            TripEntryImpl tripEntry = graph.getTripEntryForId(trip.getId());
            // prune the trip
            if (tripEntry == null)
                continue;
            /*
         * here we default the blockId to the tripId
         */
            AgencyAndId blockId = trip.getId();
            if (trip.getBlockId() != null) {
                /*
           * he have a block so set it
           */
                blockId = new AgencyAndId(trip.getId().getAgencyId(), trip.getBlockId());
            }
            tripsByBlockId.get(blockId).add(tripEntry);
        }
    }
    return tripsByBlockId;
}
Also used : FactoryMap(org.onebusaway.collections.FactoryMap) Trip(org.onebusaway.gtfs.model.Trip) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ArrayList(java.util.ArrayList) List(java.util.List) Route(org.onebusaway.gtfs.model.Route) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl)

Example 62 with Route

use of org.onebusaway.gtfs.model.Route in project onebusaway-application-modules by camsys.

the class RouteCollectionEntriesFactory method createRouteShortNameRouteCollectionMapping.

private void createRouteShortNameRouteCollectionMapping(TransitGraphImpl graph) {
    Map<AgencyAndId, List<RouteEntryImpl>> routesByKey = new HashMap<AgencyAndId, List<RouteEntryImpl>>();
    for (RouteEntryImpl routeEntry : graph.getRoutes()) {
        Route route = _gtfsDao.getRouteForId(routeEntry.getId());
        AgencyAndId key = getRouteCollectionIdForRoute(route);
        List<RouteEntryImpl> forKey = routesByKey.get(key);
        if (forKey == null) {
            forKey = new ArrayList<RouteEntryImpl>();
            routesByKey.put(key, forKey);
        }
        forKey.add(routeEntry);
    }
    for (Map.Entry<AgencyAndId, List<RouteEntryImpl>> entry : routesByKey.entrySet()) {
        AgencyAndId key = entry.getKey();
        List<RouteEntryImpl> routesForKey = entry.getValue();
        ArrayList<RouteEntry> children = new ArrayList<RouteEntry>();
        children.addAll(routesForKey);
        children.trimToSize();
        key = _uniqueService.unique(key);
        RouteCollectionEntryImpl routeCollectionEntry = new RouteCollectionEntryImpl();
        routeCollectionEntry.setId(key);
        routeCollectionEntry.setChildren(children);
        graph.putRouteCollectionEntry(routeCollectionEntry);
        for (RouteEntryImpl route : routesForKey) route.setParent(routeCollectionEntry);
    }
}
Also used : RouteEntry(org.onebusaway.transit_data_federation.services.transit_graph.RouteEntry) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RouteEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.RouteEntryImpl) RouteCollectionEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.RouteCollectionEntryImpl) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) FactoryMap(org.onebusaway.collections.FactoryMap) Route(org.onebusaway.gtfs.model.Route)

Example 63 with Route

use of org.onebusaway.gtfs.model.Route in project onebusaway-application-modules by camsys.

the class GenerateNarrativesTaskTest method testGenerateRouteNarratives.

@Test
public void testGenerateRouteNarratives() {
    RouteEntryImpl r1 = route("routeA1");
    RouteEntryImpl r2 = route("routeA2");
    RouteCollectionEntryImpl rc = routeCollection("routeA", r1, r2);
    TripEntry t1 = trip("t1");
    TripEntry t2 = trip("t2");
    TripEntry t3 = trip("t3");
    // r2's values should win out over r1's because it has more trips
    r1.setTrips(Arrays.asList(t1));
    r2.setTrips(Arrays.asList(t2, t3));
    Mockito.when(_transitGraphDao.getAllRouteCollections()).thenReturn(Arrays.asList((RouteCollectionEntry) rc));
    Route route1 = new Route();
    route1.setId(r1.getId());
    route1.setBikesAllowed(0);
    route1.setColor("#000000");
    route1.setDesc("Route One Desc");
    route1.setLongName("Route One");
    route1.setShortName("One");
    route1.setTextColor("#ff0000");
    route1.setType(3);
    route1.setUrl("http://agency.gov/route-one");
    Route route2 = new Route();
    route2.setId(r2.getId());
    route2.setBikesAllowed(1);
    route2.setColor("#0000ff");
    route2.setDesc("Route Two Desc");
    route2.setLongName("Route Two");
    route2.setShortName("Two");
    route2.setTextColor("#000000");
    route2.setType(3);
    route2.setUrl("http://agency.gov/route-two");
    Mockito.when(_gtfsDao.getRouteForId(r1.getId())).thenReturn(route1);
    Mockito.when(_gtfsDao.getRouteForId(r2.getId())).thenReturn(route2);
    _task.generateRouteNarratives(_provider);
    RouteCollectionNarrative narrative = _provider.getNarrativeForRouteCollectionId(rc.getId());
    assertEquals(route2.getColor(), narrative.getColor());
    assertEquals(route2.getDesc(), narrative.getDescription());
    assertEquals(route2.getLongName(), narrative.getLongName());
    assertEquals(route2.getShortName(), narrative.getShortName());
    assertEquals(route2.getTextColor(), narrative.getTextColor());
    assertEquals(route2.getType(), narrative.getType());
    assertEquals(route2.getUrl(), narrative.getUrl());
}
Also used : RouteCollectionEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.RouteCollectionEntryImpl) RouteEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.RouteEntryImpl) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) RouteCollectionEntry(org.onebusaway.transit_data_federation.services.transit_graph.RouteCollectionEntry) Route(org.onebusaway.gtfs.model.Route) RouteCollectionNarrative(org.onebusaway.transit_data_federation.model.narrative.RouteCollectionNarrative) Test(org.junit.Test)

Example 64 with Route

use of org.onebusaway.gtfs.model.Route in project onebusaway-application-modules by camsys.

the class BlockEntriesFactoryTest method before.

@Before
public void before() {
    _factory = new BlockEntriesFactory();
    _blockConfigFactory = Mockito.mock(BlockConfigurationEntriesFactory.class);
    _factory.setBlockConfigurationEntriesFactory(_blockConfigFactory);
    _dao = Mockito.mock(GtfsRelationalDao.class);
    _factory.setGtfsDao(_dao);
    _graph = new TransitGraphImpl();
    _route = new Route();
    _route.setId(aid("route"));
    _routeEntry = UnitTestingSupport.route("route");
    Mockito.when(_dao.getAllRoutes()).thenReturn(Arrays.asList(_route));
}
Also used : GtfsRelationalDao(org.onebusaway.gtfs.services.GtfsRelationalDao) TransitGraphImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TransitGraphImpl) Route(org.onebusaway.gtfs.model.Route) Before(org.junit.Before)

Example 65 with Route

use of org.onebusaway.gtfs.model.Route in project onebusaway-application-modules by camsys.

the class RouteEntriesFactoryTest method testProcessRoutes.

@Test
public void testProcessRoutes() {
    GtfsRelationalDao gtfsDao = Mockito.mock(GtfsRelationalDao.class);
    Agency agency = new Agency();
    agency.setId("A");
    Route routeA = new Route();
    routeA.setAgency(agency);
    routeA.setId(new AgencyAndId("A", "routeA"));
    Route routeB = new Route();
    routeB.setAgency(agency);
    routeB.setId(new AgencyAndId("A", "routeB"));
    Mockito.when(gtfsDao.getAllRoutes()).thenReturn(Arrays.asList(routeA, routeB));
    TransitGraphImpl graph = new TransitGraphImpl();
    RouteEntriesFactory factory = new RouteEntriesFactory();
    factory.setGtfsDao(gtfsDao);
    factory.setUniqueService(new UniqueServiceImpl());
    factory.processRoutes(graph);
    RouteEntryImpl routeEntryA = graph.getRouteForId(routeA.getId());
    RouteEntryImpl routeEntryB = graph.getRouteForId(routeB.getId());
    List<RouteEntry> routes = graph.getAllRoutes();
    assertEquals(2, routes.size());
    assertTrue(routes.contains(routeEntryA));
    assertTrue(routes.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) Agency(org.onebusaway.gtfs.model.Agency) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TransitGraphImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TransitGraphImpl) RouteEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.RouteEntryImpl) Route(org.onebusaway.gtfs.model.Route) Test(org.junit.Test)

Aggregations

Route (org.onebusaway.gtfs.model.Route)90 Trip (org.onebusaway.gtfs.model.Trip)52 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)46 Test (org.junit.Test)33 Stop (org.onebusaway.gtfs.model.Stop)28 Agency (org.onebusaway.gtfs.model.Agency)21 ArrayList (java.util.ArrayList)16 StopTime (org.onebusaway.gtfs.model.StopTime)14 TripPattern (org.opentripplanner.routing.edgetype.TripPattern)14 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)12 HashMap (java.util.HashMap)10 Edge (org.opentripplanner.routing.graph.Edge)8 GET (javax.ws.rs.GET)7 Path (javax.ws.rs.Path)7 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)7 TransitGraphImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TransitGraphImpl)7 List (java.util.List)6 RouteEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.RouteEntryImpl)6 TripEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl)6 Coordinate (com.vividsolutions.jts.geom.Coordinate)5