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

Migrate to GTFS-rt predictions and locations feeds #743

Merged
merged 9 commits into from
Jul 23, 2024

Conversation

PaulJKim
Copy link
Collaborator

Summary of changes

Asana Ticket: Rearchitect RTS off of RTR

This change adjusts the predictions parsing logic to allow RTS to use the GTFS-rt feeds instead of the RTR feeds. The locations parsing logic doesn't need to be change because the GTFS-rt locations feed more closely mirrors the RTR locations feed.

The discrepancies in what fields are provided in the GTFS-rt feed compared to the RTR feed necessitated some slight logic changes in the main predictions flow. Most notably, the stops_away field is not in the GTFS-rt field, but we are able to use locations data to mimic how stops_away = 0 is determined as an alternative.

Changes can be tested locally against the GTFS-rt production feeds by using the following URLs for the TRIP_UPDATE_URL and VEHICLE_POSITIONS_URL env variables respectively

  • https://cdn.mbta.com/realtime/TripUpdates_enhanced.json
  • https://cdn.mbta.com/realtime/VehiclePositions_enhanced.json

Before this is merged/deployed, we will want to put up a Terraform PR to change the values of the aforementioned env variables first. Once that is merged and applied, then we can re-deploy RTS with the new logic.

Copy link

Coverage of commit d9c11dc

Summary coverage rate:
  lines......: 72.1% (1819 of 2524 lines)
  functions..: 75.0% (507 of 676 functions)
  branches...: no data found

Files changed coverage rate:
                                                             |Lines       |Functions  |Branches    
  Filename                                                   |Rate     Num|Rate    Num|Rate     Num
  =================================================================================================
  lib/content/message/predictions.ex                         |72.1%    129| 100%    17|    -      0
  lib/fake/httpoison.ex                                      |72.7%     44|57.1%     7|    -      0
  lib/predictions/prediction.ex                              | 100%      1| 100%     2|    -      0
  lib/predictions/predictions.ex                             |95.2%     42| 100%     6|    -      0
  lib/signs/utilities/predictions.ex                         |98.6%     69| 100%    12|    -      0

Download coverage report

@PaulJKim PaulJKim requested a review from panentheos March 25, 2024 18:45
Copy link
Collaborator

@panentheos panentheos left a comment

Choose a reason for hiding this comment

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

Generally looking good, just a few small comments below.

Also, we should remove the old url defaults in runtime.exs and add the dev urls as defaults in .envrc.template

@@ -10,11 +10,23 @@ defmodule Predictions.Predictions do
predictions =
feed_message["entity"]
|> Enum.map(& &1["trip_update"])
|> Enum.filter(
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: We could use Stream here for efficiency, and/or combine this with the following reject.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah true. Might as well use the Stream versions of most of the rest of these chained operations too. Any opposition to that?

stops_away: stop_time_update["stops_away"],
stopped?: not is_nil(vehicle_location) and vehicle_location.status == :stopped_at,
vehicle_at_predicted_stop?:
not is_nil(vehicle_location) and stop_time_update["stop_id"] == vehicle_location.stop_id,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since we always look at these two values together, what do you think about combining them into a single flag like stopped_at_predicted_stop?, which would be a drop-in replacement for the previous stops_away == 0?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh good call

@@ -65,6 +65,8 @@ defmodule Engine.PredictionsTest do
assert :ets.info(predictions_table)[:size] == 2
[{{"stop_to_remove", 0}, []}] = :ets.lookup(predictions_table, {"stop_to_remove", 0})

:ets.lookup(predictions_table, {"stop_to_update", 0})
Copy link
Collaborator

Choose a reason for hiding this comment

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

This looks like it was left in accidentally.

nil -> []
stops -> [stops_away: stops, boarding_status: "Stopped #{stops} stop away"]
end

Copy link
Collaborator

Choose a reason for hiding this comment

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

This still seems like a useful bit of abstraction over some common data patterns. If we just update it to use the new flag(s), we could probably avoid modifying some of these tests.

Copy link

Coverage of commit 5419995

Summary coverage rate:
  lines......: 72.0% (1817 of 2523 lines)
  functions..: 75.0% (507 of 676 functions)
  branches...: no data found

Files changed coverage rate:
                                                             |Lines       |Functions  |Branches    
  Filename                                                   |Rate     Num|Rate    Num|Rate     Num
  =================================================================================================
  lib/content/message/predictions.ex                         |71.9%    128| 100%    17|    -      0
  lib/fake/httpoison.ex                                      |72.7%     44|57.1%     7|    -      0
  lib/predictions/prediction.ex                              | 100%      1| 100%     2|    -      0
  lib/predictions/predictions.ex                             |92.9%     42| 100%     6|    -      0
  lib/signs/utilities/predictions.ex                         |98.6%     69| 100%    12|    -      0

Download coverage report

Copy link

Coverage of commit f03d8a7

Summary coverage rate:
  lines......: 72.0% (1817 of 2523 lines)
  functions..: 75.0% (507 of 676 functions)
  branches...: no data found

Files changed coverage rate:
                                                             |Lines       |Functions  |Branches    
  Filename                                                   |Rate     Num|Rate    Num|Rate     Num
  =================================================================================================
  lib/content/message/predictions.ex                         |71.9%    128| 100%    17|    -      0
  lib/fake/httpoison.ex                                      |72.7%     44|57.1%     7|    -      0
  lib/predictions/prediction.ex                              | 100%      1| 100%     2|    -      0
  lib/predictions/predictions.ex                             |92.9%     42| 100%     6|    -      0
  lib/signs/utilities/predictions.ex                         |98.6%     69| 100%    12|    -      0

Download coverage report

Copy link
Collaborator

@panentheos panentheos left a comment

Choose a reason for hiding this comment

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

See one suggestion, then looks good! Tested by running locally.

.envrc.template Outdated Show resolved Hide resolved
Co-authored-by: Brett Heath-Wlaz <[email protected]>
Copy link

Coverage of commit 948020e

Summary coverage rate:
  lines......: 72.0% (1817 of 2523 lines)
  functions..: 75.0% (507 of 676 functions)
  branches...: no data found

Files changed coverage rate:
                                                             |Lines       |Functions  |Branches    
  Filename                                                   |Rate     Num|Rate    Num|Rate     Num
  =================================================================================================
  lib/content/message/predictions.ex                         |71.9%    128| 100%    17|    -      0
  lib/fake/httpoison.ex                                      |72.7%     44|57.1%     7|    -      0
  lib/predictions/prediction.ex                              | 100%      1| 100%     2|    -      0
  lib/predictions/predictions.ex                             |92.9%     42| 100%     6|    -      0
  lib/signs/utilities/predictions.ex                         |98.6%     69| 100%    12|    -      0

Download coverage report

Copy link

Coverage of commit 099efbe

Summary coverage rate:
  lines......: 73.2% (2022 of 2763 lines)
  functions..: 75.4% (567 of 752 functions)
  branches...: no data found

Files changed coverage rate:
                                                             |Lines       |Functions  |Branches    
  Filename                                                   |Rate     Num|Rate    Num|Rate     Num
  =================================================================================================
  lib/content/message/predictions.ex                         |71.9%    128| 100%    17|    -      0
  lib/fake/httpoison.ex                                      |72.7%     44|57.1%     7|    -      0
  lib/predictions/last_trip.ex                               |81.2%     16| 100%     3|    -      0
  lib/predictions/prediction.ex                              | 100%      1| 100%     2|    -      0
  lib/predictions/predictions.ex                             |93.0%     43| 100%     6|    -      0
  lib/signs/utilities/predictions.ex                         |98.6%     69| 100%    12|    -      0

Download coverage report

Copy link

Coverage of commit 099efbe

Summary coverage rate:
  lines......: 73.2% (2022 of 2763 lines)
  functions..: 75.4% (567 of 752 functions)
  branches...: no data found

Files changed coverage rate:
                                                             |Lines       |Functions  |Branches    
  Filename                                                   |Rate     Num|Rate    Num|Rate     Num
  =================================================================================================
  lib/content/message/predictions.ex                         |71.9%    128| 100%    17|    -      0
  lib/fake/httpoison.ex                                      |72.7%     44|57.1%     7|    -      0
  lib/predictions/last_trip.ex                               |81.2%     16| 100%     3|    -      0
  lib/predictions/prediction.ex                              | 100%      1| 100%     2|    -      0
  lib/predictions/predictions.ex                             |93.0%     43| 100%     6|    -      0
  lib/signs/utilities/predictions.ex                         |98.6%     69| 100%    12|    -      0

Download coverage report

@PaulJKim
Copy link
Collaborator Author

@panentheos When if you have a minute, could I get another pass at this one?
Some minor changes since the last time

  • Added the filtering to the last trip parsing logic
  • Started filtering out past departures
  • Cleaned up a couple references to RTR leftover

Copy link
Collaborator

@panentheos panentheos left a comment

Choose a reason for hiding this comment

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

See one comment, otherwise the changes look good.

"Green-D",
"Green-E",
"Mattapan"
] and &1["trip"]["schedule_relationship"] != "CANCELED")
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: We might want to split this route list into a helper, e.g. relevant_rail_route?, since we intend for both code paths to use the same list.

@PaulJKim PaulJKim requested a review from a team as a code owner June 13, 2024 19:24
Copy link

Coverage of commit a22e752

Summary coverage rate:
  lines......: 73.2% (2025 of 2765 lines)
  functions..: 75.4% (568 of 753 functions)
  branches...: no data found

Files changed coverage rate:
                                                             |Lines       |Functions  |Branches    
  Filename                                                   |Rate     Num|Rate    Num|Rate     Num
  =================================================================================================
  lib/content/message/predictions.ex                         |71.9%    128| 100%    17|    -      0
  lib/fake/httpoison.ex                                      |72.7%     44|57.1%     7|    -      0
  lib/predictions/last_trip.ex                               |81.2%     16| 100%     3|    -      0
  lib/predictions/prediction.ex                              | 100%      1| 100%     2|    -      0
  lib/predictions/predictions.ex                             |93.2%     44| 100%     7|    -      0
  lib/signs/utilities/predictions.ex                         |98.6%     69| 100%    12|    -      0

Download coverage report

@PaulJKim PaulJKim merged commit 58bf0b6 into main Jul 23, 2024
2 checks passed
@PaulJKim PaulJKim deleted the pk/migrate-from-rtr-to-gtfs-rt branch July 23, 2024 15:06
PaulJKim added a commit that referenced this pull request Aug 2, 2024
PaulJKim added a commit that referenced this pull request Aug 2, 2024
@PaulJKim PaulJKim restored the pk/migrate-from-rtr-to-gtfs-rt branch August 2, 2024 19:49
@PaulJKim
Copy link
Collaborator Author

PaulJKim commented Aug 2, 2024

Restoring the branch so we can deploy it to dev-green while we investigate what's going on with BRD predictions and passthrough announcements

@PaulJKim PaulJKim temporarily deployed to dev-green-linux August 2, 2024 19:58 — with GitHub Actions Inactive
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