Search in sources :

Example 6 with EncodedPolylineBean

use of org.onebusaway.geospatial.model.EncodedPolylineBean in project onebusaway-application-modules by camsys.

the class RouteBeanServiceImplTest method testGetStopsForRoute.

@Test
public void testGetStopsForRoute() {
    AgencyAndId routeId = new AgencyAndId("1", "route");
    RouteEntryImpl route = new RouteEntryImpl();
    route.setId(new AgencyAndId("1", "raw_route"));
    List<RouteEntry> routes = Arrays.asList((RouteEntry) route);
    RouteCollectionEntryImpl routeCollection = new RouteCollectionEntryImpl();
    routeCollection.setId(routeId);
    routeCollection.setChildren(routes);
    route.setParent(routeCollection);
    Mockito.when(_transitGraphDao.getRouteCollectionForId(routeId)).thenReturn(routeCollection);
    RouteCollectionNarrative.Builder rcNarrative = RouteCollectionNarrative.builder();
    Mockito.when(_narrativeService.getRouteCollectionForId(routeId)).thenReturn(rcNarrative.create());
    StopEntryImpl stopA = stop("stopA", 47.0, -122.0);
    StopEntryImpl stopB = stop("stopB", 47.1, -122.1);
    StopEntryImpl stopC = stop("stopC", 47.2, -122.2);
    BlockEntryImpl blockA = block("blockA");
    TripEntryImpl tripA = trip("tripA", "sidA");
    TripEntryImpl tripB = trip("tripB", "sidA");
    tripA.setRoute(route);
    tripA.setDirectionId("0");
    tripB.setRoute(route);
    tripB.setDirectionId("1");
    route.setTrips(Arrays.asList((TripEntry) tripA, tripB));
    TripNarrative.Builder tnA = TripNarrative.builder();
    tnA.setTripHeadsign("Destination A");
    Mockito.when(_narrativeService.getTripForId(tripA.getId())).thenReturn(tnA.create());
    TripNarrative.Builder tnB = TripNarrative.builder();
    tnB.setTripHeadsign("Destination B");
    Mockito.when(_narrativeService.getTripForId(tripB.getId())).thenReturn(tnB.create());
    stopTime(0, stopA, tripA, time(9, 00), time(9, 00), 0);
    stopTime(1, stopB, tripA, time(9, 30), time(9, 30), 100);
    stopTime(2, stopC, tripA, time(10, 00), time(10, 00), 200);
    stopTime(3, stopC, tripB, time(11, 30), time(11, 30), 0);
    stopTime(4, stopA, tripB, time(12, 30), time(12, 30), 200);
    linkBlockTrips(blockA, tripA, tripB);
    List<BlockTripIndex> blockIndices = blockTripIndices(blockA);
    Mockito.when(_blockIndexService.getBlockTripIndicesForRouteCollectionId(routeId)).thenReturn(blockIndices);
    StopBean stopBeanA = getStopBean(stopA);
    StopBean stopBeanB = getStopBean(stopB);
    StopBean stopBeanC = getStopBean(stopC);
    List<AgencyAndId> stopIds = Arrays.asList(stopA.getId(), stopB.getId(), stopC.getId());
    Mockito.when(_routeService.getStopsForRouteCollection(routeId)).thenReturn(stopIds);
    Mockito.when(_stopBeanService.getStopForId(stopA.getId())).thenReturn(stopBeanA);
    Mockito.when(_stopBeanService.getStopForId(stopB.getId())).thenReturn(stopBeanB);
    Mockito.when(_stopBeanService.getStopForId(stopC.getId())).thenReturn(stopBeanC);
    AgencyAndId shapeId = new AgencyAndId("1", "shapeId");
    Set<AgencyAndId> shapeIds = new HashSet<AgencyAndId>();
    shapeIds.add(shapeId);
    tripA.setShapeId(shapeId);
    EncodedPolylineBean polyline = new EncodedPolylineBean();
    Mockito.when(_shapeBeanService.getMergedPolylinesForShapeIds(shapeIds)).thenReturn(Arrays.asList(polyline));
    // Setup complete
    StopsForRouteBean stopsForRoute = _service.getStopsForRoute(routeId);
    List<StopBean> stops = stopsForRoute.getStops();
    assertEquals(3, stops.size());
    assertSame(stopBeanA, stops.get(0));
    assertSame(stopBeanB, stops.get(1));
    assertSame(stopBeanC, stops.get(2));
    List<EncodedPolylineBean> polylines = stopsForRoute.getPolylines();
    assertEquals(1, polylines.size());
    assertSame(polyline, polylines.get(0));
    List<StopGroupingBean> groupings = stopsForRoute.getStopGroupings();
    assertEquals(1, groupings.size());
    StopGroupingBean grouping = groupings.get(0);
    assertEquals("direction", grouping.getType());
    List<StopGroupBean> groups = grouping.getStopGroups();
    assertEquals(2, groups.size());
    StopGroupBean groupA = groups.get(0);
    StopGroupBean groupB = groups.get(1);
    NameBean nameA = groupA.getName();
    assertEquals("destination", nameA.getType());
    assertEquals("Destination A", nameA.getName());
    List<String> stopIdsA = groupA.getStopIds();
    assertEquals(3, stopIdsA.size());
    assertEquals(ids(stopA.getId(), stopB.getId(), stopC.getId()), stopIdsA);
    NameBean nameB = groupB.getName();
    assertEquals("destination", nameB.getType());
    assertEquals("Destination B", nameB.getName());
    List<String> stopIdsB = groupB.getStopIds();
    assertEquals(2, stopIdsB.size());
    assertEquals(ids(stopC.getId(), stopA.getId()), stopIdsB);
}
Also used : RouteEntry(org.onebusaway.transit_data_federation.services.transit_graph.RouteEntry) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) StopGroupBean(org.onebusaway.transit_data.model.StopGroupBean) RouteEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.RouteEntryImpl) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl) EncodedPolylineBean(org.onebusaway.geospatial.model.EncodedPolylineBean) BlockTripIndex(org.onebusaway.transit_data_federation.services.blocks.BlockTripIndex) HashSet(java.util.HashSet) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) RouteCollectionNarrative(org.onebusaway.transit_data_federation.model.narrative.RouteCollectionNarrative) StopEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl) RouteCollectionEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.RouteCollectionEntryImpl) StopGroupingBean(org.onebusaway.transit_data.model.StopGroupingBean) StopBean(org.onebusaway.transit_data.model.StopBean) BlockEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl) NameBean(org.onebusaway.transit_data.model.NameBean) TripNarrative(org.onebusaway.transit_data_federation.model.narrative.TripNarrative) Test(org.junit.Test)

Example 7 with EncodedPolylineBean

use of org.onebusaway.geospatial.model.EncodedPolylineBean in project onebusaway-application-modules by camsys.

the class PolylineEncoderTest method test4.

@Test
public void test4() {
    double[] lat = { 47.3, 47.67839087880088, 47.67845871865856, 47.682076843204875, 47.4 };
    double[] lon = { -122.3, -122.27878118907307, -122.27342376951559, -122.2735240417865, -122.4 };
    String expected = "}d_bHlqiiVKo`@sUR";
    EncodedPolylineBean actual = PolylineEncoder.createEncodings(lat, lon, 1, 3, 0);
    Assert.assertEquals(expected, actual.getPoints());
}
Also used : EncodedPolylineBean(org.onebusaway.geospatial.model.EncodedPolylineBean) Test(org.junit.Test)

Example 8 with EncodedPolylineBean

use of org.onebusaway.geospatial.model.EncodedPolylineBean in project onebusaway-application-modules by camsys.

the class PolylineEncoderTest method testEncoder.

@Test
public void testEncoder() {
    List<CoordinatePoint> points = new ArrayList<CoordinatePoint>();
    points.add(new CoordinatePoint(38.5, -120.2));
    points.add(new CoordinatePoint(40.7, -120.95));
    points.add(new CoordinatePoint(43.252, -126.453));
    String expected = "_p~iF~ps|U_ulLnnqC_mqNvxq`@";
    EncodedPolylineBean actual = PolylineEncoder.createEncodings(points, 0);
    Assert.assertEquals(expected, actual.getPoints());
    List<CoordinatePoint> decodedPoints = PolylineEncoder.decode(actual);
    GeospatialTestSupport.assertEqualsPointLists(points, decodedPoints, 1e-5);
}
Also used : CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) ArrayList(java.util.ArrayList) EncodedPolylineBean(org.onebusaway.geospatial.model.EncodedPolylineBean) Test(org.junit.Test)

Example 9 with EncodedPolylineBean

use of org.onebusaway.geospatial.model.EncodedPolylineBean in project onebusaway-application-modules by camsys.

the class PolylineEncoder method createEncodings.

/**
 * If level < 0, then {@link EncodedPolylineBean#getLevels()} will be null.
 *
 * @param points
 * @param level
 * @return
 */
public static EncodedPolylineBean createEncodings(Iterable<CoordinatePoint> points, int level) {
    StringBuilder encodedPoints = new StringBuilder();
    StringBuilder encodedLevels = new StringBuilder();
    int plat = 0;
    int plng = 0;
    int count = 0;
    for (CoordinatePoint trackpoint : points) {
        int late5 = floor1e5(trackpoint.getLat());
        int lnge5 = floor1e5(trackpoint.getLon());
        int dlat = late5 - plat;
        int dlng = lnge5 - plng;
        plat = late5;
        plng = lnge5;
        encodedPoints.append(encodeSignedNumber(dlat)).append(encodeSignedNumber(dlng));
        if (level >= 0)
            encodedLevels.append(encodeNumber(level));
        count++;
    }
    String pointsString = encodedPoints.toString();
    String levelsString = level >= 0 ? encodedLevels.toString() : null;
    return new EncodedPolylineBean(pointsString, levelsString, count);
}
Also used : CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) EncodedPolylineBean(org.onebusaway.geospatial.model.EncodedPolylineBean) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint)

Example 10 with EncodedPolylineBean

use of org.onebusaway.geospatial.model.EncodedPolylineBean in project onebusaway-application-modules by camsys.

the class SearchResultFactoryImpl method getStopResult.

@Override
public SearchResult getStopResult(StopBean stopBean, Set<RouteBean> routeFilter) {
    List<RouteAtStop> routesAtStop = new ArrayList<RouteAtStop>();
    for (RouteBean routeBean : stopBean.getRoutes()) {
        StopsForRouteBean stopsForRoute = _transitDataService.getStopsForRoute(routeBean.getId());
        List<RouteDirection> directions = new ArrayList<RouteDirection>();
        List<StopGroupingBean> stopGroupings = stopsForRoute.getStopGroupings();
        for (StopGroupingBean stopGroupingBean : stopGroupings) {
            for (StopGroupBean stopGroupBean : stopGroupingBean.getStopGroups()) {
                NameBean name = stopGroupBean.getName();
                String type = name.getType();
                if (!type.equals("destination"))
                    continue;
                List<String> polylines = new ArrayList<String>();
                for (EncodedPolylineBean polyline : stopGroupBean.getPolylines()) {
                    polylines.add(polyline.getPoints());
                }
                Boolean hasUpcomingScheduledService = null;
                // We do this to prevent checking if there is service in a direction that does not even serve this stop.
                if (stopGroupBean.getStopIds().contains(stopBean.getId())) {
                    hasUpcomingScheduledService = _transitDataService.stopHasUpcomingScheduledService((routeBean.getAgency() != null ? routeBean.getAgency().getId() : null), SystemTime.currentTimeMillis(), stopBean.getId(), routeBean.getId(), stopGroupBean.getId());
                    // if there are buses on route, always have "scheduled service"
                    Boolean routeHasVehiclesInService = _realtimeService.getVehiclesInServiceForStopAndRoute(stopBean.getId(), routeBean.getId(), SystemTime.currentTimeMillis());
                    if (routeHasVehiclesInService) {
                        hasUpcomingScheduledService = true;
                    }
                }
                directions.add(new RouteDirection(stopGroupBean, polylines, null, hasUpcomingScheduledService));
            }
        }
        RouteAtStop routeAtStop = new RouteAtStop(routeBean, directions);
        routesAtStop.add(routeAtStop);
    }
    return new StopResult(stopBean, routesAtStop);
}
Also used : RouteDirection(org.onebusaway.enterprise.webapp.actions.api.model.RouteDirection) StopGroupBean(org.onebusaway.transit_data.model.StopGroupBean) ArrayList(java.util.ArrayList) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) RouteAtStop(org.onebusaway.enterprise.webapp.actions.api.model.RouteAtStop) RouteBean(org.onebusaway.transit_data.model.RouteBean) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) StopGroupingBean(org.onebusaway.transit_data.model.StopGroupingBean) NameBean(org.onebusaway.transit_data.model.NameBean) EncodedPolylineBean(org.onebusaway.geospatial.model.EncodedPolylineBean) StopResult(org.onebusaway.enterprise.webapp.actions.api.model.StopResult)

Aggregations

EncodedPolylineBean (org.onebusaway.geospatial.model.EncodedPolylineBean)15 ArrayList (java.util.ArrayList)9 StopGroupBean (org.onebusaway.transit_data.model.StopGroupBean)7 StopGroupingBean (org.onebusaway.transit_data.model.StopGroupingBean)7 StopsForRouteBean (org.onebusaway.transit_data.model.StopsForRouteBean)7 NameBean (org.onebusaway.transit_data.model.NameBean)6 Test (org.junit.Test)5 CoordinatePoint (org.onebusaway.geospatial.model.CoordinatePoint)5 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)4 StopBean (org.onebusaway.transit_data.model.StopBean)3 HashSet (java.util.HashSet)2 RouteDirection (org.onebusaway.enterprise.webapp.actions.api.model.RouteDirection)2 RouteBean (org.onebusaway.transit_data.model.RouteBean)2 BlockTripIndex (org.onebusaway.transit_data_federation.services.blocks.BlockTripIndex)2 HashMap (java.util.HashMap)1 RouteDirection (org.onebusaway.api.actions.siri.model.RouteDirection)1 RouteResult (org.onebusaway.api.actions.siri.model.RouteResult)1 StopOnRoute (org.onebusaway.api.actions.siri.model.StopOnRoute)1 StopRouteDirection (org.onebusaway.api.actions.siri.model.StopRouteDirection)1 BeanFactoryV2 (org.onebusaway.api.model.transit.BeanFactoryV2)1