Search in sources :

Example 1 with Vehicle

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;
}
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 Vehicle

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;
}
Also used : Vehicle(org.onebusaway.nextbus.model.nextbus.Vehicle) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ArrayList(java.util.ArrayList) Body(org.onebusaway.nextbus.model.nextbus.Body) LastTime(org.onebusaway.nextbus.model.nextbus.LastTime)

Aggregations

ArrayList (java.util.ArrayList)2 Vehicle (org.onebusaway.nextbus.model.nextbus.Vehicle)2 BigDecimal (java.math.BigDecimal)1 DecimalFormat (java.text.DecimalFormat)1 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)1 Body (org.onebusaway.nextbus.model.nextbus.Body)1 LastTime (org.onebusaway.nextbus.model.nextbus.LastTime)1 TripDetailsBean (org.onebusaway.transit_data.model.trips.TripDetailsBean)1 TripStatusBean (org.onebusaway.transit_data.model.trips.TripStatusBean)1