Search in sources :

Example 6 with VehicleActivityStructure

use of uk.org.siri.siri20.VehicleActivityStructure in project OpenTripPlanner by opentripplanner.

the class SiriFuzzyTripMatcher method match.

/**
 * Matches VehicleActivity to a set of possible Trips based on tripId
 */
public Set<Trip> match(VehicleActivityStructure activity) {
    VehicleActivityStructure.MonitoredVehicleJourney monitoredVehicleJourney = activity.getMonitoredVehicleJourney();
    Set<Trip> trips = new HashSet<>();
    if (monitoredVehicleJourney != null) {
        String datedVehicleRef = null;
        if (monitoredVehicleJourney.getFramedVehicleJourneyRef() != null) {
            datedVehicleRef = monitoredVehicleJourney.getFramedVehicleJourneyRef().getDatedVehicleJourneyRef();
            if (datedVehicleRef != null) {
                trips = mappedTripsCache.get(datedVehicleRef);
            }
        }
        if (monitoredVehicleJourney.getDestinationRef() != null) {
            String destinationRef = monitoredVehicleJourney.getDestinationRef().getValue();
            ZonedDateTime arrivalTime = monitoredVehicleJourney.getDestinationAimedArrivalTime();
            if (arrivalTime != null) {
                trips = getMatchingTripsOnStopOrSiblings(destinationRef, arrivalTime);
            }
        }
    }
    return trips;
}
Also used : Trip(org.opentripplanner.model.Trip) ZonedDateTime(java.time.ZonedDateTime) VehicleActivityStructure(uk.org.siri.siri20.VehicleActivityStructure) HashSet(java.util.HashSet)

Example 7 with VehicleActivityStructure

use of uk.org.siri.siri20.VehicleActivityStructure 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()) {
        if (tripDetails == null)
            continue;
        // 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());
        boolean showApc = useApc();
        if (!TransitDataConstants.STATUS_CANCELED.equals(tripDetails.getStatus().getStatus())) {
            activity.setMonitoredVehicleJourney(new MonitoredVehicleJourney());
            SiriSupportV2.fillMonitoredVehicleJourney(activity.getMonitoredVehicleJourney(), tripDetails.getTrip(), tripDetails.getStatus(), null, OnwardCallsMode.VEHICLE_MONITORING, _presentationService, _transitDataService, maximumOnwardCalls, timePredictionRecords, tripDetails.getStatus().isPredicted(), showApc, 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)

Aggregations

VehicleActivityStructure (uk.org.siri.siri_2.VehicleActivityStructure)4 ArrayList (java.util.ArrayList)3 VehicleActivityStructure (uk.org.siri.siri20.VehicleActivityStructure)3 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)2 TimepointPredictionRecord (org.onebusaway.realtime.api.TimepointPredictionRecord)2 TripDetailsBean (org.onebusaway.transit_data.model.trips.TripDetailsBean)2 MonitoredVehicleJourney (uk.org.siri.siri_2.VehicleActivityStructure.MonitoredVehicleJourney)2 IOException (java.io.IOException)1 ZonedDateTime (java.time.ZonedDateTime)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Duration (javax.xml.datatype.Duration)1 DetailLevel (org.onebusaway.api.actions.siri.model.DetailLevel)1 ListBean (org.onebusaway.transit_data.model.ListBean)1 StopBean (org.onebusaway.transit_data.model.StopBean)1 StopsForRouteBean (org.onebusaway.transit_data.model.StopsForRouteBean)1 VehicleStatusBean (org.onebusaway.transit_data.model.VehicleStatusBean)1 ServiceAlertBean (org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean)1