Search in sources :

Example 6 with ArrivalAndDepartureBean

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

the class ArrivalsAndDeparturesForStopAction method getArrivalsAsV1.

private List<ArrivalAndDepartureBeanV1> getArrivalsAsV1(StopWithArrivalsAndDeparturesBean result) {
    List<ArrivalAndDepartureBeanV1> v1s = new ArrayList<ArrivalAndDepartureBeanV1>();
    for (ArrivalAndDepartureBean bean : result.getArrivalsAndDepartures()) {
        TripBean trip = bean.getTrip();
        RouteBean route = trip.getRoute();
        StopBean stop = bean.getStop();
        ArrivalAndDepartureBeanV1 v1 = new ArrivalAndDepartureBeanV1();
        v1.setPredictedArrivalTime(bean.getPredictedArrivalTime());
        v1.setPredictedDepartureTime(bean.getPredictedDepartureTime());
        v1.setRouteId(route.getId());
        if (trip.getRouteShortName() != null)
            v1.setRouteShortName(trip.getRouteShortName());
        else
            v1.setRouteShortName(route.getShortName());
        v1.setScheduledArrivalTime(bean.getScheduledArrivalTime());
        v1.setScheduledDepartureTime(bean.getScheduledDepartureTime());
        v1.setStatus(bean.getStatus());
        v1.setStopId(stop.getId());
        v1.setTripHeadsign(trip.getTripHeadsign());
        v1.setTripId(trip.getId());
        v1s.add(v1);
    }
    return v1s;
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) ArrivalAndDepartureBeanV1(org.onebusaway.api.model.where.ArrivalAndDepartureBeanV1) ArrayList(java.util.ArrayList) TripBean(org.onebusaway.transit_data.model.trips.TripBean) StopBean(org.onebusaway.transit_data.model.StopBean) ArrivalAndDepartureBean(org.onebusaway.transit_data.model.ArrivalAndDepartureBean)

Example 7 with ArrivalAndDepartureBean

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

the class RealtimeServiceImpl method getMonitoredStopVisitsForStop.

@Override
public List<MonitoredStopVisitStructure> getMonitoredStopVisitsForStop(String stopId, int maximumOnwardCalls, long currentTime) {
    List<MonitoredStopVisitStructure> output = new ArrayList<MonitoredStopVisitStructure>();
    for (ArrivalAndDepartureBean adBean : getArrivalsAndDeparturesForStop(stopId, currentTime)) {
        TripStatusBean statusBeanForCurrentTrip = adBean.getTripStatus();
        TripBean tripBeanForAd = adBean.getTrip();
        final RouteBean routeBean = tripBeanForAd.getRoute();
        if (statusBeanForCurrentTrip == null) {
            _log.debug("status drop");
            continue;
        }
        if (!_presentationService.include(statusBeanForCurrentTrip) || !_presentationService.include(adBean, statusBeanForCurrentTrip)) {
            _log.debug("presentation drop for vehicle=" + statusBeanForCurrentTrip.getVehicleId());
            continue;
        }
        if (!_transitDataService.stopHasRevenueServiceOnRoute((routeBean.getAgency() != null ? routeBean.getAgency().getId() : null), stopId, routeBean.getId(), adBean.getTrip().getDirectionId())) {
            _log.debug("non reveunue drop");
            continue;
        }
        // Filter out if the vehicle has realtime information and is ahead of current stop
        if (statusBeanForCurrentTrip.isPredicted() && !(adBean.hasPredictedArrivalTime() || adBean.hasPredictedDepartureTime())) {
            _log.debug("no realtime drop");
            continue;
        }
        if (statusBeanForCurrentTrip.getVehicleId() != null) {
            _log.debug("valid vehicle " + statusBeanForCurrentTrip.getVehicleId());
        }
        MonitoredStopVisitStructure stopVisit = new MonitoredStopVisitStructure();
        // Check for Realtime Data
        if (!statusBeanForCurrentTrip.isPredicted()) {
            stopVisit.setRecordedAtTime(new Date(getTime()));
        } else {
            stopVisit.setRecordedAtTime(new Date(statusBeanForCurrentTrip.getLastUpdateTime()));
        }
        List<TimepointPredictionRecord> timePredictionRecords = null;
        timePredictionRecords = createTimePredictionRecordsForStop(adBean, stopId);
        stopVisit.setMonitoredVehicleJourney(new MonitoredVehicleJourneyStructure());
        SiriSupport.fillMonitoredVehicleJourney(stopVisit.getMonitoredVehicleJourney(), tripBeanForAd, statusBeanForCurrentTrip, adBean.getStop(), OnwardCallsMode.STOP_MONITORING, _presentationService, _transitDataService, maximumOnwardCalls, timePredictionRecords, statusBeanForCurrentTrip.isPredicted(), currentTime, false);
        output.add(stopVisit);
    }
    Collections.sort(output, new Comparator<MonitoredStopVisitStructure>() {

        public int compare(MonitoredStopVisitStructure arg0, MonitoredStopVisitStructure arg1) {
            try {
                Date expectedArrival0 = arg0.getMonitoredVehicleJourney().getMonitoredCall().getExpectedArrivalTime();
                Date expectedArrival1 = arg1.getMonitoredVehicleJourney().getMonitoredCall().getExpectedArrivalTime();
                return expectedArrival0.compareTo(expectedArrival1);
            } catch (Exception e) {
                return -1;
            }
        }
    });
    return output;
}
Also used : ArrayList(java.util.ArrayList) TripBean(org.onebusaway.transit_data.model.trips.TripBean) MonitoredStopVisitStructure(uk.org.siri.siri.MonitoredStopVisitStructure) ArrivalAndDepartureBean(org.onebusaway.transit_data.model.ArrivalAndDepartureBean) Date(java.util.Date) RouteBean(org.onebusaway.transit_data.model.RouteBean) MonitoredVehicleJourneyStructure(uk.org.siri.siri.MonitoredVehicleJourneyStructure) TimepointPredictionRecord(org.onebusaway.realtime.api.TimepointPredictionRecord) TripStatusBean(org.onebusaway.transit_data.model.trips.TripStatusBean)

Example 8 with ArrivalAndDepartureBean

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

the class SiriSupport method fillOnwardCalls.

private static void fillOnwardCalls(MonitoredVehicleJourneyStructure monitoredVehicleJourney, BlockInstanceBean blockInstance, TripBean framedJourneyTripBean, TripStatusBean currentVehicleTripStatus, OnwardCallsMode onwardCallsMode, PresentationService presentationService, TransitDataService transitDataService, Map<String, TimepointPredictionRecord> stopLevelPredictions, int maximumOnwardCalls, boolean hasRealtimeData, 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 {
                // so to get the size of this one, we have to look at the next.
                if (i + 1 < blockTrips.size()) {
                    distanceOfVehicleAlongBlock = blockTrips.get(i + 1).getDistanceAlongBlock();
                }
                // bus has already served this trip, so no need to go further
                continue;
            }
        }
        if (onwardCallsMode == OnwardCallsMode.STOP_MONITORING) {
            // always include onward calls for the trip the monitored call is on ONLY.
            if (!blockTrip.getTrip().getId().equals(tripIdOfMonitoredCall)) {
                continue;
            }
        }
        boolean foundMatch = false;
        HashMap<String, Integer> visitNumberForStopMap = new HashMap<String, Integer>();
        for (BlockStopTimeBean stopTime : blockTrip.getBlockStopTimes()) {
            int visitNumber = getVisitNumber(visitNumberForStopMap, stopTime.getStopTime().getStop());
            StopBean stop = stopTime.getStopTime().getStop();
            double distanceOfCallAlongTrip = stopTime.getDistanceAlongBlock() - blockTrip.getDistanceAlongBlock();
            double distanceOfVehicleFromCall = stopTime.getDistanceAlongBlock() - distanceOfVehicleAlongBlock;
            // on future trips, count always.
            if (currentVehicleTripStatus.getActiveTrip().getId().equals(blockTrip.getTrip().getId())) {
                if (!hasRealtimeData) {
                    if (stop.getId().equals(currentVehicleTripStatus.getNextStop().getId()))
                        foundMatch = true;
                    if (foundMatch) {
                        blockTripStopsAfterTheVehicle++;
                        ArrivalsAndDeparturesQueryBean query = new ArrivalsAndDeparturesQueryBean();
                        StopWithArrivalsAndDeparturesBean result = transitDataService.getStopWithArrivalsAndDepartures(stop.getId(), query);
                        // We can't assume the first result is the correct result
                        Collections.sort(result.getArrivalsAndDepartures(), new SortByTime());
                        if (result.getArrivalsAndDepartures().isEmpty()) {
                            // bad data?  abort!
                            continue;
                        }
                        ArrivalAndDepartureBean arrivalAndDeparture = result.getArrivalsAndDepartures().get(0);
                        distanceOfVehicleFromCall = arrivalAndDeparture.getDistanceFromStop();
                    // responseTimestamp = arrivalAndDeparture.getScheduledArrivalTime();
                    } else
                        continue;
                } else 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(stop, presentationService, distanceOfCallAlongTrip, distanceOfVehicleFromCall, visitNumber, blockTripStopsAfterTheVehicle - 1, stopLevelPredictions.get(stopTime.getStopTime().getStop().getId()), hasRealtimeData, responseTimestamp, (currentVehicleTripStatus.getServiceDate() + stopTime.getStopTime().getArrivalTime() * 1000)));
            onwardCallsAdded++;
            if (onwardCallsAdded >= maximumOnwardCalls) {
                return;
            }
        }
        // if we get here, we added our stops
        return;
    }
    return;
}
Also used : BlockTripBean(org.onebusaway.transit_data.model.blocks.BlockTripBean) StopWithArrivalsAndDeparturesBean(org.onebusaway.transit_data.model.StopWithArrivalsAndDeparturesBean) HashMap(java.util.HashMap) ArrivalsAndDeparturesQueryBean(org.onebusaway.transit_data.model.ArrivalsAndDeparturesQueryBean) BlockStopTimeBean(org.onebusaway.transit_data.model.blocks.BlockStopTimeBean) ArrivalAndDepartureBean(org.onebusaway.transit_data.model.ArrivalAndDepartureBean) BigInteger(java.math.BigInteger) OnwardCallsStructure(uk.org.siri.siri.OnwardCallsStructure) StopBean(org.onebusaway.transit_data.model.StopBean)

Example 9 with ArrivalAndDepartureBean

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

the class AgencyPresenter method getAgenciesForArrivalAndDepartures.

public static List<AgencyBean> getAgenciesForArrivalAndDepartures(List<ArrivalAndDepartureBean> arrivalsAndDepartures) {
    Map<String, AgencyBean> agenciesById = new HashMap<String, AgencyBean>();
    for (ArrivalAndDepartureBean aad : arrivalsAndDepartures) {
        AgencyBean agency = aad.getTrip().getRoute().getAgency();
        agenciesById.put(agency.getId(), agency);
    }
    List<AgencyBean> agencies = new ArrayList<AgencyBean>();
    agencies.addAll(agenciesById.values());
    Collections.sort(agencies, _agencyNameComparator);
    return agencies;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrivalAndDepartureBean(org.onebusaway.transit_data.model.ArrivalAndDepartureBean) AgencyBean(org.onebusaway.transit_data.model.AgencyBean)

Example 10 with ArrivalAndDepartureBean

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

the class ArrivalsAndDeparturesModel method applyOnlyNextFilter.

private void applyOnlyNextFilter() {
    if (!_onlyNext)
        return;
    List<ArrivalAndDepartureBean> current = _result.getArrivalsAndDepartures();
    Collections.sort(current, SORT_BY_TIME);
    Map<String, ArrivalAndDepartureBean> keepers = new HashMap<String, ArrivalAndDepartureBean>();
    for (ArrivalAndDepartureBean bean : current) {
        String key = getRouteKeyForArrivalAndDeparture(bean);
        if (!keepers.containsKey(key))
            keepers.put(key, bean);
    }
    List<ArrivalAndDepartureBean> filtered = new ArrayList<ArrivalAndDepartureBean>(keepers.values());
    OrderConstraint c = _order == null ? SORT_BY_TIME : _order;
    Collections.sort(filtered, c);
    _result.setArrivalsAndDepartures(filtered);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrivalAndDepartureBean(org.onebusaway.transit_data.model.ArrivalAndDepartureBean)

Aggregations

ArrivalAndDepartureBean (org.onebusaway.transit_data.model.ArrivalAndDepartureBean)21 ArrayList (java.util.ArrayList)14 StopBean (org.onebusaway.transit_data.model.StopBean)9 TripBean (org.onebusaway.transit_data.model.trips.TripBean)8 HashMap (java.util.HashMap)7 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)6 RouteBean (org.onebusaway.transit_data.model.RouteBean)6 HashSet (java.util.HashSet)4 AgencyBean (org.onebusaway.transit_data.model.AgencyBean)4 StopsWithArrivalsAndDeparturesBean (org.onebusaway.transit_data.model.StopsWithArrivalsAndDeparturesBean)4 Date (java.util.Date)3 ArrivalsAndDeparturesQueryBean (org.onebusaway.transit_data.model.ArrivalsAndDeparturesQueryBean)3 ServiceAlertBean (org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean)3 TripStatusBean (org.onebusaway.transit_data.model.trips.TripStatusBean)3 ArrivalAndDepartureInstance (org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureInstance)3 ArrivalAndDepartureComparator (org.onebusaway.presentation.impl.ArrivalAndDepartureComparator)2 TimepointPredictionRecord (org.onebusaway.realtime.api.TimepointPredictionRecord)2 StopWithArrivalsAndDeparturesBean (org.onebusaway.transit_data.model.StopWithArrivalsAndDeparturesBean)2 TargetTime (org.onebusaway.transit_data_federation.model.TargetTime)2 BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)2