Skip to content

Conversation

@joshlarson
Copy link
Contributor

@joshlarson joshlarson commented Dec 23, 2025

This fixes an issue present in Ye Olde Schedulle Finderre, as well as previous instances of this, where commuter rail trips would only be endowed with predictions for their first stop until they actually pulled out of the station, like 👇.

Screenshot 2025-12-22 at 2 12 35 PM

Now, instead of checking only schedules or only predictions, we check predicted_schedules which already has the schedules and predictions stitched together, in order to fallback to schedules when predictions are unavailable, even within a single trip:

Screenshot 2025-12-23 at 10 41 51 AM

(Left: SF1.0 without the fix; Right: SF2.0 with the fix)


Asana Ticket: [SF/UD] CR: Use schedule data to fill in trip details when predictions are for a partial trip

@joshlarson joshlarson force-pushed the jdl/sf2.0/ud/cr-fancy-labels branch from a55dfbf to 8b0489a Compare December 23, 2025 20:52
@joshlarson joshlarson force-pushed the jdl/sf2.0/ud/refactor-predictions-schedules-fetching branch from 3703a0d to 247158b Compare December 24, 2025 16:27
Base automatically changed from jdl/sf2.0/ud/cr-fancy-labels to main December 30, 2025 17:10
@joshlarson joshlarson force-pushed the jdl/sf2.0/ud/refactor-predictions-schedules-fetching branch from 247158b to 945f281 Compare December 31, 2025 16:04
@joshlarson joshlarson marked this pull request as ready for review December 31, 2025 16:05
@joshlarson joshlarson requested a review from a team as a code owner December 31, 2025 16:05
@joshlarson joshlarson enabled auto-merge (squash) December 31, 2025 16:05

defp reject_timeless_predictions(predictions) do
predictions
defp end_of_trip?(%PredictedSchedule{schedule: schedule, prediction: prediction}) do
Copy link
Collaborator

Choose a reason for hiding this comment

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

suggestion: it's unclear from the code alone how "end of trip" means "no predicted or scheduled departure time" -- I suggest either adjusting the name of this function or adding an explanatory comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Touché.

And there are a bunch of functions in this module at this point that could use explanatory comments, since the whole thing is becoming fairly complicated. I'll probably add more of those over the next few weeks as the behavior in this module settles down (those comments are very helpful, and also quite annoying to refactor around).

defp trip_details(predictions_by_trip_id, trip_id, stop_id) do
other_stops = other_stops(predictions_by_trip_id |> Map.get(trip_id))
defp trip_details(predicted_schedules_by_trip_id, trip_id, stop_id) do
other_stops = other_stops(predicted_schedules_by_trip_id |> Map.get(trip_id))
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit/question: This variable is technically all stops, I think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, hum, yes.

I'm working on refactoring pretty much everything about trip details in an upcoming PR, so would it be okay to keep this for now, with the understanding that this is almost certainly going to get torn apart and redone pretty soon?

@joshlarson joshlarson merged commit 14532ab into main Dec 31, 2025
17 checks passed
@joshlarson joshlarson deleted the jdl/sf2.0/ud/refactor-predictions-schedules-fetching branch December 31, 2025 21: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.

3 participants