diff --git a/config/test.exs b/config/test.exs index 4eb4cb2f6..5c00e0dd2 100644 --- a/config/test.exs +++ b/config/test.exs @@ -131,9 +131,7 @@ config :screens, headway_headsign: "Test" } ] - }, - elevator_redundancy_data_path: - Path.join(~w[#{File.cwd!()} test fixtures elevator_redundancy_data.json]) + } config :screens, ScreensWeb.AuthManager, secret_key: "test key" diff --git a/lib/screens/elevator.ex b/lib/screens/elevator.ex new file mode 100644 index 000000000..0db5af5ab --- /dev/null +++ b/lib/screens/elevator.ex @@ -0,0 +1,47 @@ +defmodule Screens.Elevator do + @moduledoc """ + Exposes hand-authored data about elevator accessibility that is currently owned by the Screens + team and not (yet?) available in GTFS. + """ + + alias Screens.Facilities.Facility + alias Screens.Log + + @enforce_keys ~w[id redundancy]a + defstruct @enforce_keys + + @type t :: %__MODULE__{id: Facility.id(), redundancy: redundancy()} + + @type redundancy :: + :nearby + | :in_station + | {:different_station, summary :: String.t()} + | {:contact, summary :: String.t()} + + @data :screens + |> :code.priv_dir() + |> Path.join("elevators.json") + |> File.read!() + |> Jason.decode!() + + @callback get(Facility.id()) :: t() | nil + def get(id) do + case Map.get(@data, id) do + %{"redundancy" => 1} -> + %__MODULE__{id: id, redundancy: :nearby} + + %{"redundancy" => 2} -> + %__MODULE__{id: id, redundancy: :in_station} + + %{"redundancy" => 3, "summary" => summary} -> + %__MODULE__{id: id, redundancy: {:different_station, summary}} + + %{"redundancy" => 4, "summary" => summary} -> + %__MODULE__{id: id, redundancy: {:contact, summary}} + + _other -> + Log.warning("elevator_redundancy_not_found", id: id) + nil + end + end +end diff --git a/lib/screens/v2/candidate_generator/elevator/closures.ex b/lib/screens/v2/candidate_generator/elevator/closures.ex index a36b8608b..ed2e11328 100644 --- a/lib/screens/v2/candidate_generator/elevator/closures.ex +++ b/lib/screens/v2/candidate_generator/elevator/closures.ex @@ -2,6 +2,7 @@ defmodule Screens.V2.CandidateGenerator.Elevator.Closures do @moduledoc false alias Screens.Alerts.{Alert, InformedEntity} + alias Screens.Elevator alias Screens.Log alias Screens.Routes.Route alias Screens.Stops.Stop @@ -17,29 +18,20 @@ defmodule Screens.V2.CandidateGenerator.Elevator.Closures do alias Screens.V2.WidgetInstance.Elevator.Closure alias Screens.V2.WidgetInstance.Serializer.RoutePill alias ScreensConfig.Screen - alias ScreensConfig.V2.Elevator + alias ScreensConfig.V2.Elevator, as: ElevatorConfig import Screens.Inject @alert injected(Alert) + @elevator injected(Elevator) @facility injected(Screens.Facilities.Facility) @route injected(Route) @stop injected(Stop) - @elevator_redundancy_data :screens - |> Application.compile_env( - :elevator_redundancy_data_path, - :screens - |> :code.priv_dir() - |> Path.join("elevators/elevator_redundancy_data.json") - ) - |> File.read!() - |> Jason.decode!() - @spec elevator_status_instances(Screen.t(), NormalHeader.t(), Footer.t()) :: list(WidgetInstance.t()) def elevator_status_instances( - %Screen{app_params: %Elevator{elevator_id: elevator_id} = config}, + %Screen{app_params: %ElevatorConfig{elevator_id: elevator_id} = config}, header_instance, footer_instance ) do @@ -187,11 +179,9 @@ defmodule Screens.V2.CandidateGenerator.Elevator.Closures do defp has_nearby_redundancy?(%Alert{ informed_entities: [%{facility: %{id: informed_facility_id}} | _] }) do - if data = @elevator_redundancy_data[informed_facility_id] do - data["nearby_redundancy?"] - else - Log.warning("elevator_redundancy_not_found", facility_id: informed_facility_id) - false + case @elevator.get(informed_facility_id) do + %Elevator{redundancy: :nearby} -> true + _ -> false end end end diff --git a/priv/elevators.json b/priv/elevators.json new file mode 100644 index 000000000..b18f32efb --- /dev/null +++ b/priv/elevators.json @@ -0,0 +1,846 @@ +{ + "918": { + "summary": "", + "redundancy": 2 + }, + "925": { + "summary": "", + "redundancy": 2 + }, + "804": { + "summary": "", + "redundancy": 2 + }, + "958": { + "summary": "", + "redundancy": 3 + }, + "780": { + "summary": "", + "redundancy": null + }, + "986": { + "summary": "", + "redundancy": 3 + }, + "921": { + "summary": "", + "redundancy": 3 + }, + "725": { + "summary": "", + "redundancy": null + }, + "816": { + "summary": "", + "redundancy": 3 + }, + "866": { + "summary": "", + "redundancy": 3 + }, + "996": { + "summary": "", + "redundancy": 1 + }, + "744": { + "summary": "", + "redundancy": 2 + }, + "710": { + "summary": "", + "redundancy": 2 + }, + "842": { + "summary": "", + "redundancy": 2 + }, + "899": { + "summary": "", + "redundancy": 2 + }, + "856": { + "summary": "", + "redundancy": 3 + }, + "879": { + "summary": "", + "redundancy": 3 + }, + "901": { + "summary": "", + "redundancy": 2 + }, + "922": { + "summary": "", + "redundancy": 3 + }, + "945": { + "summary": "", + "redundancy": 3 + }, + "701": { + "summary": "", + "redundancy": 1 + }, + "771": { + "summary": "", + "redundancy": 2 + }, + "734": { + "summary": "", + "redundancy": 2 + }, + "979": { + "summary": "", + "redundancy": 2 + }, + "936": { + "summary": "", + "redundancy": 3 + }, + "957": { + "summary": "", + "redundancy": 3 + }, + "998": { + "summary": "", + "redundancy": 1 + }, + "971": { + "summary": "", + "redundancy": 3 + }, + "913": { + "summary": "", + "redundancy": 2 + }, + "855": { + "summary": "", + "redundancy": 3 + }, + "731": { + "summary": "", + "redundancy": 2 + }, + "892": { + "summary": "", + "redundancy": 2 + }, + "854": { + "summary": "", + "redundancy": 3 + }, + "815": { + "summary": "N/A", + "redundancy": 1 + }, + "712": { + "summary": "", + "redundancy": 2 + }, + "938": { + "summary": "", + "redundancy": 3 + }, + "896": { + "summary": "", + "redundancy": 4 + }, + "886": { + "summary": "", + "redundancy": 3 + }, + "994": { + "summary": "", + "redundancy": 1 + }, + "713": { + "summary": "", + "redundancy": 2 + }, + "933": { + "summary": "", + "redundancy": 3 + }, + "897": { + "summary": "", + "redundancy": 2 + }, + "769": { + "summary": "", + "redundancy": 2 + }, + "869": { + "summary": "", + "redundancy": 2 + }, + "908": { + "summary": "", + "redundancy": 2 + }, + "910": { + "summary": "", + "redundancy": 3 + }, + "813": { + "summary": "Accessible route available", + "redundancy": 2 + }, + "891": { + "summary": "", + "redundancy": 2 + }, + "947": { + "summary": "", + "redundancy": 2 + }, + "724": { + "summary": "", + "redundancy": 2 + }, + "711": { + "summary": "", + "redundancy": 2 + }, + "782": { + "summary": "", + "redundancy": null + }, + "972": { + "summary": "", + "redundancy": 3 + }, + "803": { + "summary": "", + "redundancy": 2 + }, + "978": { + "summary": "", + "redundancy": 2 + }, + "992": { + "summary": "", + "redundancy": null + }, + "859": { + "summary": "", + "redundancy": 3 + }, + "702": { + "summary": "", + "redundancy": 1 + }, + "757": { + "summary": "", + "redundancy": 1 + }, + "965": { + "summary": "", + "redundancy": 2 + }, + "722": { + "summary": "", + "redundancy": 1 + }, + "898": { + "summary": "", + "redundancy": 2 + }, + "717": { + "summary": "", + "redundancy": 2 + }, + "915": { + "summary": "", + "redundancy": 2 + }, + "807": { + "summary": "", + "redundancy": 1 + }, + "852": { + "summary": "", + "redundancy": 3 + }, + "858": { + "summary": "", + "redundancy": 3 + }, + "944": { + "summary": "", + "redundancy": 3 + }, + "850": { + "summary": "", + "redundancy": 3 + }, + "967": { + "summary": "", + "redundancy": 1 + }, + "768": { + "summary": "", + "redundancy": 1 + }, + "909": { + "summary": "", + "redundancy": 2 + }, + "970": { + "summary": "", + "redundancy": 4 + }, + "868": { + "summary": "", + "redundancy": 3 + }, + "52": { + "summary": "", + "redundancy": 4 + }, + "920": { + "summary": "", + "redundancy": 3 + }, + "949": { + "summary": "", + "redundancy": 2 + }, + "746": { + "summary": "", + "redundancy": 1 + }, + "805": { + "summary": "", + "redundancy": 1 + }, + "930": { + "summary": "", + "redundancy": 1 + }, + "719": { + "summary": "", + "redundancy": 2 + }, + "937": { + "summary": "", + "redundancy": 3 + }, + "966": { + "summary": "", + "redundancy": 2 + }, + "946": { + "summary": "", + "redundancy": 3 + }, + "814": { + "summary": "N/A", + "redundancy": 1 + }, + "709": { + "summary": "", + "redundancy": 2 + }, + "721": { + "summary": "", + "redundancy": 1 + }, + "762": { + "summary": "", + "redundancy": 1 + }, + "846": { + "summary": "", + "redundancy": 3 + }, + "802": { + "summary": "", + "redundancy": 1 + }, + "880": { + "summary": "", + "redundancy": 3 + }, + "781": { + "summary": "", + "redundancy": null + }, + "876": { + "summary": "", + "redundancy": 3 + }, + "715": { + "summary": "", + "redundancy": 2 + }, + "864": { + "summary": "", + "redundancy": 2 + }, + "969": { + "summary": "", + "redundancy": null + }, + "890": { + "summary": "", + "redundancy": 3 + }, + "927": { + "summary": "", + "redundancy": 2 + }, + "889": { + "summary": "", + "redundancy": 3 + }, + "973": { + "summary": "", + "redundancy": 2 + }, + "904": { + "summary": "", + "redundancy": 2 + }, + "870": { + "summary": "", + "redundancy": 3 + }, + "975": { + "summary": "", + "redundancy": 2 + }, + "964": { + "summary": "", + "redundancy": 3 + }, + "982": { + "summary": "", + "redundancy": 1 + }, + "847": { + "summary": "", + "redundancy": 3 + }, + "923": { + "summary": "", + "redundancy": 2 + }, + "857": { + "summary": "", + "redundancy": 3 + }, + "808": { + "summary": "", + "redundancy": 2 + }, + "732": { + "summary": "", + "redundancy": 2 + }, + "851": { + "summary": "", + "redundancy": 3 + }, + "905": { + "summary": "", + "redundancy": 2 + }, + "806": { + "summary": "", + "redundancy": 1 + }, + "849": { + "summary": "", + "redundancy": 3 + }, + "885": { + "summary": "", + "redundancy": 3 + }, + "912": { + "summary": "", + "redundancy": 2 + }, + "845": { + "summary": "", + "redundancy": 3 + }, + "811": { + "summary": "", + "redundancy": 3 + }, + "900": { + "summary": "", + "redundancy": 2 + }, + "763": { + "summary": "", + "redundancy": 1 + }, + "735": { + "summary": "", + "redundancy": 2 + }, + "823": { + "summary": "", + "redundancy": 2 + }, + "841": { + "summary": "", + "redundancy": 3 + }, + "999": { + "summary": "", + "redundancy": 1 + }, + "906": { + "summary": "", + "redundancy": 2 + }, + "954": { + "summary": "", + "redundancy": 3 + }, + "953": { + "summary": "", + "redundancy": 3 + }, + "772": { + "summary": "", + "redundancy": 1 + }, + "861": { + "summary": "", + "redundancy": 3 + }, + "952": { + "summary": "", + "redundancy": 3 + }, + "843": { + "summary": "", + "redundancy": 2 + }, + "962": { + "summary": "", + "redundancy": 3 + }, + "884": { + "summary": "", + "redundancy": 3 + }, + "831": { + "summary": "", + "redundancy": 3 + }, + "723": { + "summary": "", + "redundancy": 1 + }, + "50": { + "summary": "", + "redundancy": null + }, + "935": { + "summary": "", + "redundancy": 3 + }, + "728": { + "summary": "", + "redundancy": 2 + }, + "745": { + "summary": "", + "redundancy": 2 + }, + "765": { + "summary": "", + "redundancy": 2 + }, + "919": { + "summary": "", + "redundancy": 2 + }, + "963": { + "summary": "", + "redundancy": 3 + }, + "991": { + "summary": "", + "redundancy": null + }, + "985": { + "summary": "", + "redundancy": 2 + }, + "53": { + "summary": "", + "redundancy": 4 + }, + "736": { + "summary": "", + "redundancy": 1 + }, + "867": { + "summary": "", + "redundancy": 3 + }, + "756": { + "summary": "", + "redundancy": 1 + }, + "903": { + "summary": "", + "redundancy": 2 + }, + "940": { + "summary": "", + "redundancy": 2 + }, + "800": { + "summary": "", + "redundancy": 2 + }, + "726": { + "summary": "", + "redundancy": null + }, + "764": { + "summary": "", + "redundancy": 2 + }, + "703": { + "summary": "", + "redundancy": 1 + }, + "887": { + "summary": "", + "redundancy": 3 + }, + "872": { + "summary": "", + "redundancy": 3 + }, + "733": { + "summary": "", + "redundancy": 2 + }, + "830": { + "summary": "", + "redundancy": 3 + }, + "817": { + "summary": "", + "redundancy": 3 + }, + "853": { + "summary": "", + "redundancy": 3 + }, + "955": { + "summary": "", + "redundancy": 2 + }, + "968": { + "summary": "", + "redundancy": null + }, + "821": { + "summary": "", + "redundancy": 2 + }, + "928": { + "summary": "", + "redundancy": 4 + }, + "931": { + "summary": "", + "redundancy": 2 + }, + "766": { + "summary": "", + "redundancy": 2 + }, + "961": { + "summary": "Accessible route available", + "redundancy": 2 + }, + "993": { + "summary": "", + "redundancy": null + }, + "997": { + "summary": "", + "redundancy": 1 + }, + "812": { + "summary": "", + "redundancy": 2 + }, + "990": { + "summary": "", + "redundancy": null + }, + "926": { + "summary": "", + "redundancy": 2 + }, + "956": { + "summary": "", + "redundancy": 2 + }, + "976": { + "summary": "", + "redundancy": 3 + }, + "727": { + "summary": "", + "redundancy": null + }, + "848": { + "summary": "", + "redundancy": 2 + }, + "983": { + "summary": "", + "redundancy": 1 + }, + "743": { + "summary": "", + "redundancy": 1 + }, + "810": { + "summary": "", + "redundancy": 3 + }, + "924": { + "summary": "", + "redundancy": 2 + }, + "987": { + "summary": "", + "redundancy": 1 + }, + "720": { + "summary": "", + "redundancy": 1 + }, + "718": { + "summary": "", + "redundancy": 2 + }, + "865": { + "summary": "", + "redundancy": 2 + }, + "911": { + "summary": "", + "redundancy": 3 + }, + "981": { + "summary": "", + "redundancy": 3 + }, + "932": { + "summary": "", + "redundancy": 2 + }, + "716": { + "summary": "", + "redundancy": 2 + }, + "980": { + "summary": "", + "redundancy": 3 + }, + "948": { + "summary": "", + "redundancy": 2 + }, + "929": { + "summary": "", + "redundancy": 1 + }, + "840": { + "summary": "", + "redundancy": 2 + }, + "907": { + "summary": "", + "redundancy": 2 + }, + "844": { + "summary": "", + "redundancy": 3 + }, + "714": { + "summary": "", + "redundancy": 2 + }, + "974": { + "summary": "", + "redundancy": 2 + }, + "917": { + "summary": "", + "redundancy": 3 + }, + "770": { + "summary": "", + "redundancy": 1 + }, + "860": { + "summary": "", + "redundancy": 3 + }, + "951": { + "summary": "", + "redundancy": 3 + }, + "939": { + "summary": "", + "redundancy": 2 + }, + "934": { + "summary": "", + "redundancy": 3 + }, + "51": { + "summary": "", + "redundancy": null + }, + "708": { + "summary": "", + "redundancy": 2 + }, + "881": { + "summary": "", + "redundancy": 2 + }, + "977": { + "summary": "", + "redundancy": 3 + }, + "6476": { + "summary": "", + "redundancy": 2 + }, + "801": { + "summary": "", + "redundancy": 3 + }, + "767": { + "summary": "", + "redundancy": 1 + }, + "914": { + "summary": "", + "redundancy": 2 + }, + "995": { + "summary": "", + "redundancy": 1 + } +} \ No newline at end of file diff --git a/priv/elevators/elevator_redundancy_data.json b/priv/elevators/elevator_redundancy_data.json deleted file mode 100644 index 3620f441e..000000000 --- a/priv/elevators/elevator_redundancy_data.json +++ /dev/null @@ -1,635 +0,0 @@ -{ - "918": { - "nearby_redundancy?": false - }, - "925": { - "nearby_redundancy?": false - }, - "804": { - "nearby_redundancy?": false - }, - "958": { - "nearby_redundancy?": false - }, - "780": { - "nearby_redundancy?": false - }, - "986": { - "nearby_redundancy?": false - }, - "921": { - "nearby_redundancy?": false - }, - "725": { - "nearby_redundancy?": false - }, - "816": { - "nearby_redundancy?": false - }, - "866": { - "nearby_redundancy?": false - }, - "996": { - "nearby_redundancy?": true - }, - "744": { - "nearby_redundancy?": false - }, - "710": { - "nearby_redundancy?": false - }, - "842": { - "nearby_redundancy?": false - }, - "899": { - "nearby_redundancy?": false - }, - "856": { - "nearby_redundancy?": false - }, - "879": { - "nearby_redundancy?": false - }, - "901": { - "nearby_redundancy?": false - }, - "922": { - "nearby_redundancy?": false - }, - "945": { - "nearby_redundancy?": false - }, - "701": { - "nearby_redundancy?": true - }, - "771": { - "nearby_redundancy?": false - }, - "734": { - "nearby_redundancy?": false - }, - "979": { - "nearby_redundancy?": false - }, - "936": { - "nearby_redundancy?": false - }, - "957": { - "nearby_redundancy?": false - }, - "998": { - "nearby_redundancy?": true - }, - "971": { - "nearby_redundancy?": false - }, - "913": { - "nearby_redundancy?": false - }, - "855": { - "nearby_redundancy?": false - }, - "731": { - "nearby_redundancy?": false - }, - "892": { - "nearby_redundancy?": false - }, - "854": { - "nearby_redundancy?": false - }, - "815": { - "nearby_redundancy?": true - }, - "712": { - "nearby_redundancy?": false - }, - "938": { - "nearby_redundancy?": false - }, - "896": { - "nearby_redundancy?": false - }, - "886": { - "nearby_redundancy?": false - }, - "994": { - "nearby_redundancy?": true - }, - "713": { - "nearby_redundancy?": false - }, - "933": { - "nearby_redundancy?": false - }, - "897": { - "nearby_redundancy?": false - }, - "769": { - "nearby_redundancy?": false - }, - "869": { - "nearby_redundancy?": false - }, - "908": { - "nearby_redundancy?": false - }, - "910": { - "nearby_redundancy?": false - }, - "813": { - "nearby_redundancy?": false - }, - "891": { - "nearby_redundancy?": false - }, - "947": { - "nearby_redundancy?": false - }, - "724": { - "nearby_redundancy?": false - }, - "711": { - "nearby_redundancy?": false - }, - "782": { - "nearby_redundancy?": false - }, - "972": { - "nearby_redundancy?": false - }, - "803": { - "nearby_redundancy?": false - }, - "978": { - "nearby_redundancy?": false - }, - "992": { - "nearby_redundancy?": false - }, - "859": { - "nearby_redundancy?": false - }, - "702": { - "nearby_redundancy?": true - }, - "757": { - "nearby_redundancy?": true - }, - "965": { - "nearby_redundancy?": false - }, - "722": { - "nearby_redundancy?": true - }, - "898": { - "nearby_redundancy?": false - }, - "717": { - "nearby_redundancy?": false - }, - "915": { - "nearby_redundancy?": false - }, - "807": { - "nearby_redundancy?": true - }, - "852": { - "nearby_redundancy?": false - }, - "858": { - "nearby_redundancy?": false - }, - "944": { - "nearby_redundancy?": false - }, - "850": { - "nearby_redundancy?": false - }, - "967": { - "nearby_redundancy?": true - }, - "768": { - "nearby_redundancy?": true - }, - "909": { - "nearby_redundancy?": false - }, - "970": { - "nearby_redundancy?": false - }, - "868": { - "nearby_redundancy?": false - }, - "52": { - "nearby_redundancy?": false - }, - "920": { - "nearby_redundancy?": false - }, - "949": { - "nearby_redundancy?": false - }, - "746": { - "nearby_redundancy?": true - }, - "805": { - "nearby_redundancy?": true - }, - "930": { - "nearby_redundancy?": true - }, - "719": { - "nearby_redundancy?": false - }, - "937": { - "nearby_redundancy?": false - }, - "966": { - "nearby_redundancy?": false - }, - "946": { - "nearby_redundancy?": false - }, - "814": { - "nearby_redundancy?": true - }, - "709": { - "nearby_redundancy?": false - }, - "721": { - "nearby_redundancy?": true - }, - "762": { - "nearby_redundancy?": true - }, - "846": { - "nearby_redundancy?": false - }, - "802": { - "nearby_redundancy?": true - }, - "880": { - "nearby_redundancy?": false - }, - "781": { - "nearby_redundancy?": false - }, - "876": { - "nearby_redundancy?": false - }, - "715": { - "nearby_redundancy?": false - }, - "864": { - "nearby_redundancy?": false - }, - "969": { - "nearby_redundancy?": false - }, - "890": { - "nearby_redundancy?": false - }, - "927": { - "nearby_redundancy?": false - }, - "889": { - "nearby_redundancy?": false - }, - "973": { - "nearby_redundancy?": false - }, - "904": { - "nearby_redundancy?": false - }, - "870": { - "nearby_redundancy?": false - }, - "975": { - "nearby_redundancy?": false - }, - "964": { - "nearby_redundancy?": false - }, - "982": { - "nearby_redundancy?": true - }, - "847": { - "nearby_redundancy?": false - }, - "923": { - "nearby_redundancy?": false - }, - "857": { - "nearby_redundancy?": false - }, - "808": { - "nearby_redundancy?": false - }, - "732": { - "nearby_redundancy?": false - }, - "851": { - "nearby_redundancy?": false - }, - "905": { - "nearby_redundancy?": false - }, - "806": { - "nearby_redundancy?": true - }, - "849": { - "nearby_redundancy?": false - }, - "885": { - "nearby_redundancy?": false - }, - "912": { - "nearby_redundancy?": false - }, - "845": { - "nearby_redundancy?": false - }, - "811": { - "nearby_redundancy?": false - }, - "900": { - "nearby_redundancy?": false - }, - "763": { - "nearby_redundancy?": true - }, - "735": { - "nearby_redundancy?": false - }, - "823": { - "nearby_redundancy?": false - }, - "841": { - "nearby_redundancy?": false - }, - "999": { - "nearby_redundancy?": true - }, - "906": { - "nearby_redundancy?": false - }, - "954": { - "nearby_redundancy?": false - }, - "953": { - "nearby_redundancy?": false - }, - "772": { - "nearby_redundancy?": true - }, - "861": { - "nearby_redundancy?": false - }, - "952": { - "nearby_redundancy?": false - }, - "843": { - "nearby_redundancy?": false - }, - "962": { - "nearby_redundancy?": false - }, - "884": { - "nearby_redundancy?": false - }, - "831": { - "nearby_redundancy?": false - }, - "723": { - "nearby_redundancy?": true - }, - "50": { - "nearby_redundancy?": false - }, - "935": { - "nearby_redundancy?": false - }, - "728": { - "nearby_redundancy?": false - }, - "745": { - "nearby_redundancy?": false - }, - "765": { - "nearby_redundancy?": false - }, - "919": { - "nearby_redundancy?": false - }, - "963": { - "nearby_redundancy?": false - }, - "991": { - "nearby_redundancy?": false - }, - "985": { - "nearby_redundancy?": false - }, - "53": { - "nearby_redundancy?": false - }, - "736": { - "nearby_redundancy?": true - }, - "867": { - "nearby_redundancy?": false - }, - "756": { - "nearby_redundancy?": true - }, - "903": { - "nearby_redundancy?": false - }, - "940": { - "nearby_redundancy?": false - }, - "800": { - "nearby_redundancy?": false - }, - "726": { - "nearby_redundancy?": false - }, - "764": { - "nearby_redundancy?": false - }, - "703": { - "nearby_redundancy?": true - }, - "887": { - "nearby_redundancy?": false - }, - "872": { - "nearby_redundancy?": false - }, - "733": { - "nearby_redundancy?": false - }, - "830": { - "nearby_redundancy?": false - }, - "817": { - "nearby_redundancy?": false - }, - "853": { - "nearby_redundancy?": false - }, - "955": { - "nearby_redundancy?": false - }, - "968": { - "nearby_redundancy?": false - }, - "821": { - "nearby_redundancy?": false - }, - "928": { - "nearby_redundancy?": false - }, - "931": { - "nearby_redundancy?": false - }, - "766": { - "nearby_redundancy?": false - }, - "961": { - "nearby_redundancy?": false - }, - "993": { - "nearby_redundancy?": false - }, - "997": { - "nearby_redundancy?": true - }, - "812": { - "nearby_redundancy?": false - }, - "990": { - "nearby_redundancy?": false - }, - "926": { - "nearby_redundancy?": false - }, - "956": { - "nearby_redundancy?": false - }, - "976": { - "nearby_redundancy?": false - }, - "727": { - "nearby_redundancy?": false - }, - "848": { - "nearby_redundancy?": false - }, - "983": { - "nearby_redundancy?": true - }, - "743": { - "nearby_redundancy?": true - }, - "810": { - "nearby_redundancy?": false - }, - "924": { - "nearby_redundancy?": false - }, - "987": { - "nearby_redundancy?": true - }, - "720": { - "nearby_redundancy?": true - }, - "718": { - "nearby_redundancy?": false - }, - "865": { - "nearby_redundancy?": false - }, - "911": { - "nearby_redundancy?": false - }, - "981": { - "nearby_redundancy?": false - }, - "932": { - "nearby_redundancy?": false - }, - "716": { - "nearby_redundancy?": false - }, - "980": { - "nearby_redundancy?": false - }, - "948": { - "nearby_redundancy?": false - }, - "929": { - "nearby_redundancy?": true - }, - "840": { - "nearby_redundancy?": false - }, - "907": { - "nearby_redundancy?": false - }, - "844": { - "nearby_redundancy?": false - }, - "714": { - "nearby_redundancy?": false - }, - "974": { - "nearby_redundancy?": false - }, - "917": { - "nearby_redundancy?": false - }, - "770": { - "nearby_redundancy?": true - }, - "860": { - "nearby_redundancy?": false - }, - "951": { - "nearby_redundancy?": false - }, - "939": { - "nearby_redundancy?": false - }, - "934": { - "nearby_redundancy?": false - }, - "51": { - "nearby_redundancy?": false - }, - "708": { - "nearby_redundancy?": false - }, - "881": { - "nearby_redundancy?": false - }, - "977": { - "nearby_redundancy?": false - }, - "6476": { - "nearby_redundancy?": false - }, - "801": { - "nearby_redundancy?": false - }, - "767": { - "nearby_redundancy?": true - }, - "914": { - "nearby_redundancy?": false - }, - "995": { - "nearby_redundancy?": true - } -} diff --git a/scripts/format_elevator_data.exs b/scripts/format_elevator_data.exs index d963af9e3..2934215ce 100644 --- a/scripts/format_elevator_data.exs +++ b/scripts/format_elevator_data.exs @@ -21,13 +21,24 @@ formatted_data = {:ok, %{"elevator_id" => ""}} -> nil - {:ok, %{"elevator_id" => id, "Exiting System Categorization" => category}} -> - {id, %{nearby_redundancy?: category == "1 - Nearby"}} + {:ok, + %{ + "elevator_id" => id, + "Exiting System Categorization" => category, + "Short Text" => summary + }} -> + redundancy = + case category do + "1" <> _ -> 1 + "2" <> _ -> 2 + "3" <> _ -> 3 + "4" <> _ -> 4 + _ -> nil + end + + {id, %{redundancy: redundancy, summary: summary}} end) |> Enum.reject(&is_nil/1) |> Map.new() -File.write( - "priv/elevators/elevator_redundancy_data.json", - Jason.encode!(formatted_data, pretty: true) -) +File.write("priv/elevators.json", Jason.encode!(formatted_data, pretty: true)) diff --git a/test/fixtures/elevator_redundancy_data.json b/test/fixtures/elevator_redundancy_data.json deleted file mode 100644 index 469d07afb..000000000 --- a/test/fixtures/elevator_redundancy_data.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "112": { - "nearby_redundancy?": true - }, - "222": { - "nearby_redundancy?": true - }, - "333": { - "nearby_redundancy?": false - } -} diff --git a/test/screens/elevator_test.exs b/test/screens/elevator_test.exs new file mode 100644 index 000000000..c9ec7e927 --- /dev/null +++ b/test/screens/elevator_test.exs @@ -0,0 +1,27 @@ +defmodule Screens.ElevatorTest do + use ExUnit.Case, async: true + + alias Screens.Elevator + + import ExUnit.CaptureLog + + describe "get/1" do + test "gets elevators in each redundancy category" do + assert Elevator.get("996") == %Elevator{id: "996", redundancy: :nearby} + assert Elevator.get("918") == %Elevator{id: "918", redundancy: :in_station} + # TODO: summary text for categories 3 and 4 does not exist yet + assert Elevator.get("958") == %Elevator{id: "958", redundancy: {:different_station, ""}} + assert Elevator.get("896") == %Elevator{id: "896", redundancy: {:contact, ""}} + end + + test "returns nil and logs a warning when redundancy data does not exist" do + logs = + capture_log(fn -> + assert Elevator.get("780") == nil + assert Elevator.get("nonexistent") == nil + end) + + assert logs =~ "[warning] elevator_redundancy_not_found" + end + end +end diff --git a/test/screens/v2/candidate_generator/elevator/closures_test.exs b/test/screens/v2/candidate_generator/elevator/closures_test.exs index a12401dcf..c593a745a 100644 --- a/test/screens/v2/candidate_generator/elevator/closures_test.exs +++ b/test/screens/v2/candidate_generator/elevator/closures_test.exs @@ -3,6 +3,7 @@ defmodule Screens.V2.CandidateGenerator.Elevator.ClosuresTest do alias Screens.V2.WidgetInstance.Elevator.Closure alias Screens.Alerts.Alert + alias Screens.Elevator alias Screens.Routes.Route alias Screens.Stops.Stop alias Screens.V2.CandidateGenerator.Elevator.Closures, as: ElevatorClosures @@ -15,20 +16,26 @@ defmodule Screens.V2.CandidateGenerator.Elevator.ClosuresTest do } alias ScreensConfig.Screen - alias ScreensConfig.V2.Elevator + alias ScreensConfig.V2.Elevator, as: ElevatorConfig import Screens.Inject import Mox setup :verify_on_exit! @alert injected(Alert) + @elevator injected(Elevator) @facility injected(Screens.Facilities.Facility) @route injected(Route) @stop injected(Stop) + setup do + stub(@elevator, :get, fn id -> %Elevator{id: id, redundancy: :in_station} end) + :ok + end + describe "elevator_status_instances/3" do setup do - config = %Elevator{ + config = %ElevatorConfig{ elevator_id: "111", accessible_path_direction_arrow: :n, alternate_direction_text: "Test" @@ -81,33 +88,33 @@ defmodule Screens.V2.CandidateGenerator.Elevator.ClosuresTest do {:ok, alerts} end) - [ - ^header_instance, - %ElevatorClosuresList{ - app_params: ^config, - stations_with_closures: [ - %ElevatorClosuresList.Station{ - id: "place-test", - name: "Place Test", - route_icons: [%{type: :text, text: "RL", color: :red}], - closures: [ - %Closure{ - id: "1", - elevator_name: "Test", - elevator_id: "facility-test" - } - ] - } - ], - station_id: "place-test" - }, - ^footer_instance - ] = - ElevatorClosures.elevator_status_instances( - struct(Screen, app_id: :elevator_v2, app_params: config), - header_instance, - footer_instance - ) + assert [ + ^header_instance, + %ElevatorClosuresList{ + app_params: ^config, + stations_with_closures: [ + %ElevatorClosuresList.Station{ + id: "place-test", + name: "Place Test", + route_icons: [%{type: :text, text: "RL", color: :red}], + closures: [ + %Closure{ + id: "1", + elevator_name: "Test", + elevator_id: "facility-test" + } + ] + } + ], + station_id: "place-test" + }, + ^footer_instance + ] = + ElevatorClosures.elevator_status_instances( + struct(Screen, app_id: :elevator_v2, app_params: config), + header_instance, + footer_instance + ) end test "Groups outside closures by station", %{ @@ -150,41 +157,41 @@ defmodule Screens.V2.CandidateGenerator.Elevator.ClosuresTest do {:ok, alerts} end) - [ - ^header_instance, - %ElevatorClosuresList{ - app_params: ^config, - stations_with_closures: [ - %{ - id: "place-haecl", - name: "Haymarket", - route_icons: [%{type: :text, text: "OL", color: :orange}], - closures: [ - %{ - id: "1", - description: nil, - elevator_name: "Test 1", - elevator_id: "facility-test-1", - header_text: nil - }, - %{ - id: "2", - description: nil, - elevator_name: "Test 2", - elevator_id: "facility-test-2", - header_text: nil - } - ] - } - ] - }, - ^footer_instance - ] = - ElevatorClosures.elevator_status_instances( - struct(Screen, app_id: :elevator_v2, app_params: config), - header_instance, - footer_instance - ) + assert [ + ^header_instance, + %ElevatorClosuresList{ + app_params: ^config, + stations_with_closures: [ + %{ + id: "place-haecl", + name: "Haymarket", + route_icons: [%{type: :text, text: "OL", color: :orange}], + closures: [ + %{ + id: "1", + description: nil, + elevator_name: "Test 1", + elevator_id: "facility-test-1", + header_text: nil + }, + %{ + id: "2", + description: nil, + elevator_name: "Test 2", + elevator_id: "facility-test-2", + header_text: nil + } + ] + } + ] + }, + ^footer_instance + ] = + ElevatorClosures.elevator_status_instances( + struct(Screen, app_id: :elevator_v2, app_params: config), + header_instance, + footer_instance + ) end test "Filters alerts with no facilities or more than one facility", %{ @@ -222,19 +229,19 @@ defmodule Screens.V2.CandidateGenerator.Elevator.ClosuresTest do {:ok, alerts} end) - [ - ^header_instance, - %ElevatorClosuresList{ - app_params: ^config, - stations_with_closures: [] - }, - ^footer_instance - ] = - ElevatorClosures.elevator_status_instances( - struct(Screen, app_id: :elevator_v2, app_params: config), - header_instance, - footer_instance - ) + assert [ + ^header_instance, + %ElevatorClosuresList{ + app_params: ^config, + stations_with_closures: [] + }, + ^footer_instance + ] = + ElevatorClosures.elevator_status_instances( + struct(Screen, app_id: :elevator_v2, app_params: config), + header_instance, + footer_instance + ) end test "Filters out alerts at other stations with nearby redundancy", %{ @@ -253,7 +260,13 @@ defmodule Screens.V2.CandidateGenerator.Elevator.ClosuresTest do }} end) - expect(@route, :fetch, 2, fn _ -> {:ok, [%Route{id: "Red", type: :subway}]} end) + stub(@route, :fetch, fn _ -> {:ok, [%Route{id: "Red", type: :subway}]} end) + + stub(@elevator, :get, fn + "112" -> %Elevator{id: "112", redundancy: :nearby} + "222" -> %Elevator{id: "222", redundancy: :nearby} + "333" -> %Elevator{id: "333", redundancy: :in_station} + end) expect(@alert, :fetch_elevator_alerts_with_facilities, fn -> alerts = [ @@ -289,54 +302,54 @@ defmodule Screens.V2.CandidateGenerator.Elevator.ClosuresTest do {:ok, alerts} end) - [ - ^header_instance, - %ElevatorClosuresList{ - app_params: %ScreensConfig.V2.Elevator{ - elevator_id: "111", - alternate_direction_text: "Test", - accessible_path_direction_arrow: :n, - evergreen_content: [], - accessible_path_image_url: nil, - accessible_path_image_here_coordinates: %{y: 0, x: 0} - }, - stations_with_closures: [ - %ElevatorClosuresList.Station{ - id: "place-test", - name: "This Station", - route_icons: [%{type: :text, text: "RL", color: :red}], - closures: [ - %Closure{ - id: "1", - elevator_name: "In Station Elevator", - elevator_id: "112" - } - ] - }, - %ElevatorClosuresList.Station{ - id: "place-test-no-redundancy", - name: "Other No Redundancy", - route_icons: [%{type: :text, text: "RL", color: :red}], - closures: [ - %Closure{ - id: "3", - elevator_name: "Other Without Redundancy", - elevator_id: "333", - description: nil, - header_text: nil - } - ] - } - ], - station_id: "place-test" - }, - ^footer_instance - ] = - ElevatorClosures.elevator_status_instances( - struct(Screen, app_id: :elevator_v2, app_params: config), - header_instance, - footer_instance - ) + assert [ + ^header_instance, + %ElevatorClosuresList{ + app_params: %ScreensConfig.V2.Elevator{ + elevator_id: "111", + alternate_direction_text: "Test", + accessible_path_direction_arrow: :n, + evergreen_content: [], + accessible_path_image_url: nil, + accessible_path_image_here_coordinates: %{y: 0, x: 0} + }, + stations_with_closures: [ + %ElevatorClosuresList.Station{ + id: "place-test", + name: "This Station", + route_icons: [%{type: :text, text: "RL", color: :red}], + closures: [ + %Closure{ + id: "1", + elevator_name: "In Station Elevator", + elevator_id: "112" + } + ] + }, + %ElevatorClosuresList.Station{ + id: "place-test-no-redundancy", + name: "Other No Redundancy", + route_icons: [%{type: :text, text: "RL", color: :red}], + closures: [ + %Closure{ + id: "3", + elevator_name: "Other Without Redundancy", + elevator_id: "333", + description: nil, + header_text: nil + } + ] + } + ], + station_id: "place-test" + }, + ^footer_instance + ] = + ElevatorClosures.elevator_status_instances( + struct(Screen, app_id: :elevator_v2, app_params: config), + header_instance, + footer_instance + ) end test "Returns CurrentElevatorClosed if configured elevator is closed", %{ @@ -377,25 +390,25 @@ defmodule Screens.V2.CandidateGenerator.Elevator.ClosuresTest do closed_header_instance = %{header_instance | variant: :closed} closed_footer_instance = %{footer_instance | variant: :closed} - [ - ^closed_header_instance, - %CurrentElevatorClosed{ - app_params: ^config, - closure: %Closure{ - id: "1", - elevator_name: "Test", - elevator_id: "111", - description: nil, - header_text: nil - } - }, - ^closed_footer_instance - ] = - ElevatorClosures.elevator_status_instances( - struct(Screen, app_id: :elevator_v2, app_params: config), - header_instance, - footer_instance - ) + assert [ + ^closed_header_instance, + %CurrentElevatorClosed{ + app_params: ^config, + closure: %Closure{ + id: "1", + elevator_name: "Test", + elevator_id: "111", + description: nil, + header_text: nil + } + }, + ^closed_footer_instance + ] = + ElevatorClosures.elevator_status_instances( + struct(Screen, app_id: :elevator_v2, app_params: config), + header_instance, + footer_instance + ) end test "Return empty routes on API error", %{ @@ -427,32 +440,32 @@ defmodule Screens.V2.CandidateGenerator.Elevator.ClosuresTest do {:ok, alerts} end) - [ - ^header_instance, - %ElevatorClosuresList{ - app_params: ^config, - stations_with_closures: [ - %ElevatorClosuresList.Station{ - id: "place-test", - name: "Place Test", - closures: [ - %Closure{ - id: "1", - elevator_name: "Test", - elevator_id: "facility-test" - } - ] - } - ], - station_id: "place-test" - }, - ^footer_instance - ] = - ElevatorClosures.elevator_status_instances( - struct(Screen, app_id: :elevator_v2, app_params: config), - header_instance, - footer_instance - ) + assert [ + ^header_instance, + %ElevatorClosuresList{ + app_params: ^config, + stations_with_closures: [ + %ElevatorClosuresList.Station{ + id: "place-test", + name: "Place Test", + closures: [ + %Closure{ + id: "1", + elevator_name: "Test", + elevator_id: "facility-test" + } + ] + } + ], + station_id: "place-test" + }, + ^footer_instance + ] = + ElevatorClosures.elevator_status_instances( + struct(Screen, app_id: :elevator_v2, app_params: config), + header_instance, + footer_instance + ) end end end diff --git a/test/support/mocks.ex b/test/support/mocks.ex index 1f39a3458..9cc2d99c3 100644 --- a/test/support/mocks.ex +++ b/test/support/mocks.ex @@ -1,6 +1,7 @@ injected_modules = [ Screens.Alerts.Alert, Screens.Config.Cache, + Screens.Elevator, Screens.Facilities.Facility, Screens.Headways, Screens.RoutePatterns.RoutePattern,