Skip to content

Commit

Permalink
Added comments that call out some Mercury specific logic. (#2175)
Browse files Browse the repository at this point in the history
  • Loading branch information
cmaddox5 authored Aug 30, 2024
1 parent ee539a3 commit c7d9904
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/screens/v2/screen_data.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ defmodule Screens.V2.ScreenData do
data: serializable_map() | nil,
force_reload: boolean(),
disabled: boolean(),
# Mercury uses this to help optimize data refreshes
# https://app.asana.com/0/1185117109217413/1205234924224431/f
last_deploy_timestamp: DateTime.t()
}
@type paging_metadata :: %{
Expand Down
2 changes: 2 additions & 0 deletions lib/screens/v2/widget_instance/departures.ex
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,8 @@ defmodule Screens.V2.WidgetInstance.Departures do
serialize_timestamp(departure_time, now)
end

# time_in_epoch is used by Mercury so they can calculate timestamps on their own.
# https://app.asana.com/0/1176097567827729/1205730972991228/f
%{time: time, time_in_epoch: DateTime.to_unix(departure_time)}
end

Expand Down
2 changes: 2 additions & 0 deletions lib/screens/v2/widget_instance/line_map.ex
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ defmodule Screens.V2.WidgetInstance.LineMap do
if index < 0 do
[]
else
# time_in_epoch is used by Mercury so they can calculate times on their own.
# https://app.asana.com/0/1176097567827729/1205730972991228/f
departure_time_epoch = d |> Departure.time() |> DateTime.to_unix()
[%{id: vehicle_id, index: index, label: label, time_in_epoch: departure_time_epoch}]
end
Expand Down
2 changes: 2 additions & 0 deletions lib/screens/v2/widget_instance/normal_header.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ defmodule Screens.V2.WidgetInstance.NormalHeader do
time: DateTime.t()
}

# Mercury adds their own time so we omit the time in the response.
# https://app.asana.com/0/1185117109217413/1206070378353406/f
def serialize(
%__MODULE__{
screen: %Screen{vendor: :mercury, app_id: :gl_eink_v2},
Expand Down
2 changes: 2 additions & 0 deletions lib/screens_web/controllers/v2/screen_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ defmodule ScreensWeb.V2.ScreenController do

# Handles widget page GET requests with widget data as a query param.
# Phoenix does not automatically decode JSON received in query params.
# Primarily used by Mercury so not all requests need to run through the framework.
# https://app.asana.com/0/1185117109217413/1205234924224431/f
def widget(conn, %{"app_id" => app_id, "widget" => json_data}) when is_binary(json_data) do
case Jason.decode(json_data) do
{:ok, widget_data} ->
Expand Down

0 comments on commit c7d9904

Please sign in to comment.