Search in sources :

Example 1 with StopsForRouteBean

use of org.onebusaway.transit_data.model.StopsForRouteBean in project onebusaway-application-modules by camsys.

the class RouteConfigAction method getModel.

@Override
public Body<Route> getModel() {
    Body<Route> body = new Body<Route>();
    if (isValid(body)) {
        List<String> agencyIds = processAgencyIds(agencyId);
        List<AgencyAndId> routeIds = new ArrayList<AgencyAndId>();
        List<RouteBean> routeBeans = new ArrayList<RouteBean>();
        int routes_count = 1;
        if (processRouteIds(routeId, routeIds, agencyIds, body)) {
            for (AgencyAndId routeId : routeIds) {
                routeBeans.add(_transitDataService.getRouteForId(routeId.toString()));
            }
        } else if (routeId == null) {
            routeBeans = _transitDataService.getRoutesForAgencyId(agencyId).getList();
        }
        Collections.sort(routeBeans, new Comparator<RouteBean>() {

            AlphanumComparator alphaComparator = new AlphanumComparator();

            public int compare(RouteBean arg0, RouteBean arg1) {
                return alphaComparator.compare(arg0.getId(), arg1.getId());
            }
        });
        for (RouteBean routeBean : routeBeans) {
            // Limit Number of Routes Returned
            if (routes_count > MAX_ROUTES)
                break;
            Route route = new Route();
            route.setTag(getIdNoAgency(routeBean.getId()));
            route.setTitle(route.getTag() + " " + routeBean.getLongName());
            route.setShortTitle(routeBean.getShortName());
            route.setColor(routeBean.getColor());
            route.setOppositeColor(routeBean.getTextColor());
            StopsForRouteBean stopsForRoute = _transitDataService.getStopsForRoute(routeBean.getId());
            // Stops
            for (StopBean stopBean : stopsForRoute.getStops()) {
                Stop stop = new Stop();
                stop.setTag(getIdNoAgency(stopBean.getId()));
                stop.setTitle(stopBean.getName());
                stop.setLat(stopBean.getLat());
                stop.setLon(stopBean.getLon());
                stop.setStopId(stopBean.getCode());
                route.getStops().add(stop);
            }
            // Directions
            for (StopGroupingBean stopGroupingBean : stopsForRoute.getStopGroupings()) {
                for (StopGroupBean stopGroupBean : stopGroupingBean.getStopGroups()) {
                    Direction direction = new Direction();
                    direction.setTag(stopGroupBean.getId());
                    direction.setTitle(stopGroupBean.getName().getName());
                    for (String stopId : stopGroupBean.getStopIds()) {
                        direction.getStops().add(new DisplayStop(getIdNoAgency(stopId)));
                    }
                    route.getDirections().add(direction);
                }
            }
            // PolyLines
            for (EncodedPolylineBean polyline : stopsForRoute.getPolylines()) {
                Path path = new Path();
                List<CoordinatePoint> coordinatePoints = PolylineEncoder.decode(polyline);
                for (CoordinatePoint coordinatePoint : coordinatePoints) {
                    path.getPoints().add(new Point(coordinatePoint.getLat(), coordinatePoint.getLon()));
                }
                route.getPaths().add(path);
            }
            body.getResponse().add(route);
            routes_count++;
        }
    }
    return body;
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) DisplayStop(org.onebusaway.nextbus.model.nextbus.DisplayStop) Stop(org.onebusaway.nextbus.model.nextbus.Stop) StopGroupBean(org.onebusaway.transit_data.model.StopGroupBean) ArrayList(java.util.ArrayList) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) Direction(org.onebusaway.nextbus.model.nextbus.Direction) RouteBean(org.onebusaway.transit_data.model.RouteBean) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) DisplayStop(org.onebusaway.nextbus.model.nextbus.DisplayStop) EncodedPolylineBean(org.onebusaway.geospatial.model.EncodedPolylineBean) Body(org.onebusaway.nextbus.model.nextbus.Body) Route(org.onebusaway.nextbus.model.nextbus.Route) DisplayRoute(org.onebusaway.nextbus.model.nextbus.DisplayRoute) Path(org.onebusaway.nextbus.model.nextbus.Path) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) Point(org.onebusaway.nextbus.model.nextbus.Point) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) Point(org.onebusaway.nextbus.model.nextbus.Point) StopGroupingBean(org.onebusaway.transit_data.model.StopGroupingBean) AlphanumComparator(org.onebusaway.util.comparators.AlphanumComparator) StopBean(org.onebusaway.transit_data.model.StopBean)

Example 2 with StopsForRouteBean

use of org.onebusaway.transit_data.model.StopsForRouteBean in project onebusaway-application-modules by camsys.

the class RealtimeServiceV2Impl method getAnnotatedStopPointStructures.

@Override
public Map<Boolean, List<AnnotatedStopPointStructure>> getAnnotatedStopPointStructures(List<String> agencyIds, List<AgencyAndId> routeIds, DetailLevel detailLevel, long currentTime, Map<Filters, String> filters) {
    // Cache stops by route so we don't need to call the transit data service repeatedly for the same route
    Map<String, StopsForRouteBean> stopsForRouteCache = new HashMap<String, StopsForRouteBean>();
    // Store processed StopBean as AnnotatedStopPointStructure
    List<AnnotatedStopPointStructure> annotatedStopPoints = new ArrayList<AnnotatedStopPointStructure>();
    // AnnotatedStopPointStructures List with hasUpcomingScheduledService
    Map<Boolean, List<AnnotatedStopPointStructure>> output = new HashMap<Boolean, List<AnnotatedStopPointStructure>>();
    String upcomingScheduledService = filters.get(Filters.UPCOMING_SCHEDULED_SERVICE);
    Boolean upcomingServiceAllStops = true;
    if (upcomingScheduledService != null && upcomingScheduledService.trim().equalsIgnoreCase("false")) {
        upcomingServiceAllStops = false;
    }
    for (AgencyAndId aid : routeIds) {
        String routeId = AgencyAndId.convertToString(aid);
        StopsForRouteBean stopsForLineRef = _transitDataService.getStopsForRoute(routeId);
        processAnnotatedStopPoints(agencyIds, routeIds, stopsForLineRef.getStops(), annotatedStopPoints, filters, stopsForRouteCache, detailLevel, currentTime);
    }
    output.put(upcomingServiceAllStops, annotatedStopPoints);
    return output;
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) HashMap(java.util.HashMap) AnnotatedStopPointStructure(uk.org.siri.siri_2.AnnotatedStopPointStructure) ArrayList(java.util.ArrayList) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) List(java.util.List) ArrayList(java.util.ArrayList)

Example 3 with StopsForRouteBean

use of org.onebusaway.transit_data.model.StopsForRouteBean in project onebusaway-application-modules by camsys.

the class RealtimeServiceV2Impl method getRouteResult.

private RouteResult getRouteResult(RouteBean routeBean, Map<Filters, String> filters) {
    List<RouteDirection> directions = new ArrayList<RouteDirection>();
    StopsForRouteBean stopsForRoute = _transitDataService.getStopsForRoute(routeBean.getId());
    // Filter Values
    String directionIdFilter = filters.get(Filters.DIRECTION_REF);
    String upcomingScheduledServiceFilter = filters.get(Filters.UPCOMING_SCHEDULED_SERVICE);
    // create stop ID->stop bean map
    Map<String, StopBean> stopIdToStopBeanMap = new HashMap<String, StopBean>();
    for (StopBean stopBean : stopsForRoute.getStops()) {
        stopIdToStopBeanMap.put(stopBean.getId(), stopBean);
    }
    List<StopGroupingBean> stopGroupings = stopsForRoute.getStopGroupings();
    for (StopGroupingBean stopGroupingBean : stopGroupings) {
        for (StopGroupBean stopGroupBean : stopGroupingBean.getStopGroups()) {
            NameBean name = stopGroupBean.getName();
            String type = name.getType();
            String directionId = stopGroupBean.getId();
            // Destination and DirectionId Filter
            if (!type.equals("destination") || !SiriSupportV2.passFilter(directionId, directionIdFilter))
                continue;
            List<String> polylines = new ArrayList<String>();
            for (EncodedPolylineBean polyline : stopGroupBean.getPolylines()) {
                polylines.add(polyline.getPoints());
            }
            // TODO - Re-evaluate the best method to determine upcoming scheduled service
            Boolean routeHasUpcomingScheduledService = _transitDataService.routeHasUpcomingScheduledService((routeBean.getAgency() != null ? routeBean.getAgency().getId() : null), SystemTime.currentTimeMillis(), routeBean.getId(), directionId);
            // if there are buses on route, always have "scheduled service"
            Boolean routeHasVehiclesInService = getVehiclesInServiceForRoute(routeBean.getId(), directionId, SystemTime.currentTimeMillis());
            if (routeHasVehiclesInService) {
                routeHasUpcomingScheduledService = true;
            }
            String hasUpcomingScheduledServiceVal = String.valueOf(routeHasUpcomingScheduledService);
            // String hasUpcomingScheduledServiceVal = String.valueOf(routeHasVehiclesInService);
            if (!SiriSupportV2.passFilter(hasUpcomingScheduledServiceVal, upcomingScheduledServiceFilter) || routeHasUpcomingScheduledService == null || !routeHasUpcomingScheduledService)
                continue;
            // stops in this direction
            List<StopOnRoute> stopsOnRoute = null;
            if (!stopGroupBean.getStopIds().isEmpty()) {
                stopsOnRoute = new ArrayList<StopOnRoute>();
                for (String stopId : stopGroupBean.getStopIds()) {
                    // service in this direction
                    StopBean stopBean = stopIdToStopBeanMap.get(stopId);
                    Boolean stopHasUpcomingScheduledService = _transitDataService.stopHasUpcomingScheduledService((routeBean.getAgency() != null ? routeBean.getAgency().getId() : null), SystemTime.currentTimeMillis(), stopBean.getId(), routeBean.getId(), stopGroupBean.getId());
                    stopsOnRoute.add(new StopOnRoute(stopBean, stopHasUpcomingScheduledService));
                }
            }
            directions.add(new RouteDirection(stopGroupBean, polylines, stopsOnRoute, routeHasUpcomingScheduledService));
        }
    }
    return new RouteResult(routeBean, directions);
}
Also used : RouteDirection(org.onebusaway.api.actions.siri.model.RouteDirection) StopRouteDirection(org.onebusaway.api.actions.siri.model.StopRouteDirection) HashMap(java.util.HashMap) StopGroupBean(org.onebusaway.transit_data.model.StopGroupBean) ArrayList(java.util.ArrayList) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) StopGroupingBean(org.onebusaway.transit_data.model.StopGroupingBean) RouteResult(org.onebusaway.api.actions.siri.model.RouteResult) StopBean(org.onebusaway.transit_data.model.StopBean) NameBean(org.onebusaway.transit_data.model.NameBean) EncodedPolylineBean(org.onebusaway.geospatial.model.EncodedPolylineBean) StopOnRoute(org.onebusaway.api.actions.siri.model.StopOnRoute)

Example 4 with StopsForRouteBean

use of org.onebusaway.transit_data.model.StopsForRouteBean in project onebusaway-application-modules by camsys.

the class RealtimeServiceV2Impl method processAnnotatedStopPoints.

private void processAnnotatedStopPoints(List<String> agencyIds, List<AgencyAndId> routeIds, List<StopBean> stopBeans, List<AnnotatedStopPointStructure> annotatedStopPoints, Map<Filters, String> filters, Map<String, StopsForRouteBean> stopsForRouteCache, DetailLevel detailLevel, long currentTime) {
    for (StopBean stopBean : stopBeans) {
        List<StopsForRouteBean> stopsForRouteList = new ArrayList<StopsForRouteBean>();
        boolean filterByLineRef = (routeIds != null && routeIds.size() > 0) ? true : false;
        boolean containsLineRef = false;
        // Get a list of all the routes for the stop
        for (RouteBean route : stopBean.getRoutes()) {
            // Filter By AgencyID
            if (route.getAgency() == null || !agencyIds.contains(route.getAgency().getId()))
                continue;
            // Add list of stops retreived from route to cache
            StopsForRouteBean stopsForRoute = stopsForRouteCache.get(route.getId());
            if (stopsForRoute == null) {
                stopsForRoute = _transitDataService.getStopsForRoute(route.getId());
                stopsForRouteCache.put(route.getId(), stopsForRoute);
            }
            if (stopsForRoute != null)
                stopsForRouteList.add(stopsForRoute);
            if (filterByLineRef && routeIds.contains(AgencyAndIdLibrary.convertFromString(route.getId())))
                containsLineRef = true;
        }
        // Filter By LineRef
        if (filterByLineRef && !containsLineRef)
            continue;
        // Get Stops with List of Routes, Direction, and Upcoming Service Info
        StopRouteDirection stopRouteDirection = getStopRouteDirection(stopBean, stopsForRouteList, filters);
        // Skip if No Route Directions Found
        if (stopRouteDirection == null)
            continue;
        // Used to filter stops that don't have any routes that match hasUpcomingScheduledStop
        if (stopRouteDirection.getRouteDirections() == null || stopRouteDirection.getRouteDirections().size() == 0)
            continue;
        AnnotatedStopPointStructure annotatedStopPoint = new AnnotatedStopPointStructure();
        boolean isValid = SiriSupportV2.fillAnnotatedStopPointStructure(annotatedStopPoint, stopRouteDirection, filters, detailLevel, currentTime);
        if (isValid)
            annotatedStopPoints.add(annotatedStopPoint);
    }
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) StopRouteDirection(org.onebusaway.api.actions.siri.model.StopRouteDirection) AnnotatedStopPointStructure(uk.org.siri.siri_2.AnnotatedStopPointStructure) ArrayList(java.util.ArrayList) StopBean(org.onebusaway.transit_data.model.StopBean) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean)

Example 5 with StopsForRouteBean

use of org.onebusaway.transit_data.model.StopsForRouteBean in project onebusaway-application-modules by camsys.

the class RealtimeServiceTest method initialize.

@Before
public void initialize() {
    // Agency Bean
    AgencyBean agency = new AgencyBean();
    agency.setId("1");
    // Route Bean
    Builder routeBuilder = RouteBean.builder();
    routeBuilder.setAgency(agency);
    routeBuilder.setId("1_100194");
    routeBean = routeBuilder.create();
    // Route Bean List
    routes = new ArrayList<RouteBean>(1);
    routes.add(routeBean);
    // Stop Bean
    stopBean = new StopBean();
    stopBean.setId("1_430");
    stopBean.setName("3rd Ave & Pine St");
    stopBean.setLon(-122.338662);
    stopBean.setLat(47.610813);
    stopBean.setRoutes(routes);
    // Stop Bean List
    stops = new ArrayList<StopBean>(1);
    stops.add(stopBean);
    // Stop Group
    stopIds = new ArrayList<String>(1);
    stopIds.add(stopBean.getId());
    stopGroupName = new NameBean("destination", "Destination");
    stopGroup = new StopGroupBean();
    stopGroup.setId("0");
    stopGroup.setStopIds(stopIds);
    stopGroup.setName(stopGroupName);
    // Stop Group List
    stopGroups = new ArrayList<StopGroupBean>(1);
    stopGroups.add(stopGroup);
    // Stop Grouping
    stopGrouping = new StopGroupingBean();
    stopGrouping.setStopGroups(stopGroups);
    // Stop Grouping List
    List<StopGroupingBean> stopGroupings = new ArrayList<StopGroupingBean>(1);
    stopGroupings.add(stopGrouping);
    // Stops For Route
    stopsForRouteBean = new StopsForRouteBean();
    stopsForRouteBean.setRoute(routeBean);
    stopsForRouteBean.setStopGroupings(stopGroupings);
    stopsForRouteBean.setStops(stops);
}
Also used : Builder(org.onebusaway.transit_data.model.RouteBean.Builder) EqualsBuilder(org.apache.commons.lang.builder.EqualsBuilder) StopGroupBean(org.onebusaway.transit_data.model.StopGroupBean) ArrayList(java.util.ArrayList) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) Matchers.anyString(org.mockito.Matchers.anyString) RouteBean(org.onebusaway.transit_data.model.RouteBean) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) StopGroupingBean(org.onebusaway.transit_data.model.StopGroupingBean) StopBean(org.onebusaway.transit_data.model.StopBean) NameBean(org.onebusaway.transit_data.model.NameBean) AgencyBean(org.onebusaway.transit_data.model.AgencyBean) Before(org.junit.Before)

Aggregations

StopsForRouteBean (org.onebusaway.transit_data.model.StopsForRouteBean)26 ArrayList (java.util.ArrayList)21 StopGroupBean (org.onebusaway.transit_data.model.StopGroupBean)21 StopGroupingBean (org.onebusaway.transit_data.model.StopGroupingBean)21 NameBean (org.onebusaway.transit_data.model.NameBean)16 StopBean (org.onebusaway.transit_data.model.StopBean)15 RouteBean (org.onebusaway.transit_data.model.RouteBean)13 HashMap (java.util.HashMap)10 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)8 EncodedPolylineBean (org.onebusaway.geospatial.model.EncodedPolylineBean)7 HashSet (java.util.HashSet)5 List (java.util.List)5 Matchers.anyString (org.mockito.Matchers.anyString)3 StopRouteDirection (org.onebusaway.api.actions.siri.model.StopRouteDirection)3 RouteDirection (org.onebusaway.enterprise.webapp.actions.api.model.RouteDirection)3 AgencyBean (org.onebusaway.transit_data.model.AgencyBean)3 AnnotatedStopPointStructure (uk.org.siri.siri_2.AnnotatedStopPointStructure)3 Map (java.util.Map)2 Before (org.junit.Before)2 RouteAtStop (org.onebusaway.enterprise.webapp.actions.api.model.RouteAtStop)2