Skip to content

Commit

Permalink
fix: show "BRD" only if the vehicle is at the stop (#2111)
Browse files Browse the repository at this point in the history
* fix: show "BRD" only if the vehicle is at the stop

compares the vehicle's stop to the prediction's stop and only shows
"BRD" if they match. this prevents "BRD" from showing when stops are
very close to each other (such that a prediction is within the "BRD"
window) and a vehicle is boarding at the previous stop

* chore: disable cyclomatic complexity check

* chore: add values for Stop in departures tests
  • Loading branch information
sloanelybutsurely authored Jul 15, 2024
1 parent c1d5625 commit 8d8efc1
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 24 deletions.
6 changes: 5 additions & 1 deletion lib/screens/v2/widget_instance/departures.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ defmodule Screens.V2.WidgetInstance.Departures do

alias Screens.Alerts.Alert
alias Screens.Departures.Departure
alias Screens.Predictions.Prediction
alias Screens.Routes.Route
alias Screens.Schedules.Schedule
alias Screens.Util
Expand Down Expand Up @@ -414,9 +415,12 @@ defmodule Screens.V2.WidgetInstance.Departures do
),
do: %{time: %{type: :icon, icon: :overnight}}

# credo:disable-for-next-line Credo.Check.Refactor.CyclomaticComplexity
defp serialize_time(departure, _screen, now) do
stop_id = Departure.stop_id(departure)
departure_time = Departure.time(departure)
vehicle_status = Departure.vehicle_status(departure)
vehicle_stop_id = Prediction.stop_for_vehicle(departure.prediction)
stop_type = Departure.stop_type(departure)
route_type = Departure.route_type(departure)

Expand All @@ -425,7 +429,7 @@ defmodule Screens.V2.WidgetInstance.Departures do

time =
cond do
vehicle_status == :stopped_at and second_diff < 90 ->
vehicle_status == :stopped_at and second_diff < 90 and stop_id == vehicle_stop_id ->
%{type: :text, text: "BRD"}

second_diff < 30 and stop_type == :first_stop ->
Expand Down
81 changes: 58 additions & 23 deletions test/screens/v2/widget_instance/departures_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ defmodule Screens.V2.WidgetInstance.DeparturesTest do
alias Screens.Predictions.Prediction
alias Screens.Routes.Route
alias Screens.Schedules.Schedule
alias Screens.Stops.Stop
alias Screens.Trips.Trip
alias Screens.Vehicles.Vehicle
alias Screens.V2.{Departure, WidgetInstance}
Expand Down Expand Up @@ -116,7 +117,7 @@ defmodule Screens.V2.WidgetInstance.DeparturesTest do
type: :subway,
long_name: "Orange Line"
},
stop: %Screens.Stops.Stop{id: "70015", name: "Back Bay"},
stop: %Stop{id: "70015", name: "Back Bay"},
stop_headsign: "Oak Grove"
)
}
Expand Down Expand Up @@ -542,18 +543,32 @@ defmodule Screens.V2.WidgetInstance.DeparturesTest do
prediction: %Prediction{
departure_time: ~U[2020-01-01T00:01:10Z],
route: %Route{type: :subway},
vehicle: %Vehicle{current_status: :stopped_at}
vehicle: %Vehicle{current_status: :stopped_at, stop_id: "stop-b"},
stop: %Stop{id: "stop-b"}
}
}

assert serialized_boarding ==
Departures.serialize_times_with_crowding([departure], screen, now)

departure = %Departure{
prediction: %Prediction{
departure_time: ~U[2020-01-01T00:01:10Z],
route: %Route{type: :subway},
vehicle: %Vehicle{current_status: :stopped_at, stop_id: "stop-a"},
stop: %Stop{id: "stop-b"}
}
}

assert serialized_boarding !=
Departures.serialize_times_with_crowding([departure], screen, now)

departure = %Departure{
prediction: %Prediction{
departure_time: ~U[2020-01-01T00:02:10Z],
route: %Route{type: :subway},
vehicle: %Vehicle{current_status: :stopped_at}
vehicle: %Vehicle{current_status: :stopped_at},
stop: %Stop{}
}
}

Expand All @@ -564,7 +579,8 @@ defmodule Screens.V2.WidgetInstance.DeparturesTest do
prediction: %Prediction{
departure_time: ~U[2020-01-01T00:02:10Z],
route: %Route{type: :subway},
vehicle: %Vehicle{current_status: :in_transit_to}
vehicle: %Vehicle{current_status: :in_transit_to},
stop: %Stop{}
}
}

Expand All @@ -580,7 +596,8 @@ defmodule Screens.V2.WidgetInstance.DeparturesTest do
prediction: %Prediction{
arrival_time: nil,
departure_time: ~U[2020-01-01T00:00:10Z],
route: %Route{type: :subway}
route: %Route{type: :subway},
stop: %Stop{}
}
}

Expand All @@ -591,7 +608,8 @@ defmodule Screens.V2.WidgetInstance.DeparturesTest do
prediction: %Prediction{
arrival_time: nil,
departure_time: ~U[2020-01-01T00:00:40Z],
route: %Route{type: :subway}
route: %Route{type: :subway},
stop: %Stop{}
}
}

Expand All @@ -602,7 +620,8 @@ defmodule Screens.V2.WidgetInstance.DeparturesTest do
prediction: %Prediction{
arrival_time: ~U[2020-01-01T00:00:10Z],
departure_time: ~U[2020-01-01T00:00:10Z],
route: %Route{type: :subway}
route: %Route{type: :subway},
stop: %Stop{}
}
}

Expand All @@ -618,7 +637,8 @@ defmodule Screens.V2.WidgetInstance.DeparturesTest do
prediction: %Prediction{
arrival_time: ~U[2020-01-01T00:00:10Z],
departure_time: ~U[2020-01-01T00:00:10Z],
route: %Route{type: :subway}
route: %Route{type: :subway},
stop: %Stop{}
}
}

Expand All @@ -629,7 +649,8 @@ defmodule Screens.V2.WidgetInstance.DeparturesTest do
prediction: %Prediction{
arrival_time: ~U[2020-01-01T00:00:40Z],
departure_time: ~U[2020-01-01T00:00:40Z],
route: %Route{type: :subway}
route: %Route{type: :subway},
stop: %Stop{}
}
}

Expand Down Expand Up @@ -683,7 +704,8 @@ defmodule Screens.V2.WidgetInstance.DeparturesTest do
prediction: %Prediction{
arrival_time: ~U[2020-01-01T00:20:00Z],
departure_time: ~U[2020-01-01T00:20:00Z],
route: %Route{type: :subway}
route: %Route{type: :subway},
stop: %Stop{}
}
}

Expand All @@ -694,7 +716,8 @@ defmodule Screens.V2.WidgetInstance.DeparturesTest do
prediction: %Prediction{
arrival_time: ~U[2020-01-01T00:20:00Z],
departure_time: ~U[2020-01-01T00:20:00Z],
route: %Route{type: :rail}
route: %Route{type: :rail},
stop: %Stop{}
}
}

Expand All @@ -705,7 +728,8 @@ defmodule Screens.V2.WidgetInstance.DeparturesTest do
prediction: %Prediction{
arrival_time: ~U[2020-01-01T00:20:00Z],
departure_time: ~U[2020-01-01T00:20:00Z],
route: %Route{type: :bus}
route: %Route{type: :bus},
stop: %Stop{}
}
}

Expand All @@ -716,7 +740,8 @@ defmodule Screens.V2.WidgetInstance.DeparturesTest do
prediction: %Prediction{
arrival_time: ~U[2020-01-01T00:20:00Z],
departure_time: ~U[2020-01-01T00:20:00Z],
route: %Route{type: :ferry}
route: %Route{type: :ferry},
stop: %Stop{}
}
}

Expand Down Expand Up @@ -745,7 +770,8 @@ defmodule Screens.V2.WidgetInstance.DeparturesTest do
prediction: %Prediction{
arrival_time: ~U[2020-01-01T05:20:00Z],
departure_time: ~U[2020-01-01T05:20:00Z],
route: %Route{type: :subway}
route: %Route{type: :subway},
stop: %Stop{}
}
}

Expand All @@ -760,12 +786,14 @@ defmodule Screens.V2.WidgetInstance.DeparturesTest do
prediction: %Prediction{
arrival_time: ~U[2020-01-01T02:20:00Z],
departure_time: ~U[2020-01-01T02:20:00Z],
route: %Route{type: :rail}
route: %Route{type: :rail},
stop: %Stop{}
},
schedule: %Schedule{
arrival_time: ~U[2020-01-01T02:15:00Z],
departure_time: ~U[2020-01-01T02:15:00Z],
route: %Route{type: :rail}
route: %Route{type: :rail},
stop: %Stop{}
}
}

Expand Down Expand Up @@ -793,12 +821,14 @@ defmodule Screens.V2.WidgetInstance.DeparturesTest do
prediction: %Prediction{
arrival_time: ~U[2020-01-01T02:20:00Z],
departure_time: ~U[2020-01-01T02:20:00Z],
route: %Route{type: :rail}
route: %Route{type: :rail},
stop: %Stop{}
},
schedule: %Schedule{
arrival_time: ~U[2020-01-01T02:20:00Z],
departure_time: ~U[2020-01-01T02:20:00Z],
route: %Route{type: :rail}
route: %Route{type: :rail},
stop: %Stop{}
}
}

Expand All @@ -813,12 +843,14 @@ defmodule Screens.V2.WidgetInstance.DeparturesTest do
prediction: %Prediction{
arrival_time: ~U[2020-01-01T02:20:00Z],
departure_time: ~U[2020-01-01T02:20:00Z],
route: %Route{type: :bus}
route: %Route{type: :bus},
stop: %Stop{}
},
schedule: %Schedule{
arrival_time: ~U[2020-01-01T02:15:00Z],
departure_time: ~U[2020-01-01T02:15:00Z],
route: %Route{type: :bus}
route: %Route{type: :bus},
stop: %Stop{}
}
}

Expand All @@ -833,12 +865,14 @@ defmodule Screens.V2.WidgetInstance.DeparturesTest do
prediction: %Prediction{
arrival_time: ~U[2020-01-01T00:00:10Z],
departure_time: ~U[2020-01-01T00:00:10Z],
route: %Route{type: :rail}
route: %Route{type: :rail},
stop: %Stop{}
},
schedule: %Schedule{
arrival_time: ~U[2020-01-01T00:05:00Z],
departure_time: ~U[2020-01-01T00:05:00Z],
route: %Route{type: :rail}
route: %Route{type: :rail},
stop: %Stop{}
}
}

Expand All @@ -854,7 +888,8 @@ defmodule Screens.V2.WidgetInstance.DeparturesTest do
prediction: %Prediction{
arrival_time: ~U[2020-01-01T02:20:00Z],
departure_time: ~U[2020-01-01T02:20:00Z],
route: %Route{type: :rail}
route: %Route{type: :rail},
stop: %Stop{}
}
}

Expand Down

0 comments on commit 8d8efc1

Please sign in to comment.