Search in sources :

Example 11 with RouteCollectionEntry

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

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

the class GenerateRouteCollectionSearchIndexTaskTest method testGenerateStopSearchIndex.

@Test
public void testGenerateStopSearchIndex() throws CorruptIndexException, IOException, ParseException {
    RouteCollectionEntryImpl routeA = routeCollection("routeA");
    RouteCollectionEntryImpl routeB = routeCollection("routeB");
    RouteCollectionEntryImpl routeC = routeCollection("routeC");
    RouteCollectionNarrative.Builder routeNarrativeA = RouteCollectionNarrative.builder();
    routeNarrativeA.setShortName("10");
    routeNarrativeA.setLongName("El Diez");
    RouteCollectionNarrative.Builder routeNarrativeB = RouteCollectionNarrative.builder();
    routeNarrativeB.setShortName("11");
    routeNarrativeB.setLongName("El Once");
    RouteCollectionNarrative.Builder routeNarrativeC = RouteCollectionNarrative.builder();
    routeNarrativeC.setShortName("100");
    Mockito.when(_transitGraphDao.getAllRouteCollections()).thenReturn(Arrays.asList((RouteCollectionEntry) routeA, routeB, routeC));
    Mockito.when(_narrativeService.getRouteCollectionForId(routeA.getId())).thenReturn(routeNarrativeA.create());
    Mockito.when(_narrativeService.getRouteCollectionForId(routeB.getId())).thenReturn(routeNarrativeB.create());
    Mockito.when(_narrativeService.getRouteCollectionForId(routeC.getId())).thenReturn(routeNarrativeC.create());
    _task.run();
    Mockito.verify(_refreshService).refresh(RefreshableResources.ROUTE_COLLECTION_SEARCH_DATA);
    RouteCollectionSearchServiceImpl searchService = new RouteCollectionSearchServiceImpl();
    searchService.setBundle(_bundle);
    searchService.initialize();
    SearchResult<AgencyAndId> ids = searchService.searchForRoutesByName("10", 10, MIN_SCORE);
    assertEquals(1, ids.size());
    assertEquals(routeA.getId(), ids.getResult(0));
    ids = searchService.searchForRoutesByName("el diez", 10, MIN_SCORE);
    assertEquals(1, ids.size());
    assertEquals(routeA.getId(), ids.getResult(0));
    ids = searchService.searchForRoutesByName("diez", 10, MIN_SCORE);
    assertEquals(1, ids.size());
    assertEquals(routeA.getId(), ids.getResult(0));
    ids = searchService.searchForRoutesByName("11", 10, MIN_SCORE);
    assertEquals(1, ids.size());
    assertEquals(routeB.getId(), ids.getResult(0));
    ids = searchService.searchForRoutesByName("100", 10, MIN_SCORE);
    assertEquals(1, ids.size());
    assertEquals(routeC.getId(), ids.getResult(0));
}
Also used : RouteCollectionEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.RouteCollectionEntryImpl) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) RouteCollectionEntry(org.onebusaway.transit_data_federation.services.transit_graph.RouteCollectionEntry) RouteCollectionSearchServiceImpl(org.onebusaway.transit_data_federation.impl.RouteCollectionSearchServiceImpl) RouteCollectionNarrative(org.onebusaway.transit_data_federation.model.narrative.RouteCollectionNarrative) Test(org.junit.Test)

Example 13 with RouteCollectionEntry

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

the class AgencyServiceImpl method getAgencyIdsAndCenterPoints.

@Cacheable
public Map<String, CoordinatePoint> getAgencyIdsAndCenterPoints() {
    Map<String, CoordinatePoint> centersByAgencyId = new HashMap<String, CoordinatePoint>();
    for (AgencyEntry agency : _graph.getAllAgencies()) {
        StopsCenterOfMass centerOfMass = new StopsCenterOfMass();
        for (RouteCollectionEntry routeCollection : agency.getRouteCollections()) {
            for (RouteEntry route : routeCollection.getChildren()) {
                for (TripEntry trip : route.getTrips()) {
                    for (StopTimeEntry stopTime : trip.getStopTimes()) {
                        StopEntry stop = stopTime.getStop();
                        centerOfMass.lats += stop.getStopLat();
                        centerOfMass.lons += stop.getStopLon();
                        centerOfMass.count++;
                    }
                }
            }
        }
        if (centerOfMass.count == 0) {
            _log.warn("Agency has no service: " + agency);
        } else {
            double lat = centerOfMass.lats / centerOfMass.count;
            double lon = centerOfMass.lons / centerOfMass.count;
            centersByAgencyId.put(agency.getId(), new CoordinatePoint(lat, lon));
        }
    }
    return centersByAgencyId;
}
Also used : CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) RouteEntry(org.onebusaway.transit_data_federation.services.transit_graph.RouteEntry) HashMap(java.util.HashMap) StopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) RouteCollectionEntry(org.onebusaway.transit_data_federation.services.transit_graph.RouteCollectionEntry) AgencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.AgencyEntry) Cacheable(org.onebusaway.container.cache.Cacheable)

Example 14 with RouteCollectionEntry

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

the class RoutesBeanServiceImpl method getRouteIdsForAgencyId.

@Cacheable
@Override
public ListBean<String> getRouteIdsForAgencyId(String agencyId) {
    AgencyEntry agency = _graphDao.getAgencyForId(agencyId);
    if (agency == null)
        throw new NoSuchAgencyServiceException(agencyId);
    List<String> ids = new ArrayList<String>();
    for (RouteCollectionEntry routeCollection : agency.getRouteCollections()) {
        AgencyAndId id = routeCollection.getId();
        ids.add(AgencyAndIdLibrary.convertToString(id));
    }
    return new ListBean<String>(ids, false);
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) NoSuchAgencyServiceException(org.onebusaway.exceptions.NoSuchAgencyServiceException) ArrayList(java.util.ArrayList) ListBean(org.onebusaway.transit_data.model.ListBean) RouteCollectionEntry(org.onebusaway.transit_data_federation.services.transit_graph.RouteCollectionEntry) AgencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.AgencyEntry) Cacheable(org.onebusaway.container.cache.Cacheable)

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