Classifies every contact's likely non-LOS propagation mechanism and persists the result on contacts.propagation_mechanism. Mechanism is determined in priority order: 1. user_declared_prop_mode (ADIF PROP_MODE from the operator log) 2. EME — moon-ephemeris check, ≥2m band, >1800 km path 3. aurora — Kp≥5 + high-lat path, 50-432 MHz 4. sporadic-E — foEs × 5 ≥ band_mhz, 400-2500 km path 5. meteor_scatter — ±3 days of a shower peak, VHF/UHF 6. rain_scatter — common-volume radar heavy rain, 5-11 GHz ≤800 km 7. tropo_duct — HRRR native_best_duct ≥ band or ducting_detected 8. line_of_sight — ≤50 km path 9. troposcatter — default Persisted via MechanismClassifyWorker (queue: :mechanism, unique on contact_id). Submit-time enqueue path includes :mechanism by default; BackfillEnqueueWorker cron now handles :mechanism alongside existing types so prod continuously backfills any contact with propagation_mechanism_status in (:pending, :queued, :failed). Also added :radar to the cron's type list so common-volume radar backfill runs automatically rather than only via `mix radar_backfill`. New modules: - Microwaveprop.Propagation.MoonEphemeris — Meeus low-precision moon position, accuracy ±1° — enough for the mutual-visibility EME test - Microwaveprop.Propagation.MechanismClassifier — plug-in priority chain over the evidence map - Microwaveprop.Workers.MechanismClassifyWorker — assembles inputs from HRRR / native profiles / common-volume radar / solar_indices / ionosonde + calls the classifier ADIF importer now reads PROP_MODE into user_declared_prop_mode so operator-tagged mechanisms (EME/ES/MS/RS/AS/AUR) become ground truth.
141 lines
4.1 KiB
Elixir
141 lines
4.1 KiB
Elixir
defmodule Microwaveprop.Workers.MechanismClassifyWorkerTest do
|
|
use Microwaveprop.DataCase, async: true
|
|
|
|
alias Microwaveprop.Radio.Contact
|
|
alias Microwaveprop.Radio.ContactCommonVolumeRadar
|
|
alias Microwaveprop.Workers.MechanismClassifyWorker
|
|
|
|
defp create_contact(attrs \\ %{}) do
|
|
default = %{
|
|
station1: "W5AA",
|
|
station2: "K5TR",
|
|
qso_timestamp: ~U[2024-08-15 19:00:00Z],
|
|
mode: "CW",
|
|
band: Decimal.new("10000"),
|
|
grid1: "EM12",
|
|
grid2: "EM00",
|
|
pos1: %{"lat" => 32.9, "lon" => -97.0},
|
|
pos2: %{"lat" => 30.3, "lon" => -97.7},
|
|
distance_km: Decimal.new("295")
|
|
}
|
|
|
|
{:ok, contact} =
|
|
%Contact{}
|
|
|> Contact.changeset(Map.merge(default, attrs))
|
|
|> Repo.insert()
|
|
|
|
contact
|
|
end
|
|
|
|
defp create_radar(contact, attrs) do
|
|
{:ok, row} =
|
|
%ContactCommonVolumeRadar{}
|
|
|> ContactCommonVolumeRadar.changeset(
|
|
Map.merge(
|
|
%{
|
|
contact_id: contact.id,
|
|
observed_at: DateTime.to_naive(contact.qso_timestamp),
|
|
max_dbz: 42.0,
|
|
mean_dbz: 28.0,
|
|
pixel_count: 100,
|
|
rain_pixel_count: 80,
|
|
heavy_rain_pixel_count: 15,
|
|
core_pixel_count: 3,
|
|
coverage_pct: 85.0,
|
|
common_volume_km2: 1_200.0
|
|
},
|
|
attrs
|
|
)
|
|
)
|
|
|> Repo.insert()
|
|
|
|
row
|
|
end
|
|
|
|
describe "perform/1" do
|
|
test "classifies a 10 GHz contact with heavy rain in CV as :rain_scatter" do
|
|
contact = create_contact()
|
|
create_radar(contact, %{})
|
|
|
|
assert :ok =
|
|
MechanismClassifyWorker.perform(%Oban.Job{
|
|
args: %{"contact_id" => contact.id}
|
|
})
|
|
|
|
reloaded = Repo.get!(Contact, contact.id)
|
|
assert reloaded.propagation_mechanism == "rain_scatter"
|
|
assert reloaded.propagation_mechanism_status == :complete
|
|
assert reloaded.propagation_mechanism_confidence == :high
|
|
end
|
|
|
|
test "classifies a plain 10 GHz short-path contact with no enrichment as :troposcatter" do
|
|
contact = create_contact()
|
|
|
|
assert :ok =
|
|
MechanismClassifyWorker.perform(%Oban.Job{
|
|
args: %{"contact_id" => contact.id}
|
|
})
|
|
|
|
reloaded = Repo.get!(Contact, contact.id)
|
|
assert reloaded.propagation_mechanism == "troposcatter"
|
|
assert reloaded.propagation_mechanism_status == :complete
|
|
assert reloaded.propagation_mechanism_confidence == :low
|
|
end
|
|
|
|
test "trusts user_declared_prop_mode='EME' over physics" do
|
|
contact =
|
|
create_contact(%{
|
|
user_declared_prop_mode: "EME",
|
|
band: Decimal.new("1296"),
|
|
distance_km: Decimal.new("400")
|
|
})
|
|
|
|
assert :ok =
|
|
MechanismClassifyWorker.perform(%Oban.Job{
|
|
args: %{"contact_id" => contact.id}
|
|
})
|
|
|
|
reloaded = Repo.get!(Contact, contact.id)
|
|
assert reloaded.propagation_mechanism == "eme"
|
|
assert reloaded.propagation_mechanism_confidence == :high
|
|
end
|
|
|
|
test "short 5 km path classifies as :line_of_sight" do
|
|
contact =
|
|
create_contact(%{
|
|
pos1: %{"lat" => 32.90, "lon" => -97.0},
|
|
pos2: %{"lat" => 32.93, "lon" => -97.0},
|
|
distance_km: Decimal.new("5")
|
|
})
|
|
|
|
assert :ok =
|
|
MechanismClassifyWorker.perform(%Oban.Job{
|
|
args: %{"contact_id" => contact.id}
|
|
})
|
|
|
|
reloaded = Repo.get!(Contact, contact.id)
|
|
assert reloaded.propagation_mechanism == "line_of_sight"
|
|
end
|
|
|
|
test "contact without positions is marked unavailable, not failed" do
|
|
contact = create_contact(%{pos1: nil, pos2: nil})
|
|
|
|
assert :ok =
|
|
MechanismClassifyWorker.perform(%Oban.Job{
|
|
args: %{"contact_id" => contact.id}
|
|
})
|
|
|
|
reloaded = Repo.get!(Contact, contact.id)
|
|
assert reloaded.propagation_mechanism_status == :unavailable
|
|
end
|
|
|
|
test "missing contact (deleted) returns :ok gracefully" do
|
|
fake_id = Ecto.UUID.generate()
|
|
|
|
assert :ok =
|
|
MechanismClassifyWorker.perform(%Oban.Job{
|
|
args: %{"contact_id" => fake_id}
|
|
})
|
|
end
|
|
end
|
|
end
|