Skip to content

Commit

Permalink
Merge branch 'delay_on_added_trips' into aubin-test
Browse files Browse the repository at this point in the history
  • Loading branch information
miklcct committed Jan 21, 2025
2 parents 2c0a659 + c43c11c commit 82571fd
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public UpdateResult applyTripUpdates(
serviceDate,
backwardsDelayPropagationType
);
case ADDED -> validateAndHandleAddedTrip(
case NEW, ADDED -> validateAndHandleAddedTrip(
tripUpdate,
tripDescriptor,
tripId,
Expand Down Expand Up @@ -302,7 +302,7 @@ public UpdateResult applyTripUpdates(
/**
* Remove previous realtime updates for this trip. This is necessary to avoid previous stop
* pattern modifications from persisting. If a trip was previously added with the
* ScheduleRelationship ADDED and is now cancelled or deleted, we still want to keep the realtime
* ScheduleRelationship NEW and is now cancelled or deleted, we still want to keep the realtime
* added trip pattern.
*/
private void purgePatternModifications(
Expand All @@ -323,7 +323,7 @@ private void purgePatternModifications(
) {
// Remove previous realtime updates for this trip. This is necessary to avoid previous
// stop pattern modifications from persisting. If a trip was previously added with the ScheduleRelationship
// ADDED and is now cancelled or deleted, we still want to keep the realtime added trip pattern.
// NEW and is now cancelled or deleted, we still want to keep the realtime added trip pattern.
this.snapshotManager.revertTripToScheduledTripPattern(tripId, serviceDate);
}
}
Expand Down Expand Up @@ -465,7 +465,7 @@ private Result<UpdateSuccess, UpdateError> handleScheduledTrip(
}

/**
* Validate and handle GTFS-RT TripUpdate message containing an ADDED trip.
* Validate and handle GTFS-RT TripUpdate message containing an NEW trip.
*
* @param tripUpdate GTFS-RT TripUpdate message
* @param tripDescriptor GTFS-RT TripDescriptor
Expand All @@ -489,9 +489,7 @@ private Result<UpdateSuccess, UpdateError> validateAndHandleAddedTrip(
final Trip trip = transitEditorService.getScheduledTrip(tripId);

if (trip != null) {
// TODO: should we support this and add a new instantiation of this trip (making it
// frequency based)?
debug(tripId, serviceDate, "Graph already contains trip id of ADDED trip, skipping.");
debug(tripId, serviceDate, "Graph already contains trip id of NEW trip, skipping.");
return UpdateError.result(tripId, TRIP_ALREADY_EXISTS);
}

Expand All @@ -501,7 +499,7 @@ private Result<UpdateSuccess, UpdateError> validateAndHandleAddedTrip(
debug(
tripId,
serviceDate,
"ADDED trip doesn't have a start date in TripDescriptor, skipping."
"NEW trip doesn't have a start date in TripDescriptor, skipping."
);
return UpdateError.result(tripId, NO_START_DATE);
}
Expand All @@ -520,7 +518,7 @@ private Result<UpdateSuccess, UpdateError> validateAndHandleAddedTrip(

// check if after filtering the stops we still have at least 2
if (stopTimeUpdates.size() < 2) {
debug(tripId, serviceDate, "ADDED trip has fewer than two known stops, skipping.");
debug(tripId, serviceDate, "NEW trip has fewer than two known stops, skipping.");
return UpdateError.result(tripId, TOO_FEW_STOPS);
}

Expand Down Expand Up @@ -556,7 +554,7 @@ private List<StopTimeUpdate> removeUnknownStops(
debug(
tripId,
serviceDate,
"Stop '{}' not found in graph. Removing from ADDED trip.",
"Stop '{}' not found in graph. Removing from NEW trip.",
st.getStopId()
);
}
Expand All @@ -566,7 +564,7 @@ private List<StopTimeUpdate> removeUnknownStops(
}

/**
* Check stop time updates of trip update that results in a new trip (ADDED or MODIFIED) and find
* Check stop time updates of trip update that results in a new trip (NEW or REPLACEMENT) and find
* all stops of that trip.
*
* @return stops when stop time updates are correct; null if there are errors
Expand Down Expand Up @@ -601,7 +599,7 @@ private List<StopLocation> checkNewStopTimeUpdatesAndFindStops(
}
previousStopSequence = stopSequence;
} else {
// Allow missing stop sequences for ADDED and MODIFIED trips
// Allow missing stop sequences for NEW and REPLACEMENT trips
}

// Find stops
Expand Down Expand Up @@ -668,7 +666,7 @@ private List<StopLocation> checkNewStopTimeUpdatesAndFindStops(
}

/**
* Handle GTFS-RT TripUpdate message containing an ADDED trip.
* Handle GTFS-RT TripUpdate message containing an NEW trip.
*
* @param stopTimeUpdates GTFS-RT stop time updates
* @param tripDescriptor GTFS-RT TripDescriptor
Expand Down Expand Up @@ -717,7 +715,7 @@ private Result<UpdateSuccess, UpdateError> handleAddedTrip(
debug(
tripId,
serviceDate,
"ADDED trip has service date {} for which no service id is available, skipping.",
"NEW trip has service date {} for which no service id is available, skipping.",
serviceDate.toString()
);
return UpdateError.result(tripId, NO_SERVICE_ON_DATE);
Expand Down Expand Up @@ -869,7 +867,7 @@ private Result<UpdateSuccess, UpdateError> addTripToGraphAndBuffer(
debug(
trip.getId(),
serviceDate,
"ADDED trip has invalid arrival time (compared to start date in " +
"NEW trip has invalid arrival time (compared to start date in " +
"TripDescriptor), skipping."
);
return UpdateError.result(trip.getId(), INVALID_ARRIVAL_TIME);
Expand All @@ -885,7 +883,7 @@ private Result<UpdateSuccess, UpdateError> addTripToGraphAndBuffer(
debug(
trip.getId(),
serviceDate,
"ADDED trip has invalid departure time (compared to start date in " +
"NEW trip has invalid departure time (compared to start date in " +
"TripDescriptor), skipping."
);
return UpdateError.result(trip.getId(), INVALID_DEPARTURE_TIME);
Expand Down Expand Up @@ -1070,7 +1068,7 @@ private boolean cancelPreviouslyAddedTrip(
}

/**
* Validate and handle GTFS-RT TripUpdate message containing a MODIFIED trip.
* Validate and handle GTFS-RT TripUpdate message containing a REPLACEMENT trip.
*
* @param tripUpdate GTFS-RT TripUpdate message
* @param tripDescriptor GTFS-RT TripDescriptor
Expand All @@ -1094,8 +1092,7 @@ private Result<UpdateSuccess, UpdateError> validateAndHandleModifiedTrip(
Trip trip = transitEditorService.getTrip(tripId);

if (trip == null) {
// TODO: should we support this and consider it an ADDED trip?
debug(tripId, serviceDate, "Feed does not contain trip id of MODIFIED trip, skipping.");
debug(tripId, serviceDate, "Feed does not contain trip id of REPLACEMENT trip, skipping.");
return UpdateError.result(tripId, TRIP_NOT_FOUND);
}

Expand Down
43 changes: 26 additions & 17 deletions gtfs-realtime-protobuf/src/main/proto/gtfs-realtime.proto
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ message TripUpdate {
// To specify a completely certain prediction, set its uncertainty to 0.
optional int32 uncertainty = 3;

// Scheduled time for an added or replacement trip.
// Scheduled time for a new or replacement trip.
// In Unix time (i.e., number of seconds since January 1st 1970 00:00:00
// UTC).
optional int64 scheduled_time = 4;
Expand Down Expand Up @@ -278,22 +278,9 @@ message TripUpdate {
optional string assigned_stop_id = 1;

// The updated headsign of the vehicle at the stop.
// NOTE: This field is still experimental, and subject to change. It may be formally adopted in the future.
optional string stop_headsign = 2;

// The updated pickup of the vehicle at the stop.
optional DropOffPickupType pickup_type = 3;

// The updated drop off of the vehicle at the stop.
optional DropOffPickupType drop_off_type = 4;

// The extensions namespace allows 3rd-party developers to extend the
// GTFS Realtime Specification in order to add and evaluate new features
// and modifications to the spec.
extensions 1000 to 1999;

// The following extension IDs are reserved for private use by any organization.
extensions 9000 to 9999;

enum DropOffPickupType {
// Regularly scheduled pickup/dropoff.
REGULAR = 0;
Expand All @@ -307,6 +294,22 @@ message TripUpdate {
// Must coordinate with driver to arrange pickup/dropoff.
COORDINATE_WITH_DRIVER = 3;
}

// The updated pickup of the vehicle at the stop.
// NOTE: This field is still experimental, and subject to change. It may be formally adopted in the future.
optional DropOffPickupType pickup_type = 3;

// The updated drop off of the vehicle at the stop.
// NOTE: This field is still experimental, and subject to change. It may be formally adopted in the future.
optional DropOffPickupType drop_off_type = 4;

// The extensions namespace allows 3rd-party developers to extend the
// GTFS Realtime Specification in order to add and evaluate new features
// and modifications to the spec.
extensions 1000 to 1999;

// The following extension IDs are reserved for private use by any organization.
extensions 9000 to 9999;
}

// Realtime updates for certain properties defined within GTFS stop_times.txt
Expand Down Expand Up @@ -829,8 +832,10 @@ message TripDescriptor {
// enough to the scheduled trip to be associated with it.
SCHEDULED = 0;

// An extra trip unrelated to any existing trips, for example, to respond to sudden passenger load.
ADDED = 1;
// This value has been deprecated as the behavior was unspecified.
// Use DUPLICATED for an extra trip that is the same as a scheduled trip except the start date or time,
// or NEW for an extra trip that is unrelated to an existing trip.
ADDED = 1 [deprecated = true];

// A trip that is running with no schedule associated to it (GTFS frequencies.txt exact_times=0).
// Trips with ScheduleRelationship=UNSCHEDULED must also set all StopTimeUpdates.ScheduleRelationship=UNSCHEDULED.
Expand Down Expand Up @@ -870,6 +875,10 @@ message TripDescriptor {
// real-time predictions.
// NOTE: This field is still experimental, and subject to change. It may be formally adopted in the future.
DELETED = 7;

// An extra trip unrelated to any existing trips, for example, to respond to sudden passenger load.
// NOTE: This field is still experimental, and subject to change. It may be formally adopted in the future.
NEW = 8;
}
optional ScheduleRelationship schedule_relationship = 4;

Expand Down

0 comments on commit 82571fd

Please sign in to comment.