Search in sources :

Example 6 with RouteCollectionEntry

use of org.onebusaway.transit_data_federation.services.transit_graph.RouteCollectionEntry 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 7 with RouteCollectionEntry

use of org.onebusaway.transit_data_federation.services.transit_graph.RouteCollectionEntry 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 8 with RouteCollectionEntry

use of org.onebusaway.transit_data_federation.services.transit_graph.RouteCollectionEntry in project onebusaway-application-modules by camsys.

the class GenerateNarrativesTask method generateRouteNarratives.

public void generateRouteNarratives(NarrativeProviderImpl provider) {
    for (RouteCollectionEntry routeCollectionEntry : _transitGraphDao.getAllRouteCollections()) {
        List<Route> routes = new ArrayList<Route>();
        Counter<Route> tripCounts = new Counter<Route>();
        for (RouteEntry routeEntry : routeCollectionEntry.getChildren()) {
            Route route = _gtfsDao.getRouteForId(routeEntry.getId());
            routes.add(route);
            int tripCount = routeEntry.getTrips().size();
            tripCounts.increment(route, tripCount);
        }
        RouteCollectionNarrative.Builder builder = RouteCollectionNarrative.builder();
        setPropertiesOfRouteCollectionFromRoutes(routes, tripCounts, builder);
        provider.setNarrativeForRouteCollectionId(routeCollectionEntry.getId(), builder.create());
    }
}
Also used : RouteEntry(org.onebusaway.transit_data_federation.services.transit_graph.RouteEntry) Counter(org.onebusaway.collections.Counter) DoubleArrayList(cern.colt.list.DoubleArrayList) ArrayList(java.util.ArrayList) RouteCollectionEntry(org.onebusaway.transit_data_federation.services.transit_graph.RouteCollectionEntry) Route(org.onebusaway.gtfs.model.Route) ProjectedPoint(org.onebusaway.transit_data_federation.model.ProjectedPoint) RouteCollectionNarrative(org.onebusaway.transit_data_federation.model.narrative.RouteCollectionNarrative)

Example 9 with RouteCollectionEntry

use of org.onebusaway.transit_data_federation.services.transit_graph.RouteCollectionEntry in project onebusaway-application-modules by camsys.

the class GenerateRouteCollectionSearchIndexTask method buildIndex.

private void buildIndex() throws IOException, ParseException {
    IndexWriter writer = new IndexWriter(_bundle.getRouteSearchIndexPath(), new StandardAnalyzer(ENGLISH_STOP_WORDS), true, IndexWriter.MaxFieldLength.LIMITED);
    for (RouteCollectionEntry routeCollection : _transitGraphDao.getAllRouteCollections()) {
        RouteCollectionNarrative narrative = _narrativeService.getRouteCollectionForId(routeCollection.getId());
        Document document = getRouteCollectionAsDocument(routeCollection, narrative);
        writer.addDocument(document);
    }
    writer.optimize();
    writer.close();
    _refreshService.refresh(RefreshableResources.ROUTE_COLLECTION_SEARCH_DATA);
}
Also used : IndexWriter(org.apache.lucene.index.IndexWriter) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) RouteCollectionEntry(org.onebusaway.transit_data_federation.services.transit_graph.RouteCollectionEntry) Document(org.apache.lucene.document.Document) RouteCollectionNarrative(org.onebusaway.transit_data_federation.model.narrative.RouteCollectionNarrative)

Example 10 with RouteCollectionEntry

use of org.onebusaway.transit_data_federation.services.transit_graph.RouteCollectionEntry in project onebusaway-application-modules by camsys.

the class RouteCollectionEntriesFactory method groupRouteCollectionsByAgencyId.

private void groupRouteCollectionsByAgencyId(TransitGraphImpl graph) {
    Map<String, ArrayList<RouteCollectionEntry>> entriesByAgencyId = new FactoryMap<String, ArrayList<RouteCollectionEntry>>(new ArrayList<RouteCollectionEntry>());
    for (RouteCollectionEntry entry : graph.getAllRouteCollections()) {
        String agencyId = entry.getId().getAgencyId();
        entriesByAgencyId.get(agencyId).add(entry);
    }
    for (Map.Entry<String, ArrayList<RouteCollectionEntry>> entry : entriesByAgencyId.entrySet()) {
        String agencyId = entry.getKey();
        ArrayList<RouteCollectionEntry> routeCollections = entry.getValue();
        routeCollections.trimToSize();
        AgencyEntryImpl agencyEntry = graph.getAgencyForId(agencyId);
        agencyEntry.setRouteCollections(routeCollections);
    }
}
Also used : FactoryMap(org.onebusaway.collections.FactoryMap) AgencyEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.AgencyEntryImpl) ArrayList(java.util.ArrayList) RouteCollectionEntry(org.onebusaway.transit_data_federation.services.transit_graph.RouteCollectionEntry) HashMap(java.util.HashMap) Map(java.util.Map) FactoryMap(org.onebusaway.collections.FactoryMap)

Aggregations

RouteCollectionEntry (org.onebusaway.transit_data_federation.services.transit_graph.RouteCollectionEntry)14 RouteEntry (org.onebusaway.transit_data_federation.services.transit_graph.RouteEntry)7 ArrayList (java.util.ArrayList)6 Cacheable (org.onebusaway.container.cache.Cacheable)6 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)6 RouteCollectionNarrative (org.onebusaway.transit_data_federation.model.narrative.RouteCollectionNarrative)5 AgencyEntry (org.onebusaway.transit_data_federation.services.transit_graph.AgencyEntry)5 Test (org.junit.Test)4 TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)4 HashMap (java.util.HashMap)3 Route (org.onebusaway.gtfs.model.Route)3 AgencyEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.AgencyEntryImpl)3 RouteEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.RouteEntryImpl)3 StopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry)3 NoSuchAgencyServiceException (org.onebusaway.exceptions.NoSuchAgencyServiceException)2 GtfsRelationalDao (org.onebusaway.gtfs.services.GtfsRelationalDao)2 ListBean (org.onebusaway.transit_data.model.ListBean)2 UniqueServiceImpl (org.onebusaway.transit_data_federation.bundle.tasks.UniqueServiceImpl)2 RouteCollectionEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.RouteCollectionEntryImpl)2 TransitGraphImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TransitGraphImpl)2