Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle informed trip descriptors with empty trip ids and non-empty route #18

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

cedarbaum
Copy link
Collaborator

@cedarbaum cedarbaum commented Sep 23, 2024

Overview

This change handles an edge case where the trip entity selector is used for providing alerts for a given route without a tripId.

For example, the MTA buses provide alerts in this form sometimes:

 {
      "id": "MTA NYCT_lmm:planned_work:9387",
      "alert": {
        ...
        "informedEntity": [
          {
            "agencyId": "MTA NYCT",
            "trip": {
              "routeId": "M14D+",
              "directionId": 1
            }
          },
          {
            "agencyId": "MTA NYCT",
            "trip": {
              "routeId": "M14D+",
              "directionId": 0
            }
          }
        ],
       ...
    },
}

In the above case, the alert effectively applies to the whole route since both directions are covered.

Note also that a tripID is not always required to uniquely identify a trip. A trip can sometimes be identified with a combination of route_id, direction_id, start_time, and start_date (see GTFS spec). If the tripID is empty but all of these fields are provided, we can consider the trip as potentially identifiable.

We therefore consider the following cases for how to handle this:

1.) An alert has informed trips with no identifiable trip instance, a routeId, and both directions are specified (one in each entity, as in the above example): consider this alert as affecting the entire route and add a route informed entity.

2.) An alert has an informed trip with no identifiable trip instance, a routeId, and no directions are specified: consider this alert as affecting the entire route and add a route informed entity.

3.) An alert has an informed trip with no identifiable trip instance, a routeId and a single direction is specified: consider this alert as affecting the route running in that direction and inform the route/direction combination.

In all 3 cases, the alert will not be associated with any trips, since a trip descriptor is required to uniquely identify a trip instance.

This change also discards informed entities for an alert that are considered of no use (i.e. they don't match any entities).

@cedarbaum cedarbaum force-pushed the handle_route_alerts_in_trip_desc branch from 202a308 to 7d1e8f6 Compare September 23, 2024 04:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant