Search in sources :

Example 1 with TripDetailsBean

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

the class VehicleLocationsAction method getVehiclesForRoute.

private List<Vehicle> getVehiclesForRoute(String routeId, ListBean<TripDetailsBean> trips) {
    DecimalFormat df = new DecimalFormat();
    df.setMaximumFractionDigits(6);
    List<Vehicle> vehiclesList = new ArrayList<Vehicle>();
    for (TripDetailsBean tripDetails : trips.getList()) {
        TripStatusBean tripStatus = tripDetails.getStatus();
        // filter out interlined routes
        if (routeId != null && !tripDetails.getTrip().getRoute().getId().equals(routeId))
            continue;
        Vehicle vehicle = new Vehicle();
        String vehicleId = null;
        if (tripStatus.getVehicleId() != null) {
            vehicleId = getIdNoAgency(tripStatus.getVehicleId());
        } else
            continue;
        vehicle.setId(vehicleId);
        vehicle.setLat(new BigDecimal(df.format(tripStatus.getLocation().getLat())));
        vehicle.setLon(new BigDecimal(df.format(tripStatus.getLocation().getLon())));
        vehicle.setHeading((int) tripStatus.getOrientation());
        vehicle.setDirTag(tripStatus.getActiveTrip().getDirectionId());
        vehicle.setPredictable(tripStatus.isPredicted());
        vehicle.setRouteTag(getIdNoAgency(tripStatus.getActiveTrip().getRoute().getId()));
        vehicle.setTripTag(getIdNoAgency(tripStatus.getActiveTrip().getId()));
        vehicle.setBlock(getIdNoAgency(tripStatus.getActiveTrip().getBlockId()));
        int secondsSinceUpdate = 0;
        if (tripStatus.getLastUpdateTime() > 0)
            secondsSinceUpdate = (int) TimeUnit.MILLISECONDS.toSeconds(SystemTime.currentTimeMillis() - tripStatus.getLastUpdateTime());
        vehicle.setSecsSinceReport(secondsSinceUpdate);
        vehiclesList.add(vehicle);
    }
    return vehiclesList;
}
Also used : Vehicle(org.onebusaway.nextbus.model.nextbus.Vehicle) DecimalFormat(java.text.DecimalFormat) ArrayList(java.util.ArrayList) TripStatusBean(org.onebusaway.transit_data.model.trips.TripStatusBean) TripDetailsBean(org.onebusaway.transit_data.model.trips.TripDetailsBean) BigDecimal(java.math.BigDecimal)

Example 2 with TripDetailsBean

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

the class TripStatusBeanServiceImpl method getTripEntryAndBlockLocationAsTripDetails.

private TripDetailsBean getTripEntryAndBlockLocationAsTripDetails(BlockTripInstance blockTripInstance, BlockLocation blockLocation, TripDetailsInclusionBean inclusion, long time) {
    TripBean trip = null;
    long serviceDate = blockTripInstance.getServiceDate();
    FrequencyBean frequency = null;
    TripStopTimesBean stopTimes = null;
    TripStatusBean status = null;
    AgencyAndId vehicleId = null;
    boolean missing = false;
    FrequencyEntry frequencyLabel = blockTripInstance.getFrequencyLabel();
    if (frequencyLabel != null) {
        frequency = FrequencyBeanLibrary.getBeanForFrequency(serviceDate, frequencyLabel);
    }
    BlockTripEntry blockTrip = blockTripInstance.getBlockTrip();
    TripEntry tripEntry = blockTrip.getTrip();
    if (inclusion.isIncludeTripBean()) {
        trip = _tripBeanService.getTripForId(tripEntry.getId());
        if (trip == null)
            missing = true;
    }
    if (inclusion.isIncludeTripSchedule()) {
        stopTimes = _tripStopTimesBeanService.getStopTimesForBlockTrip(blockTripInstance);
        if (stopTimes == null)
            missing = true;
    }
    if (inclusion.isIncludeTripStatus() && blockLocation != null) {
        status = getBlockLocationAsStatusBean(blockLocation, time);
        if (status == null)
            missing = true;
        else
            vehicleId = AgencyAndIdLibrary.convertFromString(status.getVehicleId());
    }
    List<ServiceAlertBean> situations = _serviceAlertBeanService.getServiceAlertsForVehicleJourney(time, blockTripInstance, vehicleId);
    if (missing)
        return null;
    String tripId = AgencyAndIdLibrary.convertToString(tripEntry.getId());
    TripDetailsBean bean = new TripDetailsBean();
    bean.setTripId(tripId);
    bean.setServiceDate(serviceDate);
    bean.setFrequency(frequency);
    bean.setTrip(trip);
    bean.setSchedule(stopTimes);
    bean.setStatus(status);
    bean.setSituations(situations);
    return bean;
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) TripBean(org.onebusaway.transit_data.model.trips.TripBean) FrequencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) TripStopTimesBean(org.onebusaway.transit_data.model.TripStopTimesBean) FrequencyBean(org.onebusaway.transit_data.model.schedule.FrequencyBean) TripStatusBean(org.onebusaway.transit_data.model.trips.TripStatusBean) ServiceAlertBean(org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean) TripDetailsBean(org.onebusaway.transit_data.model.trips.TripDetailsBean)

Example 3 with TripDetailsBean

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

the class TripStatusBeanServiceImpl method getTripsForId.

@Override
public ListBean<TripDetailsBean> getTripsForId(TripDetailsQueryBean query) {
    AgencyAndId tripId = AgencyAndIdLibrary.convertFromString(query.getTripId());
    long serviceDate = query.getServiceDate();
    AgencyAndId vehicleId = AgencyAndIdLibrary.convertFromString(query.getVehicleId());
    long time = query.getTime();
    TripEntry tripEntry = _transitGraphDao.getTripEntryForId(tripId);
    if (tripEntry == null)
        return new ListBean<TripDetailsBean>();
    Map<BlockInstance, List<BlockLocation>> locationsByInstance = _blockStatusService.getBlocks(tripEntry.getBlock().getId(), serviceDate, vehicleId, time);
    List<TripDetailsBean> tripDetails = new ArrayList<TripDetailsBean>();
    for (Map.Entry<BlockInstance, List<BlockLocation>> entry : locationsByInstance.entrySet()) {
        BlockInstance blockInstance = entry.getKey();
        List<BlockLocation> locations = entry.getValue();
        BlockTripInstance blockTripInstance = BlockTripInstanceLibrary.getBlockTripInstance(blockInstance, tripId);
        if (blockTripInstance == null)
            throw new IllegalStateException("expected blockTrip for trip=" + tripEntry + " and block=" + blockInstance);
        /**
         * If we have no locations for the specified block instance, it means the
         * block is not currently active. But we can still attempt to construct a
         * trip details
         */
        if (locations.isEmpty()) {
            TripDetailsBean details = getTripEntryAndBlockLocationAsTripDetails(blockTripInstance, null, query.getInclusion(), time);
            tripDetails.add(details);
        } else {
            for (BlockLocation location : locations) {
                TripDetailsBean details = getBlockLocationAsTripDetails(blockTripInstance, location, query.getInclusion(), time);
                tripDetails.add(details);
            }
        }
    }
    return new ListBean<TripDetailsBean>(tripDetails, false);
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) BlockTripInstance(org.onebusaway.transit_data_federation.services.blocks.BlockTripInstance) ArrayList(java.util.ArrayList) ListBean(org.onebusaway.transit_data.model.ListBean) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) BlockLocation(org.onebusaway.transit_data_federation.services.realtime.BlockLocation) BlockInstance(org.onebusaway.transit_data_federation.services.blocks.BlockInstance) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) TripDetailsBean(org.onebusaway.transit_data.model.trips.TripDetailsBean)

Example 4 with TripDetailsBean

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

the class TripStatusBeanServiceImpl method getBlockLocationsAsTripDetails.

/**
 **
 * Private Methods
 ***
 */
private ListBean<TripDetailsBean> getBlockLocationsAsTripDetails(List<BlockLocation> locations, TripDetailsInclusionBean inclusion, long time) {
    List<TripDetailsBean> tripDetails = new ArrayList<TripDetailsBean>();
    for (BlockLocation location : locations) {
        TripDetailsBean details = getBlockLocationAsTripDetails(location.getActiveTripInstance(), location, inclusion, time);
        tripDetails.add(details);
    }
    return new ListBean<TripDetailsBean>(tripDetails, false);
}
Also used : ArrayList(java.util.ArrayList) ListBean(org.onebusaway.transit_data.model.ListBean) BlockLocation(org.onebusaway.transit_data_federation.services.realtime.BlockLocation) TripDetailsBean(org.onebusaway.transit_data.model.trips.TripDetailsBean)

Example 5 with TripDetailsBean

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

the class RealtimeServiceV2Impl method getVehicleActivityForVehicle.

@Override
public VehicleActivityStructure getVehicleActivityForVehicle(String vehicleId, int maximumOnwardCalls, DetailLevel detailLevel, long currentTime) {
    TripForVehicleQueryBean query = new TripForVehicleQueryBean();
    query.setTime(new Date(currentTime));
    query.setVehicleId(vehicleId);
    TripDetailsInclusionBean inclusion = new TripDetailsInclusionBean();
    inclusion.setIncludeTripStatus(true);
    inclusion.setIncludeTripBean(true);
    query.setInclusion(inclusion);
    TripDetailsBean tripDetailsForCurrentTrip = _transitDataService.getTripDetailsForVehicleAndTime(query);
    if (tripDetailsForCurrentTrip != null) {
        if (!_presentationService.include(tripDetailsForCurrentTrip.getStatus()))
            return null;
        VehicleActivityStructure output = new VehicleActivityStructure();
        output.setRecordedAtTime(DateUtil.toXmlGregorianCalendar(tripDetailsForCurrentTrip.getStatus().getLastUpdateTime()));
        List<TimepointPredictionRecord> timePredictionRecords = null;
        timePredictionRecords = _transitDataService.getPredictionRecordsForTrip(AgencyAndId.convertFromString(vehicleId).getAgencyId(), tripDetailsForCurrentTrip.getStatus());
        output.setMonitoredVehicleJourney(new MonitoredVehicleJourney());
        SiriSupportV2.fillMonitoredVehicleJourney(output.getMonitoredVehicleJourney(), tripDetailsForCurrentTrip.getTrip(), tripDetailsForCurrentTrip.getStatus(), null, OnwardCallsMode.VEHICLE_MONITORING, _presentationService, _transitDataService, maximumOnwardCalls, timePredictionRecords, tripDetailsForCurrentTrip.getStatus().isPredicted(), detailLevel, currentTime, null);
        return output;
    }
    return null;
}
Also used : TripForVehicleQueryBean(org.onebusaway.transit_data.model.trips.TripForVehicleQueryBean) TimepointPredictionRecord(org.onebusaway.realtime.api.TimepointPredictionRecord) TripDetailsInclusionBean(org.onebusaway.transit_data.model.trips.TripDetailsInclusionBean) VehicleActivityStructure(uk.org.siri.siri_2.VehicleActivityStructure) Date(java.util.Date) TripDetailsBean(org.onebusaway.transit_data.model.trips.TripDetailsBean) MonitoredVehicleJourney(uk.org.siri.siri_2.VehicleActivityStructure.MonitoredVehicleJourney)

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