fix: accept 4-char Maidenhead grids in PSK Reporter spots

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 <noreply@anthropic.com>
This commit is contained in:
Graham McInitre 2026-07-20 13:54:32 -05:00
parent ba17a41683
commit 3f5b4cd60b
2 changed files with 12 additions and 16 deletions

View file

@ -169,14 +169,12 @@ defmodule Microwaveprop.Pskr do
} }
end end
# Require ≥ 6-char locators on both ends. 4-char grids cover # Require ≥ 4-char locators on both ends. 4-char grids cover
# ~70 km × 100 km, so the midpoint and path distance error # ~70 km × 100 km — less precise for HRRR calibration but still
# dwarfs any HRRR cell match (3 km native) and the resulting # useful for spot display and coarse path analysis.
# calibration sample geometry is meaningless. Drop the spot
# entirely rather than store a low-precision row.
# #
# Maidenhead validity enforces even length + correct alphabet # 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 # locator we can store as-is. Uppercase for consistent indexing
# — the unique key is case-sensitive. # — the unique key is case-sensitive.
defp fetch_grid(json, key) do defp fetch_grid(json, key) do
@ -186,7 +184,7 @@ defmodule Microwaveprop.Pskr do
cond do cond do
not Maidenhead.valid?(upper) -> {:error, {:bad_grid, key, grid}} 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} true -> {:ok, upper}
end end

View file

@ -38,16 +38,14 @@ defmodule Microwaveprop.PskrTest do
assert DateTime.to_unix(spot.transmit_time) == 1_662_407_697 assert DateTime.to_unix(spot.transmit_time) == 1_662_407_697
end end
test "rejects 4-char grids on either end (insufficient precision)" do test "accepts 4-char grids on both ends" do
# A 4-char locator is ~70 km × 100 km — the midpoint and sender_4 = @sample |> Map.put("sl", "EM12") |> Jason.encode!()
# distance error swamps any HRRR cell match (3 km native). receiver_4 = @sample |> Map.put("rl", "DM43") |> Jason.encode!()
# 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!()
assert {:error, _} = Pskr.parse_spot(sender_short) assert {:ok, spot} = Pskr.parse_spot(sender_4)
assert {:error, _} = Pskr.parse_spot(receiver_short) assert spot.sender_grid == "EM12"
assert {:ok, spot} = Pskr.parse_spot(receiver_4)
assert spot.receiver_grid == "DM43"
end end
test "preserves extended-square (8-char) precision" do test "preserves extended-square (8-char) precision" do