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

extract prediction helpers #867

Merged
merged 1 commit into from
Jan 13, 2025
Merged

extract prediction helpers #867

merged 1 commit into from
Jan 13, 2025

Conversation

panentheos
Copy link
Collaborator

@panentheos panentheos commented Jan 7, 2025

Summary of changes

This extracts several helpers related to predictions, as a part of the larger message refactoring effort. Notes:

  • Removes special handling of "approaching" predictions, since only the audio path cares about them.
  • Unifies the logic for determining "approximate" minute values, fixing some potential edge cases.
  • Fixes a rare historical edge case where approaching predictions wouldn't be read out during the normal read loop.

Aside from these few cases, the overall system behavior should be unchanged.

@panentheos panentheos requested a review from a team as a code owner January 7, 2025 16:19
@spec prediction_approaching?(Predictions.Prediction.t(), boolean()) :: boolean()
def prediction_approaching?(prediction, terminal?) do
!terminal? and !prediction.stopped_at_predicted_stop? and
prediction_seconds(prediction, terminal?) in 31..60
Copy link
Collaborator

Choose a reason for hiding this comment

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

Technically terminal? can only ever be false when predictions_seconds/2 is called here. Should we just explicitly pass false as the second param?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I kind of went back and forth on that. Technically we could just hardcode it, but it creates a little bit of unnecessary coupling in the logic, so I'm inclined to leave it this way.

Copy link
Collaborator

@PaulJKim PaulJKim left a comment

Choose a reason for hiding this comment

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

Looks good!

@panentheos panentheos merged commit 04d9e98 into main Jan 13, 2025
2 checks passed
@panentheos panentheos deleted the bhw/prediction-helpers branch January 13, 2025 15:11
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