GtfsRealtime.VehiclePosition v = entity.getVehicle(); if (StringUtils.isEmpty(v.getVehicle().getId())) { if (vehicleIds.contains(v.getVehicle().getId())) { RuleUtils.addOccurrence(E052, "entity ID " + entity.getId() + " has vehicle.id " + v.getVehicle().getId(), e052List, _log); } else { vehicleIds.add(v.getVehicle().getId()); if (v.hasPosition() && v.getPosition().hasSpeed()) { if (v.getPosition().getSpeed() > MAX_REALISTIC_SPEED_METERS_PER_SECOND || v.getPosition().getSpeed() < 0f) { " speed of " + v.getPosition().getSpeed() + " m/s (" + String.format("%.2f", GtfsUtils.toMilesPerHour(v.getPosition().getSpeed())) + " mph)"; RuleUtils.addOccurrence(W004, prefix, w004List, _log); if (v.hasPosition()) { GtfsRealtime.Position position = v.getPosition(); String id = getVehicleId(entity, v); if (!position.hasLatitude() || !position.hasLongitude()) {
if (vp.hasVehicle() && vp.getVehicle().hasId()) { long otherTimestamp = otherUpdate.getTimestamp(); if (vp.getTimestamp() > otherTimestamp) { vehiclePositionsByVehicleId.put(vehicleId, vp); } else if (vp.hasTrip()) { TripDescriptor td = vp.getTrip(); long time = vp.hasTimestamp() ? vp.getTimestamp() * 1000 : currentTime(); BlockDescriptor bd = getTripDescriptorAsBlockDescriptor(result, td, time); && update.vehiclePosition.hasVehicle() && update.vehiclePosition.getVehicle().hasId()) { vehicleId = getVehicleId(update.vehiclePosition);
if (v.hasStopId()) { if (!gtfsMetadata.getStopIds().contains(v.getStopId())) { String prefix = (v.hasVehicle() && v.getVehicle().hasId() ? "vehicle_id " + v.getVehicle().getId() + " " : "") + "stop_id " + v.getStopId(); RuleUtils.addOccurrence(E011, prefix, e011List, _log); Integer locationType = gtfsMetadata.getStopToLocationTypeMap().get(v.getStopId()); if (locationType != null && locationType != 0) { String prefix = (v.hasVehicle() && v.getVehicle().hasId() ? "vehicle_id " + v.getVehicle().getId() + " " : "") + "stop_id " + v.getStopId(); RuleUtils.addOccurrence(E015, prefix, e015List, _log);
long vehicleTimestamp = vehiclePosition.getTimestamp(); RuleUtils.addOccurrence(W001, "vehicle_id " + vehiclePosition.getVehicle().getId(), w001List, _log); } else { String prefix = "vehicle_id " + vehiclePosition.getVehicle().getId() + " timestamp " + vehicleTimestamp; if (headerTimestamp != 0 && vehicleTimestamp > headerTimestamp) { long ageSeconds = Math.abs(TimeUnit.MILLISECONDS.toSeconds(ageMillis)); String vehicleTimestampText = TimestampUtils.posixToClock(vehicleTimestamp, gtfsMetadata.getTimeZone()); RuleUtils.addOccurrence(E050, "vehicle_id " + vehiclePosition.getVehicle().getId() + " timestamp " + vehicleTimestampText + " (" + vehicleTimestamp + ") is " + ageMinutes + " min " + ageSeconds % 60 + " sec greater than " + currentTimeText + " (" + currentTimeMillis + ")", e050List, _log);
if (entity.hasVehicle() && entity.getVehicle().hasTrip()) { GtfsRealtime.TripDescriptor trip = entity.getVehicle().getTrip(); if (!trip.hasTripId()) { checkW006(entity, trip, errorListW006); if (!GtfsUtils.isAddedTrip(trip)) { RuleUtils.addOccurrence(E003, "vehicle_id " + entity.getVehicle().getVehicle().getId() + " trip_id " + tripId, errorListE003, _log); RuleUtils.addOccurrence(E016, "vehicle_id " + entity.getVehicle().getVehicle().getId() + " trip_id " + tripId, errorListE016, _log);
String vehicleId = entity.getVehicle().getVehicle().getId(); String tripId = ""; if (entity.getVehicle().hasTrip() && entity.getVehicle().getTrip().hasTripId()) { tripId = entity.getVehicle().getTrip().getTripId();
List<Frequency> frequenceTypeOneList = gtfsMetadata.getExactTimesOneTrips().get(vehiclePosition.getTrip().getTripId()); if (frequenceTypeOneList != null) { boolean foundMatch = false; _log.debug("start time = " + startTime); _log.debug("formatted start time = " + gtfsStartTimeString); if (vehiclePosition.hasTrip() && vehiclePosition.getTrip().getStartTime().equals(gtfsStartTimeString)) { String prefix = "GTFS-rt trip_id " + vehiclePosition.getTrip().getTripId() + " has start_time of " + vehiclePosition.getTrip().getStartTime() + " and GTFS frequencies.txt start_time is " + gtfsStartTimeString + " with a headway of " + headwaySecs + " seconds "; RuleUtils.addOccurrence(E019, prefix, errorListE019, _log);
if (vehicle.hasTimestamp()) gpsTime = vehicle.getTimestamp()*Time.MS_PER_SEC; else { logger.warn("For vehicleId={} GPS time not available in " Position position = vehicle.getPosition(); if (vehicle.hasTrip()) { TripDescriptor tripDescriptor = vehicle.getTrip(); if (tripDescriptor.hasTripId()) { avlReport.setAssignment(tripDescriptor.getTripId(),
if (vehiclePosition.hasTrip() && gtfsMetadata.getExactTimesZeroTripIds().contains(vehiclePosition.getTrip().getTripId())) { if (!vehiclePosition.getTrip().hasStartDate()) { RuleUtils.addOccurrence(E006, "vehicle_id " + vehiclePosition.getVehicle().getId() + " trip_id " + vehiclePosition.getTrip().getTripId() + " is missing start_date", errorListE006, _log); if (!vehiclePosition.getTrip().hasStartTime()) { RuleUtils.addOccurrence(E006, "vehicle_id " + vehiclePosition.getVehicle().getId() + " trip_id " + vehiclePosition.getTrip().getTripId() + " is missing start_time", errorListE006, _log); if (!(!vehiclePosition.getTrip().hasScheduleRelationship() || vehiclePosition.getTrip().getScheduleRelationship().equals(GtfsRealtime.TripDescriptor.ScheduleRelationship.UNSCHEDULED))) { String prefix = "vehicle_id " + vehiclePosition.getVehicle().getId() + " trip_id " + vehiclePosition.getTrip().getTripId() + " schedule_relationship " + vehiclePosition.getTrip().getScheduleRelationship(); RuleUtils.addOccurrence(E013, prefix, errorListE013, _log); if (!vehiclePosition.getVehicle().hasId()) { RuleUtils.addOccurrence(W005, "entity ID" + entity.getId() + "with trip_id " + vehiclePosition.getTrip().getTripId(), errorListW005, _log);
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 (entity.getVehicle().hasVehicle()) { VehicleDescriptor vd = entity.getVehicle().getVehicle(); if (vd.hasId()) { vpm.setVehicleId(vd.getId()); if (entity.getVehicle().hasPosition()) { Position p = entity.getVehicle().getPosition(); vpm.setLat(p.getLatitude()); vpm.setLon(p.getLongitude()); if (entity.getVehicle().hasTrip()) { if (vpm.getTripId() == null) { if (entity.getVehicle().getTrip().hasTripId()) { vpm.setTripId(entity.getVehicle().getTrip().getTripId()); if (entity.getVehicle().getTrip().hasRouteId()) { vpm.setRouteId(entity.getVehicle().getTrip().getRouteId()); if (entity.getVehicle().hasStopId()) {
if (!vehicle.hasPosition()) { continue; Position position = vehicle.getPosition(); Vehicle v = new Vehicle(); v.setId(vehicleId);
GtfsRealtime.Position position = v.getPosition(); String id = getVehicleId(entity, v);
private void applyVehiclePositionToRecord(MonitoredResult result, BlockDescriptor blockDescriptor, VehiclePosition vehiclePosition, VehicleLocationRecord record) { Position position = vehiclePosition.getPosition(); if (vehiclePosition.hasTimestamp()) { record.setTimeOfLocationUpdate(TimeUnit.SECONDS.toMillis(vehiclePosition.getTimestamp())); //vehicle timestamp is in seconds } record.setCurrentLocationLat(position.getLatitude()); record.setCurrentLocationLon(position.getLongitude()); if (result != null) { result.addLatLon(position.getLatitude(), position.getLongitude()); } if (_scheduleAdherenceFromLocation) { CoordinatePoint location = new CoordinatePoint(position.getLatitude(), position.getLongitude()); double totalDistance = blockDescriptor.getBlockInstance().getBlock().getTotalBlockDistance(); long timestamp = vehiclePosition.hasTimestamp() ? record.getTimeOfLocationUpdate() : record.getTimeOfRecord(); ScheduledBlockLocation loc = _blockGeospatialService.getBestScheduledBlockLocationForLocation( blockDescriptor.getBlockInstance(), location, timestamp, 0, totalDistance); long serviceDateTime = record.getServiceDate(); long effectiveScheduleTime = loc.getScheduledTime() + (serviceDateTime/1000); double deviation = timestamp/1000 - effectiveScheduleTime; double oldDeviation = record.getScheduleDeviation(); record.setScheduleDeviation(deviation); _log.debug("deviation reset to {} from {} for vehicle {}", deviation, oldDeviation, vehiclePosition.getVehicle().getId()); } }
public Builder mergeFrom(com.google.transit.realtime.GtfsRealtime.VehiclePosition other) { if (other == com.google.transit.realtime.GtfsRealtime.VehiclePosition.getDefaultInstance()) return this; if (other.hasTrip()) { mergeTrip(other.getTrip()); if (other.hasVehicle()) { mergeVehicle(other.getVehicle()); if (other.hasPosition()) { mergePosition(other.getPosition()); if (other.hasCurrentStopSequence()) { setCurrentStopSequence(other.getCurrentStopSequence()); if (other.hasStopId()) { bitField0_ |= 0x00000010; stopId_ = other.stopId_; onChanged(); if (other.hasCurrentStatus()) { setCurrentStatus(other.getCurrentStatus()); if (other.hasTimestamp()) { setTimestamp(other.getTimestamp()); if (other.hasCongestionLevel()) { setCongestionLevel(other.getCongestionLevel()); if (other.hasOccupancyStatus()) { setOccupancyStatus(other.getOccupancyStatus());
/** * Returns the vehicleID. If vehicle ID not available then returns vehicle * label. Returns null if no VehicleDescription associated with the vehicle * or if no ID or label associated with the VehicleDescription. * * @param vehicle * @return vehicle ID or label or null if there isn't one */ private static String getVehicleId(VehiclePosition vehicle) { if (!vehicle.hasVehicle()) { return null; } VehicleDescriptor desc = vehicle.getVehicle(); // Return vehicle ID if there is one if (desc.hasId()) return desc.getId(); // No vehicle ID so return vehicle label if there is one if (desc.hasLabel()) return desc.getLabel(); // No ID nor label so return null return null; }
public final boolean isInitialized() { byte isInitialized = memoizedIsInitialized; if (isInitialized != -1) return isInitialized == 1; if (hasTrip()) { if (!getTrip().isInitialized()) { memoizedIsInitialized = 0; return false; } } if (hasVehicle()) { if (!getVehicle().isInitialized()) { memoizedIsInitialized = 0; return false; } } if (hasPosition()) { if (!getPosition().isInitialized()) { memoizedIsInitialized = 0; return false; } } if (!extensionsAreInitialized()) { memoizedIsInitialized = 0; return false; } memoizedIsInitialized = 1; return true; }
/** * Returns vehicle and route IDs text (vehicle_id X route_id = Y) for the given entity if the entity is a VehiclePosition, or the route ID text (route_id = Y) for the given entity if the entity is a TripUpdate * * @param entity Either the VehiclePosition or TripUpdate for which to generate the ID text * @return vehicle and route IDs text (vehicle_id X route_id = Y) for the given entity if the entity is a VehiclePosition, or the route ID text (route_id = Y) for the given entity if the entity is a TripUpdate */ public static String getVehicleAndRouteId(Object entity) { if (!(entity instanceof GtfsRealtime.VehiclePosition || entity instanceof GtfsRealtime.TripUpdate)) { throw new IllegalArgumentException("entity must be instance of VehiclePosition or TripUpdate"); } String ids = null; if (entity instanceof GtfsRealtime.VehiclePosition) { GtfsRealtime.VehiclePosition vp = (GtfsRealtime.VehiclePosition) entity; ids = "vehicle_id " + vp.getVehicle().getId() + " route_id " + vp.getTrip().getRouteId(); } else if (entity instanceof GtfsRealtime.TripUpdate) { GtfsRealtime.TripUpdate tu = (GtfsRealtime.TripUpdate) entity; ids = "route_id " + tu.getTrip().getRouteId(); } return ids; }
/** * Returns vehicle and trip IDs text (vehicle_id X trip_id = Y) for the given entity if the entity is a VehiclePosition, or the trip ID text (trip_id = Y) for the given entity if the entity is a TripUpdate * * @param entity Either the VehiclePosition or TripUpdate for which to generate the ID text * @return vehicle and trip IDs text (vehicle_id X trip_id = Y) for the given entity if the entity is a VehiclePosition, or the trip ID text (trip_id = Y) for the given entity if the entity is a TripUpdate */ public static String getVehicleAndTripIdText(Object entity) { if (!(entity instanceof GtfsRealtime.VehiclePosition || entity instanceof GtfsRealtime.TripUpdate)) { throw new IllegalArgumentException("entity must be instance of VehiclePosition or TripUpdate"); } String ids = null; if (entity instanceof GtfsRealtime.VehiclePosition) { GtfsRealtime.VehiclePosition vp = (GtfsRealtime.VehiclePosition) entity; ids = "vehicle_id " + vp.getVehicle().getId() + " trip_id " + vp.getTrip().getTripId(); } else if (entity instanceof GtfsRealtime.TripUpdate) { GtfsRealtime.TripUpdate tu = (GtfsRealtime.TripUpdate) entity; ids = "trip_id " + tu.getTrip().getTripId(); } return ids; }
/** * Returns the vehicleID. Returns null if no VehicleDescription associated * with the vehicle or if no ID associated with the VehicleDescription. * * @param vehicle * @return vehicle ID or null if there isn't one */ private static String getLicensePlate(VehiclePosition vehicle) { if (!vehicle.hasVehicle()) { return null; } VehicleDescriptor desc = vehicle.getVehicle(); if (!desc.hasLicensePlate()) { return null; } return desc.getLicensePlate(); }