-
Notifications
You must be signed in to change notification settings - Fork 13
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
Conversation
2d94e04
to
61d5d0f
Compare
6c49ce6
to
50a0bcd
Compare
50a0bcd
to
4f64616
Compare
e08f304
to
4ceff54
Compare
5d24251
to
7020026
Compare
There was a problem hiding this 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 |
There was a problem hiding this comment.
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"] |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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()]} |
There was a problem hiding this comment.
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()]}
29e341c
to
946552f
Compare
There was a problem hiding this 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()] |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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()] |
There was a problem hiding this comment.
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"] |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
|
||
If we are given something tha tis not a DateTime, AmbiguousDateTime, or an error tuple, we log the input and return `now`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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() |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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.