Search in sources :

Example 21 with TripBean

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

the class RealtimeServiceV2Impl method getMonitoredStopVisitsForStop.

@Override
public List<MonitoredStopVisitStructure> getMonitoredStopVisitsForStop(String stopId, int maximumOnwardCalls, DetailLevel detailLevel, long currentTime, List<AgencyAndId> routeIds, Map<Filters, String> filters) {
    List<MonitoredStopVisitStructure> output = new ArrayList<MonitoredStopVisitStructure>();
    String directionId = filters.get(Filters.DIRECTION_REF);
    int maximumStopVisits = SiriSupportV2.convertToNumeric(filters.get(Filters.MAX_STOP_VISITS), Integer.MAX_VALUE);
    Integer minimumStopVisitsPerLine = SiriSupportV2.convertToNumeric(filters.get(Filters.MIN_STOP_VISITS), null);
    Map<AgencyAndId, Integer> visitCountByLine = new HashMap<AgencyAndId, Integer>();
    int visitCount = 0;
    for (ArrivalAndDepartureBean adBean : getArrivalsAndDeparturesForStop(stopId, currentTime)) {
        TripStatusBean statusBeanForCurrentTrip = adBean.getTripStatus();
        TripBean tripBeanForAd = adBean.getTrip();
        if (statusBeanForCurrentTrip == null)
            continue;
        if (!_presentationService.include(statusBeanForCurrentTrip) || !_presentationService.include(adBean, statusBeanForCurrentTrip))
            continue;
        MonitoredStopVisitStructure stopVisit = new MonitoredStopVisitStructure();
        stopVisit.setRecordedAtTime(DateUtil.toXmlGregorianCalendar(statusBeanForCurrentTrip.getLastUpdateTime()));
        List<TimepointPredictionRecord> timePredictionRecords = null;
        timePredictionRecords = _transitDataService.getPredictionRecordsForTrip(AgencyAndId.convertFromString(stopId).getAgencyId(), statusBeanForCurrentTrip);
        MonitoredVehicleJourneyStructure mvjourney = new MonitoredVehicleJourneyStructure();
        stopVisit.setMonitoredVehicleJourney(mvjourney);
        SiriSupportV2.fillMonitoredVehicleJourney(mvjourney, tripBeanForAd, statusBeanForCurrentTrip, adBean.getStop(), OnwardCallsMode.STOP_MONITORING, _presentationService, _transitDataService, maximumOnwardCalls, timePredictionRecords, statusBeanForCurrentTrip.isPredicted(), detailLevel, currentTime, filters);
        // FILTERS
        AgencyAndId thisRouteId = AgencyAndIdLibrary.convertFromString(mvjourney.getLineRef().getValue());
        String thisDirectionId = mvjourney.getDirectionRef().getValue();
        if (routeIds.size() > 0 && !routeIds.contains(thisRouteId))
            continue;
        if (directionId != null && !thisDirectionId.equals(directionId))
            continue;
        // Monitored Stop Visits
        Map<String, MonitoredStopVisitStructure> visitsMap = new HashMap<String, MonitoredStopVisitStructure>();
        // visit count filters
        Integer visitCountForThisLine = visitCountByLine.get(thisRouteId);
        if (visitCountForThisLine == null) {
            visitCountForThisLine = 0;
        }
        if (visitCount >= maximumStopVisits) {
            if (minimumStopVisitsPerLine == null) {
                break;
            } else {
                if (visitCountForThisLine >= minimumStopVisitsPerLine) {
                    continue;
                }
            }
        }
        // unique stops filters
        if (stopVisit.getMonitoredVehicleJourney() == null || stopVisit.getMonitoredVehicleJourney().getVehicleRef() == null || StringUtils.isBlank(stopVisit.getMonitoredVehicleJourney().getVehicleRef().getValue())) {
            continue;
        } else {
            String visitKey = stopVisit.getMonitoredVehicleJourney().getVehicleRef().getValue();
            if (visitsMap.containsKey(stopVisit.getMonitoredVehicleJourney().getVehicleRef().getValue())) {
                if (stopVisit.getMonitoredVehicleJourney().getProgressStatus() == null) {
                    visitsMap.remove(visitKey);
                    visitsMap.put(visitKey, stopVisit);
                }
                continue;
            } else {
                visitsMap.put(stopVisit.getMonitoredVehicleJourney().getVehicleRef().getValue(), stopVisit);
            }
        }
        output.add(stopVisit);
        visitCount++;
        visitCountForThisLine++;
        visitCountByLine.put(thisRouteId, visitCountForThisLine);
    }
    Collections.sort(output, new Comparator<MonitoredStopVisitStructure>() {

        public int compare(MonitoredStopVisitStructure arg0, MonitoredStopVisitStructure 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 : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SiriExtensionWrapper(org.onebusaway.transit_data_federation.siri.SiriExtensionWrapper) TripBean(org.onebusaway.transit_data.model.trips.TripBean) MonitoredStopVisitStructure(uk.org.siri.siri_2.MonitoredStopVisitStructure) ArrivalAndDepartureBean(org.onebusaway.transit_data.model.ArrivalAndDepartureBean) MonitoredVehicleJourneyStructure(uk.org.siri.siri_2.MonitoredVehicleJourneyStructure) TimepointPredictionRecord(org.onebusaway.realtime.api.TimepointPredictionRecord) TripStatusBean(org.onebusaway.transit_data.model.trips.TripStatusBean)

Example 22 with TripBean

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

the class BeanFactoryV2 method getTripStopTimes.

public TripStopTimesV2Bean getTripStopTimes(TripStopTimesBean tripStopTimes) {
    TripStopTimesV2Bean bean = new TripStopTimesV2Bean();
    bean.setTimeZone(tripStopTimes.getTimeZone());
    List<TripStopTimeV2Bean> instances = new ArrayList<TripStopTimeV2Bean>();
    for (TripStopTimeBean sti : tripStopTimes.getStopTimes()) {
        TripStopTimeV2Bean stiBean = new TripStopTimeV2Bean();
        stiBean.setArrivalTime(sti.getArrivalTime());
        stiBean.setDepartureTime(sti.getDepartureTime());
        stiBean.setStopHeadsign(sti.getStopHeadsign());
        stiBean.setDistanceAlongTrip(sti.getDistanceAlongTrip());
        stiBean.setStopId(sti.getStop().getId());
        addToReferences(sti.getStop());
        instances.add(stiBean);
    }
    bean.setStopTimes(instances);
    TripBean nextTrip = tripStopTimes.getNextTrip();
    if (nextTrip != null) {
        bean.setNextTripId(nextTrip.getId());
        addToReferences(nextTrip);
    }
    TripBean prevTrip = tripStopTimes.getPreviousTrip();
    if (prevTrip != null) {
        bean.setPreviousTripId(prevTrip.getId());
        addToReferences(prevTrip);
    }
    FrequencyBean freq = tripStopTimes.getFrequency();
    if (freq != null)
        bean.setFrequency(getFrequency(freq));
    return bean;
}
Also used : FrequencyBean(org.onebusaway.transit_data.model.schedule.FrequencyBean) ArrayList(java.util.ArrayList) TripStopTimeBean(org.onebusaway.transit_data.model.TripStopTimeBean) BlockTripBean(org.onebusaway.transit_data.model.blocks.BlockTripBean) TripBean(org.onebusaway.transit_data.model.trips.TripBean)

Example 23 with TripBean

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

the class BeanFactoryV2 method getTripStatus.

public TripStatusV2Bean getTripStatus(TripStatusBean tripStatus) {
    TripStatusV2Bean bean = new TripStatusV2Bean();
    TripBean activeTrip = tripStatus.getActiveTrip();
    if (activeTrip != null) {
        bean.setActiveTripId(activeTrip.getId());
        bean.setBlockTripSequence(tripStatus.getBlockTripSequence());
        addToReferences(activeTrip);
    }
    bean.setServiceDate(tripStatus.getServiceDate());
    FrequencyBean frequency = tripStatus.getFrequency();
    if (frequency != null)
        bean.setFrequency(getFrequency(frequency));
    bean.setScheduledDistanceAlongTrip(tripStatus.getScheduledDistanceAlongTrip());
    bean.setTotalDistanceAlongTrip(tripStatus.getTotalDistanceAlongTrip());
    bean.setPosition(tripStatus.getLocation());
    if (tripStatus.isOrientationSet())
        bean.setOrientation(tripStatus.getOrientation());
    StopBean closestStop = tripStatus.getClosestStop();
    if (closestStop != null) {
        bean.setClosestStop(closestStop.getId());
        addToReferences(closestStop);
        bean.setClosestStopTimeOffset(tripStatus.getClosestStopTimeOffset());
    }
    StopBean nextStop = tripStatus.getNextStop();
    if (nextStop != null) {
        bean.setNextStop(nextStop.getId());
        addToReferences(nextStop);
        bean.setNextStopTimeOffset(tripStatus.getNextStopTimeOffset());
    }
    bean.setPhase(tripStatus.getPhase());
    bean.setStatus(tripStatus.getStatus());
    bean.setPredicted(tripStatus.isPredicted());
    if (tripStatus.getLastUpdateTime() > 0)
        bean.setLastUpdateTime(tripStatus.getLastUpdateTime());
    if (tripStatus.getLastLocationUpdateTime() > 0)
        bean.setLastLocationUpdateTime(tripStatus.getLastLocationUpdateTime());
    if (tripStatus.isLastKnownDistanceAlongTripSet())
        bean.setLastKnownDistanceAlongTrip(tripStatus.getLastKnownDistanceAlongTrip());
    bean.setLastKnownLocation(tripStatus.getLastKnownLocation());
    if (tripStatus.isLastKnownOrientationSet())
        bean.setLastKnownOrientation(tripStatus.getLastKnownOrientation());
    if (tripStatus.isScheduleDeviationSet())
        bean.setScheduleDeviation((int) tripStatus.getScheduleDeviation());
    if (tripStatus.isDistanceAlongTripSet())
        bean.setDistanceAlongTrip(tripStatus.getDistanceAlongTrip());
    bean.setVehicleId(tripStatus.getVehicleId());
    List<ServiceAlertBean> situations = tripStatus.getSituations();
    if (situations != null && !situations.isEmpty()) {
        List<String> situationIds = new ArrayList<String>();
        for (ServiceAlertBean situation : situations) {
            situationIds.add(situation.getId());
            addToReferences(situation);
        }
        bean.setSituationIds(situationIds);
    }
    return bean;
}
Also used : FrequencyBean(org.onebusaway.transit_data.model.schedule.FrequencyBean) ArrayList(java.util.ArrayList) BlockTripBean(org.onebusaway.transit_data.model.blocks.BlockTripBean) TripBean(org.onebusaway.transit_data.model.trips.TripBean) StopBean(org.onebusaway.transit_data.model.StopBean) ServiceAlertBean(org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean)

Example 24 with TripBean

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

the class BeanFactoryV2 method getVehicleStatus.

public VehicleStatusV2Bean getVehicleStatus(VehicleStatusBean vehicleStatus) {
    VehicleStatusV2Bean bean = new VehicleStatusV2Bean();
    bean.setLastUpdateTime(vehicleStatus.getLastUpdateTime());
    if (vehicleStatus.getLastLocationUpdateTime() > 0)
        bean.setLastLocationUpdateTime(vehicleStatus.getLastLocationUpdateTime());
    bean.setLocation(vehicleStatus.getLocation());
    bean.setPhase(vehicleStatus.getPhase());
    bean.setStatus(vehicleStatus.getStatus());
    bean.setVehicleId(vehicleStatus.getVehicleId());
    TripBean trip = vehicleStatus.getTrip();
    if (trip != null) {
        bean.setTripId(trip.getId());
        addToReferences(trip);
    }
    TripStatusBean tripStatus = vehicleStatus.getTripStatus();
    if (tripStatus != null)
        bean.setTripStatus(getTripStatus(tripStatus));
    return bean;
}
Also used : BlockTripBean(org.onebusaway.transit_data.model.blocks.BlockTripBean) TripBean(org.onebusaway.transit_data.model.trips.TripBean) TripStatusBean(org.onebusaway.transit_data.model.trips.TripStatusBean)

Example 25 with TripBean

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

the class VehiclePositionsForAgencyAction method fillFeedMessage.

@Override
protected void fillFeedMessage(FeedMessage.Builder feed, String agencyId, long timestamp) {
    ListBean<VehicleStatusBean> vehicles = _service.getAllVehiclesForAgency(agencyId, timestamp);
    for (VehicleStatusBean vehicle : vehicles.getList()) {
        FeedEntity.Builder entity = feed.addEntityBuilder();
        entity.setId(Integer.toString(feed.getEntityCount()));
        VehiclePosition.Builder vehiclePosition = entity.getVehicleBuilder();
        TripStatusBean tripStatus = vehicle.getTripStatus();
        if (tripStatus != null) {
            TripBean activeTrip = tripStatus.getActiveTrip();
            RouteBean route = activeTrip.getRoute();
            TripDescriptor.Builder tripDesc = vehiclePosition.getTripBuilder();
            tripDesc.setTripId(normalizeId(activeTrip.getId()));
            tripDesc.setRouteId(normalizeId(route.getId()));
        }
        VehicleDescriptor.Builder vehicleDesc = vehiclePosition.getVehicleBuilder();
        vehicleDesc.setId(normalizeId(vehicle.getVehicleId()));
        CoordinatePoint location = vehicle.getLocation();
        if (location != null) {
            Position.Builder position = vehiclePosition.getPositionBuilder();
            position.setLatitude((float) location.getLat());
            position.setLongitude((float) location.getLon());
        }
        vehiclePosition.setTimestamp(vehicle.getLastUpdateTime() / 1000);
    }
}
Also used : CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) VehiclePosition(com.google.transit.realtime.GtfsRealtime.VehiclePosition) Position(com.google.transit.realtime.GtfsRealtime.Position) TripBean(org.onebusaway.transit_data.model.trips.TripBean) VehicleStatusBean(org.onebusaway.transit_data.model.VehicleStatusBean) RouteBean(org.onebusaway.transit_data.model.RouteBean) VehiclePosition(com.google.transit.realtime.GtfsRealtime.VehiclePosition) TripDescriptor(com.google.transit.realtime.GtfsRealtime.TripDescriptor) TripStatusBean(org.onebusaway.transit_data.model.trips.TripStatusBean) FeedEntity(com.google.transit.realtime.GtfsRealtime.FeedEntity) VehicleDescriptor(com.google.transit.realtime.GtfsRealtime.VehicleDescriptor)

Aggregations

TripBean (org.onebusaway.transit_data.model.trips.TripBean)28 RouteBean (org.onebusaway.transit_data.model.RouteBean)14 TripStatusBean (org.onebusaway.transit_data.model.trips.TripStatusBean)12 ArrayList (java.util.ArrayList)11 ArrivalAndDepartureBean (org.onebusaway.transit_data.model.ArrivalAndDepartureBean)8 StopBean (org.onebusaway.transit_data.model.StopBean)8 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)6 BlockTripBean (org.onebusaway.transit_data.model.blocks.BlockTripBean)6 FrequencyBean (org.onebusaway.transit_data.model.schedule.FrequencyBean)6 Date (java.util.Date)5 ServiceAlertBean (org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean)5 FeedEntity (com.google.transit.realtime.GtfsRealtime.FeedEntity)4 Test (org.junit.Test)4 VehicleStatusBean (org.onebusaway.transit_data.model.VehicleStatusBean)4 BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)4 BlockTripEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry)4 TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)4 TimepointPredictionRecord (org.onebusaway.realtime.api.TimepointPredictionRecord)3 TripStopTimesBean (org.onebusaway.transit_data.model.TripStopTimesBean)3 FrequencyEntry (org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry)3