use of org.onebusaway.nextbus.model.nextbus.Vehicle 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.nextbus.model.nextbus.Vehicle in project onebusaway-application-modules by camsys.
the class VehicleLocationsAction method getModel.
@Override
public Body<Vehicle> getModel() {
Body<Vehicle> body = new Body<Vehicle>();
List<AgencyAndId> routeIds = new ArrayList<AgencyAndId>();
List<String> agencies = new ArrayList<String>();
if (isValid(body)) {
agencies.add(agencyId);
processRouteIds(routeId, routeIds, agencies, body, false);
// Valid Route Specified
if (routeIds.size() > 0) {
for (AgencyAndId routeId : routeIds) {
body.getResponse().addAll(getVehiclesForRoute(routeId.toString(), getAllTripsForRoute(routeId.toString(), getT())));
}
} else // Invalid Route Specified, return results for first 100 results for agency
{
body.getResponse().addAll(getVehiclesForRoute(null, getAllTripsForAgency(agencyId, getT())));
}
body.setLastTime(new LastTime(SystemTime.currentTimeMillis()));
}
return body;
}
Aggregations