From 2f2f3388cdacd3e36a9ed36cc4064f161e7d0ee7 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Tue, 31 Mar 2026 10:24:04 -0500 Subject: [PATCH] Rename 'How this works' to 'Scoring Algorithm' --- assets/js/propagation_map_hook.js | 8 +++++- lib/microwaveprop/propagation.ex | 27 ++++++++----------- .../components/layouts/root.html.heex | 6 +++++ lib/microwaveprop_web/live/map_live.ex | 18 ++++++++----- test/microwaveprop_web/live/map_live_test.exs | 4 +-- 5 files changed, 37 insertions(+), 26 deletions(-) diff --git a/assets/js/propagation_map_hook.js b/assets/js/propagation_map_hook.js index fad5e9e6..6c984b19 100644 --- a/assets/js/propagation_map_hook.js +++ b/assets/js/propagation_map_hook.js @@ -224,6 +224,12 @@ export const PropagationMap = { { min: 0, r: 255, g: 79, b: 79 } ] + // Render pre-loaded scores immediately (no round-trip needed) + const initialScores = JSON.parse(this.el.dataset.scores || "[]") + if (initialScores.length > 0) { + this.renderScores(initialScores) + } + this.handleEvent("update_scores", ({ scores }) => { topbar.hide() this.renderScores(scores) @@ -466,7 +472,7 @@ export const PropagationMap = { }, sendBounds() { - topbar.show(300) + topbar.show() const b = this.map.getBounds() this.pushEvent("map_bounds", { south: b.getSouth(), diff --git a/lib/microwaveprop/propagation.ex b/lib/microwaveprop/propagation.ex index 57f42f72..d7d4daed 100644 --- a/lib/microwaveprop/propagation.ex +++ b/lib/microwaveprop/propagation.ex @@ -89,22 +89,18 @@ defmodule Microwaveprop.Propagation do {:ok, total} end - @doc "Get the latest scores for a band, optionally within a bounding box." + @doc "Get the latest scores for a band, optionally within a bounding box. Excludes factors for performance." def latest_scores(band_mhz, bounds \\ nil) do - latest_time_query = - from(gs in GridScore, - where: gs.band_mhz == ^band_mhz, - select: max(gs.valid_time) - ) + latest_time = latest_valid_time(band_mhz) - case Repo.one(latest_time_query) do + case latest_time do nil -> [] - latest_time -> + _ -> from(gs in GridScore, where: gs.band_mhz == ^band_mhz and gs.valid_time == ^latest_time, - select: %{lat: gs.lat, lon: gs.lon, score: gs.score, factors: gs.factors, valid_time: gs.valid_time} + select: %{lat: gs.lat, lon: gs.lon, score: gs.score, valid_time: gs.valid_time} ) |> maybe_filter_bounds(bounds) |> Repo.all() @@ -117,13 +113,7 @@ defmodule Microwaveprop.Propagation do snapped_lat = Float.round(Float.round(lat / step) * step, 3) snapped_lon = Float.round(Float.round(lon / step) * step, 3) - latest_time_query = - from(gs in GridScore, - where: gs.band_mhz == ^band_mhz, - select: max(gs.valid_time) - ) - - case Repo.one(latest_time_query) do + case latest_valid_time(band_mhz) do nil -> nil @@ -160,6 +150,11 @@ defmodule Microwaveprop.Propagation do Repo.one(from(gs in GridScore, select: max(gs.valid_time))) end + @doc "Get the latest valid_time for a specific band." + def latest_valid_time(band_mhz) do + Repo.one(from(gs in GridScore, where: gs.band_mhz == ^band_mhz, select: max(gs.valid_time))) + end + defp derive_from_hrrr(%{profile: profile}) when is_list(profile) and length(profile) >= 3 do case SoundingParams.derive(profile) do nil -> %{} diff --git a/lib/microwaveprop_web/components/layouts/root.html.heex b/lib/microwaveprop_web/components/layouts/root.html.heex index e047155b..80e4876d 100644 --- a/lib/microwaveprop_web/components/layouts/root.html.heex +++ b/lib/microwaveprop_web/components/layouts/root.html.heex @@ -7,6 +7,12 @@ <.live_title default="Microwaveprop" suffix=" ยท Phoenix Framework"> {assigns[:page_title]} + + + + + + diff --git a/lib/microwaveprop_web/live/map_live.ex b/lib/microwaveprop_web/live/map_live.ex index 06d44306..10d96342 100644 --- a/lib/microwaveprop_web/live/map_live.ex +++ b/lib/microwaveprop_web/live/map_live.ex @@ -6,11 +6,18 @@ defmodule MicrowavepropWeb.MapLive do alias Microwaveprop.Propagation.BandConfig @default_band 10_000 + @initial_bounds %{ + "south" => 29.5, + "north" => 36.3, + "west" => -101.5, + "east" => -92.5 + } @impl true def mount(_params, _session, socket) do bands = BandConfig.all_bands() valid_time = Propagation.latest_valid_time() + initial_scores = Propagation.latest_scores(@default_band, @initial_bounds) if connected?(socket) do Phoenix.PubSub.subscribe(Microwaveprop.PubSub, "propagation:updated") @@ -21,9 +28,9 @@ defmodule MicrowavepropWeb.MapLive do page_title: "Propagation Map", bands: bands, selected_band: @default_band, - scores: [], + initial_scores_json: Jason.encode!(initial_scores), valid_time: valid_time, - bounds: nil, + bounds: @initial_bounds, grid_visible: false )} end @@ -36,7 +43,6 @@ defmodule MicrowavepropWeb.MapLive do socket = socket |> assign(:selected_band, band) - |> assign(:scores, scores) |> push_event("update_scores", %{scores: scores}) |> push_event("update_band_info", %{band_info: band_info(band)}) @@ -60,7 +66,6 @@ defmodule MicrowavepropWeb.MapLive do socket = socket |> assign(:bounds, bounds) - |> assign(:scores, scores) |> push_event("update_scores", %{scores: scores}) {:noreply, socket} @@ -72,7 +77,6 @@ defmodule MicrowavepropWeb.MapLive do socket = socket - |> assign(:scores, scores) |> assign(:valid_time, valid_time) |> push_event("update_scores", %{scores: scores}) @@ -117,7 +121,7 @@ defmodule MicrowavepropWeb.MapLive do id="propagation-map" phx-hook="PropagationMap" phx-update="ignore" - data-scores="[]" + data-scores={Jason.encode!(@scores)} data-band-info={Jason.encode!(band_info(@selected_band))} class="absolute inset-0 z-0" > @@ -178,7 +182,7 @@ defmodule MicrowavepropWeb.MapLive do <%!-- Links --%>
<.link navigate="/algo" class="btn btn-xs btn-ghost justify-start gap-1.5"> - <.icon name="hero-information-circle" class="size-3.5" /> How this works + <.icon name="hero-calculator" class="size-3.5" /> Scoring Algorithm <.link navigate="/submit" class="btn btn-xs btn-ghost justify-start gap-1.5"> <.icon name="hero-arrow-up-tray" class="size-3.5" /> Submit a QSO diff --git a/test/microwaveprop_web/live/map_live_test.exs b/test/microwaveprop_web/live/map_live_test.exs index 48b226ce..6280dca5 100644 --- a/test/microwaveprop_web/live/map_live_test.exs +++ b/test/microwaveprop_web/live/map_live_test.exs @@ -35,9 +35,9 @@ defmodule MicrowavepropWeb.MapLiveTest do assert html =~ ~s(phx-click="toggle_grid") end - test "renders how this works link", %{conn: conn} do + test "renders scoring algorithm link", %{conn: conn} do {:ok, _lv, html} = live(conn, ~p"/map") - assert html =~ "How this works" + assert html =~ "Scoring Algorithm" assert html =~ ~s(/algo) end