defmodule MicrowavepropWeb.PskrSpotsLive do @moduledoc "`/pskreporter` — recent PSK Reporter spot aggregates." use MicrowavepropWeb, :live_view import Ecto.Query alias Microwaveprop.Format alias Microwaveprop.Pskr.SpotHourly alias Microwaveprop.Repo @limit 100 @impl true def mount(_params, _session, socket) do spots = fetch_recent_spots() {:ok, assign(socket, page_title: "PSK Reporter Spots", spots: spots )} end defp fetch_recent_spots do SpotHourly |> order_by(desc: :last_spot_at) |> limit(@limit) |> Repo.all() end defp fmt_dt(nil), do: "—" defp fmt_dt(dt), do: Calendar.strftime(dt, "%Y-%m-%d %H:%M UTC") defp fmt_snr(min, max) when min == max, do: "#{min} dB" defp fmt_snr(min, max), do: "#{min}–#{max} dB" @impl true def render(assigns) do ~H""" <.header> PSK Reporter Spots <:subtitle>Last {@limit} spot aggregates from the MQTT firehose
<%= for spot <- @spots do %> <% end %>
Last Heard (UTC) Band From Grid To Grid Distance Spots SNR Modes
{fmt_dt(spot.last_spot_at)} {spot.band} {spot.sender_grid} {spot.receiver_grid} {Format.distance_km(spot.distance_km)} {Format.number(spot.spot_count)} {fmt_snr(spot.min_snr_db, spot.max_snr_db)} {mode}

No PSK Reporter spots received yet. The MQTT listener is running — spots will appear here as they arrive.

""" end end