Search in sources :

Example 1 with OnwardCallsStructure

use of uk.org.siri.siri_2.OnwardCallsStructure 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)

Aggregations

BigInteger (java.math.BigInteger)1 HashMap (java.util.HashMap)1 BlockStopTimeBean (org.onebusaway.transit_data.model.blocks.BlockStopTimeBean)1 BlockTripBean (org.onebusaway.transit_data.model.blocks.BlockTripBean)1 OnwardCallsStructure (uk.org.siri.siri_2.OnwardCallsStructure)1