Search in sources :

Example 1 with VehicleStatus

use of org.onebusaway.transit_data_federation.services.realtime.VehicleStatus in project onebusaway-application-modules by camsys.

the class VehicleStatusBeanServiceImpl method getAllVehiclesForAgency.

@Override
public ListBean<VehicleStatusBean> getAllVehiclesForAgency(String agencyId, long time) {
    List<VehicleStatus> statuses = _vehicleStatusService.getAllVehicleStatuses();
    List<VehicleStatusBean> beans = new ArrayList<VehicleStatusBean>();
    for (VehicleStatus status : statuses) {
        AgencyAndId vid = status.getVehicleId();
        if (!vid.getAgencyId().equals(agencyId))
            continue;
        VehicleStatusBean bean = getStatusAsBean(status, time);
        beans.add(bean);
    }
    return new ListBean<VehicleStatusBean>(beans, false);
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ArrayList(java.util.ArrayList) ListBean(org.onebusaway.transit_data.model.ListBean) VehicleStatus(org.onebusaway.transit_data_federation.services.realtime.VehicleStatus) VehicleStatusBean(org.onebusaway.transit_data.model.VehicleStatusBean)

Example 2 with VehicleStatus

use of org.onebusaway.transit_data_federation.services.realtime.VehicleStatus in project onebusaway-application-modules by camsys.

the class GtfsRealtimeServiceImpl method getVehiclePositions.

@Override
public FeedMessage getVehiclePositions() {
    FeedMessage.Builder feedMessage = createFeedWithDefaultHeader();
    List<VehicleStatus> statuses = _vehicleStatusService.getAllVehicleStatuses();
    for (VehicleStatus status : statuses) {
        VehicleLocationRecord record = status.getRecord();
        VehiclePosition.Builder vehiclePosition = VehiclePosition.newBuilder();
        if (record.isCurrentLocationSet()) {
            Position.Builder position = Position.newBuilder();
            position.setLatitude((float) record.getCurrentLocationLat());
            position.setLongitude((float) record.getCurrentLocationLon());
            vehiclePosition.setPosition(position);
        }
        VehicleDescriptor.Builder vehicleDescriptor = VehicleDescriptor.newBuilder();
        vehicleDescriptor.setId(AgencyAndId.convertToString(record.getVehicleId()));
        vehiclePosition.setVehicle(vehicleDescriptor);
        if (record.getTimeOfLocationUpdate() != 0)
            vehiclePosition.setTimestamp(record.getTimeOfLocationUpdate() / 1000);
        else
            vehiclePosition.setTimestamp(record.getTimeOfRecord() / 1000);
        /**
         * TODO: Block? Trip?
         */
        FeedEntity.Builder feedEntity = FeedEntity.newBuilder();
        feedEntity.setVehicle(vehiclePosition);
        feedEntity.setId(vehicleDescriptor.getId());
        feedMessage.addEntity(feedEntity);
    }
    return feedMessage.build();
}
Also used : VehicleLocationRecord(org.onebusaway.realtime.api.VehicleLocationRecord) VehicleStatus(org.onebusaway.transit_data_federation.services.realtime.VehicleStatus)

Example 3 with VehicleStatus

use of org.onebusaway.transit_data_federation.services.realtime.VehicleStatus in project onebusaway-application-modules by camsys.

the class VehicleStatusServiceImpl method getAllVehicleStatuses.

@Override
public List<VehicleStatus> getAllVehicleStatuses() {
    ArrayList<VehicleStatus> statuses = new ArrayList<VehicleStatus>();
    for (VehicleLocationRecord record : _vehicleRecordsById.values()) {
        VehicleStatus status = new VehicleStatus();
        status.setRecord(record);
        statuses.add(status);
    }
    return statuses;
}
Also used : ArrayList(java.util.ArrayList) VehicleLocationRecord(org.onebusaway.realtime.api.VehicleLocationRecord) VehicleStatus(org.onebusaway.transit_data_federation.services.realtime.VehicleStatus)

Example 4 with VehicleStatus

use of org.onebusaway.transit_data_federation.services.realtime.VehicleStatus in project onebusaway-application-modules by camsys.

the class VehicleStatusServiceImpl method getVehicleStatusForId.

/**
 **
 * {@link VehicleStatusService} Interface
 ***
 */
@Override
public VehicleStatus getVehicleStatusForId(AgencyAndId vehicleId) {
    VehicleLocationRecord record = _vehicleRecordsById.get(vehicleId);
    if (record == null)
        return null;
    List<VehicleLocationRecord> records = new ArrayList<VehicleLocationRecord>();
    VehicleLocationCacheElements elements = _vehicleLocationRecordCache.getRecordForVehicleId(vehicleId);
    if (elements != null) {
        for (VehicleLocationCacheElement element : elements.getElements()) records.add(element.getRecord());
    }
    VehicleStatus status = new VehicleStatus();
    status.setRecord(record);
    status.setAllRecords(records);
    return status;
}
Also used : VehicleLocationCacheElements(org.onebusaway.transit_data_federation.services.realtime.VehicleLocationCacheElements) VehicleLocationCacheElement(org.onebusaway.transit_data_federation.services.realtime.VehicleLocationCacheElement) ArrayList(java.util.ArrayList) VehicleLocationRecord(org.onebusaway.realtime.api.VehicleLocationRecord) VehicleStatus(org.onebusaway.transit_data_federation.services.realtime.VehicleStatus)

Aggregations

VehicleStatus (org.onebusaway.transit_data_federation.services.realtime.VehicleStatus)4 ArrayList (java.util.ArrayList)3 VehicleLocationRecord (org.onebusaway.realtime.api.VehicleLocationRecord)3 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)1 ListBean (org.onebusaway.transit_data.model.ListBean)1 VehicleStatusBean (org.onebusaway.transit_data.model.VehicleStatusBean)1 VehicleLocationCacheElement (org.onebusaway.transit_data_federation.services.realtime.VehicleLocationCacheElement)1 VehicleLocationCacheElements (org.onebusaway.transit_data_federation.services.realtime.VehicleLocationCacheElements)1