From 3f5b4cd60b7dc640362b659fef14e0c3b6733b61 Mon Sep 17 00:00:00 2001 From: Graham McInitre Date: Mon, 20 Jul 2026 13:54:32 -0500 Subject: [PATCH] fix: accept 4-char Maidenhead grids in PSK Reporter spots MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously required ≥6-char locators; 4-char fields (~70×100 km) were dropped. They're less precise for HRRR calibration but still useful for spot display and coarse path analysis. Lowers the minimum from 6 to 4 characters. Co-Authored-By: Claude --- lib/microwaveprop/pskr.ex | 12 +++++------- test/microwaveprop/pskr_test.exs | 16 +++++++--------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/lib/microwaveprop/pskr.ex b/lib/microwaveprop/pskr.ex index 8852df23..9596f2f4 100644 --- a/lib/microwaveprop/pskr.ex +++ b/lib/microwaveprop/pskr.ex @@ -169,14 +169,12 @@ defmodule Microwaveprop.Pskr do } end - # Require ≥ 6-char locators on both ends. 4-char grids cover - # ~70 km × 100 km, so the midpoint and path distance error - # dwarfs any HRRR cell match (3 km native) and the resulting - # calibration sample geometry is meaningless. Drop the spot - # entirely rather than store a low-precision row. + # Require ≥ 4-char locators on both ends. 4-char grids cover + # ~70 km × 100 km — less precise for HRRR calibration but still + # useful for spot display and coarse path analysis. # # Maidenhead validity enforces even length + correct alphabet - # per position, so a passing string is a legal 6/8/10-char + # per position, so a passing string is a legal 4/6/8/10-char # locator we can store as-is. Uppercase for consistent indexing # — the unique key is case-sensitive. defp fetch_grid(json, key) do @@ -186,7 +184,7 @@ defmodule Microwaveprop.Pskr do cond do not Maidenhead.valid?(upper) -> {:error, {:bad_grid, key, grid}} - String.length(upper) < 6 -> {:error, {:short_grid, key, grid}} + String.length(upper) < 4 -> {:error, {:short_grid, key, grid}} true -> {:ok, upper} end diff --git a/test/microwaveprop/pskr_test.exs b/test/microwaveprop/pskr_test.exs index df06803b..7d3cdbca 100644 --- a/test/microwaveprop/pskr_test.exs +++ b/test/microwaveprop/pskr_test.exs @@ -38,16 +38,14 @@ defmodule Microwaveprop.PskrTest do assert DateTime.to_unix(spot.transmit_time) == 1_662_407_697 end - test "rejects 4-char grids on either end (insufficient precision)" do - # A 4-char locator is ~70 km × 100 km — the midpoint and - # distance error swamps any HRRR cell match (3 km native). - # Drop the spot rather than store a calibration sample whose - # geometry is meaningless. - sender_short = @sample |> Map.put("sl", "EM12") |> Jason.encode!() - receiver_short = @sample |> Map.put("rl", "DM43") |> Jason.encode!() + test "accepts 4-char grids on both ends" do + sender_4 = @sample |> Map.put("sl", "EM12") |> Jason.encode!() + receiver_4 = @sample |> Map.put("rl", "DM43") |> Jason.encode!() - assert {:error, _} = Pskr.parse_spot(sender_short) - assert {:error, _} = Pskr.parse_spot(receiver_short) + assert {:ok, spot} = Pskr.parse_spot(sender_4) + assert spot.sender_grid == "EM12" + assert {:ok, spot} = Pskr.parse_spot(receiver_4) + assert spot.receiver_grid == "DM43" end test "preserves extended-square (8-char) precision" do