Search in sources :

Example 1 with RouteResult

use of org.onebusaway.api.actions.siri.model.RouteResult 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 2 with RouteResult

use of org.onebusaway.api.actions.siri.model.RouteResult in project onebusaway-application-modules by camsys.

the class RealtimeServiceV2Impl method getAnnotatedLineStructures.

@Override
public Map<Boolean, List<AnnotatedLineStructure>> getAnnotatedLineStructures(List<String> agencyIds, List<AgencyAndId> routeIds, DetailLevel detailLevel, long currentTime, Map<Filters, String> filters) {
    // Store processed StopBean as AnnotatedStopPointStructure
    List<AnnotatedLineStructure> annotatedLines = new ArrayList<AnnotatedLineStructure>();
    // AnnotatedStopPointStructures List with hasUpcomingScheduledService
    Map<Boolean, List<AnnotatedLineStructure>> output = new HashMap<Boolean, List<AnnotatedLineStructure>>();
    Boolean upcomingServiceAllStops = null;
    for (AgencyAndId rteId : routeIds) {
        String routeId = AgencyAndId.convertToString(rteId);
        RouteBean routeBean = _transitDataService.getRouteForId(routeId);
        // Filter By AgencyID
        if (routeBean.getAgency() == null || !agencyIds.contains(routeBean.getAgency().getId()))
            continue;
        AnnotatedLineStructure annotatedLineStructure = new AnnotatedLineStructure();
        RouteResult routeResult = getRouteResult(routeBean, filters);
        // Skip Routes with no stops
        if (routeResult.getDirections() == null || routeResult.getDirections().size() == 0)
            continue;
        boolean isValid = SiriSupportV2.fillAnnotatedLineStructure(annotatedLineStructure, routeResult, filters, detailLevel, currentTime);
        if (isValid)
            annotatedLines.add(annotatedLineStructure);
    }
    output.put(upcomingServiceAllStops, annotatedLines);
    return output;
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) HashMap(java.util.HashMap) RouteResult(org.onebusaway.api.actions.siri.model.RouteResult) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) AnnotatedLineStructure(uk.org.siri.siri_2.AnnotatedLineStructure)

Aggregations

ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 RouteResult (org.onebusaway.api.actions.siri.model.RouteResult)2 StopsForRouteBean (org.onebusaway.transit_data.model.StopsForRouteBean)2 List (java.util.List)1 RouteDirection (org.onebusaway.api.actions.siri.model.RouteDirection)1 StopOnRoute (org.onebusaway.api.actions.siri.model.StopOnRoute)1 StopRouteDirection (org.onebusaway.api.actions.siri.model.StopRouteDirection)1 EncodedPolylineBean (org.onebusaway.geospatial.model.EncodedPolylineBean)1 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)1 NameBean (org.onebusaway.transit_data.model.NameBean)1 RouteBean (org.onebusaway.transit_data.model.RouteBean)1 StopBean (org.onebusaway.transit_data.model.StopBean)1 StopGroupBean (org.onebusaway.transit_data.model.StopGroupBean)1 StopGroupingBean (org.onebusaway.transit_data.model.StopGroupingBean)1 AnnotatedLineStructure (uk.org.siri.siri_2.AnnotatedLineStructure)1