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));
}
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));
}
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());
}
}
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);
}
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);
}
}
Aggregations