Search in sources :

Example 1 with VehicleDescriptor

use of com.google.transit.realtime.GtfsRealtime.VehicleDescriptor in project onebusaway-application-modules by camsys.

the class TripUpdateConvertor method readFeedEntity.

@Override
public TripUpdateModel readFeedEntity(FeedEntity entity, long timestamp) {
    if (entity.hasTripUpdate()) {
        TripUpdateModel tu = new TripUpdateModel();
        TripDescriptor t = entity.getTripUpdate().getTrip();
        if (entity.getTripUpdate().hasTimestamp()) {
            timestamp = entity.getTripUpdate().getTimestamp() * 1000;
        }
        tu.setTimestamp(new Date(timestamp));
        if (entity.getTripUpdate().hasDelay()) {
            tu.setDelay(entity.getTripUpdate().getDelay());
        }
        if (t.hasTripId())
            tu.setTripId(t.getTripId());
        if (t.hasRouteId()) {
            tu.setRouteId(t.getRouteId());
        }
        if (t.hasStartDate() && t.hasStartTime()) {
            tu.setTripStart(GtfsRealtimeConversionLibrary.parseDate(t.getStartDate(), t.getStartTime()));
        }
        tu.setScheduleRelationship(findRelationship(t));
        VehicleDescriptor vehicle = entity.getTripUpdate().getVehicle();
        if (vehicle != null) {
            tu.setVehicleId(vehicle.getId());
            tu.setVehicleLabel(vehicle.getLabel());
            tu.setVehicleLicensePlate(vehicle.getLicensePlate());
        }
        for (StopTimeUpdate stu : entity.getTripUpdate().getStopTimeUpdateList()) {
            StopTimeUpdateModel stopTimeUpdate = readStopTimeUpdate(stu, tu.getScheduleRelationship());
            if (stopTimeUpdate != null) {
                stopTimeUpdate.setTripUpdateModel(tu);
                tu.addStopTimeUpdateModel(stopTimeUpdate);
            }
        }
        return tu;
    }
    return null;
}
Also used : StopTimeUpdateModel(org.onebusaway.gtfs_realtime.model.StopTimeUpdateModel) TripDescriptor(com.google.transit.realtime.GtfsRealtime.TripDescriptor) StopTimeUpdate(com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeUpdate) VehicleDescriptor(com.google.transit.realtime.GtfsRealtime.VehicleDescriptor) Date(java.util.Date) TripUpdateModel(org.onebusaway.gtfs_realtime.model.TripUpdateModel)

Example 2 with VehicleDescriptor

use of com.google.transit.realtime.GtfsRealtime.VehicleDescriptor in project onebusaway-application-modules by camsys.

the class VehiclePositionConvertor method readFeedEntity.

@Override
public VehiclePositionModel readFeedEntity(FeedEntity entity, long timestamp) {
    if (entity == null)
        return null;
    VehiclePositionModel vpm = new VehiclePositionModel();
    if (entity.hasVehicle()) {
        if (entity.getVehicle().hasTimestamp()) {
            timestamp = entity.getVehicle().getTimestamp() * 1000;
        }
        if (entity.getVehicle().hasTrip()) {
            TripDescriptor td = entity.getVehicle().getTrip();
            if (td.hasTripId()) {
                vpm.setTripId(td.getTripId());
            }
            if (td.hasRouteId()) {
                vpm.setRouteId(td.getRouteId());
            }
            if (td.hasStartDate() && td.hasStartTime()) {
                vpm.setTripStart(GtfsRealtimeConversionLibrary.parseDate(td.getStartDate(), td.getStartTime()));
            }
        }
        if (entity.getVehicle().hasVehicle()) {
            VehicleDescriptor vd = entity.getVehicle().getVehicle();
            if (vd.hasId()) {
                vpm.setVehicleId(vd.getId());
            }
            if (vd.hasLabel()) {
                vpm.setVehicleLabel(vd.getLabel());
            }
            if (vd.hasLicensePlate()) {
                vpm.setVehicleLicensePlate(vd.getLicensePlate());
            }
        }
        if (entity.getVehicle().hasPosition()) {
            Position p = entity.getVehicle().getPosition();
            vpm.setLat(p.getLatitude());
            vpm.setLon(p.getLongitude());
            if (p.hasBearing()) {
                vpm.setBearing(p.getBearing());
            }
            if (p.hasSpeed()) {
                vpm.setSpeed(p.getSpeed());
            }
        }
        if (entity.getVehicle().hasTrip()) {
            if (vpm.getTripId() == null) {
                if (entity.getVehicle().getTrip().hasTripId()) {
                    vpm.setTripId(entity.getVehicle().getTrip().getTripId());
                }
            }
            if (vpm.getRouteId() == null) {
                if (entity.getVehicle().getTrip().hasRouteId()) {
                    vpm.setRouteId(entity.getVehicle().getTrip().getRouteId());
                }
            }
        }
    }
    if (entity.getVehicle().hasStopId()) {
        vpm.setStopId(entity.getVehicle().getStopId());
    }
    vpm.setTimestamp(new Date(timestamp));
    return vpm;
}
Also used : TripDescriptor(com.google.transit.realtime.GtfsRealtime.TripDescriptor) Position(com.google.transit.realtime.GtfsRealtime.Position) VehiclePositionModel(org.onebusaway.gtfs_realtime.model.VehiclePositionModel) VehicleDescriptor(com.google.transit.realtime.GtfsRealtime.VehicleDescriptor) Date(java.util.Date)

Aggregations

TripDescriptor (com.google.transit.realtime.GtfsRealtime.TripDescriptor)2 VehicleDescriptor (com.google.transit.realtime.GtfsRealtime.VehicleDescriptor)2 Date (java.util.Date)2 Position (com.google.transit.realtime.GtfsRealtime.Position)1 StopTimeUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeUpdate)1 StopTimeUpdateModel (org.onebusaway.gtfs_realtime.model.StopTimeUpdateModel)1 TripUpdateModel (org.onebusaway.gtfs_realtime.model.TripUpdateModel)1 VehiclePositionModel (org.onebusaway.gtfs_realtime.model.VehiclePositionModel)1