Search in sources :

Example 11 with TripBean

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

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

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

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

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

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