-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
unify no service audio code paths #844
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
defmodule Content.Audio.NoService do | ||
@enforce_keys [:destination, :route, :use_shuttle?] | ||
defstruct @enforce_keys ++ [use_routes?: false] | ||
|
||
@type t :: %__MODULE__{ | ||
destination: PaEss.destination(), | ||
route: String.t() | nil, | ||
use_shuttle?: boolean(), | ||
use_routes?: boolean() | ||
} | ||
|
||
@spec from_messages(Content.Message.t(), Content.Message.t()) :: [t()] | ||
def from_messages( | ||
%Content.Message.Alert.NoService{route: route, destination: destination}, | ||
%Content.Message.Alert.UseShuttleBus{} | ||
) do | ||
[%__MODULE__{route: route, destination: destination, use_shuttle?: true}] | ||
end | ||
|
||
def from_messages( | ||
%Content.Message.Alert.NoService{route: route, destination: destination}, | ||
%Content.Message.Empty{} | ||
) do | ||
[%__MODULE__{route: route, destination: destination, use_shuttle?: false}] | ||
end | ||
|
||
def from_messages( | ||
%Content.Message.Alert.NoService{route: route, destination: destination}, | ||
%Content.Message.Alert.UseRoutes{} | ||
) do | ||
[%__MODULE__{route: route, destination: destination, use_shuttle?: false, use_routes?: true}] | ||
end | ||
|
||
def from_messages( | ||
%Content.Message.Alert.DestinationNoService{route: route, destination: destination}, | ||
nil | ||
) do | ||
[%__MODULE__{route: route, destination: destination, use_shuttle?: false}] | ||
end | ||
|
||
def from_messages( | ||
%Content.Message.Alert.NoServiceUseShuttle{route: route, destination: destination}, | ||
nil | ||
) do | ||
[%__MODULE__{route: route, destination: destination, use_shuttle?: true}] | ||
end | ||
|
||
defimpl Content.Audio do | ||
@there_is_no "861" | ||
@service_at_this_station "863" | ||
|
||
def to_params(%Content.Audio.NoService{use_routes?: true} = audio) do | ||
{:ad_hoc, {tts_text(audio), :audio}} | ||
end | ||
|
||
def to_params(%Content.Audio.NoService{ | ||
destination: nil, | ||
route: route, | ||
use_shuttle?: use_shuttle? | ||
}) do | ||
line_var = PaEss.Utilities.line_to_var(route) | ||
|
||
if use_shuttle? do | ||
{:canned, {"199", [line_var], :audio}} | ||
else | ||
PaEss.Utilities.take_message([@there_is_no, line_var, @service_at_this_station], :audio) | ||
end | ||
end | ||
|
||
def to_params(%Content.Audio.NoService{} = audio) do | ||
{:ad_hoc, {tts_text(audio), :audio}} | ||
end | ||
|
||
def to_tts(%Content.Audio.NoService{} = audio) do | ||
{tts_text(audio), nil} | ||
end | ||
|
||
def to_logs(%Content.Audio.NoService{}) do | ||
[] | ||
end | ||
|
||
defp tts_text(%Content.Audio.NoService{ | ||
route: route, | ||
destination: destination, | ||
use_shuttle?: use_shuttle?, | ||
use_routes?: use_routes? | ||
}) do | ||
shuttle = if(use_shuttle?, do: " Use shuttle.", else: "") | ||
|
||
cond do | ||
use_routes? -> | ||
# Hardcoded for Union Square | ||
"No Train Service. Use routes 86, 87, or 91" | ||
|
||
destination -> | ||
{:ok, destination_text} = PaEss.Utilities.destination_to_ad_hoc_string(destination) | ||
"No #{destination_text} service.#{shuttle}" | ||
|
||
true -> | ||
line = if(route, do: "#{route} Line", else: "train") | ||
"There is no #{line} service at this station.#{shuttle}" | ||
end | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this clause not come first in the
cond
block? Based on the definition forfrom_messages/2
above for this special case, it looks likedestination
could still be truthyThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently it doesn't matter, because we always generate a destination-less
Message.Alert.NoService
for this case. I've got a followup PR that changes that code path and this logic, but I went ahead and swapped it anyway.