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

Planned disruptions logic #2373

Merged
merged 69 commits into from
Feb 11, 2025
Merged

Planned disruptions logic #2373

merged 69 commits into from
Feb 11, 2025

Conversation

anthonyshull
Copy link
Contributor

https://app.asana.com/0/555089885850811/1209323323089311/f

This is the backend logic for planned disruptions. It also includes today's disruptions for the system status component.

@anthonyshull anthonyshull changed the base branch from main to ags/datetime-utils-lib February 10, 2025 19:15
@anthonyshull anthonyshull force-pushed the ags/datetime-utils-lib branch from 2d94e04 to 61d5d0f Compare February 10, 2025 19:16
@anthonyshull anthonyshull force-pushed the ags/planned-disruptions-logic branch 2 times, most recently from 6c49ce6 to 50a0bcd Compare February 10, 2025 20:18
@anthonyshull anthonyshull force-pushed the ags/planned-disruptions-logic branch from 50a0bcd to 4f64616 Compare February 10, 2025 22:35
@anthonyshull anthonyshull marked this pull request as ready for review February 10, 2025 22:36
@anthonyshull anthonyshull requested a review from a team as a code owner February 10, 2025 22:36
@anthonyshull anthonyshull force-pushed the ags/planned-disruptions-logic branch 3 times, most recently from e08f304 to 4ceff54 Compare February 10, 2025 23:51
@anthonyshull anthonyshull added the do not merge ⏳ it's waiting on something label Feb 10, 2025
@anthonyshull anthonyshull force-pushed the ags/planned-disruptions-logic branch from 5d24251 to 7020026 Compare February 11, 2025 11:26
Base automatically changed from ags/datetime-utils-lib to main February 11, 2025 16:46
Copy link
Collaborator

@thecristen thecristen left a comment

Choose a reason for hiding this comment

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

There's a lot here! Thanks for adding the tests and supporting behaviours and mocks.

service_range_after_next_week: 0
]

import Mox
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't forget the setup :verify_on_exit! cleanup! ✨

A collection of functions that help to work with routes in a unified way.
"""

@subway_route_ids ["Blue", "Green", "Orange", "Red"]
Copy link
Collaborator

Choose a reason for hiding this comment

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

I can see a future where we work branches/lines/routes and relationships into here in some way.

Copy link
Contributor

Choose a reason for hiding this comment

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

Couple of thoughts on this line of code in particular:

Idea: Would it be worth having a type for line ID that only allows these four values? Then the type of subway_route_ids would be [Dotcom.Routes.line_id()].

Also, the name subway_route_ids() is misleading, because "Green" is not a Route ID - the subway Route ID's are "Red", "Mattapan", "Orange", "Green-B", "Green-C", "Green-D", "Green-E", and "Blue". I'd call this subway_line_ids or subway_lines.

And finally - love extracting this and putting it somewhere clean and universal!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Eventually, we won't need this because we'll just be able to query routes by type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And then query alerts by whatever attributes.

@doc """
Disruptions that occur during today's service range.
"""
@spec todays_disruptions() :: %{Utils.ServiceDateTime.named_service_range() => [Alert.t()]}
Copy link
Collaborator

Choose a reason for hiding this comment

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

technically just %{today: [Alert.t()]}

@anthonyshull anthonyshull force-pushed the ags/planned-disruptions-logic branch from 29e341c to 946552f Compare February 11, 2025 17:06
@anthonyshull anthonyshull merged commit 9c7a295 into main Feb 11, 2025
17 checks passed
@anthonyshull anthonyshull deleted the ags/planned-disruptions-logic branch February 11, 2025 17:58
Copy link
Contributor

@joshlarson joshlarson left a comment

Choose a reason for hiding this comment

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

A lot of this looks great! Nice to see a bunch of kind of universal concerns moving into better homes.

I have two comments that are blocking, related to the actual functionality:

  • It looks like todays_disruptions includes alerts that shouldn't be included, and the tests don't make it clear what happens in that circumstance.
  • The way subway_route_ids() looks like it will miss all green line and Mattapan alerts.

@doc """
Returns a list of the alert effects that are considered service-impacting.
"""
@spec service_impacting_effects() :: [atom()]
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion: I think you could move the type from SystemStatus.Alerts here.

(When you started on this PR, I don't think the PR introducing that type had been merged yet)

Disruptions that occur during today's service range.
"""
@spec todays_disruptions() :: %{Utils.ServiceDateTime.named_service_range() => [Alert.t()]}
def todays_disruptions() do
Copy link
Contributor

Choose a reason for hiding this comment

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

I may be reading this wrong, but it looks like this will include alerts from earlier today, even if their effect periods have ended. If so, we should double-check the requirements, because I had thought that we only want to include alerts if they're either currently active or will be active later in the day.

Either way, I think it would be good to have a test explicitly highlighting the "earlier-today" alerts behavior.

Copy link
Contributor Author

@anthonyshull anthonyshull Feb 11, 2025

Choose a reason for hiding this comment

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

This is grabbing today's disruptions. If the view doesn't want ones that are earlier than now they can remove them. The intention here isn't to do all of the work for the only current consumer. They will still have to do grouping and sorting by line if they want it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And, it will only get those alerts if the effect period ended after the start of the service day. So, the disruption effected 'today'.

@doc """
Returns a list of route ids for all subway routes.
"""
@spec subway_route_ids() :: [String.t()]
Copy link
Contributor

Choose a reason for hiding this comment

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

Praise This is a better place for this than where it was - nice to see this attr gradually migrating to its optimal home 🏠

A collection of functions that help to work with routes in a unified way.
"""

@subway_route_ids ["Blue", "Green", "Orange", "Red"]
Copy link
Contributor

Choose a reason for hiding this comment

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

Couple of thoughts on this line of code in particular:

Idea: Would it be worth having a type for line ID that only allows these four values? Then the type of subway_route_ids would be [Dotcom.Routes.line_id()].

Also, the name subway_route_ids() is misleading, because "Green" is not a Route ID - the subway Route ID's are "Red", "Mattapan", "Orange", "Green-B", "Green-C", "Green-D", "Green-E", and "Blue". I'd call this subway_line_ids or subway_lines.

And finally - love extracting this and putting it somewhere clean and universal!

@@ -92,7 +88,7 @@ defmodule Dotcom.SystemStatus.Alerts do
}
"""
def filter_relevant(alerts) do
alerts |> Enum.filter(fn %{effect: effect} -> effect in @service_effects end)
alerts |> Enum.filter(&service_impacting_alert?/1)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice!

I could eventually see this whole module getting lumped into Dotcom.Alerts, but that's a project for a future day.

Comment on lines +42 to +43

If we are given something tha tis not a DateTime, AmbiguousDateTime, or an error tuple, we log the input and return `now`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
If we are given something tha tis not a DateTime, AmbiguousDateTime, or an error tuple, we log the input and return `now`.

Begone!

# 2. Filters out non-service-impacting alerts
# 3. Groups them according to service range.
defp disruption_groups() do
subway_route_ids()
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this will work correctly (unless I missed a change in by_route_ids/2. Green line alerts aren't associated with the route ID "Green" - they're associated with the branches - "Green-B"/etc. This will also miss Mattapan alerts, I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was pulling Green Line alerts with this code. I can check to see if we want Mattapan alerts to show up in this component. Right now it only shows the main lines. Easy to add if we need/want them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
do not merge ⏳ it's waiting on something
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants