Skip to content

Commit

Permalink
Remove predictions that don't have a departure time (#2128)
Browse files Browse the repository at this point in the history
* start

* reset test
  • Loading branch information
anthonyshull authored Jul 12, 2024
1 parent 1f0e83a commit 1d75e50
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
11 changes: 11 additions & 0 deletions lib/dotcom_web/channels/predictions_channel.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ defmodule DotcomWeb.PredictionsChannel do
@moduledoc """
Channel allowing clients to subscribe to streams of predictions.
"""

use DotcomWeb, :channel

require Routes.Route

alias Routes.Route
alias Phoenix.{Channel, Socket}
alias Predictions.{Prediction, PredictionsPubSub}
Expand Down Expand Up @@ -48,11 +51,19 @@ defmodule DotcomWeb.PredictionsChannel do
|> Enum.reject(fn prediction ->
is_nil(prediction.trip) ||
is_skipped_or_cancelled?(prediction) ||
no_departure_time?(prediction) ||
is_in_past?(prediction) ||
terminal_stop?(prediction)
end)
end

# Used to filter out predictions that have an arrival time but no departure time.
# This is common when shuttles are being used at non-terminal stops.
defp no_departure_time?(prediction) do
prediction.arrival_time != nil &&
prediction.departure_time == nil
end

# Keeping this style until we change all of these.
# credo:disable-for-next-line Credo.Check.Readability.PredicateFunctionNames
defp is_skipped_or_cancelled?(prediction) do
Expand Down
16 changes: 8 additions & 8 deletions test/support/factories/predictions/prediction.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ defmodule Test.Support.Factories.Predictions.Prediction do
def prediction_factory do
%Prediction{
id: FactoryHelpers.build(:id),
trip: Trip.build(:trip) |> FactoryHelpers.nullable_item(),
stop: Stop.build(:stop),
arrival_time: Timex.now() |> Timex.shift(minutes: 10),
departure_time: Timex.now() |> Timex.shift(minutes: 15),
direction_id: FactoryHelpers.build(:direction_id),
platform_stop_id: FactoryHelpers.build(:nullable_id),
route: Route.build(:route),
vehicle_id: FactoryHelpers.build(:nullable_id),
direction_id: FactoryHelpers.build(:direction_id),
arrival_time: Faker.DateTime.forward(1),
departure_time: Faker.DateTime.forward(1),
time: Faker.DateTime.forward(1),
schedule_relationship:
Faker.Util.pick([:added, :unscheduled, :cancelled, :skipped, :no_data])
|> FactoryHelpers.nullable_item(),
track: Faker.Util.digit() |> FactoryHelpers.nullable_item()
stop: Stop.build(:stop),
time: Faker.DateTime.forward(1),
track: Faker.Util.digit() |> FactoryHelpers.nullable_item(),
trip: Trip.build(:trip) |> FactoryHelpers.nullable_item(),
vehicle_id: FactoryHelpers.build(:nullable_id)
}
end
end

0 comments on commit 1d75e50

Please sign in to comment.