feat: add total spot count and per-band breakdown to /pskreporter header
This commit is contained in:
parent
51dda456aa
commit
3297147c31
2 changed files with 42 additions and 6 deletions
|
|
@ -18,7 +18,9 @@ defmodule MicrowavepropWeb.PskrSpotsLive do
|
||||||
assign(socket,
|
assign(socket,
|
||||||
page_title: "PSK Reporter Spots",
|
page_title: "PSK Reporter Spots",
|
||||||
limit: @limit,
|
limit: @limit,
|
||||||
spots: spots
|
spots: spots,
|
||||||
|
total_spots: fetch_total_spots(),
|
||||||
|
band_counts: fetch_band_counts()
|
||||||
)}
|
)}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -29,6 +31,20 @@ defmodule MicrowavepropWeb.PskrSpotsLive do
|
||||||
|> Repo.all()
|
|> Repo.all()
|
||||||
end
|
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(nil), do: "—"
|
||||||
defp fmt_dt(dt), do: Calendar.strftime(dt, "%Y-%m-%d %H:%M UTC")
|
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</:subtitle>
|
<:subtitle>Last {@limit} spot aggregates from the MQTT firehose</:subtitle>
|
||||||
</.header>
|
</.header>
|
||||||
|
|
||||||
|
<div class="flex flex-wrap items-baseline gap-x-6 gap-y-1 text-sm mb-4">
|
||||||
|
<span class="font-semibold">
|
||||||
|
Total spots stored: <span class="font-mono">{Format.number(@total_spots)}</span>
|
||||||
|
</span>
|
||||||
|
<span :for={{band, count} <- @band_counts} class="text-base-content/70">
|
||||||
|
<span class="badge badge-sm mr-1">{band}</span>
|
||||||
|
<span class="font-mono">{Format.number(count)}</span>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="overflow-x-auto">
|
<div class="overflow-x-auto">
|
||||||
<table class="table table-sm table-zebra whitespace-nowrap">
|
<table class="table table-sm table-zebra whitespace-nowrap">
|
||||||
<thead>
|
<thead>
|
||||||
|
|
|
||||||
|
|
@ -69,17 +69,27 @@ defmodule MicrowavepropWeb.PskrSpotsLiveTest do
|
||||||
{:ok, _lv, html} = live(conn, ~p"/pskreporter")
|
{:ok, _lv, html} = live(conn, ~p"/pskreporter")
|
||||||
assert html =~ "No PSK Reporter spots received yet"
|
assert html =~ "No PSK Reporter spots received yet"
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
describe "with spots in the database" do
|
describe "with spots in the database" do
|
||||||
test "displays spot grid and count data in table", %{conn: conn} do
|
test "displays total spots count and per-band counts", %{conn: conn} do
|
||||||
insert_spot(%{sender_grid: "EM12KL", receiver_grid: "DM43ST", spot_count: 42})
|
insert_spot(%{band: "2m", spot_count: 42})
|
||||||
|
insert_spot(%{band: "70cm", spot_count: 7})
|
||||||
|
|
||||||
{:ok, _lv, html} = live(conn, ~p"/pskreporter")
|
{:ok, _lv, html} = live(conn, ~p"/pskreporter")
|
||||||
|
|
||||||
assert html =~ "EM12KL"
|
assert html =~ "Total spots stored:"
|
||||||
assert html =~ "DM43ST"
|
# 42 + 7 = 49 total
|
||||||
assert html =~ "42"
|
assert html =~ "49"
|
||||||
|
# Band badges show per-band counts
|
||||||
|
assert html =~ "2m"
|
||||||
|
assert html =~ "70cm"
|
||||||
end
|
end
|
||||||
|
|
||||||
test "displays band as badge", %{conn: conn} do
|
test "displays band as badge", %{conn: conn} do
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue