Fetch elevation data along the path between two stations via the Open-Meteo Elevation API (with Open-Topo-Data fallback), compute Fresnel zone clearance, earth bulge, and knife-edge diffraction loss, and store the results per QSO. - terrain_profiles table with migration and TerrainProfile schema - ElevationClient with batched API calls and fallback - TerrainAnalysis with Fresnel/diffraction physics (ITU-R P.526-15) - TerrainProfileWorker on Oban :terrain queue - QsoWeatherEnqueueWorker enqueues terrain jobs automatically - QSO show page displays verdict badge and collapsible elevation table - Reorder show page: terrain, soundings, solar, HRRR, surface obs - Fix Dockerfile wgrib2 build (add cmake dependency)
96 lines
2.5 KiB
Elixir
96 lines
2.5 KiB
Elixir
defmodule Microwaveprop.TerrainTest do
|
|
use Microwaveprop.DataCase, async: true
|
|
|
|
alias Microwaveprop.Radio.Qso
|
|
alias Microwaveprop.Terrain
|
|
|
|
@qso_attrs %{
|
|
station1: "W5XD",
|
|
station2: "K5TR",
|
|
qso_timestamp: ~U[2026-03-28 18:00:00Z],
|
|
mode: "CW",
|
|
band: Decimal.new("1296"),
|
|
pos1: %{"lat" => 32.9, "lon" => -97.0},
|
|
pos2: %{"lat" => 30.3, "lon" => -97.7}
|
|
}
|
|
|
|
defp create_qso do
|
|
{:ok, qso} =
|
|
%Qso{}
|
|
|> Qso.changeset(@qso_attrs)
|
|
|> Repo.insert()
|
|
|
|
qso
|
|
end
|
|
|
|
defp terrain_attrs(qso) do
|
|
%{
|
|
qso_id: qso.id,
|
|
sample_count: 65,
|
|
path_points: [
|
|
%{"lat" => 32.9, "lon" => -97.0, "elev" => 200.0, "dist_km" => 0.0},
|
|
%{"lat" => 30.3, "lon" => -97.7, "elev" => 180.0, "dist_km" => 295.0}
|
|
],
|
|
verdict: "CLEAR",
|
|
max_elevation_m: 450.0,
|
|
min_clearance_m: 120.0,
|
|
diffraction_db: 0.0,
|
|
fresnel_hit_count: 0,
|
|
obstructed_count: 0
|
|
}
|
|
end
|
|
|
|
describe "upsert_terrain_profile/1" do
|
|
test "inserts a new terrain profile" do
|
|
qso = create_qso()
|
|
attrs = terrain_attrs(qso)
|
|
|
|
assert {:ok, profile} = Terrain.upsert_terrain_profile(attrs)
|
|
assert profile.qso_id == qso.id
|
|
assert profile.sample_count == 65
|
|
assert profile.verdict == "CLEAR"
|
|
end
|
|
|
|
test "upserts on conflict (same qso_id)" do
|
|
qso = create_qso()
|
|
attrs = terrain_attrs(qso)
|
|
|
|
{:ok, _} = Terrain.upsert_terrain_profile(attrs)
|
|
|
|
updated_attrs = Map.merge(attrs, %{verdict: "BLOCKED", diffraction_db: 6.5})
|
|
{:ok, profile} = Terrain.upsert_terrain_profile(updated_attrs)
|
|
|
|
assert profile.verdict == "BLOCKED"
|
|
assert profile.diffraction_db == 6.5
|
|
end
|
|
end
|
|
|
|
describe "get_terrain_profile/1" do
|
|
test "returns profile for a QSO" do
|
|
qso = create_qso()
|
|
{:ok, _} = Terrain.upsert_terrain_profile(terrain_attrs(qso))
|
|
|
|
profile = Terrain.get_terrain_profile(qso.id)
|
|
assert profile.qso_id == qso.id
|
|
end
|
|
|
|
test "returns nil when no profile exists" do
|
|
qso = create_qso()
|
|
assert Terrain.get_terrain_profile(qso.id) == nil
|
|
end
|
|
end
|
|
|
|
describe "has_terrain_profile?/1" do
|
|
test "returns true when profile exists" do
|
|
qso = create_qso()
|
|
{:ok, _} = Terrain.upsert_terrain_profile(terrain_attrs(qso))
|
|
|
|
assert Terrain.has_terrain_profile?(qso.id)
|
|
end
|
|
|
|
test "returns false when no profile exists" do
|
|
qso = create_qso()
|
|
refute Terrain.has_terrain_profile?(qso.id)
|
|
end
|
|
end
|
|
end
|