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 update_type #863

Merged
merged 6 commits into from
Jan 3, 2025
Merged

Migrate to update_type #863

merged 6 commits into from
Jan 3, 2025

Conversation

PaulJKim
Copy link
Collaborator

Summary of changes

Asana Ticket: Migrate to Update_type for trip type

RTS currently uses the uncertainty field in order to distinguish different types of predictions (mid trip, terminal, and reverse). This field will eventually be deprecated by the Transit Data team and has been replaced by a new field provided at the trip level called update_type. This PR migrates RTS to using this new field in favor of uncertainty which also made it easier to clean up the predictions feed parsing code a bit as well.

Reviewer Checklist

  • Meets ticket's acceptance criteria
  • Any new or changed functions have typespecs
  • Tests were added for any new functionality (don't just rely on Codecov)
  • If signs.json was changed, there is a follow-up PR to signs_ui to update its dependency on this project
  • This branch was deployed to the staging environment and is currently running with no unexpected increase in warnings, and no errors or crashes (compare on Splunk: staging vs. prod)

@PaulJKim PaulJKim requested a review from a team as a code owner December 21, 2024 00:14
@@ -372,7 +368,7 @@ defmodule Predictions.PredictionsTest do
}, _} = get_all(feed_message, @current_time)
end

test "include predictions with low uncertainty" do
test "include non reverse predictions" do
reassign_env(:filter_uncertain_predictions?, true)
Copy link
Contributor

Choose a reason for hiding this comment

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

drive-by: Could we rename this flag, since we're otherwise removing the concept of "uncertainty" from the code? Maybe filter_reverse_predictions?. (Curious why this is configurable in the first place.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, we should definitely rename it but I was thinking maybe in a small follow-up task or something since we'd want to change that in the devops repo as well. In terms of why it's configurable, I'd guess it's because back then RTS was running on opstech3 and we would often take advantage of flags like this to quickly change up flags to adjust what RTS was doing. It was added in a really old PR a few years back and may not be necessary anymore. #369

Copy link
Contributor

Choose a reason for hiding this comment

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

Hm, yeah, maybe more useful initially as a "feature flag" in the time immediately after the feature was added. I think we could outright remove it now, if @panentheos agrees.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah you're probably right. The feature flag isn't something we'd likely prefer to use in a situation where we want to filter out any sort of prediction type at large anyway since that requires infra to get involved these days. In the more recent past when we've filtered out terminal/reverse predictions on some heavy rail lines, we just introduced a temporary code change and then revert it when predictions were trustworthy again.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yep, I don't think we need as a configurable option. Let's remove it!

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 some small comments, otherwise looks good!

route_id = trip_update["trip"]["route_id"]
direction_id = trip_update["trip"]["direction_id"]
trip_id = trip_update["trip"]["trip_id"]
revenue_trip? = trip_update["trip"]["revenue"]
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 inline some of these below to shorten the boilerplate a bit. Alternatively, we could destructure the function param directly, as long as these fields will always be present.

defp has_departed?(prediction) do
prediction.seconds_until_departure && prediction.seconds_until_departure < 0 &&
not prediction.stopped_at_predicted_stop?
prediction.seconds_until_departure < 0 and not prediction.stopped_at_predicted_stop?
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: Technically this works, because nil < 0 == false according to Elixir's term ordering rules, but I think I prefer the explicit check as a reminder that seconds_until_departure might be nil

@@ -372,7 +368,7 @@ defmodule Predictions.PredictionsTest do
}, _} = get_all(feed_message, @current_time)
end

test "include predictions with low uncertainty" do
test "include non reverse predictions" do
reassign_env(:filter_uncertain_predictions?, true)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yep, I don't think we need as a configurable option. Let's remove it!

@@ -1928,7 +1926,8 @@ defmodule Signs.RealtimeTest do
stopped_at_predicted_stop?: Keyword.get(opts, :stopped_at_predicted_stop, false),
boarding_status: Keyword.get(opts, :boarding_status),
revenue_trip?: true,
vehicle_id: "v1"
vehicle_id: "v1",
type: Keyword.get(opts, :prediction_type, :mid_trip)
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: Why not name this option type for consistency?

@PaulJKim PaulJKim merged commit cda9804 into main Jan 3, 2025
2 checks passed
@PaulJKim PaulJKim deleted the pk/migrate-to-update-type branch January 3, 2025 18:14
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.

3 participants