Search in sources :

Example 1 with StopOnRoute

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

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

the class SiriSupportV2 method fillAnnotatedLineStructure.

public static boolean fillAnnotatedLineStructure(AnnotatedLineStructure annotatedLineStructure, RouteResult routeResult, Map<Filters, String> filters, DetailLevel detailLevel, long currentTime) {
    Directions directions = new Directions();
    // Set Line Value
    LineRefStructure line = new LineRefStructure();
    line.setValue(routeResult.getId());
    NaturalLanguageStringStructure lineName = new NaturalLanguageStringStructure();
    lineName.setValue(routeResult.getShortName());
    // DETAIL - minimum: Return only the name and identifier of stops
    // ideally, this would return only stops with scheduled service
    annotatedLineStructure.setLineRef(line);
    annotatedLineStructure.getLineName().add(lineName);
    annotatedLineStructure.setDirections(directions);
    annotatedLineStructure.setMonitored(true);
    // Loop through Direction Ids
    for (RouteDirection direction : routeResult.getDirections()) {
        // Check for existing stops in direction
        if (direction == null | direction.getStops().size() == 0)
            continue;
        String directionId = direction.getDirectionId();
        // Journey patterns - holds stop points for direction
        JourneyPattern pattern = new JourneyPattern();
        JourneyPatterns patterns = new JourneyPatterns();
        // Directions
        DirectionRefStructure dirRefStructure = new DirectionRefStructure();
        dirRefStructure.setValue(directionId);
        RouteDirectionStructure routeDirectionStructure = new RouteDirectionStructure();
        NaturalLanguageStringStructure directionName = new NaturalLanguageStringStructure();
        directionName.setValue(direction.getDestination());
        routeDirectionStructure.getDirectionName().add(directionName);
        directions.getDirection().add(routeDirectionStructure);
        // Destination
        Destinations destinations = new Destinations();
        AnnotatedDestinationStructure annotatedDest = new AnnotatedDestinationStructure();
        DestinationRefStructure destRef = new DestinationRefStructure();
        destRef.setValue(direction.getDestination());
        annotatedDest.setDestinationRef(destRef);
        destinations.getDestination().add(annotatedDest);
        // Stops
        StopsInPattern stopsInPattern = new StopsInPattern();
        List<StopOnRoute> scheduledStops = new ArrayList<StopOnRoute>();
        List<StopOnRoute> allStops = new ArrayList<StopOnRoute>();
        // Categorize by Scheduled and Unscheduled Stops
        for (StopOnRoute stop : direction.getStops()) {
            if (stop.getHasUpcomingScheduledStop() != null && stop.getHasUpcomingScheduledStop())
                scheduledStops.add(stop);
            allStops.add(stop);
        }
        if (detailLevel.equals(DetailLevel.NORMAL)) {
            for (int i = 0; i < scheduledStops.size(); i++) {
                StopOnRoute stop = direction.getStops().get(i);
                BigDecimal stopLat = new BigDecimal(stop.getLatitude());
                BigDecimal stopLon = new BigDecimal(stop.getLongitude());
                LocationStructure location = new LocationStructure();
                location.setLongitude(stopLon.setScale(6, BigDecimal.ROUND_HALF_DOWN));
                location.setLatitude(stopLat.setScale(6, BigDecimal.ROUND_HALF_DOWN));
                StopPointInPatternStructure pointInPattern = new StopPointInPatternStructure();
                pointInPattern.setLocation(location);
                pointInPattern.setOrder(BigInteger.valueOf(i));
                NaturalLanguageStringStructure stopName = new NaturalLanguageStringStructure();
                stopName.setValue(stop.getName());
                pointInPattern.getStopName().add(stopName);
                StopPointRefStructure spr = new StopPointRefStructure();
                spr.setValue(stop.getId());
                stopsInPattern.getStopPointInPattern().add(pointInPattern);
            }
        }
        if (detailLevel.equals(DetailLevel.STOPS) || detailLevel.equals(DetailLevel.FULL)) {
            for (int i = 0; i < allStops.size(); i++) {
                StopOnRoute stop = direction.getStops().get(i);
                Boolean hasUpcomingScheduledService = stop.getHasUpcomingScheduledStop();
                BigDecimal stopLat = new BigDecimal(stop.getLatitude());
                BigDecimal stopLon = new BigDecimal(stop.getLongitude());
                LocationStructure location = new LocationStructure();
                location.setLongitude(stopLon.setScale(6, BigDecimal.ROUND_HALF_DOWN));
                location.setLatitude(stopLat.setScale(6, BigDecimal.ROUND_HALF_DOWN));
                StopPointRefStructure spr = new StopPointRefStructure();
                spr.setValue(stop.getId());
                StopPointInPatternStructure pointInPattern = new StopPointInPatternStructure();
                pointInPattern.setLocation(location);
                pointInPattern.setOrder(BigInteger.valueOf(i));
                NaturalLanguageStringStructure stopName = new NaturalLanguageStringStructure();
                stopName.setValue(stop.getName());
                pointInPattern.getStopName().add(stopName);
                pointInPattern.setStopPointRef(spr);
                stopsInPattern.getStopPointInPattern().add(pointInPattern);
                // HasUpcomingService Extension
                SiriUpcomingServiceExtension upcomingService = new SiriUpcomingServiceExtension();
                upcomingService.setUpcomingScheduledService(hasUpcomingScheduledService);
                ExtensionsStructure upcomingServiceExtensions = new ExtensionsStructure();
                upcomingServiceExtensions.setAny(upcomingService);
                pointInPattern.setExtensions(upcomingServiceExtensions);
            }
        }
        String includePolylineFilter = filters.get(Filters.INCLUDE_POLYLINES);
        if (includePolylineFilter != null && passFilter("true", includePolylineFilter)) {
            // Polyline Extension
            SiriPolyLinesExtension polylines = new SiriPolyLinesExtension();
            for (String polyline : direction.getPolylines()) {
                polylines.getPolylines().add(polyline);
            }
            ExtensionsStructure PolylineExtension = new ExtensionsStructure();
            PolylineExtension.setAny(polylines);
            routeDirectionStructure.setExtensions(PolylineExtension);
        }
        routeDirectionStructure.setJourneyPatterns(patterns);
        pattern.setStopsInPattern(stopsInPattern);
        patterns.getJourneyPattern().add(pattern);
        routeDirectionStructure.setDirectionRef(dirRefStructure);
    }
    return true;
}
Also used : NaturalLanguageStringStructure(uk.org.siri.siri_2.NaturalLanguageStringStructure) DestinationRefStructure(uk.org.siri.siri_2.DestinationRefStructure) Directions(uk.org.siri.siri_2.AnnotatedLineStructure.Directions) Destinations(uk.org.siri.siri_2.AnnotatedLineStructure.Destinations) ArrayList(java.util.ArrayList) LocationStructure(uk.org.siri.siri_2.LocationStructure) ExtensionsStructure(uk.org.siri.siri_2.ExtensionsStructure) JourneyPattern(uk.org.siri.siri_2.RouteDirectionStructure.JourneyPatterns.JourneyPattern) StopPointRefStructure(uk.org.siri.siri_2.StopPointRefStructure) RouteDirection(org.onebusaway.api.actions.siri.model.RouteDirection) StopRouteDirection(org.onebusaway.api.actions.siri.model.StopRouteDirection) AnnotatedDestinationStructure(uk.org.siri.siri_2.AnnotatedDestinationStructure) SiriPolyLinesExtension(org.onebusaway.transit_data_federation.siri.SiriPolyLinesExtension) StopPointInPatternStructure(uk.org.siri.siri_2.StopPointInPatternStructure) JourneyPatterns(uk.org.siri.siri_2.RouteDirectionStructure.JourneyPatterns) LineRefStructure(uk.org.siri.siri_2.LineRefStructure) StopsInPattern(uk.org.siri.siri_2.RouteDirectionStructure.JourneyPatterns.JourneyPattern.StopsInPattern) BigDecimal(java.math.BigDecimal) RouteDirectionStructure(uk.org.siri.siri_2.RouteDirectionStructure) SiriUpcomingServiceExtension(org.onebusaway.transit_data_federation.siri.SiriUpcomingServiceExtension) DirectionRefStructure(uk.org.siri.siri_2.DirectionRefStructure) StopOnRoute(org.onebusaway.api.actions.siri.model.StopOnRoute)

Aggregations

ArrayList (java.util.ArrayList)2 RouteDirection (org.onebusaway.api.actions.siri.model.RouteDirection)2 StopOnRoute (org.onebusaway.api.actions.siri.model.StopOnRoute)2 StopRouteDirection (org.onebusaway.api.actions.siri.model.StopRouteDirection)2 BigDecimal (java.math.BigDecimal)1 HashMap (java.util.HashMap)1 RouteResult (org.onebusaway.api.actions.siri.model.RouteResult)1 EncodedPolylineBean (org.onebusaway.geospatial.model.EncodedPolylineBean)1 NameBean (org.onebusaway.transit_data.model.NameBean)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 StopsForRouteBean (org.onebusaway.transit_data.model.StopsForRouteBean)1 SiriPolyLinesExtension (org.onebusaway.transit_data_federation.siri.SiriPolyLinesExtension)1 SiriUpcomingServiceExtension (org.onebusaway.transit_data_federation.siri.SiriUpcomingServiceExtension)1 AnnotatedDestinationStructure (uk.org.siri.siri_2.AnnotatedDestinationStructure)1 Destinations (uk.org.siri.siri_2.AnnotatedLineStructure.Destinations)1 Directions (uk.org.siri.siri_2.AnnotatedLineStructure.Directions)1 DestinationRefStructure (uk.org.siri.siri_2.DestinationRefStructure)1 DirectionRefStructure (uk.org.siri.siri_2.DirectionRefStructure)1