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
# 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

View file

@ -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