Search in sources :

Example 11 with TripDetailsBean

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

the class RealtimeServiceV2Impl method getVehicleActivityForRoute.

/**
 * SIRI METHODS
 */
@Override
public List<VehicleActivityStructure> getVehicleActivityForRoute(String routeId, String directionId, int maximumOnwardCalls, DetailLevel detailLevel, long currentTime) {
    List<VehicleActivityStructure> output = new ArrayList<VehicleActivityStructure>();
    ListBean<TripDetailsBean> trips = getAllTripsForRoute(routeId, currentTime);
    for (TripDetailsBean tripDetails : trips.getList()) {
        // filter out interlined routes
        if (routeId != null && !tripDetails.getTrip().getRoute().getId().equals(routeId))
            continue;
        // filtered out by user
        if (directionId != null && !tripDetails.getTrip().getDirectionId().equals(directionId))
            continue;
        if (!_presentationService.include(tripDetails.getStatus()))
            continue;
        VehicleActivityStructure activity = new VehicleActivityStructure();
        activity.setRecordedAtTime(DateUtil.toXmlGregorianCalendar(tripDetails.getStatus().getLastUpdateTime()));
        List<TimepointPredictionRecord> timePredictionRecords = null;
        timePredictionRecords = _transitDataService.getPredictionRecordsForTrip(AgencyAndId.convertFromString(routeId).getAgencyId(), tripDetails.getStatus());
        activity.setMonitoredVehicleJourney(new MonitoredVehicleJourney());
        SiriSupportV2.fillMonitoredVehicleJourney(activity.getMonitoredVehicleJourney(), tripDetails.getTrip(), tripDetails.getStatus(), null, OnwardCallsMode.VEHICLE_MONITORING, _presentationService, _transitDataService, maximumOnwardCalls, timePredictionRecords, tripDetails.getStatus().isPredicted(), detailLevel, currentTime, null);
        output.add(activity);
    }
    Collections.sort(output, new Comparator<VehicleActivityStructure>() {

        public int compare(VehicleActivityStructure arg0, VehicleActivityStructure 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 : ArrayList(java.util.ArrayList) SiriExtensionWrapper(org.onebusaway.transit_data_federation.siri.SiriExtensionWrapper) TimepointPredictionRecord(org.onebusaway.realtime.api.TimepointPredictionRecord) VehicleActivityStructure(uk.org.siri.siri_2.VehicleActivityStructure) TripDetailsBean(org.onebusaway.transit_data.model.trips.TripDetailsBean) MonitoredVehicleJourney(uk.org.siri.siri_2.VehicleActivityStructure.MonitoredVehicleJourney)

Example 12 with TripDetailsBean

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

the class TripDetailsAction method show.

public DefaultHttpHeaders show() throws ServiceException {
    if (!isVersion(V2))
        return setUnknownVersionResponse();
    if (hasErrors())
        return setValidationErrorsResponse();
    TripDetailsQueryBean query = new TripDetailsQueryBean();
    query.setTripId(_id);
    if (_serviceDate != null)
        query.setServiceDate(_serviceDate.getTime());
    query.setTime(_time.getTime());
    query.setVehicleId(_vehicleId);
    TripDetailsInclusionBean inclusion = query.getInclusion();
    inclusion.setIncludeTripBean(_includeTrip);
    inclusion.setIncludeTripSchedule(_includeSchedule);
    inclusion.setIncludeTripStatus(_includeStatus);
    TripDetailsBean trip = _service.getSingleTripDetails(query);
    if (trip == null)
        return setResourceNotFoundResponse();
    BeanFactoryV2 factory = getBeanFactoryV2();
    EntryWithReferencesBean<TripDetailsV2Bean> response = factory.getResponse(trip);
    return setOkResponse(response);
}
Also used : TripDetailsV2Bean(org.onebusaway.api.model.transit.TripDetailsV2Bean) TripDetailsQueryBean(org.onebusaway.transit_data.model.trips.TripDetailsQueryBean) TripDetailsInclusionBean(org.onebusaway.transit_data.model.trips.TripDetailsInclusionBean) TripDetailsBean(org.onebusaway.transit_data.model.trips.TripDetailsBean) BeanFactoryV2(org.onebusaway.api.model.transit.BeanFactoryV2)

Example 13 with TripDetailsBean

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

the class TripForVehicleAction method show.

public DefaultHttpHeaders show() throws ServiceException {
    if (!isVersion(V2))
        return setUnknownVersionResponse();
    if (hasErrors())
        return setValidationErrorsResponse();
    TripForVehicleQueryBean query = new TripForVehicleQueryBean();
    query.setVehicleId(_id);
    query.setTime(_time);
    TripDetailsInclusionBean inclusion = query.getInclusion();
    inclusion.setIncludeTripBean(_includeTrip);
    inclusion.setIncludeTripSchedule(_includeSchedule);
    inclusion.setIncludeTripStatus(_includeStatus);
    TripDetailsBean trip = _service.getTripDetailsForVehicleAndTime(query);
    if (trip == null)
        return setResourceNotFoundResponse();
    BeanFactoryV2 factory = getBeanFactoryV2();
    EntryWithReferencesBean<TripDetailsV2Bean> response = factory.getResponse(trip);
    return setOkResponse(response);
}
Also used : TripForVehicleQueryBean(org.onebusaway.transit_data.model.trips.TripForVehicleQueryBean) TripDetailsV2Bean(org.onebusaway.api.model.transit.TripDetailsV2Bean) TripDetailsInclusionBean(org.onebusaway.transit_data.model.trips.TripDetailsInclusionBean) TripDetailsBean(org.onebusaway.transit_data.model.trips.TripDetailsBean) BeanFactoryV2(org.onebusaway.api.model.transit.BeanFactoryV2)

Example 14 with TripDetailsBean

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

the class TripsForLocationAction method index.

public DefaultHttpHeaders index() throws IOException, ServiceException {
    if (!isVersion(V2))
        return setUnknownVersionResponse();
    if (hasErrors())
        return setValidationErrorsResponse();
    CoordinateBounds bounds = _searchBoundsFactory.createBounds();
    long time = SystemTime.currentTimeMillis();
    if (_time != 0)
        time = _time;
    TripsForBoundsQueryBean query = new TripsForBoundsQueryBean();
    query.setBounds(bounds);
    query.setTime(time);
    query.setMaxCount(_maxCount.getMaxCount());
    TripDetailsInclusionBean inclusion = query.getInclusion();
    inclusion.setIncludeTripBean(_includeTrip);
    inclusion.setIncludeTripSchedule(_includeSchedule);
    inclusion.setIncludeTripStatus(_includeStatus);
    BeanFactoryV2 factory = getBeanFactoryV2();
    try {
        ListBean<TripDetailsBean> trips = _service.getTripsForBounds(query);
        return setOkResponse(factory.getTripDetailsResponse(trips));
    } catch (OutOfServiceAreaServiceException ex) {
        return setOkResponse(factory.getEmptyList(TripDetailsV2Bean.class, true));
    }
}
Also used : OutOfServiceAreaServiceException(org.onebusaway.exceptions.OutOfServiceAreaServiceException) TripDetailsInclusionBean(org.onebusaway.transit_data.model.trips.TripDetailsInclusionBean) TripsForBoundsQueryBean(org.onebusaway.transit_data.model.trips.TripsForBoundsQueryBean) TripDetailsBean(org.onebusaway.transit_data.model.trips.TripDetailsBean) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds) BeanFactoryV2(org.onebusaway.api.model.transit.BeanFactoryV2)

Example 15 with TripDetailsBean

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

the class MetricResource method getScheduledTrips.

protected int getScheduledTrips(String agencyId, String routeId) {
    Set<TripDetailsBean> agencyTrips = new HashSet<TripDetailsBean>();
    TripsForBoundsQueryBean query = new TripsForBoundsQueryBean();
    List<CoordinateBounds> allBounds = getTDS().getAgencyIdsWithCoverageArea().get(agencyId);
    for (CoordinateBounds bounds : allBounds) {
        query.setBounds(bounds);
        query.setTime(SystemTime.currentTimeMillis());
        query.setMaxCount(Integer.MAX_VALUE);
        TripDetailsInclusionBean inclusion = query.getInclusion();
        inclusion.setIncludeTripBean(true);
        ListBean<TripDetailsBean> allTrips = getTDS().getTripsForBounds(query);
        if (allTrips == null) {
            continue;
        }
        _log.debug("allTrips size=" + allTrips.getList().size());
        AgencyAndId routeAndId = new AgencyAndId(agencyId, routeId);
        for (TripDetailsBean trip : allTrips.getList()) {
            if (trip.getTripId().startsWith(agencyId)) {
                if (routeId == null || routeAndId.toString().equals(trip.getTrip().getRoute().getId())) {
                    agencyTrips.add(trip);
                }
            }
        }
    }
    return agencyTrips.size();
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TripDetailsInclusionBean(org.onebusaway.transit_data.model.trips.TripDetailsInclusionBean) TripsForBoundsQueryBean(org.onebusaway.transit_data.model.trips.TripsForBoundsQueryBean) TripDetailsBean(org.onebusaway.transit_data.model.trips.TripDetailsBean) HashSet(java.util.HashSet) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds)

Aggregations

TripDetailsBean (org.onebusaway.transit_data.model.trips.TripDetailsBean)16 TripDetailsInclusionBean (org.onebusaway.transit_data.model.trips.TripDetailsInclusionBean)10 ArrayList (java.util.ArrayList)6 BeanFactoryV2 (org.onebusaway.api.model.transit.BeanFactoryV2)5 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)4 TimepointPredictionRecord (org.onebusaway.realtime.api.TimepointPredictionRecord)4 Date (java.util.Date)3 OutOfServiceAreaServiceException (org.onebusaway.exceptions.OutOfServiceAreaServiceException)3 TripForVehicleQueryBean (org.onebusaway.transit_data.model.trips.TripForVehicleQueryBean)3 TripDetailsV2Bean (org.onebusaway.api.model.transit.TripDetailsV2Bean)2 CoordinateBounds (org.onebusaway.geospatial.model.CoordinateBounds)2 ListBean (org.onebusaway.transit_data.model.ListBean)2 TripDetailsQueryBean (org.onebusaway.transit_data.model.trips.TripDetailsQueryBean)2 TripStatusBean (org.onebusaway.transit_data.model.trips.TripStatusBean)2 TripsForBoundsQueryBean (org.onebusaway.transit_data.model.trips.TripsForBoundsQueryBean)2 BlockLocation (org.onebusaway.transit_data_federation.services.realtime.BlockLocation)2 BlockTripEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry)2 TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)2 SiriExtensionWrapper (org.onebusaway.transit_data_federation.siri.SiriExtensionWrapper)2 VehicleActivityStructure (uk.org.siri.siri.VehicleActivityStructure)2