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

fix: Handle platform closures #2107

Merged
merged 32 commits into from
Jul 18, 2024
Merged

fix: Handle platform closures #2107

merged 32 commits into from
Jul 18, 2024

Conversation

cmaddox5
Copy link
Contributor

@cmaddox5 cmaddox5 commented Jul 3, 2024

Asana task: Handle single-child-stop alerts on pre-fares

This PR adds support for platform closures on Pre-Fare alerts and SubwayStatus. A few key changes:

  1. A platform closure that affects the screen's home stop shows a single screen alert instead of a takeover.
  2. A full screen alert uses the fallback template where only the OIO text is displayed.
  3. A flex zone alert shows the platform that is closed.
  4. The subway status uses generic text that directs the user to dotcom.

Note: I definitely want to get code review started to catch an obvious mistakes, but I think a lot of this testing needs to be in dev-green using a variety of real alerts. I think I covered all the bases in tests but will let Dave work out any others. Feel free to do the same.

  • Tests added?

@cmaddox5 cmaddox5 requested a review from a team as a code owner July 3, 2024 19:15
@cmaddox5 cmaddox5 marked this pull request as draft July 5, 2024 16:06
@cmaddox5 cmaddox5 marked this pull request as ready for review July 8, 2024 17:22
lib/screens/stops/stop.ex Outdated Show resolved Hide resolved
Comment on lines 599 to 602
Enum.reject(
informed_entities,
&(String.starts_with?(&1.stop, "place-") or &1.route_type != 1)
)
Copy link
Contributor

Choose a reason for hiding this comment

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

question: is there a way to rewrite this as a filter and explicitly include things instead of excluding things we don't want?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah sure. Platform IDs will always be integers so I can check that stop is an integer and route_type == 1.

Copy link
Contributor

Choose a reason for hiding this comment

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

We're very much not guaranteed that platform stop IDs will always look like integers — it would be better to look at the location_type of the stop, which tells you explicitly whether a stop is a specific "stopping location" (type 0, a.k.a. a platform) or not.

Copy link
Contributor

Choose a reason for hiding this comment

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

(That said, all current subway platform stop IDs do look like integers, and at this point it's possible enough other teams have made this assumption — contra the documented best practice of treating all IDs as opaque — that introducing a new platform stop ID that didn't look like an integer would be considered a breaking change.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm yeah I see your concern. The issue is location_type is not added to informed_entities. I could add a bit more stability by passing the list of subway platforms to the function and find a union of the lists. The only problem with that is it makes the function dependent on a separate API call. That's not really a problem in this PR considering we are guaranteed to have that list when making the call. It might be better if I turn this into a Stop module function. Then I can just map informed_entities into their IDs and do the union that way.

Copy link
Contributor

Choose a reason for hiding this comment

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

The only problem with that is it makes the function dependent on a separate API call.

Yep, that's pretty much the only fully-correct way to do this, as there's no way to fetch related resources on alert informed entities as part of the same call. Fetch alert -> fetch stops matching the IDs in the alert -> get attributes of stops. Of course, we are already doing a stop fetch here to get the full set of child stops for the parent station, so this doesn't strictly need to introduce a new API call, just change the parameters of an existing one.

That said, the shortcut of assuming place- is a parent station (and that parent stations and child stops are the only kinds of stop that will appear in a station closure alert) is probably going to be durable enough, kinda like how we assume a route is Commuter Rail iff the ID starts with CR-. It pains me a tiny bit, though.

lib/screens/v2/widget_instance/reconstructed_alert.ex Outdated Show resolved Hide resolved
Copy link

Coverage of commit 288958a

Summary coverage rate:
  lines......: 45.3% (2963 of 6545 lines)
  functions..: 41.1% (1050 of 2557 functions)
  branches...: no data found

Files changed coverage rate:
                                                                          |Lines       |Functions  |Branches    
  Filename                                                                |Rate     Num|Rate    Num|Rate     Num
  ==============================================================================================================
  lib/screens/alerts/alert.ex                                             |30.8%    117|34.0%    47|    -      0
  lib/screens/cldr.ex                                                     | 100%      1|16.7%    12|    -      0
  lib/screens/stops/parser.ex                                             | 0.0%      1| 0.0%     1|    -      0
  lib/screens/stops/stop.ex                                               |41.8%     91|57.6%    33|    -      0
  lib/screens/v2/candidate_generator/widgets/reconstructed_alert.ex       |82.5%    103|83.3%    24|    -      0
  lib/screens/v2/candidate_generator/widgets/subway_status.ex             | 0.0%     18| 0.0%     7|    -      0
  lib/screens/v2/widget_instance/reconstructed_alert.ex                   |87.9%    354| 100%    46|    -      0
  lib/screens/v2/widget_instance/subway_status.ex                         |90.0%    209|92.9%    42|    -      0

Download coverage report

lib/screens/stops/stop.ex Outdated Show resolved Hide resolved
def informed_parent_stations(%__MODULE__{
informed_entities: informed_entities
}) do
Enum.filter(informed_entities, &String.starts_with?(&1.stop, "place-"))
Copy link
Contributor

Choose a reason for hiding this comment

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

It appears we already have InformedEntity.parent_station? for this.

lib/screens/v2/widget_instance/reconstructed_alert.ex Outdated Show resolved Hide resolved
lib/screens/v2/widget_instance/reconstructed_alert.ex Outdated Show resolved Hide resolved
lib/screens/v2/widget_instance/reconstructed_alert.ex Outdated Show resolved Hide resolved
lib/screens/v2/widget_instance/subway_status.ex Outdated Show resolved Hide resolved
lib/screens/v2/widget_instance/subway_status.ex Outdated Show resolved Hide resolved
@mbta mbta deleted a comment from github-actions bot Jul 12, 2024
@mbta mbta deleted a comment from github-actions bot Jul 12, 2024
@mbta mbta deleted a comment from github-actions bot Jul 12, 2024
@mbta mbta deleted a comment from github-actions bot Jul 12, 2024
Copy link

Coverage of commit cd4a08a

Summary coverage rate:
  lines......: 45.2% (2956 of 6542 lines)
  functions..: 41.1% (1050 of 2556 functions)
  branches...: no data found

Files changed coverage rate:
                                                                          |Lines       |Functions  |Branches    
  Filename                                                                |Rate     Num|Rate    Num|Rate     Num
  ==============================================================================================================
  lib/screens/alerts/alert.ex                                             |29.9%    117|34.0%    47|    -      0
  lib/screens/cldr.ex                                                     | 100%      1|16.7%    12|    -      0
  lib/screens/stops/parser.ex                                             | 0.0%      1| 0.0%     1|    -      0
  lib/screens/stops/stop.ex                                               |41.8%     91|57.6%    33|    -      0
  lib/screens/v2/candidate_generator/widgets/reconstructed_alert.ex       |81.7%    104|83.3%    24|    -      0
  lib/screens/v2/candidate_generator/widgets/subway_status.ex             | 0.0%     18| 0.0%     7|    -      0
  lib/screens/v2/widget_instance/reconstructed_alert.ex                   |87.8%    343| 100%    45|    -      0
  lib/screens/v2/widget_instance/subway_status.ex                         |89.5%    210|92.9%    42|    -      0

Download coverage report

Copy link

Coverage of commit 112d98b

Summary coverage rate:
  lines......: 45.2% (2956 of 6542 lines)
  functions..: 41.1% (1050 of 2556 functions)
  branches...: no data found

Files changed coverage rate:
                                                                          |Lines       |Functions  |Branches    
  Filename                                                                |Rate     Num|Rate    Num|Rate     Num
  ==============================================================================================================
  lib/screens/alerts/alert.ex                                             |29.9%    117|34.0%    47|    -      0
  lib/screens/cldr.ex                                                     | 100%      1|16.7%    12|    -      0
  lib/screens/stops/parser.ex                                             | 0.0%      1| 0.0%     1|    -      0
  lib/screens/stops/stop.ex                                               |41.8%     91|57.6%    33|    -      0
  lib/screens/v2/candidate_generator/widgets/reconstructed_alert.ex       |81.7%    104|83.3%    24|    -      0
  lib/screens/v2/candidate_generator/widgets/subway_status.ex             | 0.0%     18| 0.0%     7|    -      0
  lib/screens/v2/widget_instance/reconstructed_alert.ex                   |87.8%    343| 100%    45|    -      0
  lib/screens/v2/widget_instance/subway_status.ex                         |89.5%    210|92.9%    42|    -      0

Download coverage report

Copy link
Contributor

@digitalcora digitalcora left a comment

Choose a reason for hiding this comment

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

Some minor comments. I think the latest refactor turned out well! Approving this assuming we re-test in dev-green with some real alerts, just to be sure the various changes didn't introduce a bug.

@@ -360,6 +360,9 @@ defmodule Screens.V2.WidgetInstance.SubwayStatus do
Map.merge(%{route_pill: serialize_route_pill(route_id)}, serialize_alert(alert, route_id))
end

@spec serialize_alert(Alert.t() | nil, String.t()) :: alert()
Copy link
Contributor

Choose a reason for hiding this comment

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

We could use the type Route.id() here to be clear about the meaning (and same below).

lib/screens/v2/widget_instance/subway_status.ex Outdated Show resolved Hide resolved
Copy link

Coverage of commit 776f822

Summary coverage rate:
  lines......: 45.2% (2956 of 6542 lines)
  functions..: 41.1% (1050 of 2556 functions)
  branches...: no data found

Files changed coverage rate:
                                                                          |Lines       |Functions  |Branches    
  Filename                                                                |Rate     Num|Rate    Num|Rate     Num
  ==============================================================================================================
  lib/screens/alerts/alert.ex                                             |29.9%    117|34.0%    47|    -      0
  lib/screens/cldr.ex                                                     | 100%      1|16.7%    12|    -      0
  lib/screens/stops/parser.ex                                             | 0.0%      1| 0.0%     1|    -      0
  lib/screens/stops/stop.ex                                               |41.8%     91|57.6%    33|    -      0
  lib/screens/v2/candidate_generator/widgets/reconstructed_alert.ex       |81.7%    104|83.3%    24|    -      0
  lib/screens/v2/candidate_generator/widgets/subway_status.ex             | 0.0%     18| 0.0%     7|    -      0
  lib/screens/v2/widget_instance/reconstructed_alert.ex                   |87.8%    343| 100%    45|    -      0
  lib/screens/v2/widget_instance/subway_status.ex                         |89.5%    210|92.9%    42|    -      0

Download coverage report

Copy link

Coverage of commit efe032a

Summary coverage rate:
  lines......: 45.2% (2953 of 6540 lines)
  functions..: 41.1% (1050 of 2556 functions)
  branches...: no data found

Files changed coverage rate:
                                                                          |Lines       |Functions  |Branches    
  Filename                                                                |Rate     Num|Rate    Num|Rate     Num
  ==============================================================================================================
  lib/screens/alerts/alert.ex                                             |29.9%    117|34.0%    47|    -      0
  lib/screens/cldr.ex                                                     | 100%      1|16.7%    12|    -      0
  lib/screens/stops/parser.ex                                             | 0.0%      1| 0.0%     1|    -      0
  lib/screens/stops/stop.ex                                               |41.8%     91|57.6%    33|    -      0
  lib/screens/v2/candidate_generator/widgets/reconstructed_alert.ex       |81.7%    104|83.3%    24|    -      0
  lib/screens/v2/candidate_generator/widgets/subway_status.ex             | 0.0%     18| 0.0%     7|    -      0
  lib/screens/v2/widget_instance/reconstructed_alert.ex                   |87.4%    341| 100%    45|    -      0
  lib/screens/v2/widget_instance/subway_status.ex                         |89.5%    210|92.9%    42|    -      0

Download coverage report

@cmaddox5 cmaddox5 merged commit ddfe9ab into main Jul 18, 2024
11 checks passed
@cmaddox5 cmaddox5 deleted the cm/alert-handle-platform-closure branch July 18, 2024 18:47
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.

4 participants