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;
}
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;
}
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);
}
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);
}
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;
}
Aggregations