Skip to content

Commit

Permalink
Move route_id check to a shared helper
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulJKim committed Jun 13, 2024
1 parent 099efbe commit a22e752
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
14 changes: 4 additions & 10 deletions lib/predictions/last_trip.ex
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
defmodule Predictions.LastTrip do
alias Predictions.Predictions

defp get_running_trips(predictions_feed) do
predictions_feed["entity"]
|> Stream.map(& &1["trip_update"])
|> Stream.filter(
&(&1["trip"]["route_id"] in [
"Red",
"Blue",
"Orange",
"Green-B",
"Green-C",
"Green-D",
"Green-E",
"Mattapan"
] and &1["trip"]["schedule_relationship"] != "CANCELED")
&(Predictions.relevant_rail_route?(&1["trip"]["route_id"]) and
&1["trip"]["schedule_relationship"] != "CANCELED")
)
end

Expand Down
25 changes: 15 additions & 10 deletions lib/predictions/predictions.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,8 @@ defmodule Predictions.Predictions do
feed_message["entity"]
|> Stream.map(& &1["trip_update"])
|> Stream.filter(
&(&1["trip"]["route_id"] in [
"Red",
"Blue",
"Orange",
"Green-B",
"Green-C",
"Green-D",
"Green-E",
"Mattapan"
] and &1["trip"]["schedule_relationship"] != "CANCELED")
&(relevant_rail_route?(&1["trip"]["route_id"]) and
&1["trip"]["schedule_relationship"] != "CANCELED")
)
|> Stream.flat_map(&transform_stop_time_updates/1)
|> Stream.filter(fn {update, _, _, _, _, _, _} ->
Expand Down Expand Up @@ -125,6 +117,19 @@ defmodule Predictions.Predictions do
Jason.decode!(body)
end

def relevant_rail_route?(route_id) do
route_id in [
"Red",
"Blue",
"Orange",
"Green-B",
"Green-C",
"Green-D",
"Green-E",
"Mattapan"
]
end

@spec translate_schedule_relationship(String.t()) :: :skipped | :scheduled
defp translate_schedule_relationship("SKIPPED") do
:skipped
Expand Down

0 comments on commit a22e752

Please sign in to comment.