Search in sources :

Example 6 with TripStatusBean

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

the class BeanFactoryV2 method getTripDetails.

public TripDetailsV2Bean getTripDetails(TripDetailsBean tripDetails) {
    TripDetailsV2Bean bean = new TripDetailsV2Bean();
    bean.setTripId(tripDetails.getTripId());
    bean.setServiceDate(tripDetails.getServiceDate());
    if (tripDetails.getFrequency() != null)
        bean.setFrequency(getFrequency(tripDetails.getFrequency()));
    TripBean trip = tripDetails.getTrip();
    if (trip != null)
        addToReferences(trip);
    TripStopTimesBean stopTimes = tripDetails.getSchedule();
    if (stopTimes != null)
        bean.setSchedule(getTripStopTimes(stopTimes));
    TripStatusBean status = tripDetails.getStatus();
    if (status != null)
        bean.setStatus(getTripStatus(status));
    List<ServiceAlertBean> situations = tripDetails.getSituations();
    if (!CollectionsLibrary.isEmpty(situations)) {
        List<String> situationIds = new ArrayList<String>();
        for (ServiceAlertBean situation : situations) {
            addToReferences(situation);
            situationIds.add(situation.getId());
        }
        bean.setSituationIds(situationIds);
    }
    return bean;
}
Also used : ArrayList(java.util.ArrayList) BlockTripBean(org.onebusaway.transit_data.model.blocks.BlockTripBean) TripBean(org.onebusaway.transit_data.model.trips.TripBean) TripStatusBean(org.onebusaway.transit_data.model.trips.TripStatusBean) ServiceAlertBean(org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean) TripStopTimesBean(org.onebusaway.transit_data.model.TripStopTimesBean)

Example 7 with TripStatusBean

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

the class BeanFactoryV2 method getArrivalAndDeparture.

public ArrivalAndDepartureV2Bean getArrivalAndDeparture(ArrivalAndDepartureBean ad) {
    TripBean trip = ad.getTrip();
    RouteBean route = trip.getRoute();
    StopBean stop = ad.getStop();
    ArrivalAndDepartureV2Bean bean = new ArrivalAndDepartureV2Bean();
    bean.setTripId(trip.getId());
    addToReferences(trip);
    bean.setServiceDate(ad.getServiceDate());
    bean.setVehicleId(ad.getVehicleId());
    bean.setStopId(stop.getId());
    addToReferences(stop);
    bean.setStopSequence(ad.getStopSequence());
    bean.setBlockTripSequence(ad.getBlockTripSequence());
    bean.setTotalStopsInTrip(ad.getTotalStopsInTrip());
    bean.setRouteId(route.getId());
    addToReferences(route);
    String routeShortName = ad.getRouteShortName();
    if (routeShortName == null || routeShortName.isEmpty())
        routeShortName = trip.getRouteShortName();
    if (routeShortName == null || routeShortName.isEmpty())
        routeShortName = route.getShortName();
    bean.setRouteShortName(routeShortName);
    bean.setRouteLongName(route.getLongName());
    String tripHeadsign = ad.getTripHeadsign();
    if (tripHeadsign == null || tripHeadsign.isEmpty())
        tripHeadsign = trip.getTripHeadsign();
    bean.setTripHeadsign(tripHeadsign);
    bean.setArrivalEnabled(ad.isArrivalEnabled());
    bean.setDepartureEnabled(ad.isDepartureEnabled());
    bean.setScheduledArrivalTime(ad.getScheduledArrivalTime());
    bean.setScheduledDepartureTime(ad.getScheduledDepartureTime());
    bean.setPredictedArrivalTime(ad.getPredictedArrivalTime());
    bean.setPredictedDepartureTime(ad.getPredictedDepartureTime());
    bean.setScheduledArrivalInterval(getTimeInterval(ad.getScheduledArrivalInterval()));
    bean.setScheduledDepartureInterval(getTimeInterval(ad.getScheduledDepartureInterval()));
    bean.setPredictedArrivalInterval(getTimeInterval(ad.getPredictedArrivalInterval()));
    bean.setPredictedDepartureInterval(getTimeInterval(ad.getPredictedDepartureInterval()));
    if (ad.getFrequency() != null)
        bean.setFrequency(getFrequency(ad.getFrequency()));
    bean.setStatus(ad.getStatus());
    if (ad.isDistanceFromStopSet())
        bean.setDistanceFromStop(ad.getDistanceFromStop());
    bean.setNumberOfStopsAway(ad.getNumberOfStopsAway());
    TripStatusBean tripStatus = ad.getTripStatus();
    if (tripStatus != null)
        bean.setTripStatus(getTripStatus(tripStatus));
    bean.setPredicted(ad.isPredicted());
    bean.setLastUpdateTime(ad.getLastUpdateTime());
    List<ServiceAlertBean> situations = ad.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 : RouteBean(org.onebusaway.transit_data.model.RouteBean) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) 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) TripStatusBean(org.onebusaway.transit_data.model.trips.TripStatusBean) ServiceAlertBean(org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean)

Example 8 with TripStatusBean

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

the class TripUpdatesForAgencyAction 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()) {
        TripStatusBean tripStatus = vehicle.getTripStatus();
        if (tripStatus == null) {
            continue;
        }
        TripBean activeTrip = tripStatus.getActiveTrip();
        RouteBean route = activeTrip.getRoute();
        FeedEntity.Builder entity = feed.addEntityBuilder();
        entity.setId(Integer.toString(feed.getEntityCount()));
        TripUpdate.Builder tripUpdate = entity.getTripUpdateBuilder();
        TripDescriptor.Builder tripDesc = tripUpdate.getTripBuilder();
        tripDesc.setTripId(normalizeId(activeTrip.getId()));
        tripDesc.setRouteId(normalizeId(route.getId()));
        VehicleDescriptor.Builder vehicleDesc = tripUpdate.getVehicleBuilder();
        vehicleDesc.setId(normalizeId(vehicle.getVehicleId()));
        if (tripStatus.getTimepointPredictions() != null && tripStatus.getTimepointPredictions().size() > 0) {
            for (TimepointPredictionBean timepointPrediction : tripStatus.getTimepointPredictions()) {
                AgencyAndId stopId = modifiedStopId(agencyId, timepointPrediction.getTimepointId());
                if (!stopId.getAgencyId().equals(agencyId))
                    continue;
                TripUpdate.StopTimeUpdate.Builder stopTimeUpdate = tripUpdate.addStopTimeUpdateBuilder();
                stopTimeUpdate.setStopId(normalizeId(stopId.toString()));
                TripUpdate.StopTimeEvent.Builder arrival = stopTimeUpdate.getArrivalBuilder();
                if (timepointPrediction.getTimepointPredictedArrivalTime() != -1) {
                    arrival.setTime(timepointPrediction.getTimepointPredictedArrivalTime() / 1000L);
                }
                TripUpdate.StopTimeEvent.Builder departure = stopTimeUpdate.getDepartureBuilder();
                if (timepointPrediction.getTimepointPredictedDepartureTime() != -1) {
                    departure.setTime(timepointPrediction.getTimepointPredictedDepartureTime() / 1000L);
                }
            }
            tripUpdate.setTimestamp(vehicle.getLastUpdateTime() / 1000);
        } else {
            StopBean nextStop = tripStatus.getNextStop();
            if (nextStop != null) {
                AgencyAndId stopId = modifiedStopId(agencyId, nextStop.getId());
                if (stopId.getAgencyId().equals(agencyId)) {
                    TripUpdate.StopTimeUpdate.Builder stopTimeUpdate = tripUpdate.addStopTimeUpdateBuilder();
                    stopTimeUpdate.setStopId(normalizeId(stopId.toString()));
                    TripUpdate.StopTimeEvent.Builder departure = stopTimeUpdate.getDepartureBuilder();
                    departure.setTime(timestamp / 1000 + tripStatus.getNextStopTimeOffset());
                }
            }
        }
        tripUpdate.setDelay((int) tripStatus.getScheduleDeviation());
        tripUpdate.setTimestamp(vehicle.getLastUpdateTime() / 1000);
    }
}
Also used : TimepointPredictionBean(org.onebusaway.transit_data.model.trips.TimepointPredictionBean) TripUpdate(com.google.transit.realtime.GtfsRealtime.TripUpdate) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TripBean(org.onebusaway.transit_data.model.trips.TripBean) VehicleStatusBean(org.onebusaway.transit_data.model.VehicleStatusBean) RouteBean(org.onebusaway.transit_data.model.RouteBean) TripDescriptor(com.google.transit.realtime.GtfsRealtime.TripDescriptor) StopBean(org.onebusaway.transit_data.model.StopBean) TripStatusBean(org.onebusaway.transit_data.model.trips.TripStatusBean) FeedEntity(com.google.transit.realtime.GtfsRealtime.FeedEntity) VehicleDescriptor(com.google.transit.realtime.GtfsRealtime.VehicleDescriptor)

Example 9 with TripStatusBean

use of org.onebusaway.transit_data.model.trips.TripStatusBean 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 10 with TripStatusBean

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

the class TripAction method getActualServiceDate.

private long getActualServiceDate() {
    TripStatusBean status = _tripDetails.getStatus();
    if (status != null)
        return status.getServiceDate();
    Calendar c = Calendar.getInstance(_timeZone);
    // Initial set time to noon
    c.set(Calendar.HOUR_OF_DAY, 12);
    c.set(Calendar.MINUTE, 0);
    c.set(Calendar.SECOND, 0);
    c.set(Calendar.MILLISECOND, 0);
    // Subtract 12 hours. Usually takes you to midnight, except on DST days
    c.add(Calendar.HOUR_OF_DAY, -12);
    return c.getTimeInMillis();
}
Also used : Calendar(java.util.Calendar) TripStatusBean(org.onebusaway.transit_data.model.trips.TripStatusBean)

Aggregations

TripStatusBean (org.onebusaway.transit_data.model.trips.TripStatusBean)16 TripBean (org.onebusaway.transit_data.model.trips.TripBean)12 ArrayList (java.util.ArrayList)8 RouteBean (org.onebusaway.transit_data.model.RouteBean)6 StopBean (org.onebusaway.transit_data.model.StopBean)5 FeedEntity (com.google.transit.realtime.GtfsRealtime.FeedEntity)4 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)4 VehicleStatusBean (org.onebusaway.transit_data.model.VehicleStatusBean)4 ServiceAlertBean (org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean)4 Date (java.util.Date)3 Test (org.junit.Test)3 TimepointPredictionRecord (org.onebusaway.realtime.api.TimepointPredictionRecord)3 ArrivalAndDepartureBean (org.onebusaway.transit_data.model.ArrivalAndDepartureBean)3 BlockTripBean (org.onebusaway.transit_data.model.blocks.BlockTripBean)3 BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)3 FeedMessage (com.google.transit.realtime.GtfsRealtime.FeedMessage)2 TripDescriptor (com.google.transit.realtime.GtfsRealtime.TripDescriptor)2 TripUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate)2 VehicleDescriptor (com.google.transit.realtime.GtfsRealtime.VehicleDescriptor)2 VehiclePosition (com.google.transit.realtime.GtfsRealtime.VehiclePosition)2