Skip to content

Commit

Permalink
Filter out past departures and adjust last trip filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulJKim committed Jun 12, 2024
1 parent cae438f commit 8251ca9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
13 changes: 12 additions & 1 deletion lib/predictions/last_trip.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,18 @@ defmodule Predictions.LastTrip do
defp get_running_trips(predictions_feed) do
predictions_feed["entity"]
|> Stream.map(& &1["trip_update"])
|> Enum.reject(&(&1["trip"]["schedule_relationship"] == "CANCELED"))
|> 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")
)
end

def get_last_trips(predictions_feed) do
Expand Down
7 changes: 4 additions & 3 deletions lib/predictions/predictions.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ defmodule Predictions.Predictions do
end)
|> Stream.map(&prediction_from_update(&1, current_time))
|> Enum.reject(
&(is_nil(&1.seconds_until_arrival) and is_nil(&1.seconds_until_departure) and
is_nil(&1.seconds_until_passthrough))
&((is_nil(&1.seconds_until_arrival) and is_nil(&1.seconds_until_departure) and
is_nil(&1.seconds_until_passthrough)) or
(&1.seconds_until_departure && &1.seconds_until_departure < 0))
)

vehicles_running_revenue_trips =
Expand Down Expand Up @@ -99,7 +100,7 @@ defmodule Predictions.Predictions do
direction_id: direction_id,
seconds_until_arrival: max(0, seconds_until_arrival),
arrival_certainty: stop_time_update["arrival"]["uncertainty"],
seconds_until_departure: max(0, seconds_until_departure),
seconds_until_departure: seconds_until_departure,
departure_certainty: stop_time_update["departure"]["uncertainty"],
seconds_until_passthrough: max(0, seconds_until_passthrough),
schedule_relationship:
Expand Down

0 comments on commit 8251ca9

Please sign in to comment.