Search in sources :

Example 1 with MonitoredVehicleJourneyStructure

use of uk.org.siri.siri_2.MonitoredVehicleJourneyStructure in project onebusaway-application-modules by camsys.

the class VehicleMonitoringV2Action method index.

public DefaultHttpHeaders index() throws IOException {
    long currentTimestamp = getTime();
    processGoogleAnalytics();
    // _monitoringActionSupport.setupGoogleAnalytics(_request, _configurationService);
    _realtimeService.setTime(currentTimestamp);
    String detailLevelParam = _request.getParameter(VEHICLE_MONITORING_DETAIL_LEVEL);
    // get the detail level parameter or set it to default if not specified
    DetailLevel detailLevel;
    if (DetailLevel.contains(detailLevelParam)) {
        detailLevel = DetailLevel.valueOf(detailLevelParam.toUpperCase());
    } else {
        detailLevel = DetailLevel.NORMAL;
    }
    // User Parameters
    String lineRef = _request.getParameter(LINE_REF);
    String vehicleRef = _request.getParameter(VEHICLE_REF);
    String directionId = _request.getParameter(DIRECTION_REF);
    String agencyId = _request.getParameter(OPERATOR_REF);
    String maxOnwardCallsParam = _request.getParameter(MAX_ONWARD_CALLS);
    String maxStopVisitsParam = _request.getParameter(MAX_STOP_VISITS);
    String minStopVisitsParam = _request.getParameter(MIN_STOP_VISITS);
    // Error Strings
    String routeIdsErrorString = "";
    /*
     * We need to support the user providing no agency id which means 'all agencies'.
    So, this array will hold a single agency if the user provides it or all
    agencies if the user provides none. We'll iterate over them later while 
    querying for vehicles and routes
    */
    List<AgencyAndId> routeIds = new ArrayList<AgencyAndId>();
    List<String> agencyIds = processAgencyIds(agencyId);
    List<AgencyAndId> vehicleIds = processVehicleIds(vehicleRef, agencyIds);
    routeIdsErrorString = processRouteIds(lineRef, routeIds, agencyIds);
    int maximumOnwardCalls = 0;
    if (detailLevel.equals(DetailLevel.CALLS)) {
        maximumOnwardCalls = SiriSupportV2.convertToNumeric(maxOnwardCallsParam, Integer.MAX_VALUE);
    }
    String gaLabel = null;
    // *** CASE 1: single vehicle, ignore any other filters
    if (vehicleIds.size() > 0) {
        gaLabel = vehicleRef;
        List<VehicleActivityStructure> activities = new ArrayList<VehicleActivityStructure>();
        try {
            for (AgencyAndId vehicleId : vehicleIds) {
                VehicleActivityStructure activity = _realtimeService.getVehicleActivityForVehicle(vehicleId.toString(), maximumOnwardCalls, detailLevel, currentTimestamp);
                if (activity != null) {
                    activities.add(activity);
                }
            }
        } catch (Exception e) {
            _log.info(e.getMessage(), e);
        }
        // No vehicle id validation, so we pass null for error
        _response = generateSiriResponse(activities, null, null, currentTimestamp);
    // *** CASE 2: by route, using direction id, if provided
    } else if (lineRef != null) {
        gaLabel = lineRef;
        List<VehicleActivityStructure> activities = new ArrayList<VehicleActivityStructure>();
        for (AgencyAndId routeId : routeIds) {
            List<VehicleActivityStructure> activitiesForRoute = _realtimeService.getVehicleActivityForRoute(routeId.toString(), directionId, maximumOnwardCalls, detailLevel, currentTimestamp);
            if (activitiesForRoute != null) {
                activities.addAll(activitiesForRoute);
            }
        }
        if (vehicleIds.size() > 0) {
            List<VehicleActivityStructure> filteredActivities = new ArrayList<VehicleActivityStructure>();
            for (VehicleActivityStructure activity : activities) {
                MonitoredVehicleJourneyStructure journey = activity.getMonitoredVehicleJourney();
                AgencyAndId thisVehicleId = AgencyAndIdLibrary.convertFromString(journey.getVehicleRef().getValue());
                // user filtering
                if (!vehicleIds.contains(thisVehicleId))
                    continue;
                filteredActivities.add(activity);
            }
            activities = filteredActivities;
        }
        Exception error = null;
        if (lineRef != null && routeIds.size() == 0) {
            error = new Exception(routeIdsErrorString.trim());
        }
        _response = generateSiriResponse(activities, routeIds, error, currentTimestamp);
    // *** CASE 3: all vehicles
    } else {
        try {
            gaLabel = "All Vehicles";
            // int hashKey = _siriCacheService.hash(maximumOnwardCalls, agencyIds, _type);
            List<VehicleActivityStructure> activities = new ArrayList<VehicleActivityStructure>();
            // if (!_siriCacheService.containsKey(hashKey)) {
            for (String agency : agencyIds) {
                ListBean<VehicleStatusBean> vehicles = _transitDataService.getAllVehiclesForAgency(agency, currentTimestamp);
                for (VehicleStatusBean v : vehicles.getList()) {
                    VehicleActivityStructure activity = _realtimeService.getVehicleActivityForVehicle(v.getVehicleId(), maximumOnwardCalls, detailLevel, currentTimestamp);
                    if (activity != null) {
                        activities.add(activity);
                    }
                }
            }
            // There is no input (route id) to validate, so pass null error
            _response = generateSiriResponse(activities, null, null, currentTimestamp);
        // _siriCacheService.store(hashKey, getVehicleMonitoring());
        // } else {
        // _cachedResponse = _siriCacheService.retrieve(hashKey);
        // }
        } catch (Exception e) {
            _log.error("vm all broke:", e);
            throw new RuntimeException(e);
        }
    }
    try {
        this._servletResponse.getWriter().write(getVehicleMonitoring());
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ArrayList(java.util.ArrayList) ListBean(org.onebusaway.transit_data.model.ListBean) IOException(java.io.IOException) IOException(java.io.IOException) VehicleStatusBean(org.onebusaway.transit_data.model.VehicleStatusBean) MonitoredVehicleJourneyStructure(uk.org.siri.siri_2.MonitoredVehicleJourneyStructure) DetailLevel(org.onebusaway.api.actions.siri.model.DetailLevel) ArrayList(java.util.ArrayList) List(java.util.List) VehicleActivityStructure(uk.org.siri.siri_2.VehicleActivityStructure)

Example 2 with MonitoredVehicleJourneyStructure

use of uk.org.siri.siri_2.MonitoredVehicleJourneyStructure in project onebusaway-application-modules by camsys.

the class SiriSupportV2 method fillMonitoredVehicleJourney.

/**
 * NOTE: The tripDetails bean here may not be for the trip the vehicle is
 * currently on in the case of A-D for stop!
 * @param filters
 */
public static void fillMonitoredVehicleJourney(MonitoredVehicleJourneyStructure monitoredVehicleJourney, TripBean framedJourneyTripBean, TripStatusBean currentVehicleTripStatus, StopBean monitoredCallStopBean, OnwardCallsMode onwardCallsMode, PresentationService presentationService, TransitDataService transitDataService, int maximumOnwardCalls, List<TimepointPredictionRecord> stopLevelPredictions, boolean hasRealtimeData, DetailLevel detailLevel, long responseTimestamp, Map<Filters, String> filters) {
    BlockInstanceBean blockInstance = transitDataService.getBlockInstance(currentVehicleTripStatus.getActiveTrip().getBlockId(), currentVehicleTripStatus.getServiceDate());
    List<BlockTripBean> blockTrips = blockInstance.getBlockConfiguration().getTrips();
    if (monitoredCallStopBean == null) {
        monitoredCallStopBean = currentVehicleTripStatus.getNextStop();
    }
    /**
     *******************************************
     */
    // Route ID
    LineRefStructure lineRef = new LineRefStructure();
    lineRef.setValue(framedJourneyTripBean.getRoute().getId());
    DirectionRefStructure directionRef = new DirectionRefStructure();
    directionRef.setValue(framedJourneyTripBean.getDirectionId());
    // Route Short Name
    NaturalLanguageStringStructure routeShortName = new NaturalLanguageStringStructure();
    String shortName = framedJourneyTripBean.getRoute().getShortName();
    if (!isBlank(currentVehicleTripStatus.getActiveTrip().getRouteShortName())) {
        // look for an override like an express desginator
        shortName = currentVehicleTripStatus.getActiveTrip().getRouteShortName();
    }
    if (shortName == null) {
        shortName = framedJourneyTripBean.getRoute().getId().split("_")[1];
    }
    routeShortName.setValue(shortName);
    // Agency Id
    OperatorRefStructure operatorRef = new OperatorRefStructure();
    operatorRef.setValue(AgencySupportLibrary.getAgencyForId(framedJourneyTripBean.getRoute().getId()));
    // Framed Journey
    FramedVehicleJourneyRefStructure framedJourney = new FramedVehicleJourneyRefStructure();
    DataFrameRefStructure dataFrame = new DataFrameRefStructure();
    dataFrame.setValue(String.format("%1$tY-%1$tm-%1$td", currentVehicleTripStatus.getServiceDate()));
    framedJourney.setDataFrameRef(dataFrame);
    framedJourney.setDatedVehicleJourneyRef(framedJourneyTripBean.getId());
    // Shape Id
    JourneyPatternRefStructure journeyPattern = new JourneyPatternRefStructure();
    journeyPattern.setValue(framedJourneyTripBean.getShapeId());
    // Destination
    NaturalLanguageStringStructure headsign = new NaturalLanguageStringStructure();
    headsign.setValue(framedJourneyTripBean.getTripHeadsign());
    // Vehicle Id
    VehicleRefStructure vehicleRef = new VehicleRefStructure();
    if (currentVehicleTripStatus.getVehicleId() == null) {
        String tripId = framedJourneyTripBean.getId();
        String blockId = framedJourneyTripBean.getBlockId();
        String directionId = framedJourneyTripBean.getDirectionId();
        String vehicleIdHash = Integer.toString((tripId + blockId + directionId).hashCode());
        String agencyName = tripId.split("_")[0];
        String vehicleId = agencyName + "_" + vehicleIdHash;
        vehicleRef.setValue(vehicleId);
    } else {
        vehicleRef.setValue(currentVehicleTripStatus.getVehicleId());
    }
    // Set Origin and Destination stops from Block trips.
    StopBean lastStop = new StopBean();
    JourneyPlaceRefStructure origin = new JourneyPlaceRefStructure();
    for (int i = 0; i < blockTrips.size(); i++) {
        BlockTripBean blockTrip = blockTrips.get(i);
        if (blockTrip.getTrip().getId().equals(framedJourneyTripBean.getId())) {
            List<BlockStopTimeBean> stops = blockTrip.getBlockStopTimes();
            origin.setValue(stops.get(0).getStopTime().getStop().getId());
            lastStop = stops.get(stops.size() - 1).getStopTime().getStop();
            break;
        }
    }
    // location
    // if vehicle is detected to be on detour, use actual lat/lon, not
    // snapped location.
    LocationStructure location = new LocationStructure();
    DecimalFormat df = new DecimalFormat();
    df.setMaximumFractionDigits(6);
    if (presentationService.isOnDetour(currentVehicleTripStatus)) {
        location.setLatitude(new BigDecimal(df.format(currentVehicleTripStatus.getLastKnownLocation().getLat())));
        location.setLongitude(new BigDecimal(df.format(currentVehicleTripStatus.getLastKnownLocation().getLon())));
    } else {
        location.setLatitude(new BigDecimal(df.format(currentVehicleTripStatus.getLocation().getLat())));
        location.setLongitude(new BigDecimal(df.format(currentVehicleTripStatus.getLocation().getLon())));
    }
    // progress status
    List<String> progressStatuses = new ArrayList<String>();
    if (presentationService.isInLayover(currentVehicleTripStatus)) {
        progressStatuses.add("layover");
    }
    // "prevTrip" really means not on the framedvehiclejourney trip
    if (!framedJourneyTripBean.getId().equals(currentVehicleTripStatus.getActiveTrip().getId())) {
        progressStatuses.add("prevTrip");
    }
    if (!progressStatuses.isEmpty()) {
        NaturalLanguageStringStructure progressStatus = new NaturalLanguageStringStructure();
        progressStatus.setValue(StringUtils.join(progressStatuses, ","));
        monitoredVehicleJourney.getProgressStatus().add(progressStatus);
    }
    // scheduled depature time
    if (presentationService.isBlockLevelInference(currentVehicleTripStatus) && (presentationService.isInLayover(currentVehicleTripStatus) || !framedJourneyTripBean.getId().equals(currentVehicleTripStatus.getActiveTrip().getId()))) {
        BlockStopTimeBean originDepartureStopTime = null;
        for (int t = 0; t < blockTrips.size(); t++) {
            BlockTripBean thisTrip = blockTrips.get(t);
            BlockTripBean nextTrip = null;
            if (t + 1 < blockTrips.size()) {
                nextTrip = blockTrips.get(t + 1);
            }
            if (thisTrip.getTrip().getId().equals(currentVehicleTripStatus.getActiveTrip().getId())) {
                // just started new trip
                if (currentVehicleTripStatus.getDistanceAlongTrip() < (0.5 * currentVehicleTripStatus.getTotalDistanceAlongTrip())) {
                    originDepartureStopTime = thisTrip.getBlockStopTimes().get(0);
                // at end of previous trip
                } else {
                    if (nextTrip != null) {
                        originDepartureStopTime = nextTrip.getBlockStopTimes().get(0);
                    }
                }
                break;
            }
        }
        if (originDepartureStopTime != null) {
            long departureTime = currentVehicleTripStatus.getServiceDate() + (originDepartureStopTime.getStopTime().getDepartureTime() * 1000);
            monitoredVehicleJourney.setOriginAimedDepartureTime(DateUtil.toXmlGregorianCalendar(departureTime));
        }
    }
    Map<String, TimepointPredictionRecord> stopIdToPredictionRecordMap = new HashMap<String, TimepointPredictionRecord>();
    // (build map of stop IDs to TPRs)
    if (stopLevelPredictions != null) {
        for (TimepointPredictionRecord tpr : stopLevelPredictions) {
            stopIdToPredictionRecordMap.put(AgencyAndId.convertToString(tpr.getTimepointId()), tpr);
        }
    }
    // monitored call
    if (!presentationService.isOnDetour(currentVehicleTripStatus))
        fillMonitoredCall(monitoredVehicleJourney, blockInstance, currentVehicleTripStatus, monitoredCallStopBean, presentationService, transitDataService, stopIdToPredictionRecordMap, hasRealtimeData, detailLevel, responseTimestamp);
    // detail level - minimal
    if (detailLevel.equals(DetailLevel.MINIMUM) || detailLevel.equals(DetailLevel.BASIC) || detailLevel.equals(DetailLevel.NORMAL) || detailLevel.equals(DetailLevel.CALLS)) {
        monitoredVehicleJourney.getPublishedLineName().add(routeShortName);
        monitoredVehicleJourney.getDestinationName().add(headsign);
        monitoredVehicleJourney.setMonitored(currentVehicleTripStatus.isPredicted());
        monitoredVehicleJourney.getVehicleMode().add(toVehicleMode(currentVehicleTripStatus.getVehicleType()));
        monitoredVehicleJourney.setVehicleRef(vehicleRef);
        monitoredVehicleJourney.setBearing((float) currentVehicleTripStatus.getOrientation());
        monitoredVehicleJourney.setVehicleLocation(location);
    }
    // detail level - basic
    if (detailLevel.equals(DetailLevel.BASIC) || detailLevel.equals(DetailLevel.NORMAL) || detailLevel.equals(DetailLevel.CALLS)) {
        monitoredVehicleJourney.setFramedVehicleJourneyRef(framedJourney);
        monitoredVehicleJourney.setDirectionRef(directionRef);
        // since LineRef is fully qualified with operatorref, moving OperatorRef to normal detail
        // monitoredVehicleJourney.setOperatorRef(operatorRef);
        DestinationRefStructure dest = new DestinationRefStructure();
        dest.setValue(lastStop.getId());
        monitoredVehicleJourney.setDestinationRef(dest);
        monitoredVehicleJourney.setLineRef(lineRef);
        monitoredVehicleJourney.setProgressRate(getProgressRateForPhaseAndStatus(currentVehicleTripStatus.getStatus(), currentVehicleTripStatus.getPhase()));
    }
    // detail level - normal
    if (detailLevel.equals(DetailLevel.NORMAL) || detailLevel.equals(DetailLevel.CALLS)) {
        monitoredVehicleJourney.setOperatorRef(operatorRef);
        // block ref
        if (presentationService.isBlockLevelInference(currentVehicleTripStatus)) {
            BlockRefStructure blockRef = new BlockRefStructure();
            blockRef.setValue(framedJourneyTripBean.getBlockId());
            monitoredVehicleJourney.setBlockRef(blockRef);
        }
        monitoredVehicleJourney.setOriginRef(origin);
        monitoredVehicleJourney.setJourneyPatternRef(journeyPattern);
    }
    // onward calls
    if (detailLevel.equals(DetailLevel.CALLS)) {
        if (!presentationService.isOnDetour(currentVehicleTripStatus))
            fillOnwardCalls(monitoredVehicleJourney, blockInstance, framedJourneyTripBean, currentVehicleTripStatus, onwardCallsMode, presentationService, transitDataService, stopIdToPredictionRecordMap, maximumOnwardCalls, responseTimestamp);
    }
    // situations
    fillSituations(monitoredVehicleJourney, currentVehicleTripStatus);
    return;
}
Also used : NaturalLanguageStringStructure(uk.org.siri.siri_2.NaturalLanguageStringStructure) BlockTripBean(org.onebusaway.transit_data.model.blocks.BlockTripBean) HashMap(java.util.HashMap) DestinationRefStructure(uk.org.siri.siri_2.DestinationRefStructure) DecimalFormat(java.text.DecimalFormat) ArrayList(java.util.ArrayList) LocationStructure(uk.org.siri.siri_2.LocationStructure) DataFrameRefStructure(uk.org.siri.siri_2.DataFrameRefStructure) BlockStopTimeBean(org.onebusaway.transit_data.model.blocks.BlockStopTimeBean) OperatorRefStructure(uk.org.siri.siri_2.OperatorRefStructure) JourneyPlaceRefStructure(uk.org.siri.siri_2.JourneyPlaceRefStructure) FramedVehicleJourneyRefStructure(uk.org.siri.siri_2.FramedVehicleJourneyRefStructure) JourneyPatternRefStructure(uk.org.siri.siri_2.JourneyPatternRefStructure) BlockRefStructure(uk.org.siri.siri_2.BlockRefStructure) LineRefStructure(uk.org.siri.siri_2.LineRefStructure) BigDecimal(java.math.BigDecimal) BlockInstanceBean(org.onebusaway.transit_data.model.blocks.BlockInstanceBean) TimepointPredictionRecord(org.onebusaway.realtime.api.TimepointPredictionRecord) StopBean(org.onebusaway.transit_data.model.StopBean) DirectionRefStructure(uk.org.siri.siri_2.DirectionRefStructure) VehicleRefStructure(uk.org.siri.siri_2.VehicleRefStructure)

Example 3 with MonitoredVehicleJourneyStructure

use of uk.org.siri.siri_2.MonitoredVehicleJourneyStructure in project onebusaway-application-modules by camsys.

the class SiriSupportV2 method fillOnwardCalls.

/**
 * PRIVATE STATIC METHODS
 */
private static void fillOnwardCalls(MonitoredVehicleJourneyStructure monitoredVehicleJourney, BlockInstanceBean blockInstance, TripBean framedJourneyTripBean, TripStatusBean currentVehicleTripStatus, OnwardCallsMode onwardCallsMode, PresentationService presentationService, TransitDataService transitDataService, Map<String, TimepointPredictionRecord> stopLevelPredictions, int maximumOnwardCalls, long responseTimestamp) {
    String tripIdOfMonitoredCall = framedJourneyTripBean.getId();
    monitoredVehicleJourney.setOnwardCalls(new OnwardCallsStructure());
    // no need to go further if this is the case!
    if (maximumOnwardCalls == 0) {
        return;
    }
    List<BlockTripBean> blockTrips = blockInstance.getBlockConfiguration().getTrips();
    double distanceOfVehicleAlongBlock = 0;
    int blockTripStopsAfterTheVehicle = 0;
    int onwardCallsAdded = 0;
    boolean foundActiveTrip = false;
    for (int i = 0; i < blockTrips.size(); i++) {
        BlockTripBean blockTrip = blockTrips.get(i);
        if (!foundActiveTrip) {
            if (currentVehicleTripStatus.getActiveTrip().getId().equals(blockTrip.getTrip().getId())) {
                distanceOfVehicleAlongBlock += currentVehicleTripStatus.getDistanceAlongTrip();
                foundActiveTrip = true;
            } else {
                // next.
                if (i + 1 < blockTrips.size()) {
                    distanceOfVehicleAlongBlock = blockTrips.get(i + 1).getDistanceAlongBlock();
                }
                // further
                continue;
            }
        }
        if (onwardCallsMode == OnwardCallsMode.STOP_MONITORING) {
            // is on ONLY.
            if (!blockTrip.getTrip().getId().equals(tripIdOfMonitoredCall)) {
                continue;
            }
        }
        HashMap<String, Integer> visitNumberForStopMap = new HashMap<String, Integer>();
        for (BlockStopTimeBean stopTime : blockTrip.getBlockStopTimes()) {
            int visitNumber = getVisitNumber(visitNumberForStopMap, stopTime.getStopTime().getStop());
            // on future trips, count always.
            if (currentVehicleTripStatus.getActiveTrip().getId().equals(blockTrip.getTrip().getId())) {
                if (stopTime.getDistanceAlongBlock() >= distanceOfVehicleAlongBlock) {
                    blockTripStopsAfterTheVehicle++;
                } else {
                    // stop is behind the bus--no need to go further
                    continue;
                }
            // future trip--bus hasn't reached this trip yet, so count
            // all stops
            } else {
                blockTripStopsAfterTheVehicle++;
            }
            monitoredVehicleJourney.getOnwardCalls().getOnwardCall().add(getOnwardCallStructure(stopTime.getStopTime().getStop(), presentationService, stopTime.getDistanceAlongBlock() - blockTrip.getDistanceAlongBlock(), stopTime.getDistanceAlongBlock() - distanceOfVehicleAlongBlock, visitNumber, blockTripStopsAfterTheVehicle - 1, stopLevelPredictions.get(stopTime.getStopTime().getStop().getId()), responseTimestamp));
            onwardCallsAdded++;
            if (onwardCallsAdded >= maximumOnwardCalls) {
                return;
            }
        }
        // if we get here, we added our stops
        return;
    }
    return;
}
Also used : BigInteger(java.math.BigInteger) BlockTripBean(org.onebusaway.transit_data.model.blocks.BlockTripBean) OnwardCallsStructure(uk.org.siri.siri_2.OnwardCallsStructure) HashMap(java.util.HashMap) BlockStopTimeBean(org.onebusaway.transit_data.model.blocks.BlockStopTimeBean)

Example 4 with MonitoredVehicleJourneyStructure

use of uk.org.siri.siri_2.MonitoredVehicleJourneyStructure in project onebusaway-application-modules by camsys.

the class RealtimeServiceV2Impl method getMonitoredStopVisitsForStop.

@Override
public List<MonitoredStopVisitStructure> getMonitoredStopVisitsForStop(String stopId, int maximumOnwardCalls, DetailLevel detailLevel, long currentTime, List<AgencyAndId> routeIds, Map<Filters, String> filters) {
    List<MonitoredStopVisitStructure> output = new ArrayList<MonitoredStopVisitStructure>();
    String directionId = filters.get(Filters.DIRECTION_REF);
    int maximumStopVisits = SiriSupportV2.convertToNumeric(filters.get(Filters.MAX_STOP_VISITS), Integer.MAX_VALUE);
    Integer minimumStopVisitsPerLine = SiriSupportV2.convertToNumeric(filters.get(Filters.MIN_STOP_VISITS), null);
    Map<AgencyAndId, Integer> visitCountByLine = new HashMap<AgencyAndId, Integer>();
    int visitCount = 0;
    for (ArrivalAndDepartureBean adBean : getArrivalsAndDeparturesForStop(stopId, currentTime)) {
        TripStatusBean statusBeanForCurrentTrip = adBean.getTripStatus();
        TripBean tripBeanForAd = adBean.getTrip();
        if (statusBeanForCurrentTrip == null)
            continue;
        if (!_presentationService.include(statusBeanForCurrentTrip) || !_presentationService.include(adBean, statusBeanForCurrentTrip))
            continue;
        MonitoredStopVisitStructure stopVisit = new MonitoredStopVisitStructure();
        stopVisit.setRecordedAtTime(DateUtil.toXmlGregorianCalendar(statusBeanForCurrentTrip.getLastUpdateTime()));
        List<TimepointPredictionRecord> timePredictionRecords = null;
        timePredictionRecords = _transitDataService.getPredictionRecordsForTrip(AgencyAndId.convertFromString(stopId).getAgencyId(), statusBeanForCurrentTrip);
        MonitoredVehicleJourneyStructure mvjourney = new MonitoredVehicleJourneyStructure();
        stopVisit.setMonitoredVehicleJourney(mvjourney);
        SiriSupportV2.fillMonitoredVehicleJourney(mvjourney, tripBeanForAd, statusBeanForCurrentTrip, adBean.getStop(), OnwardCallsMode.STOP_MONITORING, _presentationService, _transitDataService, maximumOnwardCalls, timePredictionRecords, statusBeanForCurrentTrip.isPredicted(), detailLevel, currentTime, filters);
        // FILTERS
        AgencyAndId thisRouteId = AgencyAndIdLibrary.convertFromString(mvjourney.getLineRef().getValue());
        String thisDirectionId = mvjourney.getDirectionRef().getValue();
        if (routeIds.size() > 0 && !routeIds.contains(thisRouteId))
            continue;
        if (directionId != null && !thisDirectionId.equals(directionId))
            continue;
        // Monitored Stop Visits
        Map<String, MonitoredStopVisitStructure> visitsMap = new HashMap<String, MonitoredStopVisitStructure>();
        // visit count filters
        Integer visitCountForThisLine = visitCountByLine.get(thisRouteId);
        if (visitCountForThisLine == null) {
            visitCountForThisLine = 0;
        }
        if (visitCount >= maximumStopVisits) {
            if (minimumStopVisitsPerLine == null) {
                break;
            } else {
                if (visitCountForThisLine >= minimumStopVisitsPerLine) {
                    continue;
                }
            }
        }
        // unique stops filters
        if (stopVisit.getMonitoredVehicleJourney() == null || stopVisit.getMonitoredVehicleJourney().getVehicleRef() == null || StringUtils.isBlank(stopVisit.getMonitoredVehicleJourney().getVehicleRef().getValue())) {
            continue;
        } else {
            String visitKey = stopVisit.getMonitoredVehicleJourney().getVehicleRef().getValue();
            if (visitsMap.containsKey(stopVisit.getMonitoredVehicleJourney().getVehicleRef().getValue())) {
                if (stopVisit.getMonitoredVehicleJourney().getProgressStatus() == null) {
                    visitsMap.remove(visitKey);
                    visitsMap.put(visitKey, stopVisit);
                }
                continue;
            } else {
                visitsMap.put(stopVisit.getMonitoredVehicleJourney().getVehicleRef().getValue(), stopVisit);
            }
        }
        output.add(stopVisit);
        visitCount++;
        visitCountForThisLine++;
        visitCountByLine.put(thisRouteId, visitCountForThisLine);
    }
    Collections.sort(output, new Comparator<MonitoredStopVisitStructure>() {

        public int compare(MonitoredStopVisitStructure arg0, MonitoredStopVisitStructure arg1) {
            try {
                SiriExtensionWrapper wrapper0 = (SiriExtensionWrapper) arg0.getMonitoredVehicleJourney().getMonitoredCall().getExtensions().getAny();
                SiriExtensionWrapper wrapper1 = (SiriExtensionWrapper) arg1.getMonitoredVehicleJourney().getMonitoredCall().getExtensions().getAny();
                return wrapper0.getDistances().getDistanceFromCall().compareTo(wrapper1.getDistances().getDistanceFromCall());
            } catch (Exception e) {
                return -1;
            }
        }
    });
    return output;
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SiriExtensionWrapper(org.onebusaway.transit_data_federation.siri.SiriExtensionWrapper) TripBean(org.onebusaway.transit_data.model.trips.TripBean) MonitoredStopVisitStructure(uk.org.siri.siri_2.MonitoredStopVisitStructure) ArrivalAndDepartureBean(org.onebusaway.transit_data.model.ArrivalAndDepartureBean) MonitoredVehicleJourneyStructure(uk.org.siri.siri_2.MonitoredVehicleJourneyStructure) TimepointPredictionRecord(org.onebusaway.realtime.api.TimepointPredictionRecord) TripStatusBean(org.onebusaway.transit_data.model.trips.TripStatusBean)

Example 5 with MonitoredVehicleJourneyStructure

use of uk.org.siri.siri_2.MonitoredVehicleJourneyStructure in project onebusaway-application-modules by camsys.

the class SiriSupportV2 method fillSituations.

private static void fillSituations(MonitoredVehicleJourneyStructure monitoredVehicleJourney, TripStatusBean tripStatus) {
    if (tripStatus == null || tripStatus.getSituations() == null || tripStatus.getSituations().isEmpty()) {
        return;
    }
    List<SituationRefStructure> situationRef = monitoredVehicleJourney.getSituationRef();
    for (ServiceAlertBean situation : tripStatus.getSituations()) {
        SituationRefStructure sitRef = new SituationRefStructure();
        SituationSimpleRefStructure sitSimpleRef = new SituationSimpleRefStructure();
        sitSimpleRef.setValue(situation.getId());
        sitRef.setSituationSimpleRef(sitSimpleRef);
        situationRef.add(sitRef);
    }
}
Also used : SituationRefStructure(uk.org.siri.siri_2.SituationRefStructure) ServiceAlertBean(org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean) SituationSimpleRefStructure(uk.org.siri.siri_2.SituationSimpleRefStructure)

Aggregations

ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)2 TimepointPredictionRecord (org.onebusaway.realtime.api.TimepointPredictionRecord)2 BlockStopTimeBean (org.onebusaway.transit_data.model.blocks.BlockStopTimeBean)2 BlockTripBean (org.onebusaway.transit_data.model.blocks.BlockTripBean)2 MonitoredVehicleJourneyStructure (uk.org.siri.siri_2.MonitoredVehicleJourneyStructure)2 IOException (java.io.IOException)1 BigDecimal (java.math.BigDecimal)1 BigInteger (java.math.BigInteger)1 DecimalFormat (java.text.DecimalFormat)1 List (java.util.List)1 DetailLevel (org.onebusaway.api.actions.siri.model.DetailLevel)1 ArrivalAndDepartureBean (org.onebusaway.transit_data.model.ArrivalAndDepartureBean)1 ListBean (org.onebusaway.transit_data.model.ListBean)1 StopBean (org.onebusaway.transit_data.model.StopBean)1 VehicleStatusBean (org.onebusaway.transit_data.model.VehicleStatusBean)1 BlockInstanceBean (org.onebusaway.transit_data.model.blocks.BlockInstanceBean)1 ServiceAlertBean (org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean)1 TripBean (org.onebusaway.transit_data.model.trips.TripBean)1