Search in sources :

Example 1 with StopTimeUpdateModel

use of org.onebusaway.gtfs_realtime.model.StopTimeUpdateModel 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 StopTimeUpdateModel

use of org.onebusaway.gtfs_realtime.model.StopTimeUpdateModel in project onebusaway-application-modules by camsys.

the class GtfsRealtimeRetrieverImpl method writeTripUpdate.

private TripUpdate writeTripUpdate(TripUpdateModel model) {
    TripUpdate.Builder tu = TripUpdate.newBuilder();
    TripDescriptor.Builder t = TripDescriptor.newBuilder();
    if (model.getDelay() != null) {
        tu.setDelay(model.getDelay());
    }
    if (model.getTripId() != null) {
        t.setTripId(parseId(model.getTripId()));
    }
    if (model.getRouteId() != null) {
        t.setRouteId(parseId(model.getRouteId()));
    }
    if (model.getTripStart() != null) {
        Date date = model.getTripStart();
        String startDate = new SimpleDateFormat(GTFS_RT_DATE_FORMAT).format(date);
        String startTime = new SimpleDateFormat(GTFS_RT_TIME_FORMAT).format(date);
        t.setStartDate(startDate);
        t.setStartTime(startTime);
    }
    TripDescriptor.ScheduleRelationship sr = TripDescriptor.ScheduleRelationship.valueOf(model.getScheduleRelationship());
    if (sr != null) {
        t.setScheduleRelationship(sr);
    }
    if (model.getVehicleId() != null) {
        VehicleDescriptor.Builder v = VehicleDescriptor.newBuilder();
        v.setId(model.getVehicleId());
        if (!StringUtils.isEmpty(model.getVehicleLabel())) {
            v.setLabel(model.getVehicleLabel());
        }
        if (!StringUtils.isEmpty(model.getVehicleLicensePlate())) {
            v.setLicensePlate(model.getVehicleLicensePlate());
        }
        tu.setVehicle(v.build());
    }
    for (StopTimeUpdateModel stum : model.getStopTimeUpdates()) {
        StopTimeUpdate stu = writeStopTimeUpdate(stum);
        if (stum != null) {
            tu.addStopTimeUpdate(stu);
        }
    }
    tu.setTrip(t);
    return tu.build();
}
Also used : TripUpdate(com.google.transit.realtime.GtfsRealtime.TripUpdate) StopTimeUpdateModel(org.onebusaway.gtfs_realtime.model.StopTimeUpdateModel) TripDescriptor(com.google.transit.realtime.GtfsRealtime.TripDescriptor) StopTimeUpdate(com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeUpdate) SimpleDateFormat(java.text.SimpleDateFormat) VehicleDescriptor(com.google.transit.realtime.GtfsRealtime.VehicleDescriptor) Date(java.util.Date)

Example 3 with StopTimeUpdateModel

use of org.onebusaway.gtfs_realtime.model.StopTimeUpdateModel in project onebusaway-application-modules by camsys.

the class FeedServiceImpl method readTripUpdates.

@Override
public List<TripUpdateModel> readTripUpdates(FeedMessage tripUpdates, GtfsRealtimeEntitySource entitySource) {
    List<TripUpdateModel> updates = GtfsRealtimeConversionLibrary.readTripUpdates(tripUpdates);
    for (TripUpdateModel tripUpdate : updates) {
        String agencyId = getAgencyId(entitySource);
        addAgencyIdToTripId(tripUpdate, agencyId, entitySource);
        addAgencyIdToRouteId(tripUpdate, agencyId, entitySource);
        // Check stop id
        for (StopTimeUpdateModel stopTimeUpdate : tripUpdate.getStopTimeUpdates()) {
            addAgencyIdToStopId(stopTimeUpdate, agencyId, entitySource);
        }
        _persistor.persist(tripUpdate);
    }
    return updates;
}
Also used : StopTimeUpdateModel(org.onebusaway.gtfs_realtime.model.StopTimeUpdateModel) TripUpdateModel(org.onebusaway.gtfs_realtime.model.TripUpdateModel)

Example 4 with StopTimeUpdateModel

use of org.onebusaway.gtfs_realtime.model.StopTimeUpdateModel in project onebusaway-application-modules by camsys.

the class TripUpdateConvertor method readStopTimeUpdate.

private static StopTimeUpdateModel readStopTimeUpdate(StopTimeUpdate stu, int scheduleRelationship) {
    if (stu == null)
        return null;
    StopTimeUpdateModel stum = new StopTimeUpdateModel();
    if (stu.hasStopSequence()) {
        stum.setStopSequence(stu.getStopSequence());
    }
    if (stu.hasStopId()) {
        stum.setStopId(stu.getStopId());
    }
    if (stu.getArrival() != null) {
        // flatten stop time event
        if (stu.getArrival().hasDelay()) {
            stum.setArrivalDelay(stu.getArrival().getDelay());
        }
        if (stu.getArrival().hasTime()) {
            stum.setArrivalTime(new Date(stu.getArrival().getTime() * 1000));
        }
        if (stu.getArrival().hasUncertainty()) {
            stum.setArrivalUncertainty(stu.getArrival().getUncertainty());
        }
    }
    if (stu.getDeparture() != null) {
        if (stu.getDeparture().hasDelay()) {
            stum.setDepartureDelay(stu.getDeparture().getDelay());
        }
        if (stu.getDeparture().hasTime()) {
            stum.setDepartureTime(new Date(stu.getDeparture().getTime() * 1000));
        }
        if (stu.getDeparture().hasUncertainty()) {
            stum.setDepartureUncertainty(stu.getDeparture().getUncertainty());
        }
    }
    stum.setScheduleRelationship(scheduleRelationship);
    return stum;
}
Also used : StopTimeUpdateModel(org.onebusaway.gtfs_realtime.model.StopTimeUpdateModel) Date(java.util.Date)

Aggregations

StopTimeUpdateModel (org.onebusaway.gtfs_realtime.model.StopTimeUpdateModel)4 Date (java.util.Date)3 TripDescriptor (com.google.transit.realtime.GtfsRealtime.TripDescriptor)2 StopTimeUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeUpdate)2 VehicleDescriptor (com.google.transit.realtime.GtfsRealtime.VehicleDescriptor)2 TripUpdateModel (org.onebusaway.gtfs_realtime.model.TripUpdateModel)2 TripUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate)1 SimpleDateFormat (java.text.SimpleDateFormat)1