Search in sources :

Example 31 with RouteBean

use of org.onebusaway.transit_data.model.RouteBean 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 32 with RouteBean

use of org.onebusaway.transit_data.model.RouteBean 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 33 with RouteBean

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

the class BookmarkPresentationServiceImpl method getRoutesForRouteFilter.

private List<RouteBean> getRoutesForRouteFilter(RouteFilterBean routeFilter) {
    List<RouteBean> routes = new ArrayList<RouteBean>();
    for (String routeId : routeFilter.getRouteIds()) {
        RouteBean route = _transitDataService.getRouteForId(routeId);
        if (route != null)
            routes.add(route);
    }
    Collections.sort(routes, new RouteNameComparator());
    return routes;
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) ArrayList(java.util.ArrayList)

Example 34 with RouteBean

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

the class ArrivalsAndDeparturesForRouteAction method getRouteIdsForMatchingRoutes.

private Set<String> getRouteIdsForMatchingRoutes() {
    StopsWithArrivalsAndDeparturesBean result = _model.getResult();
    Set<String> ids = new HashSet<String>();
    for (StopBean stop : result.getStops()) {
        for (RouteBean route : stop.getRoutes()) {
            if (route.getShortName().equals(_route))
                ids.add(route.getId());
        }
    }
    return ids;
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) StopsWithArrivalsAndDeparturesBean(org.onebusaway.transit_data.model.StopsWithArrivalsAndDeparturesBean) StopBean(org.onebusaway.transit_data.model.StopBean) HashSet(java.util.HashSet)

Example 35 with RouteBean

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

the class ArrivalsAndDeparturesModel method getRouteKeyForArrivalAndDeparture.

private String getRouteKeyForArrivalAndDeparture(ArrivalAndDepartureBean bean) {
    String name = bean.getRouteShortName();
    if (name != null)
        return name;
    TripBean trip = bean.getTrip();
    name = trip.getRouteShortName();
    if (name != null)
        return name;
    RouteBean route = trip.getRoute();
    name = route.getShortName();
    if (name != null)
        return name;
    return route.getId();
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) TripBean(org.onebusaway.transit_data.model.trips.TripBean)

Aggregations

RouteBean (org.onebusaway.transit_data.model.RouteBean)63 ArrayList (java.util.ArrayList)35 StopsForRouteBean (org.onebusaway.transit_data.model.StopsForRouteBean)24 StopBean (org.onebusaway.transit_data.model.StopBean)22 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)18 TripBean (org.onebusaway.transit_data.model.trips.TripBean)14 StopGroupBean (org.onebusaway.transit_data.model.StopGroupBean)12 StopGroupingBean (org.onebusaway.transit_data.model.StopGroupingBean)12 List (java.util.List)9 HashMap (java.util.HashMap)7 HashSet (java.util.HashSet)7 CoordinateBounds (org.onebusaway.geospatial.model.CoordinateBounds)7 NameBean (org.onebusaway.transit_data.model.NameBean)7 Date (java.util.Date)6 Test (org.junit.Test)6 AgencyBean (org.onebusaway.transit_data.model.AgencyBean)6 ArrivalAndDepartureBean (org.onebusaway.transit_data.model.ArrivalAndDepartureBean)6 IOException (java.io.IOException)5 Matchers.anyString (org.mockito.Matchers.anyString)5 SearchQueryBean (org.onebusaway.transit_data.model.SearchQueryBean)5