Search in sources :

Example 11 with RouteEntryImpl

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

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

the class RouteCollectionEntriesFactory method createOneToOneRouteCollectionMapping.

private void createOneToOneRouteCollectionMapping(TransitGraphImpl graph) {
    for (RouteEntryImpl routeEntry : graph.getRoutes()) {
        RouteCollectionEntryImpl routeCollectionEntry = new RouteCollectionEntryImpl();
        routeCollectionEntry.setId(routeEntry.getId());
        ArrayList<RouteEntry> routes = new ArrayList<RouteEntry>();
        routes.add(routeEntry);
        routes.trimToSize();
        routeCollectionEntry.setChildren(routes);
        graph.putRouteCollectionEntry(routeCollectionEntry);
        routeEntry.setParent(routeCollectionEntry);
    }
}
Also used : RouteEntry(org.onebusaway.transit_data_federation.services.transit_graph.RouteEntry) RouteCollectionEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.RouteCollectionEntryImpl) ArrayList(java.util.ArrayList) RouteEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.RouteEntryImpl)

Example 13 with RouteEntryImpl

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

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

Example 15 with RouteEntryImpl

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

the class TripEntriesFactory method processTrips.

public void processTrips(TransitGraphImpl graph) {
    Collection<Route> routes = _gtfsDao.getAllRoutes();
    int routeIndex = 0;
    for (Route route : routes) {
        _log.info("route processed: " + routeIndex + "/" + routes.size());
        routeIndex++;
        List<Trip> tripsForRoute = _gtfsDao.getTripsForRoute(route);
        int tripCount = tripsForRoute.size();
        int logInterval = LoggingIntervalUtil.getAppropriateLoggingInterval(tripCount);
        _log.info("trips to process: " + tripCount);
        int tripIndex = 0;
        RouteEntryImpl routeEntry = graph.getRouteForId(route.getId());
        ArrayList<TripEntry> tripEntries = new ArrayList<TripEntry>();
        for (Trip trip : tripsForRoute) {
            tripIndex++;
            if (tripIndex % logInterval == 0)
                _log.info("trips processed: " + tripIndex + "/" + tripsForRoute.size());
            TripEntryImpl tripEntry = processTrip(graph, trip);
            if (tripEntry != null) {
                tripEntry.setRoute(routeEntry);
                tripEntries.add(tripEntry);
            }
        }
        tripEntries.trimToSize();
        routeEntry.setTrips(tripEntries);
    }
    if (_stopTimeEntriesFactory.getInvalidStopToShapeMappingExceptionCount() > 0 && _throwExceptionOnInvalidStopToShapeMappingException) {
        throw new IllegalStateException("Multiple instances of InvalidStopToShapeMappingException thrown: count=" + _stopTimeEntriesFactory.getInvalidStopToShapeMappingExceptionCount() + ".  For more information on errors of this kind, see:\n" + "  https://github.com/OneBusAway/onebusaway-application-modules/wiki/Stop-to-Shape-Matching");
    }
    graph.refreshTripMapping();
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) ArrayList(java.util.ArrayList) RouteEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.RouteEntryImpl) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) Route(org.onebusaway.gtfs.model.Route) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl)

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