Skip to content

Better handle shuttle alert directionality#440

Merged
lemald merged 7 commits into
masterfrom
lem-shuttle-alert-direction-id
Jul 10, 2026
Merged

Better handle shuttle alert directionality#440
lemald merged 7 commits into
masterfrom
lem-shuttle-alert-direction-id

Conversation

@lemald

@lemald lemald commented Jul 9, 2026

Copy link
Copy Markdown
Member

Summary of changes

Asana Ticket: 🧠🐛Trains that run outside the limits of a diversion shouldn't have stops skipped

Inbound Lowell Line trains were originating at NHRML-0218-01, the normal outbound platform at North Billerica. Because the informed_entity in the alert (1017626) had activities of BOARD and RIDE, it was interpreted as the start of a shuttle, and therefore Concentrate skipped it and all of the stop time updates that came after it in the trip (since there was no other stop that counted as the end of the shuttle). However, the informed_entity also had a direction_id of 0, indicating that it was only effective in the outbound direction, and Concentrate wasn't respecting this. This change makes Concentrate reference the direction ID in the informed_entity, if present, to determine what kind of effect the alert is having on a given route and stop. If the direction ID is absent, it is assumed to apply in both directions.

Unfortunately this may be a bit hard to test without another very similar shuttle alert, schedule, and realtime tracking information. I'm hoping that the unit tests are sufficient and adequately replicate the scenario that caused the Lowell Line issue.

@lemald lemald marked this pull request as ready for review July 9, 2026 16:55
@lemald lemald requested a review from a team as a code owner July 9, 2026 16:55
@lemald lemald requested review from jzimbel-mbta and removed request for a team July 9, 2026 16:55

@jzimbel-mbta jzimbel-mbta left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good overall, just some minor suggestions and a sanity check about the updated select query.

My understanding of the approach is that direction ID (when present in an informed entity) is now included in the TimeTable ETS select query so that we avoid selecting shuttle data that doesn't apply to a trip in this direction. Does that sound right?

id: asdf-cache
# only run `asdf install` if we didn't hit the cache
- uses: asdf-vm/actions/install@v1
- uses: asdf-vm/actions/install@v4

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion:
Should the cache key also be updated to avoid using a cached install from the old version of asdf / the asdf install action? Like change -v2- to -v4- in the key, perhaps.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

]
for direction_id <- direction_ids(InformedEntity.direction_id(entity)) do
{{:route_stop, route_id, stop_id, direction_id},
shuttle_type(InformedEntity.activities(entity))}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion:
Since the value will be the same for all elements of the list, you could evaluate shuttle_type(InformedEntity.activities(entity)) once outside of this comprehension.

(Bit of a micro-optimization tbh, since the list has only 3 elements max)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread lib/concentrate/group_filter/shuttle.ex Outdated
case TimeTable.date_overlaps(@table, {:route_stop, route_id, stop_id}, date_or_timestamp) do
case TimeTable.date_overlaps(
@table,
{:route_stop, route_id, stop_id, direction_id},

@jzimbel-mbta jzimbel-mbta Jul 10, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question:
Does the shuttles timetable ETS table contain both 3-tuples that do not include direction ID, and 4-tuples that do include direction ID?

I guess I'm a little surprised that you didn't need to make any corresponding changes over in the TimeTable module (or here?) for this new record structure.

(I admit I'm a little rusty on ETS MatchSpecs, so I might be misunderstanding how this key ends up getting used in the select query.)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They now contain only the four-tuples - I didn't directly change the code in your "here" link, but I did change the cancellation_type/1 function that it calls, which is how we generate the tuples that get added to the table.

@lemald

lemald commented Jul 10, 2026

Copy link
Copy Markdown
Member Author

My understanding of the approach is that direction ID (when present in an informed entity) is now included in the TimeTable ETS select query so that we avoid selecting shuttle data that doesn't apply to a trip in this direction. Does that sound right?

Correct!

@lemald lemald deployed to dev-green July 10, 2026 15:53 — with GitHub Actions Active
@lemald lemald merged commit 08a92da into master Jul 10, 2026
4 checks passed
@lemald lemald deleted the lem-shuttle-alert-direction-id branch July 10, 2026 19:31
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.

2 participants