diff --git a/lib/microwaveprop_web/live/pskr_spots_live.ex b/lib/microwaveprop_web/live/pskr_spots_live.ex index 44657901..3b5bb9e9 100644 --- a/lib/microwaveprop_web/live/pskr_spots_live.ex +++ b/lib/microwaveprop_web/live/pskr_spots_live.ex @@ -18,7 +18,9 @@ defmodule MicrowavepropWeb.PskrSpotsLive do assign(socket, page_title: "PSK Reporter Spots", limit: @limit, - spots: spots + spots: spots, + total_spots: fetch_total_spots(), + band_counts: fetch_band_counts() )} end @@ -29,6 +31,20 @@ defmodule MicrowavepropWeb.PskrSpotsLive do |> Repo.all() end + defp fetch_total_spots do + Repo.one(from(s in SpotHourly, select: coalesce(sum(s.spot_count), 0))) + end + + defp fetch_band_counts do + Repo.all( + from(s in SpotHourly, + group_by: s.band, + select: {s.band, sum(s.spot_count)}, + order_by: [desc: sum(s.spot_count)] + ) + ) + end + defp fmt_dt(nil), do: "—" defp fmt_dt(dt), do: Calendar.strftime(dt, "%Y-%m-%d %H:%M UTC") @@ -47,6 +63,16 @@ defmodule MicrowavepropWeb.PskrSpotsLive do <:subtitle>Last {@limit} spot aggregates from the MQTT firehose +
+ + Total spots stored: {Format.number(@total_spots)} + + + {band} + {Format.number(count)} + +
+
diff --git a/test/microwaveprop_web/live/pskr_spots_live_test.exs b/test/microwaveprop_web/live/pskr_spots_live_test.exs index 0dc66368..71458166 100644 --- a/test/microwaveprop_web/live/pskr_spots_live_test.exs +++ b/test/microwaveprop_web/live/pskr_spots_live_test.exs @@ -69,17 +69,27 @@ defmodule MicrowavepropWeb.PskrSpotsLiveTest do {:ok, _lv, html} = live(conn, ~p"/pskreporter") assert html =~ "No PSK Reporter spots received yet" end + + test "shows total spots count of zero when empty", %{conn: conn} do + {:ok, _lv, html} = live(conn, ~p"/pskreporter") + assert html =~ "Total spots stored:" + assert html =~ "0" + end end describe "with spots in the database" do - test "displays spot grid and count data in table", %{conn: conn} do - insert_spot(%{sender_grid: "EM12KL", receiver_grid: "DM43ST", spot_count: 42}) + test "displays total spots count and per-band counts", %{conn: conn} do + insert_spot(%{band: "2m", spot_count: 42}) + insert_spot(%{band: "70cm", spot_count: 7}) {:ok, _lv, html} = live(conn, ~p"/pskreporter") - assert html =~ "EM12KL" - assert html =~ "DM43ST" - assert html =~ "42" + assert html =~ "Total spots stored:" + # 42 + 7 = 49 total + assert html =~ "49" + # Band badges show per-band counts + assert html =~ "2m" + assert html =~ "70cm" end test "displays band as badge", %{conn: conn} do