Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions assets/src/components/admin/inspector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ const APP_IDS = new Set(Object.keys(SCREEN_APPS));
const MAX_SSML_BILLED_CHARS = 3000;
const MAX_SSML_TOTAL_CHARS = 6000;

const anyVariantsExist = Object.values(SCREEN_APPS).some(
({ variants }) => variants.length > 0,
);

const buildIframeUrl = (
screen: ScreenWithId | null,
isSimulation: boolean,
Expand Down Expand Up @@ -235,14 +239,16 @@ const ScreenSelector: ComponentType<{
Screenplay simulation
</label>

<label>
<input
type="checkbox"
checked={isVariantEnabled}
onChange={() => setIsVariantEnabled(!isVariantEnabled)}
/>
Enable variant switcher
</label>
{anyVariantsExist && (
<label>
<input
type="checkbox"
checked={isVariantEnabled}
onChange={() => setIsVariantEnabled(!isVariantEnabled)}
/>
Enable variant switcher
</label>
)}

<button onClick={reloadFrame}>🔄 Reload Screen</button>
</fieldset>
Expand Down
2 changes: 1 addition & 1 deletion assets/src/util/admin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const SCREEN_APPS: { [key in AppId]: AppInfo } = {
bus_eink_v2: { name: "Bus E-ink", hasAudio: true, variants: [] },
bus_shelter_v2: { name: "Bus Shelter", hasAudio: true, variants: [] },
busway_v2: { name: "Sectional", hasAudio: true, variants: [] },
dup_v2: { name: "DUP", hasAudio: false, variants: ["new_departures"] },
dup_v2: { name: "DUP", hasAudio: false, variants: [] },
gl_eink_v2: { name: "GL E-ink", hasAudio: true, variants: [] },
pre_fare_v2: { name: "Pre-Fare", hasAudio: true, variants: [] },
};
Expand Down
11 changes: 1 addition & 10 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -471,16 +471,7 @@ config :screens,
"Needham Heights" => "Needham Hts",
"Houghs Neck via McGrath & Germantown" => "Houghs Neck via McGth & Gtwn",
"Houghs Neck via Germantown" => "Houghs Neck via Germntwn"
},
dup_headway_branch_stations: ["place-kencl", "place-jfk", "place-coecl"],
dup_headway_branch_terminals: [
"Boston College",
"Cleveland Circle",
"Riverside",
"Heath Street",
"Ashmont",
"Braintree"
]
}

config :screens, :screens_by_alert,
cache_module: Screens.ScreensByAlert.GenServer,
Expand Down
16 changes: 0 additions & 16 deletions lib/screens/alerts/alert.ex
Original file line number Diff line number Diff line change
Expand Up @@ -172,22 +172,6 @@ defmodule Screens.Alerts.Alert do
end
end

@doc """
Convenience for cases when it's safe to treat an API alert data outage
as if there simply aren't any alerts for the given parameters.

If the query fails for any reason, an empty list is returned.

Currently used for DUPs
"""
@spec fetch_or_empty_list(keyword()) :: list(t())
def fetch_or_empty_list(opts \\ []) do
case fetch(opts) do
{:ok, alerts} -> alerts
:error -> []
end
end

@doc """
Used by V2 e-ink and bus shelter alerts

Expand Down
123 changes: 0 additions & 123 deletions lib/screens/headways.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ defmodule Screens.Headways do
when no live departures are available ("Trains every X-Y minutes").
"""

alias Screens.Routes.Route
alias Screens.SignsUiConfig.Cache, as: SignsUi
alias Screens.Stops.Stop
alias Screens.Util
Expand Down Expand Up @@ -38,98 +37,6 @@ defmodule Screens.Headways do
silver_chelsea: [7096..7097, 74_611..74_617, 74_630..74_637]
}

# Mapping of parent station IDs and route IDs to headway keys. For brevity, omits the "place-"
# prefix which is currently common to all parent station IDs.
@stations %{
blue_trunk: {
~w[Blue],
~w[wondl rbmnl bmmnl sdmnl orhte wimnl aport mvbcl aqucl state gover bomnl]
},
glx_medford: {~w[Green-E], ~w[mdftf balsq mgngl gilmn esomr]},
glx_union: {~w[Green-D], ~w[unsqu]},
green_b: {
~w[Green-B],
~w[
bland
buest
bucen
amory
babck
brico
harvd
grigg
alsgr
wrnst
wascm
sthld
chswk
chill
sougr
lake
]
},
green_c: {
~w[Green-C],
~w[smary hwsst kntst stpul cool sumav bndhl fbkst bcnwa tapst denrd engav clmnl]
},
green_d: {
~w[Green-D],
~w[fenwy longw bvmnl brkhl bcnfd rsmnl chhil newto newtn eliot waban woodl river]
},
green_e: {
~w[Green-E],
~w[prmnl symcl nuniv mfa lngmd brmnl fenwd mispk rvrwy bckhl hsmnl]
},
# Not all of these stations are served by all Green Line branches, but "trunk" is the most
# granular division of the Green Line we have to work with
green_trunk: {
~w[Green-B Green-C Green-D Green-E],
~w[lech spmnl north haecl gover pktrm boyls armnl coecl hymnl kencl]
},
orange_trunk: {
~w[Orange],
~w[
ogmnl
mlmnl
welln
astao
sull
ccmnl
north
haecl
state
dwnxg
chncl
tumnl
bbsta
masta
rugg
rcmnl
jaksn
sbmnl
grnst
forhl
]
},
red_trunk: {
~w[Red],
~w[alfcl davis portr harsq cntsq knncl chmnl pktrm dwnxg sstat brdwy andrw jfk]
},
red_ashmont: {~w[Red], ~w[shmnl fldcr smmnl asmnl]},
red_braintree: {~w[Red], ~w[nqncy wlsta qnctr qamnl brntn]},
# combining 743 with the other three for the common stops
silver_seaport: {~w[741 742 743 746], ~w[conrd wtcst crtst sstat]},
silver_chelsea: {~w[743], ~w[aport estav boxdt belsq chels]}
}

# Mapping of stops and route IDs to headway keys for the Silver Line,
# for stops which serve more than one route.
@sl_stops %{
# congress_st_at_wtc 17_096
# combining 743 with the other three for the common stops
silver_seaport: {~w[741 742 743 746], ~w[17096]}
}

@type range :: {low :: pos_integer(), high :: pos_integer()}

@doc """
Expand All @@ -145,42 +52,12 @@ defmodule Screens.Headways do
end
end

@doc """
Gets headway values for a stop, with a route provided to disambiguate when the stop is a parent
station served by multiple routes.

⚠️ Included for compatibility with existing DUP departures logic. Prefer `get/2`.
"""
@callback get_with_route(Stop.id(), Route.id()) :: range() | nil
@callback get_with_route(Stop.id(), Route.id(), DateTime.t()) :: range() | nil
def get_with_route(stop_id, route_id, at \\ DateTime.utc_now()) do
case headway_key(stop_id, route_id) do
nil -> nil
key -> key |> SignsUi.headways() |> Map.get(period(at))
end
end

@spec headway_key(Stop.id()) :: SignsUi.headway_key() | nil
@spec headway_key(Stop.id(), Route.id()) :: SignsUi.headway_key() | nil
for {key, ranges} <- @stops, range <- ranges, stop_id <- range do
defp headway_key(unquote(to_string(stop_id))), do: unquote(to_string(key))
defp headway_key(unquote(to_string(stop_id)), _route_id), do: unquote(to_string(key))
end

for {key, {route_ids, stations}} <- @stations,
route_id <- route_ids,
station <- stations do
defp headway_key("place-" <> unquote(station), unquote(route_id)), do: unquote(to_string(key))
end

for {key, {route_ids, stations}} <- @sl_stops,
route_id <- route_ids,
station <- stations do
defp headway_key(unquote(station), unquote(route_id)), do: unquote(to_string(key))
end

defp headway_key(_stop_id), do: nil
defp headway_key(_stop_id, _route_id), do: nil

@spec period(DateTime.t()) :: :peak | :off_peak | :saturday | :sunday
defp period(datetime) do
Expand Down
4 changes: 4 additions & 0 deletions lib/screens/predictions/prediction.ex
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ defmodule Screens.Predictions.Prediction do
def stop_for_vehicle(%__MODULE__{vehicle: %Vehicle{stop_id: stop_id}}), do: stop_id
def stop_for_vehicle(_), do: nil

@spec time(t()) :: DateTime.t() | nil
def time(%__MODULE__{arrival_time: arrival, departure_time: departure}),
do: arrival || departure

def vehicle_status(%__MODULE__{vehicle: %Vehicle{current_status: current_status}}),
do: current_status

Expand Down
8 changes: 8 additions & 0 deletions lib/screens/schedules/schedule.ex
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,13 @@ defmodule Screens.Schedules.Schedule do
end
end

@spec headsign(t()) :: String.t()
def headsign(%__MODULE__{stop_headsign: headsign}) when not is_nil(headsign), do: headsign
def headsign(%__MODULE__{trip: %Trip{headsign: headsign}}), do: headsign

@spec time(t()) :: DateTime.t() | nil
def time(%__MODULE__{arrival_time: arrival, departure_time: departure}),
do: arrival || departure

defp current_service_date(now \\ DateTime.utc_now()), do: Util.service_date(now)
end
34 changes: 12 additions & 22 deletions lib/screens/v2/candidate_generator/dup.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@ defmodule Screens.V2.CandidateGenerator.Dup do
@moduledoc false

alias Screens.V2.CandidateGenerator
alias Screens.V2.CandidateGenerator.Dup.Alerts, as: AlertsInstances
alias Screens.V2.CandidateGenerator.Dup.Departures, as: DeparturesInstances
alias Screens.V2.CandidateGenerator.Dup.Alerts, as: AlertsGenerator
alias Screens.V2.CandidateGenerator.Dup.Departures, as: DeparturesGenerator
alias Screens.V2.CandidateGenerator.Widgets
alias Screens.V2.Template.Builder

@behaviour CandidateGenerator

@instance_generators [
&AlertsGenerator.alert_instances/2,
&DeparturesGenerator.instances/2,
&Widgets.EmergencyTakeover.emergency_takeover_instances/2,
&Widgets.Evergreen.evergreen_content_instances/2,
&Widgets.Header.instances/2
]

@impl CandidateGenerator
def screen_template(_screen) do
{:screen,
Expand Down Expand Up @@ -69,26 +77,8 @@ defmodule Screens.V2.CandidateGenerator.Dup do
end

@impl CandidateGenerator
def candidate_instances(
config,
now \\ DateTime.utc_now(),
header_instances_fn \\ &Widgets.Header.instances/2,
evergreen_content_instances_fn \\ &Widgets.Evergreen.evergreen_content_instances/2,
departures_instances_fn \\ &DeparturesInstances.departures_instances/2,
alerts_instances_fn \\ &AlertsInstances.alert_instances/2,
emergency_takeover_instances_fn \\ &Widgets.EmergencyTakeover.emergency_takeover_instances/2
) do
CandidateGenerator.async_stream(
[
fn -> header_instances_fn.(config, now) end,
fn -> alerts_instances_fn.(config, now) end,
fn -> departures_instances_fn.(config, now) end,
fn -> evergreen_content_instances_fn.(config, now) end,
fn -> emergency_takeover_instances_fn.(config, now) end
],
& &1.(),
timeout: 20_000
)
def candidate_instances(config, now \\ DateTime.utc_now()) do
CandidateGenerator.async_stream(@instance_generators, & &1.(config, now), timeout: 20_000)
end

@impl CandidateGenerator
Expand Down
Loading
Loading