Skip to content
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

remove old logging for stopped messages #681

Merged
merged 1 commit into from
Aug 31, 2023
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
69 changes: 0 additions & 69 deletions lib/signs/utilities/updater.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ defmodule Signs.Utilities.Updater do
bottom_changed? = not Messages.same_content?(sign.current_content_bottom, bottom_msg)
new_bottom = if bottom_changed?, do: bottom_msg, else: sign.current_content_bottom

if top_changed?, do: log_line_update(sign, new_top, "top")
if bottom_changed?, do: log_line_update(sign, new_bottom, "bottom")

if !sign.last_update ||
Timex.after?(current_time, Timex.shift(sign.last_update, seconds: 130)) ||
top_changed? ||
Expand All @@ -40,70 +37,4 @@ defmodule Signs.Utilities.Updater do
sign
end
end

defp log_line_update(sign, msg, "top" = line) do
case {sign, msg} do
{%Signs.Realtime{id: sign_id, current_content_top: %Content.Message.Predictions{}},
%Content.Message.StoppedTrain{stops_away: msg_stops_away}}
when msg_stops_away > 0 ->
Logger.info("sign_id=#{sign_id} line=#{line} status=on")

{%Signs.Realtime{
id: sign_id,
current_content_top: %Content.Message.StoppedTrain{stops_away: sign_stops_away}
}, %Content.Message.StoppedTrain{stops_away: msg_stops_away}}
when sign_stops_away == 0 and msg_stops_away > 0 ->
Logger.info("sign_id=#{sign_id} line=#{line} status=on")

{%Signs.Realtime{
id: sign_id,
current_content_top: %Content.Message.StoppedTrain{stops_away: sign_stops_away}
}, %Content.Message.Predictions{}}
when sign_stops_away > 0 ->
Logger.info("sign_id=#{sign_id} line=#{line} status=off")

{%Signs.Realtime{
id: sign_id,
current_content_top: %Content.Message.StoppedTrain{stops_away: sign_stops_away}
}, %Content.Message.StoppedTrain{stops_away: msg_stops_away}}
when sign_stops_away > 0 and msg_stops_away == 0 ->
Logger.info("sign_id=#{sign_id} line=#{line} status=off")

_ ->
:ok
end
end

defp log_line_update(sign, msg, "bottom" = line) do
case {sign, msg} do
{%Signs.Realtime{id: sign_id, current_content_bottom: %Content.Message.Predictions{}},
%Content.Message.StoppedTrain{stops_away: msg_stops_away}}
when msg_stops_away > 0 ->
Logger.info("sign_id=#{sign_id} line=#{line} status=on")

{%Signs.Realtime{
id: sign_id,
current_content_bottom: %Content.Message.StoppedTrain{stops_away: sign_stops_away}
}, %Content.Message.StoppedTrain{stops_away: msg_stops_away}}
when sign_stops_away == 0 and msg_stops_away > 0 ->
Logger.info("sign_id=#{sign_id} line=#{line} status=on")

{%Signs.Realtime{
id: sign_id,
current_content_bottom: %Content.Message.StoppedTrain{stops_away: sign_stops_away}
}, %Content.Message.Predictions{}}
when sign_stops_away > 0 ->
Logger.info("sign_id=#{sign_id} line=#{line} status=off")

{%Signs.Realtime{
id: sign_id,
current_content_bottom: %Content.Message.StoppedTrain{stops_away: sign_stops_away}
}, %Content.Message.StoppedTrain{stops_away: msg_stops_away}}
when sign_stops_away > 0 and msg_stops_away == 0 ->
Logger.info("sign_id=#{sign_id} line=#{line} status=off")

_ ->
:ok
end
end
end
98 changes: 0 additions & 98 deletions test/signs/utilities/updater_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -84,103 +84,5 @@ defmodule Signs.Utilities.UpdaterTest do
Updater.update_sign(sign, diff_top, diff_bottom, Timex.now())
refute_received({:send_audio, _, _, _, _, _})
end

test "logs when stopped train message turns on" do
diff_top = %Content.Message.StoppedTrain{destination: :alewife, stops_away: 2}
same_bottom = @sign.current_content_bottom

initial_tick_read = 10
read_period_seconds = 100

sign = %{@sign | tick_read: initial_tick_read, read_period_seconds: read_period_seconds}

log =
capture_log([level: :info], fn ->
Updater.update_sign(sign, diff_top, same_bottom, Timex.now())
end)

assert log =~ "sign_id=sign_id line=top status=on"
end

test "logs when stopped train message turns off" do
new_top = %P{destination: :alewife, minutes: 4}
new_bottom = %P{destination: :alewife, minutes: 4}

initial_tick_read = 10
read_period_seconds = 100

sign = %{
@sign
| current_content_top: %Content.Message.StoppedTrain{destination: :alewife, stops_away: 2},
current_content_bottom: %Content.Message.StoppedTrain{
destination: :alewife,
stops_away: 2
},
tick_read: initial_tick_read,
read_period_seconds: read_period_seconds
}

log =
capture_log([level: :info], fn ->
Updater.update_sign(sign, new_top, new_bottom, Timex.now())
end)

assert log =~ "sign_id=sign_id line=top status=off"
assert log =~ "sign_id=sign_id line=bottom status=off"
end

test "logs when stopped train message changes from zero to non-zero stops away" do
diff_top = %Content.Message.StoppedTrain{destination: :alewife, stops_away: 2}
same_bottom = %Content.Message.StoppedTrain{destination: :ashmont, stops_away: 2}

initial_tick_read = 10
read_period_seconds = 100

sign = %{
@sign
| current_content_top: %Content.Message.StoppedTrain{destination: :alewife, stops_away: 0},
current_content_bottom: %Content.Message.StoppedTrain{
destination: :ashmont,
stops_away: 0
},
tick_read: initial_tick_read,
read_period_seconds: read_period_seconds
}

log =
capture_log([level: :info], fn ->
Updater.update_sign(sign, diff_top, same_bottom, Timex.now())
end)

assert log =~ "sign_id=sign_id line=top status=on"
assert log =~ "sign_id=sign_id line=bottom status=on"
end

test "logs when stopped train message changes from non-zero to zero stops away" do
diff_top = %Content.Message.StoppedTrain{destination: :alewife, stops_away: 0}
same_bottom = %Content.Message.StoppedTrain{destination: :ashmont, stops_away: 0}

initial_tick_read = 10
read_period_seconds = 100

sign = %{
@sign
| current_content_top: %Content.Message.StoppedTrain{destination: :alewife, stops_away: 2},
current_content_bottom: %Content.Message.StoppedTrain{
destination: :ashmont,
stops_away: 2
},
tick_read: initial_tick_read,
read_period_seconds: read_period_seconds
}

log =
capture_log([level: :info], fn ->
Updater.update_sign(sign, diff_top, same_bottom, Timex.now())
end)

assert log =~ "sign_id=sign_id line=top status=off"
assert log =~ "sign_id=sign_id line=bottom status=off"
end
end
end
Loading