Adds the second ionospheric data source layer. Polls NOAA SWPC's free public JSON services every 5 minutes for three products: * Planetary K-index (1-min cadence) → geomagnetic_observations * 10.7 cm solar flux (hourly) → solar_flux_observations * GOES X-ray flux (1-min, 0.1-0.8nm long-wave band only) → solar_xray_observations All three products feed HF / Es scoring inputs that the propagation engine will start using in a follow-up commit: * Kp drives HF absorption and Es damping (memory notes Kp is inversely correlated with tropo/Es stability). * F10.7 is the SSN proxy for ITU-R P.533 HF MUF prediction. * GOES X-ray long-wave flux is the short-wave fade (SWF) / D-layer absorption proxy — a C-class flare starts attenuating HF within seconds of the X-ray peak. New context `Microwaveprop.SpaceWeather` exposes `upsert_*/1` and `latest_*/0` per product; `SpaceWeatherFetchWorker` pulls all three independently so one endpoint's outage doesn't block the others. Fixtures captured from live SWPC endpoints on 2026-04-15 for the parser tests. Not yet wired into scoring — that's a separate commit.
43 lines
1.5 KiB
Elixir
43 lines
1.5 KiB
Elixir
defmodule Microwaveprop.Workers.SpaceWeatherFetchWorker do
|
|
@moduledoc """
|
|
Polls NOAA SWPC's free public JSON services for the three space-weather
|
|
products we use for HF / Es scoring:
|
|
|
|
- Planetary K-index (1-min cadence) — geomagnetic disturbance level
|
|
- 10.7 cm solar flux (hourly) — SSN proxy for HF MUF prediction
|
|
- GOES X-ray flux (1-min, 0.1-0.8nm band) — short-wave fade from flares
|
|
|
|
Runs on a 5-minute cron. SWPC publishes Kp and X-ray at 1-min cadence;
|
|
5 minutes strikes a balance between freshness and request volume. Each
|
|
fetch is independent: a failure in one product doesn't block the others.
|
|
"""
|
|
|
|
use Oban.Worker,
|
|
queue: :space_weather,
|
|
max_attempts: 3,
|
|
unique: [period: 120, states: [:available, :scheduled, :executing, :retryable]]
|
|
|
|
alias Microwaveprop.SpaceWeather
|
|
alias Microwaveprop.SpaceWeather.SwpcClient
|
|
|
|
require Logger
|
|
|
|
@impl Oban.Worker
|
|
def perform(%Oban.Job{}) do
|
|
fetch_and_upsert(:kp, &SwpcClient.fetch_kp/0, &SpaceWeather.upsert_kp/1)
|
|
fetch_and_upsert(:f107, &SwpcClient.fetch_f107/0, &SpaceWeather.upsert_solar_flux/1)
|
|
fetch_and_upsert(:xrays, &SwpcClient.fetch_xrays/0, &SpaceWeather.upsert_xray/1)
|
|
:ok
|
|
end
|
|
|
|
defp fetch_and_upsert(name, fetcher, upserter) do
|
|
case fetcher.() do
|
|
{:ok, rows} ->
|
|
{:ok, count} = upserter.(rows)
|
|
Logger.info("SpaceWeatherFetch: #{name} upserted #{count} rows")
|
|
|
|
{:error, reason} ->
|
|
Logger.warning("SpaceWeatherFetch: #{name} failed: #{inspect(reason)}")
|
|
end
|
|
end
|
|
end
|