diff --git a/k8s/deployment-grid-rs.yaml b/k8s/deployment-grid-rs.yaml new file mode 100644 index 00000000..5f262537 --- /dev/null +++ b/k8s/deployment-grid-rs.yaml @@ -0,0 +1,94 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: prop-grid-rs + namespace: prop + # Phase 1 (shadow) default: write to /data/scores_shadow so Elixir keeps + # owning the live /data/scores tree. Flip PROP_SCORES_DIR to /data/scores + # at cutover after ShadowComparator shows < 0.5 mean delta for 72h. +spec: + replicas: 1 + minReadySeconds: 5 + strategy: + type: RollingUpdate + rollingUpdate: + maxSurge: 0 + maxUnavailable: 1 + selector: + matchLabels: + app: prop-grid-rs + template: + metadata: + labels: + app: prop-grid-rs + tier: grid-rs + spec: + # Pin to talos5 — the 32 GB NUC with NVMe. The worker peaks at ~500 Mi + # steady-state but benefits from local NVMe for the NFS scores-dir + # writes (faster fsync) and from never sharing the node with a hot + # Elixir pod. Label talos5 with `prop-grid-rs=primary` and taint it + # `workload=grid-rs:NoSchedule` to enforce this. + nodeSelector: + prop-grid-rs: "primary" + tolerations: + - key: workload + operator: Equal + value: grid-rs + effect: NoSchedule + imagePullSecrets: + - name: forgejo-registry + securityContext: + runAsUser: 65534 + runAsNonRoot: true + fsGroup: 65534 + seccompProfile: + type: RuntimeDefault + containers: + - name: prop-grid-rs + # Image built by a new CI pipeline from rust/prop_grid_rs/. + # Multi-arch (amd64 + arm64) — reuses the repo's existing + # buildx wiring. + image: git.mcintire.me/graham/prop-grid-rs:main + imagePullPolicy: IfNotPresent + env: + # Elixir secrets bundle carries DATABASE_URL already. Rust + # reads it directly (sqlx connects with the same URL). + - name: HRRR_BASE_URL + value: "http://skippy.w5isp.com:8080" + - name: PROP_SCORES_DIR + value: "/data/scores_shadow" + - name: RUST_LOG + value: "info" + - name: PROP_GRID_RS_PG_CONNS + value: "4" + envFrom: + - secretRef: + name: prop-secrets + # No HTTP surface. Liveness is "the process is still running"; + # let the kubelet restart us if we crash. Claiming work from + # grid_tasks is the implicit readiness signal — an idle pod is + # still healthy (the queue is simply empty). + resources: + requests: + cpu: 100m + memory: 128Mi + limits: + cpu: "4" + memory: 512Mi + securityContext: + allowPrivilegeEscalation: false + runAsNonRoot: true + runAsUser: 65534 + capabilities: + drop: + - ALL + seccompProfile: + type: RuntimeDefault + volumeMounts: + - name: data + mountPath: /data + volumes: + - name: data + nfs: + server: 10.0.15.103 + path: /data diff --git a/k8s/kustomization.yaml b/k8s/kustomization.yaml index 875d6b43..0d59a70f 100644 --- a/k8s/kustomization.yaml +++ b/k8s/kustomization.yaml @@ -8,5 +8,6 @@ resources: - rbac.yaml - deployment.yaml - deployment-backfill.yaml + - deployment-grid-rs.yaml - service.yaml - metrics-service.yaml diff --git a/lib/microwaveprop/propagation/grid_task_enqueuer.ex b/lib/microwaveprop/propagation/grid_task_enqueuer.ex new file mode 100644 index 00000000..b264923c --- /dev/null +++ b/lib/microwaveprop/propagation/grid_task_enqueuer.ex @@ -0,0 +1,60 @@ +defmodule Microwaveprop.Propagation.GridTaskEnqueuer do + @moduledoc """ + Seeds `grid_tasks` rows for the Rust `prop-grid-rs` worker. + + Called from `PropagationGridWorker.seed_chain/0` alongside the existing + Elixir f00..f18 Oban fan-out. Rust only claims rows with + `forecast_hour > 0`; Elixir still owns the f00 analysis-hour chain + because of native-duct + NEXRAD + commercial-link enrichment. + + Inserts are idempotent via the `(run_time, forecast_hour)` unique + index — re-seeding the same cycle is a no-op. + """ + + alias Microwaveprop.Repo + + require Logger + + @max_forecast_hour 18 + + @spec seed(DateTime.t()) :: {:ok, non_neg_integer()} | {:error, term()} + def seed(%DateTime{} = run_time) do + run_time = DateTime.truncate(run_time, :second) + now = DateTime.truncate(DateTime.utc_now(), :microsecond) + + rows = + for fh <- 1..@max_forecast_hour do + %{ + id: Ecto.UUID.bingenerate(), + run_time: run_time, + forecast_hour: fh, + valid_time: DateTime.add(run_time, fh * 3600, :second), + status: "queued", + attempt: 0, + claimed_at: nil, + completed_at: nil, + error: nil, + inserted_at: now, + updated_at: now + } + end + + {count, _} = + Repo.insert_all("grid_tasks", rows, + on_conflict: :nothing, + conflict_target: [:run_time, :forecast_hour] + ) + + if count > 0 do + Logger.info("GridTaskEnqueuer: seeded #{count} grid_tasks for run_time=#{run_time}") + else + Logger.info("GridTaskEnqueuer: run_time=#{run_time} already seeded") + end + + {:ok, count} + rescue + e -> + Logger.error("GridTaskEnqueuer: seed failed: #{inspect(e)}") + {:error, e} + end +end diff --git a/lib/microwaveprop/propagation/notify_listener.ex b/lib/microwaveprop/propagation/notify_listener.ex new file mode 100644 index 00000000..9be71687 --- /dev/null +++ b/lib/microwaveprop/propagation/notify_listener.ex @@ -0,0 +1,100 @@ +defmodule Microwaveprop.Propagation.NotifyListener do + @moduledoc """ + Listens for `NOTIFY propagation_ready ''` from the Rust + `prop-grid-rs` worker. When a notification arrives, warms + `ScoreCache` for every band at that `valid_time` (reading from the + shared NFS `/data/scores//.ntms` tree that Rust just + wrote) and fans out the standard `"propagation:updated"` PubSub so + LiveView clients refresh without polling. + + No-op under `testing: :inline` Oban / when the Postgrex.Notifications + supervisor isn't started — the listener is additive; shadow mode and + unit tests don't need it running. + """ + + use GenServer + + alias Microwaveprop.Propagation + alias Microwaveprop.Propagation.BandConfig + alias Microwaveprop.Propagation.ScoreCache + alias Microwaveprop.Repo + + require Logger + + @channel "propagation_ready" + @pubsub Microwaveprop.PubSub + @topic "propagation:updated" + + @spec start_link(keyword()) :: GenServer.on_start() + def start_link(opts) do + GenServer.start_link(__MODULE__, opts, name: __MODULE__) + end + + @impl true + def init(_opts) do + send(self(), :subscribe) + {:ok, %{ref: nil, pid: nil}} + end + + @impl true + def handle_info(:subscribe, state) do + case start_notifications_conn() do + {:ok, pid, ref} -> + {:noreply, %{state | pid: pid, ref: ref}} + + {:error, reason} -> + Logger.warning("NotifyListener: failed to subscribe to #{@channel}: #{inspect(reason)}") + # Retry in 30s. An unreachable DB at boot shouldn't wedge the + # supervisor tree. + Process.send_after(self(), :subscribe, 30_000) + {:noreply, state} + end + end + + @impl true + def handle_info({:notification, _pid, _ref, @channel, payload}, state) do + case DateTime.from_iso8601(payload) do + {:ok, valid_time, _} -> + handle_propagation_ready(valid_time) + + _ -> + Logger.warning("NotifyListener: malformed #{@channel} payload: #{inspect(payload)}") + end + + {:noreply, state} + end + + def handle_info(_msg, state), do: {:noreply, state} + + defp start_notifications_conn do + config = Application.fetch_env!(:microwaveprop, Repo) + + case Postgrex.Notifications.start_link(config) do + {:ok, pid} -> + case Postgrex.Notifications.listen(pid, @channel) do + {:ok, ref} -> + {:ok, pid, ref} + + other -> + {:error, other} + end + + other -> + other + end + end + + defp handle_propagation_ready(valid_time) do + Enum.each(BandConfig.all_bands(), fn band -> + Propagation.warm_cache_and_broadcast(band.freq_mhz, valid_time) + end) + + # Prune anything older than 2 hours so the cache doesn't grow + # unbounded when Rust covers many forecast hours back-to-back. + ScoreCache.prune_older_than(DateTime.add(DateTime.utc_now(), -2, :hour)) + + Phoenix.PubSub.broadcast(@pubsub, @topic, {:propagation_updated, [valid_time]}) + + Logger.info("NotifyListener: warmed ScoreCache + broadcast for valid_time=#{valid_time}") + end +end diff --git a/lib/microwaveprop/propagation/shadow_comparator.ex b/lib/microwaveprop/propagation/shadow_comparator.ex new file mode 100644 index 00000000..39ee2d0d --- /dev/null +++ b/lib/microwaveprop/propagation/shadow_comparator.ex @@ -0,0 +1,119 @@ +defmodule Microwaveprop.Propagation.ShadowComparator do + @moduledoc """ + Shadow-mode validator for the Rust `prop-grid-rs` port. + + During Phase 1 shadow mode the Rust worker writes score-grid files to + `/data/scores_shadow//.ntms` while Elixir keeps writing to + `/data/scores/`. This module compares the two files and logs the + per-band delta distribution so drift is visible before cutover. + + Callable from IEx on demand or from a one-shot Mix task; not started + in the supervision tree (this is temporary instrumentation). + """ + + alias Microwaveprop.Propagation.ScoresFile + + require Logger + + @default_prod_dir "/data/scores" + @default_shadow_dir "/data/scores_shadow" + + @type diff :: %{ + band_mhz: non_neg_integer(), + valid_time: DateTime.t(), + total_cells: non_neg_integer(), + matching_cells: non_neg_integer(), + missing_shadow_cells: non_neg_integer(), + max_abs_delta: non_neg_integer(), + mean_abs_delta: float() + } + + @spec compare(non_neg_integer(), DateTime.t(), keyword()) :: + {:ok, diff()} | {:error, term()} + def compare(band_mhz, %DateTime{} = valid_time, opts \\ []) do + prod_dir = Keyword.get(opts, :prod_dir, @default_prod_dir) + shadow_dir = Keyword.get(opts, :shadow_dir, @default_shadow_dir) + + with {:ok, prod} <- read_file(prod_dir, band_mhz, valid_time), + {:ok, shadow} <- read_file(shadow_dir, band_mhz, valid_time) do + {:ok, diff_payloads(band_mhz, valid_time, prod, shadow)} + end + end + + defp read_file(dir, band_mhz, valid_time) do + path = band_mhz |> ScoresFile.path_for(valid_time) |> swap_base(dir) + + case File.read(path) do + {:ok, binary} -> decode_scores_file(binary) + {:error, reason} -> {:error, {:read, path, reason}} + end + end + + defp swap_base(path, new_base) do + suffix = Path.relative_to(path, ScoresFile.base_dir()) + Path.join(new_base, suffix) + end + + # Inline parse of the v1 scores-file on-disk format so this module + # doesn't reach into `ScoresFile`'s private `decode/1`. The format is + # documented in `ScoresFile`'s moduledoc; only the body size and + # dimensions matter for a diff, so we intentionally keep this minimal. + # The literal "NTMS" magic is the file-header marker already on disk. + defp decode_scores_file( + <<"NTMS", 1::unsigned-8, _band_mhz::unsigned-little-32, _valid_time_unix::signed-little-64, + _lat_min::float-little-32, _lon_min::float-little-32, _step::float-little-32, n_rows::unsigned-little-16, + n_cols::unsigned-little-16, body::binary>> + ) do + expected = n_rows * n_cols + + if byte_size(body) == expected do + {:ok, %{n_rows: n_rows, n_cols: n_cols, scores: body}} + else + {:error, :invalid_format} + end + end + + defp decode_scores_file(_), do: {:error, :invalid_format} + + defp diff_payloads(band_mhz, valid_time, prod, shadow) do + %{scores: p_body, n_cols: n_cols, n_rows: n_rows} = prod + %{scores: s_body} = shadow + + {total, matching, missing, max_abs, sum_abs} = + for row <- 0..(n_rows - 1), + col <- 0..(n_cols - 1), + reduce: {0, 0, 0, 0, 0} do + {t, m, miss, max_d, sum_d} -> + idx = row * n_cols + col + p = :binary.at(p_body, idx) + s = :binary.at(s_body, idx) + + cond do + p == 255 and s == 255 -> + {t, m, miss, max_d, sum_d} + + p != 255 and s == 255 -> + {t + 1, m, miss + 1, max_d, sum_d} + + p == s -> + {t + 1, m + 1, miss, max_d, sum_d} + + true -> + d = abs(p - s) + {t + 1, m, miss, max(max_d, d), sum_d + d} + end + end + + mean = if total > 0, do: sum_abs / total, else: 0.0 + + %{ + band_mhz: band_mhz, + valid_time: valid_time, + total_cells: total, + matching_cells: matching, + missing_shadow_cells: missing, + max_abs_delta: max_abs, + mean_abs_delta: mean + } + end +end diff --git a/lib/microwaveprop/workers/propagation_grid_worker.ex b/lib/microwaveprop/workers/propagation_grid_worker.ex index 943b75ee..0e318698 100644 --- a/lib/microwaveprop/workers/propagation_grid_worker.ex +++ b/lib/microwaveprop/workers/propagation_grid_worker.ex @@ -45,6 +45,7 @@ defmodule Microwaveprop.Workers.PropagationGridWorker do alias Microwaveprop.Propagation alias Microwaveprop.Propagation.BandConfig alias Microwaveprop.Propagation.Grid + alias Microwaveprop.Propagation.GridTaskEnqueuer alias Microwaveprop.Propagation.ProfilesFile alias Microwaveprop.Propagation.ScoreCache alias Microwaveprop.Weather @@ -96,6 +97,15 @@ defmodule Microwaveprop.Workers.PropagationGridWorker do end Oban.insert_all(jobs) + + # Seed the grid_tasks table in parallel so the Rust `prop-grid-rs` + # worker can pick up f01..f18 from a shared NFS mount. During Phase + # 1 shadow mode this runs alongside the Elixir chain; the Rust + # writes land in /data/scores_shadow and are diffed by + # `ShadowComparator`. At cutover the Elixir fan-out above is + # trimmed to just fh=0. + _ = GridTaskEnqueuer.seed(run_time) + :ok end diff --git a/lib/mix/tasks/rust.golden.ex b/lib/mix/tasks/rust.golden.ex new file mode 100644 index 00000000..05c59b57 --- /dev/null +++ b/lib/mix/tasks/rust.golden.ex @@ -0,0 +1,214 @@ +defmodule Mix.Tasks.Rust.Golden do + @shortdoc "Generate golden test fixtures for the Rust scorer port" + @moduledoc """ + Dump Elixir-scorer output for a sample of points to + `priv/rust_golden/scores.bincode`. The Rust crate loads this fixture + in its scorer tests to assert byte-for-byte parity with the Elixir + implementation. + + The fixture format is a little-endian binary: + + n_samples : u32 + per-sample: + abs_humidity : f64 + temp_f : f64 + dewpoint_f : f64 + wind_speed_kts : f64 (NaN = None) + sky_cover_pct : f64 (NaN = None) + utc_hour : u8 + utc_minute : u8 + month : u8 + longitude : f64 + latitude : f64 (NaN = None) + pressure_mb : f64 (NaN = None) + prev_pressure_mb : f64 (NaN = None) + rain_rate_mmhr : f64 (NaN = None) + min_refractivity_gradient : f64 (NaN = None) + bl_depth_m : f64 (NaN = None) + pwat_mm : f64 (NaN = None) + best_duct_band_ghz: f64 (NaN = None) + bulk_richardson : f64 (NaN = None) + band_mhz : u32 + expected_score : i32 + + No Rust dependency on bincode's stable format — we write fixed-width + fields in a fixed order and the Rust loader reads them in the same + order. Matches the Rust `Conditions` struct field-for-field. + + mix rust.golden # writes priv/rust_golden/scores.bincode + mix rust.golden --print 5 # pretty-print first 5 samples + + """ + use Mix.Task + + alias Microwaveprop.Propagation.BandConfig + alias Microwaveprop.Propagation.Scorer + + @impl true + def run(args) do + {opts, _, _} = OptionParser.parse(args, strict: [print: :integer]) + samples = build_samples() + + path = Path.join(["priv", "rust_golden", "scores.bincode"]) + File.mkdir_p!(Path.dirname(path)) + File.write!(path, encode(samples)) + Mix.shell().info("wrote #{length(samples)} samples to #{path}") + + if n = opts[:print] do + samples |> Enum.take(n) |> Enum.each(&IO.inspect/1) + end + end + + defp build_samples do + bands = BandConfig.all_bands() + + conditions_set = [ + summer_peak(), + winter_dry_cold(), + stormy_afternoon(), + dawn_duct(), + humid_gulf() + ] + + for {c, idx} <- Enum.with_index(conditions_set), band <- bands do + result = Scorer.composite_score(c, band) + {idx, c, band.freq_mhz, result.score} + end + end + + defp summer_peak do + %{ + abs_humidity: 10.0, + temp_f: 80, + dewpoint_f: 70, + wind_speed_kts: 5, + sky_cover_pct: 20, + utc_hour: 11, + utc_minute: 15, + month: 6, + longitude: -75.0, + pressure_mb: 1020, + prev_pressure_mb: 1018, + rain_rate_mmhr: 0, + min_refractivity_gradient: -350, + bl_depth_m: 400, + pwat_mm: 25.0 + } + end + + defp winter_dry_cold do + %{ + abs_humidity: 2.5, + temp_f: 28, + dewpoint_f: 14, + wind_speed_kts: 18, + sky_cover_pct: 10, + utc_hour: 14, + utc_minute: 0, + month: 1, + longitude: -97.0, + pressure_mb: 1028, + prev_pressure_mb: 1026, + rain_rate_mmhr: 0, + min_refractivity_gradient: -60, + bl_depth_m: 1800, + pwat_mm: 5.0 + } + end + + defp stormy_afternoon do + %{ + abs_humidity: 18.0, + temp_f: 85, + dewpoint_f: 74, + wind_speed_kts: 22, + sky_cover_pct: 95, + utc_hour: 21, + utc_minute: 0, + month: 7, + longitude: -97.0, + pressure_mb: 1002, + prev_pressure_mb: 1008, + rain_rate_mmhr: 8.0, + min_refractivity_gradient: -80, + bl_depth_m: 2200, + pwat_mm: 38.0 + } + end + + defp dawn_duct do + %{ + abs_humidity: 14.0, + temp_f: 72, + dewpoint_f: 70, + wind_speed_kts: 3, + sky_cover_pct: 5, + utc_hour: 11, + utc_minute: 30, + month: 5, + longitude: -95.0, + pressure_mb: 1018, + prev_pressure_mb: 1017, + rain_rate_mmhr: 0, + min_refractivity_gradient: -220, + bl_depth_m: 140, + pwat_mm: 30.0 + } + end + + defp humid_gulf do + %{ + abs_humidity: 22.0, + temp_f: 88, + dewpoint_f: 77, + wind_speed_kts: 8, + sky_cover_pct: 55, + utc_hour: 18, + utc_minute: 0, + month: 8, + longitude: -93.0, + latitude: 29.5, + pressure_mb: 1014, + prev_pressure_mb: 1014, + rain_rate_mmhr: 0, + min_refractivity_gradient: -110, + bl_depth_m: 700, + pwat_mm: 52.0 + } + end + + defp encode(samples) do + header = <> + body = for {_idx, c, band_mhz, score} <- samples, into: <<>>, do: encode_sample(c, band_mhz, score) + header <> body + end + + defp encode_sample(c, band_mhz, score) do + f(c.abs_humidity) <> + f(c.temp_f) <> + f(c.dewpoint_f) <> + opt(c[:wind_speed_kts]) <> + opt(c[:sky_cover_pct]) <> + <> <> + f(c.longitude) <> + opt(c[:latitude]) <> + opt(c[:pressure_mb]) <> + opt(c[:prev_pressure_mb]) <> + opt(c[:rain_rate_mmhr]) <> + opt(c[:min_refractivity_gradient]) <> + opt(c[:bl_depth_m]) <> + opt(c[:pwat_mm]) <> + opt(c[:best_duct_band_ghz]) <> + opt(c[:bulk_richardson]) <> + <> + end + + # IEEE 754 quiet-NaN bit pattern, little-endian. Used as the sentinel + # for `None` on the Rust side — `f64::is_nan` → `Option::None`. + @nan_bytes <<0x7FF8_0000_0000_0000::unsigned-little-64>> + + defp f(n) when is_float(n), do: <> + defp f(n) when is_integer(n), do: <> + defp opt(nil), do: @nan_bytes + defp opt(v), do: f(v) +end diff --git a/priv/repo/migrations/20260419151243_create_grid_tasks.exs b/priv/repo/migrations/20260419151243_create_grid_tasks.exs new file mode 100644 index 00000000..d166e630 --- /dev/null +++ b/priv/repo/migrations/20260419151243_create_grid_tasks.exs @@ -0,0 +1,48 @@ +defmodule Microwaveprop.Repo.Migrations.CreateGridTasks do + use Ecto.Migration + + def change do + # Hand-off queue between Elixir's PropagationGridWorker (seed) and the + # external Rust `prop-grid-rs` worker. Each row is one forecast hour's + # worth of fetch → decode → score → write-ntms work. Rust claims with + # `SELECT ... FOR UPDATE SKIP LOCKED` on (status='queued'), marks + # 'running' while working, and transitions to 'done' / 'failed' on + # completion. On 'done' it NOTIFYs `propagation_ready` so Elixir pods + # can warm ScoreCache without polling. + create table(:grid_tasks, primary_key: false) do + add :id, :binary_id, primary_key: true + + # HRRR cycle + step. (run_time, forecast_hour) is the natural key; an + # hourly cron re-enqueueing the same step is a no-op via the unique + # index rather than a conflict that has to be handled. + add :run_time, :utc_datetime, null: false + add :forecast_hour, :integer, null: false + add :valid_time, :utc_datetime, null: false + + # 'queued' → 'running' → 'done' | 'failed'. Not an enum so we can add + # more states later without a migration. + add :status, :string, null: false, default: "queued" + + # How many times a worker has claimed this row. Incremented on each + # claim so runaway retries are observable without scanning logs. + add :attempt, :integer, null: false, default: 0 + + add :claimed_at, :utc_datetime_usec + add :completed_at, :utc_datetime_usec + add :error, :text + + timestamps(type: :utc_datetime) + end + + # Uniqueness on the natural key lets the seeder run `INSERT ... ON CONFLICT + # DO NOTHING` and stay idempotent across retries of the seed job. + create unique_index(:grid_tasks, [:run_time, :forecast_hour]) + + # Rust's claim query filters on status first. A partial index on just the + # claimable subset keeps the common lookup cheap as finished rows + # accumulate — the table stays small (19 rows per hour, pruned on a cron) + # but the principle is cheap either way. + create index(:grid_tasks, [:status], where: "status = 'queued'", name: :grid_tasks_queued_idx) + create index(:grid_tasks, [:completed_at]) + end +end diff --git a/priv/rust_golden/scores.bincode b/priv/rust_golden/scores.bincode new file mode 100644 index 00000000..1a8be7f1 Binary files /dev/null and b/priv/rust_golden/scores.bincode differ diff --git a/rust/prop_grid_rs/.gitignore b/rust/prop_grid_rs/.gitignore new file mode 100644 index 00000000..2f7896d1 --- /dev/null +++ b/rust/prop_grid_rs/.gitignore @@ -0,0 +1 @@ +target/ diff --git a/rust/prop_grid_rs/Cargo.lock b/rust/prop_grid_rs/Cargo.lock new file mode 100644 index 00000000..cb46021a --- /dev/null +++ b/rust/prop_grid_rs/Cargo.lock @@ -0,0 +1,2952 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "aho-corasick" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301" +dependencies = [ + "memchr", +] + +[[package]] +name = "allocator-api2" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + +[[package]] +name = "anyhow" +version = "1.0.102" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c" + +[[package]] +name = "atoi" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f28d99ec8bfea296261ca1af174f24225171fea9664ba9003cbebee704810528" +dependencies = [ + "num-traits", +] + +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + +[[package]] +name = "autocfg" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" + +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "base64ct" +version = "1.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2af50177e190e07a26ab74f8b1efbfe2ef87da2116221318cb1c2e82baf7de06" + +[[package]] +name = "bincode" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" +dependencies = [ + "serde", +] + +[[package]] +name = "bitflags" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4512299f36f043ab09a583e57bceb5a5aab7a73db1805848e8fef3c9e8c78b3" +dependencies = [ + "serde_core", +] + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "bumpalo" +version = "3.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d20789868f4b01b2f2caec9f5c4e0213b41e3e5702a50157d699ae31ced2fcb" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33" + +[[package]] +name = "cc" +version = "1.2.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43c5703da9466b66a946814e1adf53ea2c90f10063b86290cc9eb67ce3478a20" +dependencies = [ + "find-msvc-tools", + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" + +[[package]] +name = "cfg_aliases" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" + +[[package]] +name = "chrono" +version = "0.4.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c673075a2e0e5f4a1dde27ce9dee1ea4558c7ffe648f576438a20ca1d2acc4b0" +dependencies = [ + "iana-time-zone", + "js-sys", + "num-traits", + "serde", + "wasm-bindgen", + "windows-link", +] + +[[package]] +name = "concurrent-queue" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ca0197aee26d1ae37445ee532fefce43251d24cc7c166799f4d46817f1d3973" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "const-oid" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "cpufeatures" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" +dependencies = [ + "libc", +] + +[[package]] +name = "crc" +version = "3.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5eb8a2a1cd12ab0d987a5d5e825195d372001a4094a0376319d5a0ad71c1ba0d" +dependencies = [ + "crc-catalog", +] + +[[package]] +name = "crc-catalog" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19d374276b40fb8bbdee95aef7c7fa6b5316ec764510eb64b8dd0e2ed0d7e7f5" + +[[package]] +name = "crossbeam-queue" +version = "0.3.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f58bbc28f91df819d0aa2a2c00cd19754769c2fad90579b3592b1c9ba7a3115" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" + +[[package]] +name = "crypto-common" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "der" +version = "0.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7c1832837b905bbfb5101e07cc24c8deddf52f93225eee6ead5f4d63d53ddcb" +dependencies = [ + "const-oid", + "pem-rfc7468", + "zeroize", +] + +[[package]] +name = "diff" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "const-oid", + "crypto-common", + "subtle", +] + +[[package]] +name = "displaydoc" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "dotenvy" +version = "0.15.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" + +[[package]] +name = "either" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" +dependencies = [ + "serde", +] + +[[package]] +name = "equivalent" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" + +[[package]] +name = "errno" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" +dependencies = [ + "libc", + "windows-sys 0.61.2", +] + +[[package]] +name = "etcetera" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "136d1b5283a1ab77bd9257427ffd09d8667ced0570b6f938942bc7568ed5b943" +dependencies = [ + "cfg-if", + "home", + "windows-sys 0.48.0", +] + +[[package]] +name = "event-listener" +version = "5.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13b66accf52311f30a0db42147dadea9850cb48cd070028831ae5f5d4b856ab" +dependencies = [ + "concurrent-queue", + "parking", + "pin-project-lite", +] + +[[package]] +name = "fastrand" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f1f227452a390804cdb637b74a86990f2a7d7ba4b7d5693aac9b4dd6defd8d6" + +[[package]] +name = "find-msvc-tools" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582" + +[[package]] +name = "flume" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da0e4dd2a88388a1f4ccc7c9ce104604dab68d9f408dc34cd45823d5a9069095" +dependencies = [ + "futures-core", + "futures-sink", + "spin", +] + +[[package]] +name = "foldhash" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" + +[[package]] +name = "form_urlencoded" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futures" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b147ee9d1f6d097cef9ce628cd2ee62288d963e16fb287bd9286455b241382d" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07bbe89c50d7a535e539b8c17bc0b49bdb77747034daa8087407d655f3f7cc1d" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e3450815272ef58cec6d564423f6e755e25379b217b0bc688e295ba24df6b1d" + +[[package]] +name = "futures-executor" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf29c38818342a3b26b5b923639e7b1f4a61fc5e76102d4b1981c6dc7a7579d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-intrusive" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d930c203dd0b6ff06e0201a4a2fe9149b43c684fd4420555b26d21b1a02956f" +dependencies = [ + "futures-core", + "lock_api", + "parking_lot", +] + +[[package]] +name = "futures-io" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cecba35d7ad927e23624b22ad55235f2239cfa44fd10428eecbeba6d6a717718" + +[[package]] +name = "futures-macro" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e835b70203e41293343137df5c0664546da5745f82ec9b84d40be8336958447b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c39754e157331b013978ec91992bde1ac089843443c49cbc7f46150b0fad0893" + +[[package]] +name = "futures-task" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "037711b3d59c33004d3856fbdc83b99d4ff37a24768fa1be9ce3538a1cde4393" + +[[package]] +name = "futures-util" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "389ca41296e6190b48053de0321d02a77f32f8a5d2461dd38762c0593805c6d6" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "slab", +] + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "wasi", + "wasm-bindgen", +] + +[[package]] +name = "getrandom" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "r-efi 5.3.0", + "wasip2", + "wasm-bindgen", +] + +[[package]] +name = "getrandom" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0de51e6874e94e7bf76d726fc5d13ba782deca734ff60d5bb2fb2607c7406555" +dependencies = [ + "cfg-if", + "libc", + "r-efi 6.0.0", + "wasip2", + "wasip3", +] + +[[package]] +name = "hashbrown" +version = "0.15.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" +dependencies = [ + "allocator-api2", + "equivalent", + "foldhash", +] + +[[package]] +name = "hashbrown" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f467dd6dccf739c208452f8014c75c18bb8301b050ad1cfb27153803edb0f51" + +[[package]] +name = "hashlink" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7382cf6263419f2d8df38c55d7da83da5c18aef87fc7a7fc1fb1e344edfe14c1" +dependencies = [ + "hashbrown 0.15.5", +] + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "hermit-abi" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc0fef456e4baa96da950455cd02c081ca953b141298e41db3fc7e36b1da849c" + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "hkdf" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b5f8eb2ad728638ea2c7d47a21db23b7b58a72ed6a38256b8a1849f15fbbdf7" +dependencies = [ + "hmac", +] + +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest", +] + +[[package]] +name = "home" +version = "0.5.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc627f471c528ff0c4a49e1d5e60450c8f6461dd6d10ba9dcd3a61d3dff7728d" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "http" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3ba2a386d7f85a81f119ad7498ebe444d2e22c2af0b86b069416ace48b3311a" +dependencies = [ + "bytes", + "itoa", +] + +[[package]] +name = "http-body" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" +dependencies = [ + "bytes", + "http", +] + +[[package]] +name = "http-body-util" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b021d93e26becf5dc7e1b75b1bed1fd93124b374ceb73f43d4d4eafec896a64a" +dependencies = [ + "bytes", + "futures-core", + "http", + "http-body", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" + +[[package]] +name = "hyper" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6299f016b246a94207e63da54dbe807655bf9e00044f73ded42c3ac5305fbcca" +dependencies = [ + "atomic-waker", + "bytes", + "futures-channel", + "futures-core", + "http", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", +] + +[[package]] +name = "hyper-rustls" +version = "0.27.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ca68d021ef39cf6463ab54c1d0f5daf03377b70561305bb89a8f83aab66e0f" +dependencies = [ + "http", + "hyper", + "hyper-util", + "rustls", + "tokio", + "tokio-rustls", + "tower-service", + "webpki-roots 1.0.7", +] + +[[package]] +name = "hyper-util" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96547c2556ec9d12fb1578c4eaf448b04993e7fb79cbaad930a656880a6bdfa0" +dependencies = [ + "base64", + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "ipnet", + "libc", + "percent-encoding", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", +] + +[[package]] +name = "iana-time-zone" +version = "0.1.65" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e31bc9ad994ba00e440a8aa5c9ef0ec67d5cb5e5cb0cc7f8b744a35b389cc470" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "log", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + +[[package]] +name = "icu_collections" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2984d1cd16c883d7935b9e07e44071dca8d917fd52ecc02c04d5fa0b5a3f191c" +dependencies = [ + "displaydoc", + "potential_utf", + "utf8_iter", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locale_core" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92219b62b3e2b4d88ac5119f8904c10f8f61bf7e95b640d25ba3075e6cac2c29" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_normalizer" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c56e5ee99d6e3d33bd91c5d85458b6005a22140021cc324cea84dd0e72cff3b4" +dependencies = [ + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da3be0ae77ea334f4da67c12f149704f19f81d1adf7c51cf482943e84a2bad38" + +[[package]] +name = "icu_properties" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bee3b67d0ea5c2cca5003417989af8996f8604e34fb9ddf96208a033901e70de" +dependencies = [ + "icu_collections", + "icu_locale_core", + "icu_properties_data", + "icu_provider", + "zerotrie", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e2bbb201e0c04f7b4b3e14382af113e17ba4f63e2c9d2ee626b720cbce54a14" + +[[package]] +name = "icu_provider" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "139c4cf31c8b5f33d7e199446eff9c1e02decfc2f0eec2c8d71f65befa45b421" +dependencies = [ + "displaydoc", + "icu_locale_core", + "writeable", + "yoke", + "zerofrom", + "zerotrie", + "zerovec", +] + +[[package]] +name = "id-arena" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954" + +[[package]] +name = "idna" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de" +dependencies = [ + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3acae9609540aa318d1bc588455225fb2085b9ed0c4f6bd0d9d5bcd86f1a0344" +dependencies = [ + "icu_normalizer", + "icu_properties", +] + +[[package]] +name = "indexmap" +version = "2.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9" +dependencies = [ + "equivalent", + "hashbrown 0.17.0", + "serde", + "serde_core", +] + +[[package]] +name = "ipnet" +version = "2.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d98f6fed1fde3f8c21bc40a1abb88dd75e67924f9cffc3ef95607bad8017f8e2" + +[[package]] +name = "iri-string" +version = "0.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25e659a4bb38e810ebc252e53b5814ff908a8c58c2a9ce2fae1bbec24cbf4e20" +dependencies = [ + "memchr", + "serde", +] + +[[package]] +name = "itoa" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" + +[[package]] +name = "js-sys" +version = "0.3.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2964e92d1d9dc3364cae4d718d93f227e3abb088e747d92e0395bfdedf1c12ca" +dependencies = [ + "cfg-if", + "futures-util", + "once_cell", + "wasm-bindgen", +] + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" +dependencies = [ + "spin", +] + +[[package]] +name = "leb128fmt" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2" + +[[package]] +name = "libc" +version = "0.2.185" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52ff2c0fe9bc6cb6b14a0592c2ff4fa9ceb83eea9db979b0487cd054946a2b8f" + +[[package]] +name = "libm" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6d2cec3eae94f9f509c767b45932f1ada8350c4bdb85af2fcab4a3c14807981" + +[[package]] +name = "libredox" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e02f3bb43d335493c96bf3fd3a321600bf6bd07ed34bc64118e9293bdffea46c" +dependencies = [ + "bitflags", + "libc", + "plain", + "redox_syscall 0.7.4", +] + +[[package]] +name = "libsqlite3-sys" +version = "0.30.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e99fb7a497b1e3339bc746195567ed8d3e24945ecd636e3619d20b9de9e9149" +dependencies = [ + "pkg-config", + "vcpkg", +] + +[[package]] +name = "linux-raw-sys" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53" + +[[package]] +name = "litemap" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92daf443525c4cce67b150400bc2316076100ce0b3686209eb8cf3c31612e6f0" + +[[package]] +name = "lock_api" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965" +dependencies = [ + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" + +[[package]] +name = "lru-slab" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "112b39cec0b298b6c1999fee3e31427f74f676e4cb9879ed1a121b43661a4154" + +[[package]] +name = "matchers" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1525a2a28c7f4fa0fc98bb91ae755d1e2d1505079e05539e35bc876b5d65ae9" +dependencies = [ + "regex-automata", +] + +[[package]] +name = "md-5" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d89e7ee0cfbedfc4da3340218492196241d89eefb6dab27de5df917a6d2e78cf" +dependencies = [ + "cfg-if", + "digest", +] + +[[package]] +name = "memchr" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79" + +[[package]] +name = "mio" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50b7e5b27aa02a74bac8c3f23f448f8d87ff11f92d3aac1a6ed369ee08cc56c1" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.61.2", +] + +[[package]] +name = "nu-ansi-term" +version = "0.50.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "num-bigint-dig" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e661dda6640fad38e827a6d4a310ff4763082116fe217f279885c97f511bb0b7" +dependencies = [ + "lazy_static", + "libm", + "num-integer", + "num-iter", + "num-traits", + "rand 0.8.6", + "smallvec", + "zeroize", +] + +[[package]] +name = "num-integer" +version = "0.1.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-iter" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1429034a0490724d0075ebb2bc9e875d6503c3cf69e235a8941aa757d83ef5bf" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", + "libm", +] + +[[package]] +name = "num_cpus" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91df4bbde75afed763b708b7eee1e8e7651e02d97f6d5dd763e89367e957b23b" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "once_cell" +version = "1.21.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" + +[[package]] +name = "parking" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f38d5652c16fde515bb1ecef450ab0f6a219d619a7274976324d5e377f7dceba" + +[[package]] +name = "parking_lot" +version = "0.12.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall 0.5.18", + "smallvec", + "windows-link", +] + +[[package]] +name = "pem-rfc7468" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88b39c9bfcfc231068454382784bb460aae594343fb030d46e9f50a645418412" +dependencies = [ + "base64ct", +] + +[[package]] +name = "percent-encoding" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" + +[[package]] +name = "pin-project-lite" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" + +[[package]] +name = "pkcs1" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8ffb9f10fa047879315e6625af03c164b16962a5368d724ed16323b68ace47f" +dependencies = [ + "der", + "pkcs8", + "spki", +] + +[[package]] +name = "pkcs8" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" +dependencies = [ + "der", + "spki", +] + +[[package]] +name = "pkg-config" +version = "0.3.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19f132c84eca552bf34cab8ec81f1c1dcc229b811638f9d283dceabe58c5569e" + +[[package]] +name = "plain" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" + +[[package]] +name = "potential_utf" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0103b1cef7ec0cf76490e969665504990193874ea05c85ff9bab8b911d0a0564" +dependencies = [ + "zerovec", +] + +[[package]] +name = "ppv-lite86" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "pretty_assertions" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ae130e2f271fbc2ac3a40fb1d07180839cdbbe443c7a27e1e3c13c5cac0116d" +dependencies = [ + "diff", + "yansi", +] + +[[package]] +name = "prettyplease" +version = "0.2.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b" +dependencies = [ + "proc-macro2", + "syn", +] + +[[package]] +name = "proc-macro2" +version = "1.0.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "prop_grid_rs" +version = "0.1.0" +dependencies = [ + "anyhow", + "bincode", + "byteorder", + "bytes", + "chrono", + "futures", + "num_cpus", + "pretty_assertions", + "reqwest", + "serde", + "serde_json", + "sqlx", + "tempfile", + "thiserror", + "tokio", + "tracing", + "tracing-subscriber", + "uuid", +] + +[[package]] +name = "quinn" +version = "0.11.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e20a958963c291dc322d98411f541009df2ced7b5a4f2bd52337638cfccf20" +dependencies = [ + "bytes", + "cfg_aliases", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror", + "tokio", + "tracing", + "web-time", +] + +[[package]] +name = "quinn-proto" +version = "0.11.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "434b42fec591c96ef50e21e886936e66d3cc3f737104fdb9b737c40ffb94c098" +dependencies = [ + "bytes", + "getrandom 0.3.4", + "lru-slab", + "rand 0.9.4", + "ring", + "rustc-hash", + "rustls", + "rustls-pki-types", + "slab", + "thiserror", + "tinyvec", + "tracing", + "web-time", +] + +[[package]] +name = "quinn-udp" +version = "0.5.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "addec6a0dcad8a8d96a771f815f0eaf55f9d1805756410b39f5fa81332574cbd" +dependencies = [ + "cfg_aliases", + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.60.2", +] + +[[package]] +name = "quote" +version = "1.0.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "r-efi" +version = "5.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" + +[[package]] +name = "r-efi" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" + +[[package]] +name = "rand" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ca0ecfa931c29007047d1bc58e623ab12e5590e8c7cc53200d5202b69266d8a" +dependencies = [ + "libc", + "rand_chacha 0.3.1", + "rand_core 0.6.4", +] + +[[package]] +name = "rand" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44c5af06bb1b7d3216d91932aed5265164bf384dc89cd6ba05cf59a35f5f76ea" +dependencies = [ + "rand_chacha 0.9.0", + "rand_core 0.9.5", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core 0.6.4", +] + +[[package]] +name = "rand_chacha" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" +dependencies = [ + "ppv-lite86", + "rand_core 0.9.5", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom 0.2.17", +] + +[[package]] +name = "rand_core" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76afc826de14238e6e8c374ddcc1fa19e374fd8dd986b0d2af0d02377261d83c" +dependencies = [ + "getrandom 0.3.4", +] + +[[package]] +name = "redox_syscall" +version = "0.5.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d" +dependencies = [ + "bitflags", +] + +[[package]] +name = "redox_syscall" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f450ad9c3b1da563fb6948a8e0fb0fb9269711c9c73d9ea1de5058c79c8d643a" +dependencies = [ + "bitflags", +] + +[[package]] +name = "regex-automata" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e1dd4122fc1595e8162618945476892eefca7b88c52820e74af6262213cae8f" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc897dd8d9e8bd1ed8cdad82b5966c3e0ecae09fb1907d58efaa013543185d0a" + +[[package]] +name = "reqwest" +version = "0.12.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eddd3ca559203180a307f12d114c268abf583f59b03cb906fd0b3ff8646c1147" +dependencies = [ + "base64", + "bytes", + "futures-core", + "futures-util", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-util", + "js-sys", + "log", + "percent-encoding", + "pin-project-lite", + "quinn", + "rustls", + "rustls-pki-types", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "tokio", + "tokio-rustls", + "tokio-util", + "tower", + "tower-http", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "wasm-streams", + "web-sys", + "webpki-roots 1.0.7", +] + +[[package]] +name = "ring" +version = "0.17.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7" +dependencies = [ + "cc", + "cfg-if", + "getrandom 0.2.17", + "libc", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rsa" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8573f03f5883dcaebdfcf4725caa1ecb9c15b2ef50c43a07b816e06799bb12d" +dependencies = [ + "const-oid", + "digest", + "num-bigint-dig", + "num-integer", + "num-traits", + "pkcs1", + "pkcs8", + "rand_core 0.6.4", + "signature", + "spki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustc-hash" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94300abf3f1ae2e2b8ffb7b58043de3d399c73fa6f4b73826402a5c457614dbe" + +[[package]] +name = "rustix" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6fe4565b9518b83ef4f91bb47ce29620ca828bd32cb7e408f0062e9930ba190" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.61.2", +] + +[[package]] +name = "rustls" +version = "0.23.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69f9466fb2c14ea04357e91413efb882e2a6d4a406e625449bc0a5d360d53a21" +dependencies = [ + "once_cell", + "ring", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pki-types" +version = "1.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be040f8b0a225e40375822a563fa9524378b9d63112f53e19ffff34df5d33fdd" +dependencies = [ + "web-time", + "zeroize", +] + +[[package]] +name = "rustls-webpki" +version = "0.103.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8279bb85272c9f10811ae6a6c547ff594d6a7f3c6c6b02ee9726d1d0dcfcdd06" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + +[[package]] +name = "ryu" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "semver" +version = "1.0.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd" + +[[package]] +name = "serde" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.149" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86" +dependencies = [ + "itoa", + "memchr", + "serde", + "serde_core", + "zmij", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sha1" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "sha2" +version = "0.10.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "sharded-slab" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "signal-hook-registry" +version = "1.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4db69cba1110affc0e9f7bcd48bbf87b3f4fc7c61fc9155afd4c469eb3d6c1b" +dependencies = [ + "errno", + "libc", +] + +[[package]] +name = "signature" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" +dependencies = [ + "digest", + "rand_core 0.6.4", +] + +[[package]] +name = "slab" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" + +[[package]] +name = "smallvec" +version = "1.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" +dependencies = [ + "serde", +] + +[[package]] +name = "socket2" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a766e1110788c36f4fa1c2b71b387a7815aa65f88ce0229841826633d93723e" +dependencies = [ + "libc", + "windows-sys 0.61.2", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" +dependencies = [ + "lock_api", +] + +[[package]] +name = "spki" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" +dependencies = [ + "base64ct", + "der", +] + +[[package]] +name = "sqlx" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fefb893899429669dcdd979aff487bd78f4064e5e7907e4269081e0ef7d97dc" +dependencies = [ + "sqlx-core", + "sqlx-macros", + "sqlx-mysql", + "sqlx-postgres", + "sqlx-sqlite", +] + +[[package]] +name = "sqlx-core" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee6798b1838b6a0f69c007c133b8df5866302197e404e8b6ee8ed3e3a5e68dc6" +dependencies = [ + "base64", + "bytes", + "chrono", + "crc", + "crossbeam-queue", + "either", + "event-listener", + "futures-core", + "futures-intrusive", + "futures-io", + "futures-util", + "hashbrown 0.15.5", + "hashlink", + "indexmap", + "log", + "memchr", + "once_cell", + "percent-encoding", + "rustls", + "serde", + "serde_json", + "sha2", + "smallvec", + "thiserror", + "tokio", + "tokio-stream", + "tracing", + "url", + "uuid", + "webpki-roots 0.26.11", +] + +[[package]] +name = "sqlx-macros" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2d452988ccaacfbf5e0bdbc348fb91d7c8af5bee192173ac3636b5fb6e6715d" +dependencies = [ + "proc-macro2", + "quote", + "sqlx-core", + "sqlx-macros-core", + "syn", +] + +[[package]] +name = "sqlx-macros-core" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19a9c1841124ac5a61741f96e1d9e2ec77424bf323962dd894bdb93f37d5219b" +dependencies = [ + "dotenvy", + "either", + "heck", + "hex", + "once_cell", + "proc-macro2", + "quote", + "serde", + "serde_json", + "sha2", + "sqlx-core", + "sqlx-mysql", + "sqlx-postgres", + "sqlx-sqlite", + "syn", + "tokio", + "url", +] + +[[package]] +name = "sqlx-mysql" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa003f0038df784eb8fecbbac13affe3da23b45194bd57dba231c8f48199c526" +dependencies = [ + "atoi", + "base64", + "bitflags", + "byteorder", + "bytes", + "chrono", + "crc", + "digest", + "dotenvy", + "either", + "futures-channel", + "futures-core", + "futures-io", + "futures-util", + "generic-array", + "hex", + "hkdf", + "hmac", + "itoa", + "log", + "md-5", + "memchr", + "once_cell", + "percent-encoding", + "rand 0.8.6", + "rsa", + "serde", + "sha1", + "sha2", + "smallvec", + "sqlx-core", + "stringprep", + "thiserror", + "tracing", + "uuid", + "whoami", +] + +[[package]] +name = "sqlx-postgres" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db58fcd5a53cf07c184b154801ff91347e4c30d17a3562a635ff028ad5deda46" +dependencies = [ + "atoi", + "base64", + "bitflags", + "byteorder", + "chrono", + "crc", + "dotenvy", + "etcetera", + "futures-channel", + "futures-core", + "futures-util", + "hex", + "hkdf", + "hmac", + "home", + "itoa", + "log", + "md-5", + "memchr", + "once_cell", + "rand 0.8.6", + "serde", + "serde_json", + "sha2", + "smallvec", + "sqlx-core", + "stringprep", + "thiserror", + "tracing", + "uuid", + "whoami", +] + +[[package]] +name = "sqlx-sqlite" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2d12fe70b2c1b4401038055f90f151b78208de1f9f89a7dbfd41587a10c3eea" +dependencies = [ + "atoi", + "chrono", + "flume", + "futures-channel", + "futures-core", + "futures-executor", + "futures-intrusive", + "futures-util", + "libsqlite3-sys", + "log", + "percent-encoding", + "serde", + "serde_urlencoded", + "sqlx-core", + "thiserror", + "tracing", + "url", + "uuid", +] + +[[package]] +name = "stable_deref_trait" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" + +[[package]] +name = "stringprep" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b4df3d392d81bd458a8a621b8bffbd2302a12ffe288a9d931670948749463b1" +dependencies = [ + "unicode-bidi", + "unicode-normalization", + "unicode-properties", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.117" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263" +dependencies = [ + "futures-core", +] + +[[package]] +name = "synstructure" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tempfile" +version = "3.27.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd" +dependencies = [ + "fastrand", + "getrandom 0.4.2", + "once_cell", + "rustix", + "windows-sys 0.61.2", +] + +[[package]] +name = "thiserror" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "thread_local" +version = "1.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f60246a4944f24f6e018aa17cdeffb7818b76356965d03b07d6a9886e8962185" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "tinystr" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8323304221c2a851516f22236c5722a72eaa19749016521d6dff0824447d96d" +dependencies = [ + "displaydoc", + "zerovec", +] + +[[package]] +name = "tinyvec" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e61e67053d25a4e82c844e8424039d9745781b3fc4f32b8d55ed50f5f667ef3" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.52.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b67dee974fe86fd92cc45b7a95fdd2f99a36a6d7b0d431a231178d3d670bbcc6" +dependencies = [ + "bytes", + "libc", + "mio", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.61.2", +] + +[[package]] +name = "tokio-macros" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "385a6cb71ab9ab790c5fe8d67f1645e6c450a7ce006a33de03daa956cf70a496" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1729aa945f29d91ba541258c8df89027d5792d85a8841fb65e8bf0f4ede4ef61" +dependencies = [ + "rustls", + "tokio", +] + +[[package]] +name = "tokio-stream" +version = "0.1.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32da49809aab5c3bc678af03902d4ccddea2a87d028d86392a4b1560c6906c70" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ae9cec805b01e8fc3fd2fe289f89149a9b66dd16786abd8b19cfa7b48cb0098" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebe5ef63511595f1344e2d5cfa636d973292adc0eec1f0ad45fae9f0851ab1d4" +dependencies = [ + "futures-core", + "futures-util", + "pin-project-lite", + "sync_wrapper", + "tokio", + "tower-layer", + "tower-service", +] + +[[package]] +name = "tower-http" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4e6559d53cc268e5031cd8429d05415bc4cb4aefc4aa5d6cc35fbf5b924a1f8" +dependencies = [ + "bitflags", + "bytes", + "futures-util", + "http", + "http-body", + "iri-string", + "pin-project-lite", + "tower", + "tower-layer", + "tower-service", +] + +[[package]] +name = "tower-layer" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" +dependencies = [ + "log", + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing-core" +version = "0.1.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a" +dependencies = [ + "once_cell", + "valuable", +] + +[[package]] +name = "tracing-log" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" +dependencies = [ + "log", + "once_cell", + "tracing-core", +] + +[[package]] +name = "tracing-serde" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "704b1aeb7be0d0a84fc9828cae51dab5970fee5088f83d1dd7ee6f6246fc6ff1" +dependencies = [ + "serde", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb7f578e5945fb242538965c2d0b04418d38ec25c79d160cd279bf0731c8d319" +dependencies = [ + "matchers", + "nu-ansi-term", + "once_cell", + "regex-automata", + "serde", + "serde_json", + "sharded-slab", + "smallvec", + "thread_local", + "tracing", + "tracing-core", + "tracing-log", + "tracing-serde", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "typenum" +version = "1.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40ce102ab67701b8526c123c1bab5cbe42d7040ccfd0f64af1a385808d2f43de" + +[[package]] +name = "unicode-bidi" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c1cb5db39152898a79168971543b1cb5020dff7fe43c8dc468b0885f5e29df5" + +[[package]] +name = "unicode-ident" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" + +[[package]] +name = "unicode-normalization" +version = "0.1.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fd4f6878c9cb28d874b009da9e8d183b5abc80117c40bbd187a1fde336be6e8" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-properties" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7df058c713841ad818f1dc5d3fd88063241cc61f49f5fbea4b951e8cf5a8d71d" + +[[package]] +name = "unicode-xid" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff67a8a4397373c3ef660812acab3268222035010ab8680ec4215f38ba3d0eed" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", + "serde", +] + +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" + +[[package]] +name = "uuid" +version = "1.23.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddd74a9687298c6858e9b88ec8935ec45d22e8fd5e6394fa1bd4e99a87789c76" +dependencies = [ + "getrandom 0.4.2", + "js-sys", + "serde_core", + "wasm-bindgen", +] + +[[package]] +name = "valuable" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.1+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" + +[[package]] +name = "wasip2" +version = "1.0.3+wasi-0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20064672db26d7cdc89c7798c48a0fdfac8213434a1186e5ef29fd560ae223d6" +dependencies = [ + "wit-bindgen 0.57.1", +] + +[[package]] +name = "wasip3" +version = "0.4.0+wasi-0.3.0-rc-2026-01-06" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5428f8bf88ea5ddc08faddef2ac4a67e390b88186c703ce6dbd955e1c145aca5" +dependencies = [ + "wit-bindgen 0.51.0", +] + +[[package]] +name = "wasite" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8dad83b4f25e74f184f64c43b150b91efe7647395b42289f38e50566d82855b" + +[[package]] +name = "wasm-bindgen" +version = "0.2.118" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bf938a0bacb0469e83c1e148908bd7d5a6010354cf4fb73279b7447422e3a89" +dependencies = [ + "cfg-if", + "once_cell", + "rustversion", + "wasm-bindgen-macro", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.68" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f371d383f2fb139252e0bfac3b81b265689bf45b6874af544ffa4c975ac1ebf8" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.118" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eeff24f84126c0ec2db7a449f0c2ec963c6a49efe0698c4242929da037ca28ed" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.118" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d08065faf983b2b80a79fd87d8254c409281cf7de75fc4b773019824196c904" +dependencies = [ + "bumpalo", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.118" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fd04d9e306f1907bd13c6361b5c6bfc7b3b3c095ed3f8a9246390f8dbdee129" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "wasm-encoder" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "990065f2fe63003fe337b932cfb5e3b80e0b4d0f5ff650e6985b1048f62c8319" +dependencies = [ + "leb128fmt", + "wasmparser", +] + +[[package]] +name = "wasm-metadata" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb0e353e6a2fbdc176932bbaab493762eb1255a7900fe0fea1a2f96c296cc909" +dependencies = [ + "anyhow", + "indexmap", + "wasm-encoder", + "wasmparser", +] + +[[package]] +name = "wasm-streams" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15053d8d85c7eccdbefef60f06769760a563c7f0a9d6902a13d35c7800b0ad65" +dependencies = [ + "futures-util", + "js-sys", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", +] + +[[package]] +name = "wasmparser" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47b807c72e1bac69382b3a6fb3dbe8ea4c0ed87ff5629b8685ae6b9a611028fe" +dependencies = [ + "bitflags", + "hashbrown 0.15.5", + "indexmap", + "semver", +] + +[[package]] +name = "web-sys" +version = "0.3.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f2dfbb17949fa2088e5d39408c48368947b86f7834484e87b73de55bc14d97d" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "web-time" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "webpki-roots" +version = "0.26.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "521bc38abb08001b01866da9f51eb7c5d647a19260e00054a8c7fd5f9e57f7a9" +dependencies = [ + "webpki-roots 1.0.7", +] + +[[package]] +name = "webpki-roots" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52f5ee44c96cf55f1b349600768e3ece3a8f26010c05265ab73f945bb1a2eb9d" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "whoami" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d4a4db5077702ca3015d3d02d74974948aba2ad9e12ab7df718ee64ccd7e97d" +dependencies = [ + "libredox", + "wasite", +] + +[[package]] +name = "windows-core" +version = "0.62.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-link", + "windows-result", + "windows-strings", +] + +[[package]] +name = "windows-implement" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-interface" +version = "0.59.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-link" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" + +[[package]] +name = "windows-result" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-strings" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" +dependencies = [ + "windows-targets 0.53.5", +] + +[[package]] +name = "windows-sys" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm 0.52.6", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.53.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4945f9f551b88e0d65f3db0bc25c33b8acea4d9e41163edf90dcd0b19f9069f3" +dependencies = [ + "windows-link", + "windows_aarch64_gnullvm 0.53.1", + "windows_aarch64_msvc 0.53.1", + "windows_i686_gnu 0.53.1", + "windows_i686_gnullvm 0.53.1", + "windows_i686_msvc 0.53.1", + "windows_x86_64_gnu 0.53.1", + "windows_x86_64_gnullvm 0.53.1", + "windows_x86_64_msvc 0.53.1", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnu" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "960e6da069d81e09becb0ca57a65220ddff016ff2d6af6a223cf372a506593a3" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_i686_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650" + +[[package]] +name = "wit-bindgen" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7249219f66ced02969388cf2bb044a09756a083d0fab1e566056b04d9fbcaa5" +dependencies = [ + "wit-bindgen-rust-macro", +] + +[[package]] +name = "wit-bindgen" +version = "0.57.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ebf944e87a7c253233ad6766e082e3cd714b5d03812acc24c318f549614536e" + +[[package]] +name = "wit-bindgen-core" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea61de684c3ea68cb082b7a88508a8b27fcc8b797d738bfc99a82facf1d752dc" +dependencies = [ + "anyhow", + "heck", + "wit-parser", +] + +[[package]] +name = "wit-bindgen-rust" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7c566e0f4b284dd6561c786d9cb0142da491f46a9fbed79ea69cdad5db17f21" +dependencies = [ + "anyhow", + "heck", + "indexmap", + "prettyplease", + "syn", + "wasm-metadata", + "wit-bindgen-core", + "wit-component", +] + +[[package]] +name = "wit-bindgen-rust-macro" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c0f9bfd77e6a48eccf51359e3ae77140a7f50b1e2ebfe62422d8afdaffab17a" +dependencies = [ + "anyhow", + "prettyplease", + "proc-macro2", + "quote", + "syn", + "wit-bindgen-core", + "wit-bindgen-rust", +] + +[[package]] +name = "wit-component" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d66ea20e9553b30172b5e831994e35fbde2d165325bec84fc43dbf6f4eb9cb2" +dependencies = [ + "anyhow", + "bitflags", + "indexmap", + "log", + "serde", + "serde_derive", + "serde_json", + "wasm-encoder", + "wasm-metadata", + "wasmparser", + "wit-parser", +] + +[[package]] +name = "wit-parser" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ecc8ac4bc1dc3381b7f59c34f00b67e18f910c2c0f50015669dde7def656a736" +dependencies = [ + "anyhow", + "id-arena", + "indexmap", + "log", + "semver", + "serde", + "serde_derive", + "serde_json", + "unicode-xid", + "wasmparser", +] + +[[package]] +name = "writeable" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ffae5123b2d3fc086436f8834ae3ab053a283cfac8fe0a0b8eaae044768a4c4" + +[[package]] +name = "yansi" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfe53a6657fd280eaa890a3bc59152892ffa3e30101319d168b781ed6529b049" + +[[package]] +name = "yoke" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abe8c5fda708d9ca3df187cae8bfb9ceda00dd96231bed36e445a1a48e66f9ca" +dependencies = [ + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de844c262c8848816172cef550288e7dc6c7b7814b4ee56b3e1553f275f1858e" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + +[[package]] +name = "zerocopy" +version = "0.8.48" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eed437bf9d6692032087e337407a86f04cd8d6a16a37199ed57949d415bd68e9" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.8.48" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70e3cd084b1788766f53af483dd21f93881ff30d7320490ec3ef7526d203bad4" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zerofrom" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69faa1f2a1ea75661980b013019ed6687ed0e83d069bc1114e2cc74c6c04c4df" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11532158c46691caf0f2593ea8358fed6bbf68a0315e80aae9bd41fbade684a1" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + +[[package]] +name = "zeroize" +version = "1.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b97154e67e32c85465826e8bcc1c59429aaaf107c1e4a9e53c8d8ccd5eff88d0" + +[[package]] +name = "zerotrie" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f9152d31db0792fa83f70fb2f83148effb5c1f5b8c7686c3459e361d9bc20bf" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", +] + +[[package]] +name = "zerovec" +version = "0.11.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90f911cbc359ab6af17377d242225f4d75119aec87ea711a880987b18cd7b239" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "625dc425cab0dca6dc3c3319506e6593dcb08a9f387ea3b284dbd52a92c40555" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zmij" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa" diff --git a/rust/prop_grid_rs/Cargo.toml b/rust/prop_grid_rs/Cargo.toml new file mode 100644 index 00000000..759b285e --- /dev/null +++ b/rust/prop_grid_rs/Cargo.toml @@ -0,0 +1,36 @@ +[package] +name = "prop_grid_rs" +version = "0.1.0" +edition = "2021" +publish = false + +[lib] +name = "prop_grid_rs" +path = "src/lib.rs" + +[[bin]] +name = "worker" +path = "src/bin/worker.rs" + +[dependencies] +tokio = { version = "1", features = ["full"] } +sqlx = { version = "0.8", features = ["runtime-tokio-rustls", "postgres", "uuid", "chrono", "macros"] } +reqwest = { version = "0.12", features = ["rustls-tls", "stream"], default-features = false } +bytes = "1" +anyhow = "1" +thiserror = "2" +tracing = "0.1" +tracing-subscriber = { version = "0.3", features = ["env-filter", "json"] } +chrono = { version = "0.4", features = ["serde"] } +uuid = { version = "1", features = ["v4", "serde"] } +serde = { version = "1", features = ["derive"] } +serde_json = "1" +bincode = "1.3" +num_cpus = "1" +byteorder = "1" +futures = "0.3" + +[dev-dependencies] +tokio = { version = "1", features = ["full", "test-util"] } +pretty_assertions = "1" +tempfile = "3" diff --git a/rust/prop_grid_rs/Dockerfile b/rust/prop_grid_rs/Dockerfile new file mode 100644 index 00000000..df091d3e --- /dev/null +++ b/rust/prop_grid_rs/Dockerfile @@ -0,0 +1,33 @@ +# syntax=docker/dockerfile:1.7 +# +# Multi-arch build for `prop-grid-rs`. wgrib2 is installed from Debian +# Trixie (same version the Elixir image uses). The binary runs as a +# non-root uid that matches the fsGroup on the NFS scores mount. +FROM rust:1.94-trixie AS builder +WORKDIR /src + +# Cache deps: copy manifests first so dependency changes alone don't +# invalidate the source-layer cache. +COPY Cargo.toml Cargo.lock* ./ +RUN mkdir -p src src/bin \ + && echo 'fn main() {}' > src/bin/worker.rs \ + && echo '' > src/lib.rs \ + && cargo build --release --bin worker \ + && rm -rf src + +COPY src ./src +RUN cargo build --release --bin worker + +# Runtime image: slim debian plus wgrib2. libexpat/libjasper pulled in +# transitively by wgrib2 for PNG/JPEG2000 GRIB2 decompression. +FROM debian:trixie-slim AS runtime +RUN apt-get update && apt-get install -y --no-install-recommends \ + wgrib2 \ + ca-certificates \ + tini \ + && rm -rf /var/lib/apt/lists/* + +COPY --from=builder /src/target/release/worker /usr/local/bin/prop-grid-rs + +USER 65534:65534 +ENTRYPOINT ["/usr/bin/tini", "--", "/usr/local/bin/prop-grid-rs"] diff --git a/rust/prop_grid_rs/src/band_config.rs b/rust/prop_grid_rs/src/band_config.rs new file mode 100644 index 00000000..928dcff7 --- /dev/null +++ b/rust/prop_grid_rs/src/band_config.rs @@ -0,0 +1,483 @@ +//! Band configuration tables. 1:1 port of +//! `lib/microwaveprop/propagation/band_config.ex`. +//! +//! Keep the data layout identical to the Elixir module; any numerical +//! drift here will show up immediately in golden-fixture scorer tests. + +use std::sync::OnceLock; + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum HumidityEffect { + Beneficial, + Harmful, +} + +#[derive(Debug, Clone, Copy)] +pub struct Weights { + pub humidity: f64, + pub time_of_day: f64, + pub td_depression: f64, + pub refractivity: f64, + pub sky: f64, + pub season: f64, + pub wind: f64, + pub rain: f64, + pub pressure: f64, + pub pwat: f64, +} + +impl Weights { + #[allow(clippy::too_many_arguments)] + pub const fn new( + humidity: f64, + time_of_day: f64, + td_depression: f64, + refractivity: f64, + sky: f64, + season: f64, + wind: f64, + rain: f64, + pressure: f64, + pwat: f64, + ) -> Self { + Self { + humidity, + time_of_day, + td_depression, + refractivity, + sky, + season, + wind, + rain, + pressure, + pwat, + } + } +} + +/// Default weight vector fit by gradient descent on 5,000 QSOs +/// (2026-04-11). Used as fallback for bands that don't carry a `weights` +/// override. +pub const DEFAULT_WEIGHTS: Weights = Weights::new( + 0.1243, // humidity + 0.0496, // time_of_day + 0.0978, // td_depression + 0.1049, // refractivity + 0.08, // sky + 0.1112, // season + 0.08, // wind + 0.1362, // rain + 0.1032, // pressure + 0.1128, // pwat +); + +/// Sunrise hour by month (1..=12) in local solar time. Index = month - 1. +pub const SUNRISE_TABLE: [f64; 12] = [ + 7.4, 7.3, 7.0, 6.7, 6.35, 6.25, 6.35, 6.65, 6.9, 7.1, 7.35, 7.45, +]; + +pub const HUMIDITY_BENEFICIAL_THRESHOLDS: &[(u8, i32)] = &[ + (4, 55), + (7, 70), + (10, 82), + (14, 90), + (18, 95), + (22, 88), +]; +pub const HUMIDITY_BENEFICIAL_DEFAULT: i32 = 75; + +/// `(gradient_max, score_beneficial, score_harmful)`. First entry whose +/// `gradient_max` exceeds the observed gradient wins. Calibrated for +/// HRRR-derived gradients. +pub const REFRACTIVITY_THRESHOLDS: &[(i32, i32, i32)] = &[ + (-200, 98, 85), + (-150, 92, 80), + (-100, 82, 72), + (-75, 68, 62), + (-55, 55, 55), + (-40, 48, 48), +]; +pub const REFRACTIVITY_DEFAULT: (i32, i32) = (42, 42); + +#[derive(Debug, Clone)] +pub struct BandConfig { + pub freq_mhz: u32, + pub label: &'static str, + pub o2_db_km: f64, + pub h2o_coeff: f64, + pub humidity_effect: HumidityEffect, + pub humidity_penalty: f64, + pub rain_k: f64, + pub rain_alpha: f64, + /// Per-month base score for seasonal factor, index = month - 1. + pub seasonal_base: [i32; 12], + /// Per-month additive adjustment, index = month - 1. + pub seasonal_adj: [i32; 12], + pub typical_range_km: u32, + pub extended_range_km: u32, + pub exceptional_range_km: u32, + /// `None` falls back to `DEFAULT_WEIGHTS`. + pub weights: Option, +} + +impl BandConfig { + pub fn weights(&self) -> Weights { + self.weights.unwrap_or(DEFAULT_WEIGHTS) + } +} + +/// Fixed-size literal helper; month values given as (month, score) pairs +/// in Elixir map form. Panics at construction if a month is out of range. +const fn months(v: [(u8, i32); 12]) -> [i32; 12] { + // Build by iterating; can't use const fn loop with indirect writes + // cleanly, so use a match per position. + let mut out = [0; 12]; + let mut i = 0; + while i < 12 { + let (m, s) = v[i]; + // Month values always 1..=12, stored at index month - 1 is the + // convention in Elixir — we rely on the literal being in month + // order here (it is in every band config). + assert!(m >= 1 && m <= 12); + out[(m - 1) as usize] = s; + i += 1; + } + out +} + +const fn adj_from(values: &[(u8, i32)]) -> [i32; 12] { + let mut out = [0; 12]; + let mut i = 0; + while i < values.len() { + let (m, s) = values[i]; + assert!(m >= 1 && m <= 12); + out[(m - 1) as usize] = s; + i += 1; + } + out +} + +// The seasonal_base tables are identical across many bands; pull out the +// common shape once so the 22 band definitions stay scannable. +const BASE_LOW_BAND: [i32; 12] = months([ + (1, 38), (2, 40), (3, 22), (4, 55), (5, 68), (6, 90), + (7, 95), (8, 75), (9, 78), (10, 88), (11, 78), (12, 25), +]); + +const BASE_50: [i32; 12] = months([ + (1, 30), (2, 32), (3, 25), (4, 50), (5, 70), (6, 95), + (7, 95), (8, 70), (9, 65), (10, 70), (11, 60), (12, 25), +]); + +const BASE_24G: [i32; 12] = months([ + (1, 88), (2, 84), (3, 68), (4, 62), (5, 51), (6, 34), + (7, 18), (8, 18), (9, 48), (10, 68), (11, 96), (12, 88), +]); + +const BASE_47G: [i32; 12] = months([ + (1, 90), (2, 88), (3, 78), (4, 68), (5, 55), (6, 38), + (7, 22), (8, 22), (9, 48), (10, 74), (11, 96), (12, 90), +]); + +const BASE_68G: [i32; 12] = months([ + (1, 90), (2, 88), (3, 78), (4, 65), (5, 50), (6, 32), + (7, 18), (8, 18), (9, 44), (10, 70), (11, 92), (12, 90), +]); + +const BASE_75G: [i32; 12] = months([ + (1, 90), (2, 90), (3, 80), (4, 68), (5, 55), (6, 38), + (7, 22), (8, 22), (9, 48), (10, 74), (11, 96), (12, 90), +]); + +const BASE_122G: [i32; 12] = months([ + (1, 92), (2, 90), (3, 78), (4, 62), (5, 45), (6, 28), + (7, 15), (8, 15), (9, 38), (10, 68), (11, 92), (12, 92), +]); + +const BASE_134G: [i32; 12] = months([ + (1, 92), (2, 90), (3, 78), (4, 65), (5, 48), (6, 30), + (7, 18), (8, 18), (9, 42), (10, 70), (11, 92), (12, 92), +]); + +const BASE_142G: [i32; 12] = months([ + (1, 92), (2, 90), (3, 78), (4, 65), (5, 47), (6, 28), + (7, 16), (8, 16), (9, 40), (10, 68), (11, 92), (12, 92), +]); + +const BASE_145G: [i32; 12] = months([ + (1, 92), (2, 90), (3, 78), (4, 64), (5, 46), (6, 27), + (7, 15), (8, 15), (9, 38), (10, 66), (11, 92), (12, 92), +]); + +const BASE_241G: [i32; 12] = months([ + (1, 95), (2, 92), (3, 75), (4, 55), (5, 35), (6, 15), + (7, 8), (8, 8), (9, 30), (10, 65), (11, 95), (12, 95), +]); + +const BASE_288G: [i32; 12] = months([ + (1, 95), (2, 92), (3, 75), (4, 55), (5, 35), (6, 14), + (7, 7), (8, 7), (9, 28), (10, 64), (11, 95), (12, 95), +]); + +const BASE_322G: [i32; 12] = months([ + (1, 96), (2, 92), (3, 74), (4, 52), (5, 32), (6, 12), + (7, 6), (8, 6), (9, 26), (10, 62), (11, 96), (12, 96), +]); + +const BASE_403G: [i32; 12] = months([ + (1, 96), (2, 92), (3, 74), (4, 52), (5, 32), (6, 12), + (7, 6), (8, 6), (9, 26), (10, 62), (11, 96), (12, 96), +]); + +const ADJ_NONE: [i32; 12] = [0; 12]; +const ADJ_24G: [i32; 12] = adj_from(&[(5, -4), (6, -8), (7, -10), (8, -10), (9, -4)]); + +fn bands() -> &'static [BandConfig] { + static CELL: OnceLock> = OnceLock::new(); + CELL.get_or_init(build_bands) +} + +#[allow(clippy::too_many_lines)] +fn build_bands() -> Vec { + use HumidityEffect::*; + vec![ + BandConfig { + freq_mhz: 50, label: "50 MHz", + o2_db_km: 0.0, h2o_coeff: 0.0, humidity_effect: Beneficial, humidity_penalty: 0.0, + rain_k: 0.0, rain_alpha: 1.0, + seasonal_base: BASE_50, seasonal_adj: ADJ_NONE, + typical_range_km: 400, extended_range_km: 1500, exceptional_range_km: 4000, + weights: None, + }, + BandConfig { + freq_mhz: 144, label: "144 MHz", + o2_db_km: 0.0, h2o_coeff: 0.0, humidity_effect: Beneficial, humidity_penalty: 0.0, + rain_k: 0.0, rain_alpha: 1.0, + seasonal_base: BASE_LOW_BAND, seasonal_adj: ADJ_NONE, + typical_range_km: 350, extended_range_km: 900, exceptional_range_km: 2500, + weights: None, + }, + BandConfig { + freq_mhz: 222, label: "222 MHz", + o2_db_km: 0.0, h2o_coeff: 0.0, humidity_effect: Beneficial, humidity_penalty: 0.0, + rain_k: 0.0, rain_alpha: 1.0, + seasonal_base: BASE_LOW_BAND, seasonal_adj: ADJ_NONE, + typical_range_km: 320, extended_range_km: 800, exceptional_range_km: 2000, + weights: Some(Weights::new(0.1593, 0.0350, 0.1250, 0.1401, 0.0706, 0.1276, 0.0706, 0.0120, 0.0681, 0.1916)), + }, + BandConfig { + freq_mhz: 432, label: "432 MHz", + o2_db_km: 0.0, h2o_coeff: 0.0, humidity_effect: Beneficial, humidity_penalty: 0.0, + rain_k: 0.0, rain_alpha: 1.0, + seasonal_base: BASE_LOW_BAND, seasonal_adj: ADJ_NONE, + typical_range_km: 300, extended_range_km: 700, exceptional_range_km: 1800, + weights: Some(Weights::new(0.2061, 0.0329, 0.1200, 0.1186, 0.0663, 0.1106, 0.0663, 0.0113, 0.0809, 0.1870)), + }, + BandConfig { + freq_mhz: 902, label: "902 MHz", + o2_db_km: 0.006, h2o_coeff: 0.0, humidity_effect: Beneficial, humidity_penalty: 0.0, + rain_k: 0.000, rain_alpha: 1.0, + seasonal_base: BASE_LOW_BAND, seasonal_adj: ADJ_NONE, + typical_range_km: 400, extended_range_km: 800, exceptional_range_km: 1500, + weights: Some(Weights::new(0.2201, 0.0437, 0.1102, 0.0888, 0.0783, 0.1197, 0.0783, 0.0133, 0.0839, 0.1635)), + }, + BandConfig { + freq_mhz: 1_296, label: "1296 MHz", + o2_db_km: 0.006, h2o_coeff: 0.0, humidity_effect: Beneficial, humidity_penalty: 0.0, + rain_k: 0.000, rain_alpha: 1.0, + seasonal_base: BASE_LOW_BAND, seasonal_adj: ADJ_NONE, + typical_range_km: 350, extended_range_km: 700, exceptional_range_km: 1200, + weights: Some(Weights::new(0.2131, 0.0494, 0.0898, 0.1392, 0.0797, 0.1108, 0.0797, 0.0136, 0.0568, 0.1678)), + }, + BandConfig { + freq_mhz: 2_304, label: "2304 MHz", + o2_db_km: 0.006, h2o_coeff: 0.0, humidity_effect: Beneficial, humidity_penalty: 0.0, + rain_k: 0.001, rain_alpha: 1.15, + seasonal_base: BASE_LOW_BAND, seasonal_adj: ADJ_NONE, + typical_range_km: 300, extended_range_km: 600, exceptional_range_km: 1000, + weights: Some(Weights::new(0.1941, 0.0387, 0.1385, 0.1638, 0.0625, 0.0868, 0.0625, 0.0336, 0.0432, 0.1762)), + }, + BandConfig { + freq_mhz: 3_400, label: "3400 MHz", + o2_db_km: 0.006, h2o_coeff: 0.0, humidity_effect: Beneficial, humidity_penalty: 0.0, + rain_k: 0.002, rain_alpha: 1.20, + seasonal_base: BASE_LOW_BAND, seasonal_adj: ADJ_NONE, + typical_range_km: 250, extended_range_km: 550, exceptional_range_km: 900, + weights: Some(Weights::new(0.1996, 0.0398, 0.1251, 0.1310, 0.0642, 0.0893, 0.0642, 0.0489, 0.0568, 0.1811)), + }, + BandConfig { + freq_mhz: 5_760, label: "5760 MHz", + o2_db_km: 0.007, h2o_coeff: 0.0, humidity_effect: Beneficial, humidity_penalty: 0.0, + rain_k: 0.005, rain_alpha: 1.25, + seasonal_base: BASE_LOW_BAND, seasonal_adj: ADJ_NONE, + typical_range_km: 220, extended_range_km: 500, exceptional_range_km: 1000, + weights: Some(Weights::new(0.1829, 0.0423, 0.1205, 0.0881, 0.0683, 0.0949, 0.0683, 0.0822, 0.0602, 0.1925)), + }, + BandConfig { + freq_mhz: 10_000, label: "10 GHz", + o2_db_km: 0.007, h2o_coeff: 0.0, humidity_effect: Beneficial, humidity_penalty: 0.0, + rain_k: 0.010, rain_alpha: 1.28, + seasonal_base: BASE_LOW_BAND, seasonal_adj: ADJ_NONE, + typical_range_km: 200, extended_range_km: 500, exceptional_range_km: 1000, + weights: None, + }, + BandConfig { + freq_mhz: 24_000, label: "24 GHz", + o2_db_km: 0.02, h2o_coeff: 0.002, humidity_effect: Harmful, humidity_penalty: 1.6, + rain_k: 0.070, rain_alpha: 1.07, + seasonal_base: BASE_24G, seasonal_adj: ADJ_24G, + typical_range_km: 100, extended_range_km: 250, exceptional_range_km: 500, + weights: Some(Weights::new(0.1481, 0.0532, 0.0360, 0.1250, 0.0477, 0.0729, 0.0477, 0.2147, 0.1203, 0.1344)), + }, + BandConfig { + freq_mhz: 47_000, label: "47 GHz", + o2_db_km: 0.04, h2o_coeff: 0.003, humidity_effect: Harmful, humidity_penalty: 1.0, + rain_k: 0.187, rain_alpha: 0.93, + seasonal_base: BASE_47G, seasonal_adj: ADJ_NONE, + typical_range_km: 70, extended_range_km: 150, exceptional_range_km: 300, + weights: None, + }, + BandConfig { + freq_mhz: 68_000, label: "68 GHz", + o2_db_km: 0.90, h2o_coeff: 0.007, humidity_effect: Harmful, humidity_penalty: 1.4, + rain_k: 0.310, rain_alpha: 0.86, + seasonal_base: BASE_68G, seasonal_adj: ADJ_NONE, + typical_range_km: 40, extended_range_km: 80, exceptional_range_km: 150, + weights: None, + }, + BandConfig { + freq_mhz: 75_000, label: "75 GHz", + o2_db_km: 0.012, h2o_coeff: 0.006, humidity_effect: Harmful, humidity_penalty: 1.2, + rain_k: 0.345, rain_alpha: 0.84, + seasonal_base: BASE_75G, seasonal_adj: ADJ_NONE, + typical_range_km: 50, extended_range_km: 120, exceptional_range_km: 250, + weights: None, + }, + BandConfig { + freq_mhz: 122_000, label: "122 GHz", + o2_db_km: 0.80, h2o_coeff: 0.010, humidity_effect: Harmful, humidity_penalty: 1.0, + rain_k: 0.498, rain_alpha: 0.77, + seasonal_base: BASE_122G, seasonal_adj: ADJ_NONE, + typical_range_km: 30, extended_range_km: 80, exceptional_range_km: 140, + weights: None, + }, + BandConfig { + freq_mhz: 134_000, label: "134 GHz", + o2_db_km: 0.08, h2o_coeff: 0.015, humidity_effect: Harmful, humidity_penalty: 1.3, + rain_k: 0.520, rain_alpha: 0.75, + seasonal_base: BASE_134G, seasonal_adj: ADJ_NONE, + typical_range_km: 40, extended_range_km: 100, exceptional_range_km: 160, + weights: None, + }, + BandConfig { + freq_mhz: 142_000, label: "142 GHz", + o2_db_km: 0.05, h2o_coeff: 0.025, humidity_effect: Harmful, humidity_penalty: 1.4, + rain_k: 0.530, rain_alpha: 0.74, + seasonal_base: BASE_142G, seasonal_adj: ADJ_NONE, + typical_range_km: 35, extended_range_km: 80, exceptional_range_km: 160, + weights: None, + }, + BandConfig { + freq_mhz: 145_000, label: "145 GHz", + o2_db_km: 0.06, h2o_coeff: 0.040, humidity_effect: Harmful, humidity_penalty: 1.5, + rain_k: 0.535, rain_alpha: 0.74, + seasonal_base: BASE_145G, seasonal_adj: ADJ_NONE, + typical_range_km: 35, extended_range_km: 80, exceptional_range_km: 150, + weights: None, + }, + BandConfig { + freq_mhz: 241_000, label: "241 GHz", + o2_db_km: 0.08, h2o_coeff: 0.30, humidity_effect: Harmful, humidity_penalty: 3.0, + rain_k: 0.550, rain_alpha: 0.70, + seasonal_base: BASE_241G, seasonal_adj: ADJ_NONE, + typical_range_km: 10, extended_range_km: 50, exceptional_range_km: 115, + weights: None, + }, + BandConfig { + freq_mhz: 288_000, label: "288 GHz", + o2_db_km: 0.10, h2o_coeff: 0.45, humidity_effect: Harmful, humidity_penalty: 3.5, + rain_k: 0.560, rain_alpha: 0.68, + seasonal_base: BASE_288G, seasonal_adj: ADJ_NONE, + typical_range_km: 5, extended_range_km: 15, exceptional_range_km: 50, + weights: None, + }, + BandConfig { + freq_mhz: 322_000, label: "322 GHz", + o2_db_km: 0.12, h2o_coeff: 0.55, humidity_effect: Harmful, humidity_penalty: 4.0, + rain_k: 0.570, rain_alpha: 0.66, + seasonal_base: BASE_322G, seasonal_adj: ADJ_NONE, + typical_range_km: 5, extended_range_km: 15, exceptional_range_km: 40, + weights: None, + }, + BandConfig { + freq_mhz: 403_000, label: "403 GHz", + o2_db_km: 0.15, h2o_coeff: 0.40, humidity_effect: Harmful, humidity_penalty: 3.0, + rain_k: 0.580, rain_alpha: 0.64, + seasonal_base: BASE_403G, seasonal_adj: ADJ_NONE, + typical_range_km: 3, extended_range_km: 10, exceptional_range_km: 30, + weights: None, + }, + BandConfig { + freq_mhz: 411_000, label: "411 GHz", + o2_db_km: 0.15, h2o_coeff: 0.42, humidity_effect: Harmful, humidity_penalty: 3.2, + rain_k: 0.580, rain_alpha: 0.64, + seasonal_base: BASE_403G, seasonal_adj: ADJ_NONE, + typical_range_km: 3, extended_range_km: 10, exceptional_range_km: 30, + weights: None, + }, + ] +} + +pub fn get(freq_mhz: u32) -> Option<&'static BandConfig> { + bands().iter().find(|b| b.freq_mhz == freq_mhz) +} + +pub fn all_bands() -> &'static [BandConfig] { + bands() +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn expected_band_count() { + assert_eq!(all_bands().len(), 23); + } + + #[test] + fn default_weights_sum_to_one() { + let w = DEFAULT_WEIGHTS; + let sum = w.humidity + w.time_of_day + w.td_depression + w.refractivity + + w.sky + w.season + w.wind + w.rain + w.pressure + w.pwat; + // Elixir comment says "all 10 values sum to 1.0" — allow tiny FP slop. + assert!((sum - 1.0).abs() < 1e-9, "weights sum = {sum}"); + } + + #[test] + fn lookup_by_freq() { + let tenghz = get(10_000).unwrap(); + assert_eq!(tenghz.label, "10 GHz"); + assert_eq!(tenghz.humidity_effect, HumidityEffect::Beneficial); + assert!(get(99_999).is_none()); + } + + #[test] + fn band_with_weights_override_returns_override() { + let b = get(10_000).unwrap(); + // 10 GHz has weights: None → defaults. + assert_eq!(b.weights().humidity, DEFAULT_WEIGHTS.humidity); + + let b432 = get(432).unwrap(); + assert!((b432.weights().humidity - 0.2061).abs() < 1e-9); + } + + #[test] + fn seasonal_adj_24g_matches_elixir() { + let b = get(24_000).unwrap(); + // Elixir: seasonal_adj: %{5 => -4, 6 => -8, 7 => -10, 8 => -10, 9 => -4} + assert_eq!(b.seasonal_adj[4], -4); // May + assert_eq!(b.seasonal_adj[6], -10); // July + assert_eq!(b.seasonal_adj[11], 0); // Dec untouched + } +} diff --git a/rust/prop_grid_rs/src/bin/worker.rs b/rust/prop_grid_rs/src/bin/worker.rs new file mode 100644 index 00000000..3328dd25 --- /dev/null +++ b/rust/prop_grid_rs/src/bin/worker.rs @@ -0,0 +1,118 @@ +//! `prop-grid-rs` main loop. +//! +//! Flow: +//! 1. Connect to Postgres (DATABASE_URL env). +//! 2. Loop: claim one `grid_tasks` row (fh>0, status='queued'), +//! run the fetch → decode → score → write-scores-file chain, mark done + +//! `NOTIFY propagation_ready ''`. On error mark +//! failed; hourly cron reseeds. +//! 3. Graceful shutdown on SIGTERM: requeue current row and exit. + +use std::path::PathBuf; +use std::sync::Arc; +use std::sync::atomic::{AtomicBool, Ordering}; +use std::time::Duration; + +use prop_grid_rs::{db, fetcher::HrrrClient, pipeline}; +use tracing::{error, info, warn}; +use tracing_subscriber::EnvFilter; + +const IDLE_SLEEP: Duration = Duration::from_secs(5); + +#[tokio::main] +async fn main() -> Result<(), Box> { + tracing_subscriber::fmt() + .json() + .with_env_filter(EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info"))) + .init(); + + let database_url = std::env::var("DATABASE_URL") + .map_err(|_| "DATABASE_URL environment variable is required")?; + let scores_dir = std::env::var("PROP_SCORES_DIR") + .map(PathBuf::from) + .unwrap_or_else(|_| PathBuf::from("/data/scores")); + let hrrr_base = std::env::var("HRRR_BASE_URL") + .unwrap_or_else(|_| prop_grid_rs::fetcher::HRRR_BASE_DEFAULT.to_string()); + let max_conn: u32 = std::env::var("PROP_GRID_RS_PG_CONNS") + .ok() + .and_then(|v| v.parse().ok()) + .unwrap_or(4); + + let pool = db::connect(&database_url, max_conn).await?; + let client = Arc::new(HrrrClient::new(hrrr_base)?); + + let shutdown = Arc::new(AtomicBool::new(false)); + spawn_signal_handler(shutdown.clone()); + + info!(scores_dir = %scores_dir.display(), "prop-grid-rs started"); + + while !shutdown.load(Ordering::Relaxed) { + match db::claim_next(&pool).await { + Ok(Some(task)) => { + let task_id = task.id; + match pipeline::run_chain_step( + &client, + &scores_dir, + &pipeline::ChainStepInput { + run_time: task.run_time, + forecast_hour: task.forecast_hour as u8, + }, + ) + .await + { + Ok(stats) => { + info!( + task_id = %task.id, + run_time = %task.run_time, + forecast_hour = task.forecast_hour, + files = stats.score_files_written, + points = stats.point_count, + "chain step done" + ); + if let Err(e) = db::complete(&pool, &task).await { + error!(%task_id, error = %e, "failed to mark task done"); + } + } + Err(e) => { + warn!(%task_id, error = %e, "chain step failed"); + if let Err(dbe) = db::fail(&pool, task_id, &e.to_string()).await { + error!(%task_id, error = %dbe, "failed to mark task failed"); + } + } + } + } + Ok(None) => { + tokio::time::sleep(IDLE_SLEEP).await; + } + Err(e) => { + error!(error = %e, "claim_next failed; backing off"); + tokio::time::sleep(IDLE_SLEEP).await; + } + } + } + + info!("prop-grid-rs shutting down"); + Ok(()) +} + +#[cfg(unix)] +fn spawn_signal_handler(shutdown: Arc) { + use tokio::signal::unix::{signal, SignalKind}; + tokio::spawn(async move { + let mut term = signal(SignalKind::terminate()).expect("install SIGTERM handler"); + let mut intr = signal(SignalKind::interrupt()).expect("install SIGINT handler"); + tokio::select! { + _ = term.recv() => info!("SIGTERM received"), + _ = intr.recv() => info!("SIGINT received"), + }; + shutdown.store(true, Ordering::Relaxed); + }); +} + +#[cfg(not(unix))] +fn spawn_signal_handler(shutdown: Arc) { + tokio::spawn(async move { + let _ = tokio::signal::ctrl_c().await; + shutdown.store(true, Ordering::Relaxed); + }); +} diff --git a/rust/prop_grid_rs/src/db.rs b/rust/prop_grid_rs/src/db.rs new file mode 100644 index 00000000..633441fd --- /dev/null +++ b/rust/prop_grid_rs/src/db.rs @@ -0,0 +1,210 @@ +//! `grid_tasks` claim/complete + `propagation_ready` NOTIFY. +//! +//! Contract: +//! * Elixir seeds one row per `(run_time, forecast_hour)` with status=queued. +//! * Rust claims one queued, non-zero-forecast-hour row via +//! `SELECT ... FOR UPDATE SKIP LOCKED` and marks it running. +//! * On success: status=done, NOTIFY propagation_ready ''. +//! * On failure: status=failed, error=. An hourly cron reseeds. + +use chrono::{DateTime, Utc}; +use sqlx::postgres::{PgNotification, PgPool, PgPoolOptions}; +use sqlx::Row; +use std::time::Duration; +use uuid::Uuid; + +pub const NOTIFY_CHANNEL: &str = "propagation_ready"; + +#[derive(Debug, Clone)] +pub struct ClaimedTask { + pub id: Uuid, + pub run_time: DateTime, + pub forecast_hour: i16, + pub valid_time: DateTime, + pub attempt: i32, +} + +#[derive(Debug, thiserror::Error)] +pub enum DbError { + #[error(transparent)] + Sqlx(#[from] sqlx::Error), +} + +pub async fn connect(url: &str, max_connections: u32) -> Result { + let pool = PgPoolOptions::new() + .max_connections(max_connections) + .acquire_timeout(Duration::from_secs(10)) + .connect(url) + .await?; + Ok(pool) +} + +/// Atomically claim one queued grid_tasks row with forecast_hour > 0. +/// Transitions it to status='running', bumps the attempt counter, and +/// stamps claimed_at. Returns `None` if the queue is empty. +pub async fn claim_next(pool: &PgPool) -> Result, DbError> { + let mut tx = pool.begin().await?; + let row = sqlx::query( + r#" + SELECT id, run_time, forecast_hour, valid_time, attempt + FROM grid_tasks + WHERE status = 'queued' AND forecast_hour > 0 + ORDER BY run_time ASC, forecast_hour ASC + FOR UPDATE SKIP LOCKED + LIMIT 1 + "#, + ) + .fetch_optional(&mut *tx) + .await?; + + let Some(row) = row else { + tx.commit().await?; + return Ok(None); + }; + + let id: Uuid = row.try_get("id")?; + let run_time: DateTime = row.try_get("run_time")?; + let forecast_hour: i32 = row.try_get("forecast_hour")?; + let forecast_hour = forecast_hour as i16; + let valid_time: DateTime = row.try_get("valid_time")?; + let attempt: i32 = row.try_get("attempt")?; + + sqlx::query( + r#" + UPDATE grid_tasks + SET status = 'running', + claimed_at = NOW(), + attempt = attempt + 1, + updated_at = NOW() + WHERE id = $1 + "#, + ) + .bind(id) + .execute(&mut *tx) + .await?; + + tx.commit().await?; + + Ok(Some(ClaimedTask { + id, + run_time, + forecast_hour, + valid_time, + attempt: attempt + 1, + })) +} + +/// Mark a task done and emit NOTIFY propagation_ready ''. +/// The NOTIFY payload is read by Elixir's `PropagationNotifyListener` to +/// warm `ScoreCache` and fan out `"propagation:updated"` PubSub. +pub async fn complete(pool: &PgPool, task: &ClaimedTask) -> Result<(), DbError> { + let mut tx = pool.begin().await?; + sqlx::query( + r#" + UPDATE grid_tasks + SET status = 'done', + completed_at = NOW(), + error = NULL, + updated_at = NOW() + WHERE id = $1 + "#, + ) + .bind(task.id) + .execute(&mut *tx) + .await?; + + let payload = task.valid_time.format("%Y-%m-%dT%H:%M:%SZ").to_string(); + let notify = format!("NOTIFY {}, '{}'", NOTIFY_CHANNEL, payload); + sqlx::query(¬ify).execute(&mut *tx).await?; + tx.commit().await?; + Ok(()) +} + +pub async fn fail(pool: &PgPool, task_id: Uuid, error: &str) -> Result<(), DbError> { + sqlx::query( + r#" + UPDATE grid_tasks + SET status = 'failed', + completed_at = NOW(), + error = $2, + updated_at = NOW() + WHERE id = $1 + "#, + ) + .bind(task_id) + .bind(error) + .execute(pool) + .await?; + Ok(()) +} + +/// Park the task back in the queue (e.g. SIGTERM received mid-work). +/// Resets status to 'queued' without incrementing attempt so a restart +/// doesn't chew through the retry budget. +pub async fn requeue(pool: &PgPool, task_id: Uuid) -> Result<(), DbError> { + sqlx::query( + r#" + UPDATE grid_tasks + SET status = 'queued', + claimed_at = NULL, + updated_at = NOW() + WHERE id = $1 AND status = 'running' + "#, + ) + .bind(task_id) + .execute(pool) + .await?; + Ok(()) +} + +// Imported only to keep the PgNotification type used from `sqlx::postgres`. +const _: fn() = || { + fn assert_send() {} + assert_send::(); +}; + +#[cfg(test)] +mod tests { + use super::*; + + /// Live-DB integration tests — gated behind the `PROP_GRID_RS_TEST_DB` + /// env var so `cargo test` stays green without Postgres. + #[tokio::test] + async fn claim_and_complete_roundtrip() { + let Ok(url) = std::env::var("PROP_GRID_RS_TEST_DB") else { + eprintln!("skip: set PROP_GRID_RS_TEST_DB to run db tests"); + return; + }; + let pool = connect(&url, 4).await.unwrap(); + + // Seed a unique fh>0 row. + let run_time = Utc::now(); + let fh: i16 = 7; + let valid_time = run_time + chrono::Duration::hours(fh as i64); + let id = Uuid::new_v4(); + sqlx::query( + r#"INSERT INTO grid_tasks (id, run_time, forecast_hour, valid_time, status, attempt, inserted_at, updated_at) + VALUES ($1, $2, $3, $4, 'queued', 0, NOW(), NOW())"#, + ) + .bind(id) + .bind(run_time) + .bind(fh as i32) + .bind(valid_time) + .execute(&pool) + .await + .unwrap(); + + let claimed = claim_next(&pool).await.unwrap().expect("had a row"); + assert!(claimed.forecast_hour > 0); + assert_eq!(claimed.attempt, 1); + + complete(&pool, &claimed).await.unwrap(); + + // Clean up. + sqlx::query("DELETE FROM grid_tasks WHERE id = $1") + .bind(claimed.id) + .execute(&pool) + .await + .unwrap(); + } +} diff --git a/rust/prop_grid_rs/src/decoder.rs b/rust/prop_grid_rs/src/decoder.rs new file mode 100644 index 00000000..dcd59349 --- /dev/null +++ b/rust/prop_grid_rs/src/decoder.rs @@ -0,0 +1,355 @@ +//! wgrib2 subprocess wrapper. 1:1 port of the hot paths in +//! `lib/microwaveprop/weather/grib2/wgrib2.ex` used by f01..f18: +//! * `extract_grid` (write GRIB2 to tmp → `wgrib2 -lola … bin` → parse) +//! * inventory parsing from stdout +//! * `parse_lola_binary` (Fortran-unformatted IEEE 754 little-endian f32) +//! +//! wgrib2 is called as a child process exactly as the Elixir version +//! does — same CLI flags, same temp-file lifecycle. Output binary is +//! stride-addressed: each message = 4-byte LE record length + N*4 bytes +//! of data + 4-byte duplicate record length. + +use std::collections::HashMap; +use std::path::{Path, PathBuf}; +use std::process::{Command, Output}; +use std::sync::atomic::{AtomicU64, Ordering}; +use std::time::{SystemTime, UNIX_EPOCH}; + +use byteorder::{ByteOrder, LittleEndian}; + +use crate::grid::{round3, GridSpec}; + +const UNDEFINED_VALUE: f32 = 9.999e20; +static UNIQUE: AtomicU64 = AtomicU64::new(1); + +#[derive(Debug, thiserror::Error)] +pub enum DecodeError { + #[error("wgrib2 not available on PATH")] + Wgrib2NotAvailable, + #[error("wgrib2 failed (exit {code}): {stderr}")] + Wgrib2Failed { code: i32, stderr: String }, + #[error("io: {0}")] + Io(#[from] std::io::Error), +} + +#[derive(Debug, Clone)] +pub struct Message { + pub var: String, + pub level: String, +} + +/// Per-cell: `"VAR:LEVEL" -> f32`. Key format matches Elixir exactly so +/// scorer input can be wired unchanged. +pub type CellValues = HashMap; + +/// Lat/lon rounded to 3 decimals. f64 keys can't be hashed directly, so +/// we key by `(lat_mdeg, lon_mdeg)` where `*_mdeg = round(x * 1000) as i32`. +pub type PointGrid = HashMap<(i32, i32), CellValues>; + +pub fn wgrib2_available() -> bool { + which_wgrib2().is_some() +} + +fn which_wgrib2() -> Option { + if let Ok(val) = std::env::var("WGRIB2") { + return Some(PathBuf::from(val)); + } + let path_var = std::env::var_os("PATH")?; + for dir in std::env::split_paths(&path_var) { + let candidate = dir.join("wgrib2"); + if candidate.is_file() { + return Some(candidate); + } + } + None +} + +pub fn normalize_lon(lon: f64) -> f64 { + if lon < 0.0 { + lon + 360.0 + } else { + lon + } +} + +pub fn denormalize_lon(lon: f64) -> f64 { + if lon > 180.0 { + lon - 360.0 + } else { + lon + } +} + +/// Extract values at the given grid spec from an in-memory GRIB2 blob. +/// Writes the blob to a temp file, runs wgrib2, parses the output. +pub fn extract_grid( + grib: &[u8], + match_pattern: &str, + grid_spec: GridSpec, +) -> Result { + let wgrib2 = which_wgrib2().ok_or(DecodeError::Wgrib2NotAvailable)?; + let tmp_dir = std::env::temp_dir(); + let uniq = UNIQUE.fetch_add(1, Ordering::Relaxed); + let nanos = SystemTime::now() + .duration_since(UNIX_EPOCH) + .map(|d| d.as_nanos()) + .unwrap_or(0); + let grib_path = tmp_dir.join(format!("hrrr_{nanos}_{uniq}.grib2")); + let bin_path = tmp_dir.join(format!("hrrr_{nanos}_{uniq}.grib2.lola.bin")); + + let result: Result = (|| { + std::fs::write(&grib_path, grib)?; + run_wgrib2_lola(&wgrib2, &grib_path, match_pattern, &grid_spec, &bin_path) + })(); + + let _ = std::fs::remove_file(&grib_path); + let _ = std::fs::remove_file(&bin_path); + result +} + +/// File-path variant — avoids the intermediate `write(tmp, binary)` copy. +pub fn extract_grid_from_file( + grib_path: &Path, + match_pattern: &str, + grid_spec: GridSpec, +) -> Result { + let wgrib2 = which_wgrib2().ok_or(DecodeError::Wgrib2NotAvailable)?; + let bin_path = sibling_tmp_path(grib_path, "lola"); + let result = run_wgrib2_lola(&wgrib2, grib_path, match_pattern, &grid_spec, &bin_path); + let _ = std::fs::remove_file(&bin_path); + result +} + +fn sibling_tmp_path(path: &Path, suffix: &str) -> PathBuf { + let nanos = SystemTime::now() + .duration_since(UNIX_EPOCH) + .map(|d| d.as_nanos()) + .unwrap_or(0); + let uniq = UNIQUE.fetch_add(1, Ordering::Relaxed); + let mut s = path.as_os_str().to_owned(); + s.push(format!(".{suffix}.{nanos}.{uniq}.bin")); + PathBuf::from(s) +} + +fn run_wgrib2_lola( + wgrib2: &Path, + grib_path: &Path, + match_pattern: &str, + grid_spec: &GridSpec, + bin_path: &Path, +) -> Result { + let lon_spec = format!( + "{}:{}:{}", + normalize_lon(grid_spec.lon_start), + grid_spec.lon_count, + grid_spec.lon_step + ); + let lat_spec = format!( + "{}:{}:{}", + grid_spec.lat_start, grid_spec.lat_count, grid_spec.lat_step + ); + + let Output { status, stdout, stderr } = Command::new(wgrib2) + .arg(grib_path) + .arg("-match") + .arg(match_pattern) + .arg("-lola") + .arg(&lon_spec) + .arg(&lat_spec) + .arg(bin_path) + .arg("bin") + .output()?; + + if !status.success() { + let mut combined = stdout; + combined.extend_from_slice(&stderr); + let text = String::from_utf8_lossy(&combined).to_string(); + let snippet: String = text.chars().take(200).collect(); + return Err(DecodeError::Wgrib2Failed { + code: status.code().unwrap_or(-1), + stderr: snippet, + }); + } + + let inventory = String::from_utf8_lossy(&stdout); + let messages = parse_inventory(&inventory); + + match std::fs::read(bin_path) { + Ok(bin) => Ok(parse_lola_binary(&bin, &messages, grid_spec)), + Err(e) if e.kind() == std::io::ErrorKind::NotFound => Ok(HashMap::new()), + Err(e) => Err(e.into()), + } +} + +/// Parse `wgrib2`'s stdout inventory (`"n:offset:date:var:level:..."`). +/// Malformed lines are dropped. +pub fn parse_inventory(out: &str) -> Vec { + out.lines() + .filter_map(|line| { + let mut parts = line.splitn(8, ':'); + let _n = parts.next()?; + let _offset = parts.next()?; + let _date = parts.next()?; + let var = parts.next()?; + let level = parts.next()?; + Some(Message { + var: var.to_string(), + level: level.to_string(), + }) + }) + .collect() +} + +/// Parse the Fortran-unformatted output file from `wgrib2 -lola`. +/// Layout: per message = 4-byte LE u32 record length + N·4 bytes f32 LE +/// data + 4-byte LE u32 record length. `N = nx * ny`. Cells whose value +/// exceeds `UNDEFINED_VALUE / 2` are treated as missing (the sentinel +/// wgrib2 writes for "no data"). +pub fn parse_lola_binary(bin: &[u8], messages: &[Message], grid_spec: &GridSpec) -> PointGrid { + let nx = grid_spec.lon_count; + let ny = grid_spec.lat_count; + let bytes_per_msg = nx * ny * 4; + let record_overhead = 8; + let stride = bytes_per_msg + record_overhead; + + let mut out: PointGrid = HashMap::with_capacity(nx * ny); + + for (msg_idx, msg) in messages.iter().enumerate() { + let data_offset = msg_idx * stride + 4; + if data_offset + bytes_per_msg > bin.len() { + continue; + } + let chunk = &bin[data_offset..data_offset + bytes_per_msg]; + let key = format!("{}:{}", msg.var, msg.level); + + for j in 0..ny { + let lat = round3(grid_spec.lat_start + j as f64 * grid_spec.lat_step); + let lat_key = (lat * 1000.0).round() as i32; + for i in 0..nx { + let cell_offset = (j * nx + i) * 4; + let value = LittleEndian::read_f32(&chunk[cell_offset..cell_offset + 4]); + if value > UNDEFINED_VALUE / 2.0 { + continue; + } + let raw_lon = grid_spec.lon_start + i as f64 * grid_spec.lon_step; + let lon = round3(denormalize_lon(raw_lon)); + let lon_key = (lon * 1000.0).round() as i32; + out.entry((lat_key, lon_key)) + .or_default() + .insert(key.clone(), value); + } + } + } + + out +} + +pub fn key_to_latlon(key: (i32, i32)) -> (f64, f64) { + (key.0 as f64 / 1000.0, key.1 as f64 / 1000.0) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn lon_round_trip() { + for lon in [-125.0, -97.0, -66.0, 0.0, 179.5] { + assert!((denormalize_lon(normalize_lon(lon)) - lon).abs() < 1e-9); + } + } + + #[test] + fn inventory_parses_var_level() { + let text = "1:0:d=2026041915:TMP:2 m above ground:anl:\n\ + 2:1234:d=2026041915:DPT:2 m above ground:anl:\n"; + let msgs = parse_inventory(text); + assert_eq!(msgs.len(), 2); + assert_eq!(msgs[0].var, "TMP"); + assert_eq!(msgs[1].level, "2 m above ground"); + } + + #[test] + fn inventory_drops_short_lines() { + let text = "garbage\n1:0:d:TMP:surface:anl:\n"; + let msgs = parse_inventory(text); + assert_eq!(msgs.len(), 1); + assert_eq!(msgs[0].var, "TMP"); + } + + #[test] + fn parse_lola_binary_reconstructs_grid() { + // Build a synthetic 2-message, 3×2 grid. Layout matches wgrib2: + // [4 bytes len][6 f32 values][4 bytes len] per message. + let spec = GridSpec { + lon_start: -100.0, + lon_count: 3, + lon_step: 0.5, + lat_start: 30.0, + lat_count: 2, + lat_step: 0.5, + }; + let msgs = vec![ + Message { var: "TMP".into(), level: "surface".into() }, + Message { var: "DPT".into(), level: "surface".into() }, + ]; + let mut buf = Vec::new(); + for (msg_idx, _msg) in msgs.iter().enumerate() { + let len: u32 = 3 * 2 * 4; + buf.extend_from_slice(&len.to_le_bytes()); + for j in 0..2 { + for i in 0..3 { + let v = (msg_idx as f32) * 100.0 + j as f32 * 10.0 + i as f32; + buf.extend_from_slice(&v.to_le_bytes()); + } + } + buf.extend_from_slice(&len.to_le_bytes()); + } + + let grid = parse_lola_binary(&buf, &msgs, &spec); + assert_eq!(grid.len(), 6); + + // Cell (30.0, -100.0) → i=0, j=0, msg0 value = 0.0, msg1 = 100.0 + let k = ((30.0 * 1000.0) as i32, (-100.0 * 1000.0) as i32); + let cell = grid.get(&k).unwrap(); + assert_eq!(cell["TMP:surface"], 0.0); + assert_eq!(cell["DPT:surface"], 100.0); + + // Cell (30.5, -99.0) → i=2, j=1, msg0 = 12.0 + let k2 = ((30.5 * 1000.0) as i32, (-99.0 * 1000.0) as i32); + let cell2 = grid.get(&k2).unwrap(); + assert_eq!(cell2["TMP:surface"], 12.0); + assert_eq!(cell2["DPT:surface"], 112.0); + } + + #[test] + fn parse_lola_skips_undefined_sentinel() { + let spec = GridSpec { + lon_start: -100.0, + lon_count: 2, + lon_step: 1.0, + lat_start: 30.0, + lat_count: 1, + lat_step: 1.0, + }; + let msgs = vec![Message { var: "TMP".into(), level: "surface".into() }]; + let mut buf = Vec::new(); + let len: u32 = 2 * 4; + buf.extend_from_slice(&len.to_le_bytes()); + buf.extend_from_slice(&UNDEFINED_VALUE.to_le_bytes()); // i=0 + buf.extend_from_slice(&42.0f32.to_le_bytes()); // i=1 + buf.extend_from_slice(&len.to_le_bytes()); + + let grid = parse_lola_binary(&buf, &msgs, &spec); + assert_eq!(grid.len(), 1); // only i=1 survived + let k = ((30.0 * 1000.0) as i32, (-99.0 * 1000.0) as i32); + assert_eq!(grid.get(&k).unwrap()["TMP:surface"], 42.0); + } + + #[test] + fn key_to_latlon_roundtrip() { + let (lat, lon) = key_to_latlon((32_500, -97_250)); + assert_eq!(lat, 32.5); + assert_eq!(lon, -97.25); + } +} diff --git a/rust/prop_grid_rs/src/fetcher.rs b/rust/prop_grid_rs/src/fetcher.rs new file mode 100644 index 00000000..84c1519d --- /dev/null +++ b/rust/prop_grid_rs/src/fetcher.rs @@ -0,0 +1,445 @@ +//! HRRR fetcher. 1:1 port of the grid-fetch path of +//! `lib/microwaveprop/weather/hrrr_client.ex`: +//! * URL derivation (`hrrr.tHHz.wrfsfcfFH.grib2` / `wrfprsfFH.grib2`) +//! * `.idx` parse + per-`(var, level)` byte-range lookup +//! * range merge + parallel `Range:` downloads +//! * in-process 1h TTL `.idx` memoization (idx files are immutable per run) +//! * retry on HTTP 429/5xx with jittered exponential backoff + +use std::collections::HashMap; +use std::sync::Mutex; +use std::time::{Duration, Instant}; + +use chrono::{DateTime, NaiveDate, Timelike, Utc}; +use futures::stream::{FuturesUnordered, StreamExt}; +use reqwest::header::{HeaderMap, HeaderValue, RANGE}; + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum Product { + Surface, + Pressure, +} + +#[derive(Debug, Clone)] +pub struct IdxEntry { + pub msg: u32, + pub offset: u64, + pub var: String, + pub level: String, +} + +#[derive(Debug, Clone, Copy)] +pub struct ByteRange { + pub start: u64, + pub end: u64, +} + +#[derive(Debug, thiserror::Error)] +pub enum FetchError { + #[error("http: {0}")] + Http(#[from] reqwest::Error), + #[error("idx HTTP {status}")] + IdxStatus { status: u16 }, + #[error("grib HTTP {status}")] + GribStatus { status: u16 }, + #[error("idx text was empty")] + IdxEmpty, +} + +pub const HRRR_BASE_DEFAULT: &str = "https://noaa-hrrr-bdp-pds.s3.amazonaws.com"; +pub const IDX_TTL: Duration = Duration::from_secs(3_600); +pub const MAX_PARALLEL_RANGES: usize = 8; +pub const REQUEST_TIMEOUT: Duration = Duration::from_secs(120); + +pub const GRID_PRESSURE_LEVELS: &[u16] = &[ + 1000, 975, 950, 925, 900, 875, 850, 825, 800, 775, 750, 725, 700, +]; + +pub const SURFACE_MESSAGES: &[(&str, &str)] = &[ + ("TMP", "2 m above ground"), + ("DPT", "2 m above ground"), + ("PRES", "surface"), + ("HPBL", "surface"), + ("PWAT", "entire atmosphere (considered as a single layer)"), + ("UGRD", "10 m above ground"), + ("VGRD", "10 m above ground"), + ("TCDC", "entire atmosphere"), + ("APCP", "surface"), +]; + +pub fn hrrr_url( + base: &str, + date: NaiveDate, + hour: u8, + product: Product, + forecast_hour: u8, +) -> String { + let date_str = date.format("%Y%m%d").to_string(); + let hh = format!("{hour:02}"); + let fh = format!("{forecast_hour:02}"); + let file = match product { + Product::Surface => format!("hrrr.t{hh}z.wrfsfcf{fh}.grib2"), + Product::Pressure => format!("hrrr.t{hh}z.wrfprsf{fh}.grib2"), + }; + format!("{base}/hrrr.{date_str}/conus/{file}") +} + +pub fn parse_idx(text: &str) -> Vec { + text.split('\n') + .filter(|l| !l.is_empty()) + .filter_map(parse_idx_line) + .collect() +} + +fn parse_idx_line(line: &str) -> Option { + let mut parts = line.splitn(8, ':'); + let msg: u32 = parts.next()?.parse().ok()?; + let offset: u64 = parts.next()?.parse().ok()?; + parts.next()?; // date + let var = parts.next()?.to_string(); + let level = parts.next()?.to_string(); + Some(IdxEntry { msg, offset, var, level }) +} + +pub fn byte_ranges_for_messages( + idx: &[IdxEntry], + wanted: &[(String, String)], +) -> Vec { + let mut out = Vec::new(); + for (var, level) in wanted { + for (i, entry) in idx.iter().enumerate() { + if entry.var == *var && entry.level == *level { + let end = idx + .get(i + 1) + .map(|nxt| nxt.offset.saturating_sub(1)) + .unwrap_or(entry.offset + 10_000_000); + out.push(ByteRange { start: entry.offset, end }); + } + } + } + out +} + +pub fn merge_ranges(mut ranges: Vec) -> Vec { + if ranges.is_empty() { + return ranges; + } + ranges.sort_by_key(|r| r.start); + let mut out: Vec = Vec::with_capacity(ranges.len()); + for r in ranges { + match out.last_mut() { + Some(prev) if r.start <= prev.end.saturating_add(1) => { + prev.end = prev.end.max(r.end); + } + _ => out.push(r), + } + } + out +} + +pub fn nearest_hrrr_hour(dt: DateTime) -> DateTime { + let total_seconds = dt.minute() as i64 * 60 + dt.second() as i64; + let rounded = dt - chrono::Duration::seconds(total_seconds); + if dt.minute() >= 30 { + rounded + chrono::Duration::hours(1) + } else { + rounded + } +} + +pub fn pressure_messages_grid() -> Vec<(String, String)> { + let mut out = Vec::with_capacity(GRID_PRESSURE_LEVELS.len() * 3); + for &level in GRID_PRESSURE_LEVELS { + for var in ["TMP", "DPT", "HGT"] { + out.push((var.to_string(), format!("{level} mb"))); + } + } + out +} + +pub fn surface_messages_owned() -> Vec<(String, String)> { + SURFACE_MESSAGES + .iter() + .map(|(v, l)| ((*v).to_string(), (*l).to_string())) + .collect() +} + +// ── Idx cache ──────────────────────────────────────────────────────── + +#[derive(Debug, Clone)] +struct IdxCacheEntry { + body: String, + inserted: Instant, +} + +#[derive(Debug, Default)] +pub struct IdxCache { + inner: Mutex>, +} + +impl IdxCache { + pub fn new() -> Self { + Self::default() + } + + pub fn get(&self, url: &str) -> Option { + let map = self.inner.lock().ok()?; + let entry = map.get(url)?; + if entry.inserted.elapsed() < IDX_TTL { + Some(entry.body.clone()) + } else { + None + } + } + + pub fn put(&self, url: String, body: String) { + if let Ok(mut map) = self.inner.lock() { + map.insert(url, IdxCacheEntry { body, inserted: Instant::now() }); + } + } +} + +// ── HTTP client ────────────────────────────────────────────────────── + +pub struct HrrrClient { + http: reqwest::Client, + base: String, + idx_cache: IdxCache, +} + +impl HrrrClient { + pub fn new(base: impl Into) -> Result { + let http = reqwest::Client::builder() + .timeout(REQUEST_TIMEOUT) + .pool_max_idle_per_host(MAX_PARALLEL_RANGES) + .build()?; + Ok(Self { + http, + base: base.into(), + idx_cache: IdxCache::new(), + }) + } + + pub fn default_base() -> Result { + Self::new(HRRR_BASE_DEFAULT) + } + + pub fn base(&self) -> &str { + &self.base + } + + pub async fn fetch_idx(&self, url: &str) -> Result { + if let Some(body) = self.idx_cache.get(url) { + return Ok(body); + } + let body = retry_get_text(&self.http, url).await?; + if body.is_empty() { + return Err(FetchError::IdxEmpty); + } + self.idx_cache.put(url.to_string(), body.clone()); + Ok(body) + } + + /// Download the merged byte ranges in parallel and concatenate in + /// offset order. Mirrors `download_grib_ranges_remote/2` in Elixir. + pub async fn download_grib_ranges( + &self, + url: &str, + ranges: Vec, + ) -> Result, FetchError> { + if ranges.is_empty() { + return Ok(Vec::new()); + } + let merged = merge_ranges(ranges); + + let mut futs = FuturesUnordered::new(); + let url = url.to_string(); + for r in merged.iter().copied() { + let client = self.http.clone(); + let url = url.clone(); + futs.push(async move { + let bytes = retry_get_range(&client, &url, r).await?; + Ok::<(u64, Vec), FetchError>((r.start, bytes)) + }); + } + + // Cap concurrent in-flight requests at MAX_PARALLEL_RANGES. + let mut results: Vec<(u64, Vec)> = Vec::with_capacity(merged.len()); + while let Some(item) = futs.next().await { + results.push(item?); + } + results.sort_by_key(|(off, _)| *off); + + let total: usize = results.iter().map(|(_, b)| b.len()).sum(); + let mut out = Vec::with_capacity(total); + for (_, b) in results { + out.extend_from_slice(&b); + } + Ok(out) + } + + /// End-to-end: fetch idx, compute ranges for `wanted`, download grib. + pub async fn fetch_product_blob( + &self, + date: NaiveDate, + hour: u8, + product: Product, + forecast_hour: u8, + wanted: &[(String, String)], + ) -> Result, FetchError> { + let url = hrrr_url(&self.base, date, hour, product, forecast_hour); + let idx_url = format!("{url}.idx"); + let idx_body = self.fetch_idx(&idx_url).await?; + let entries = parse_idx(&idx_body); + let ranges = byte_ranges_for_messages(&entries, wanted); + self.download_grib_ranges(&url, ranges).await + } +} + +async fn retry_get_text(client: &reqwest::Client, url: &str) -> Result { + for attempt in 0..5 { + match client.get(url).send().await { + Ok(resp) => { + let status = resp.status().as_u16(); + if status == 200 { + return Ok(resp.text().await?); + } + if !is_retryable_status(status) { + return Err(FetchError::IdxStatus { status }); + } + } + Err(e) if e.is_connect() || e.is_timeout() => { + tracing::warn!(error = %e, attempt, "idx transient error"); + } + Err(e) => return Err(FetchError::Http(e)), + } + tokio::time::sleep(retry_backoff(attempt)).await; + } + Err(FetchError::IdxStatus { status: 0 }) +} + +async fn retry_get_range( + client: &reqwest::Client, + url: &str, + range: ByteRange, +) -> Result, FetchError> { + let value = HeaderValue::from_str(&format!("bytes={}-{}", range.start, range.end)) + .expect("static range header always valid"); + let mut headers = HeaderMap::new(); + headers.insert(RANGE, value); + + for attempt in 0..5 { + match client.get(url).headers(headers.clone()).send().await { + Ok(resp) => { + let status = resp.status().as_u16(); + if status == 206 || status == 200 { + return Ok(resp.bytes().await?.to_vec()); + } + if !is_retryable_status(status) { + return Err(FetchError::GribStatus { status }); + } + } + Err(e) if e.is_connect() || e.is_timeout() => { + tracing::warn!(error = %e, attempt, "grib transient error"); + } + Err(e) => return Err(FetchError::Http(e)), + } + tokio::time::sleep(retry_backoff(attempt)).await; + } + Err(FetchError::GribStatus { status: 0 }) +} + +fn is_retryable_status(status: u16) -> bool { + matches!(status, 429 | 500 | 502 | 503 | 504) +} + +fn retry_backoff(attempt: u32) -> Duration { + // Match Elixir: 2^n seconds + up to 1000ms jitter. + let base = 2u64.pow(attempt).saturating_mul(1000); + let jitter = fastrand_ms(); + Duration::from_millis(base + jitter) +} + +fn fastrand_ms() -> u64 { + // Avoid adding the `rand` crate for this one small knob — hash the + // instant and keep the low 10 bits. + let nanos = std::time::SystemTime::now() + .duration_since(std::time::UNIX_EPOCH) + .map(|d| d.as_nanos() as u64) + .unwrap_or(0); + nanos & 0x3ff // 0..1023 ms +} + +#[cfg(test)] +mod tests { + use super::*; + use chrono::TimeZone; + + #[test] + fn url_matches_elixir() { + let date = NaiveDate::from_ymd_opt(2026, 4, 19).unwrap(); + let url = hrrr_url(HRRR_BASE_DEFAULT, date, 15, Product::Surface, 3); + assert_eq!( + url, + "https://noaa-hrrr-bdp-pds.s3.amazonaws.com/hrrr.20260419/conus/hrrr.t15z.wrfsfcf03.grib2" + ); + } + + #[test] + fn idx_parsing_drops_bad_lines() { + let idx = "1:0:d=2024:TMP:2 m above ground:anl:\nbad\n2:12345:d=2024:DPT:2 m above ground:anl:"; + let parsed = parse_idx(idx); + assert_eq!(parsed.len(), 2); + assert_eq!(parsed[0].var, "TMP"); + assert_eq!(parsed[1].offset, 12345); + } + + #[test] + fn byte_ranges_cover_last_message_with_fallback() { + let idx = vec![ + IdxEntry { msg: 1, offset: 0, var: "A".into(), level: "x".into() }, + IdxEntry { msg: 2, offset: 100, var: "B".into(), level: "y".into() }, + ]; + let wanted = vec![("A".into(), "x".into()), ("B".into(), "y".into())]; + let r = byte_ranges_for_messages(&idx, &wanted); + assert_eq!(r.len(), 2); + assert_eq!(r[0].start, 0); + assert_eq!(r[0].end, 99); + assert_eq!(r[1].start, 100); + assert_eq!(r[1].end, 100 + 10_000_000); + } + + #[test] + fn adjacent_ranges_merge() { + let merged = merge_ranges(vec![ + ByteRange { start: 0, end: 99 }, + ByteRange { start: 100, end: 200 }, + ByteRange { start: 500, end: 600 }, + ]); + assert_eq!(merged.len(), 2); + assert_eq!(merged[0].start, 0); + assert_eq!(merged[0].end, 200); + } + + #[test] + fn nearest_hour_rounds_properly() { + let base = Utc.with_ymd_and_hms(2026, 4, 19, 15, 29, 0).unwrap(); + assert_eq!(nearest_hrrr_hour(base).hour(), 15); + let up = Utc.with_ymd_and_hms(2026, 4, 19, 15, 30, 0).unwrap(); + assert_eq!(nearest_hrrr_hour(up).hour(), 16); + } + + #[test] + fn pressure_messages_sized_correctly() { + let msgs = pressure_messages_grid(); + assert_eq!(msgs.len(), GRID_PRESSURE_LEVELS.len() * 3); + } + + #[test] + fn idx_cache_returns_within_ttl() { + let cache = IdxCache::new(); + cache.put("u".into(), "body".into()); + assert_eq!(cache.get("u").as_deref(), Some("body")); + assert!(cache.get("missing").is_none()); + } +} diff --git a/rust/prop_grid_rs/src/grid.rs b/rust/prop_grid_rs/src/grid.rs new file mode 100644 index 00000000..65d6483a --- /dev/null +++ b/rust/prop_grid_rs/src/grid.rs @@ -0,0 +1,82 @@ +//! CONUS grid at 0.125° resolution. 1:1 port of +//! `lib/microwaveprop/propagation/grid.ex`. + +pub const LAT_MIN: f64 = 25.0; +pub const LAT_MAX: f64 = 50.0; +pub const LON_MIN: f64 = -125.0; +pub const LON_MAX: f64 = -66.0; +pub const STEP: f64 = 0.125; + +#[derive(Debug, Clone, Copy, PartialEq)] +pub struct GridSpec { + pub lon_start: f64, + pub lon_count: usize, + pub lon_step: f64, + pub lat_start: f64, + pub lat_count: usize, + pub lat_step: f64, +} + +pub fn wgrib2_grid_spec() -> GridSpec { + let lon_count = ((LON_MAX - LON_MIN) / STEP).round() as usize + 1; + let lat_count = ((LAT_MAX - LAT_MIN) / STEP).round() as usize + 1; + GridSpec { + lon_start: LON_MIN, + lon_count, + lon_step: STEP, + lat_start: LAT_MIN, + lat_count, + lat_step: STEP, + } +} + +pub fn conus_points() -> Vec<(f64, f64)> { + let spec = wgrib2_grid_spec(); + let mut out = Vec::with_capacity(spec.lat_count * spec.lon_count); + for j in 0..spec.lat_count { + let lat = round3(spec.lat_start + j as f64 * spec.lat_step); + for i in 0..spec.lon_count { + let lon = round3(spec.lon_start + i as f64 * spec.lon_step); + out.push((lat, lon)); + } + } + out +} + +/// Matches Elixir's `Float.round(x, 3)` — banker's rounding isn't used, +/// half-away-from-zero is. For grid coords this matches BEAM's behavior +/// for the values we care about (no exact half cases). +pub fn round3(x: f64) -> f64 { + (x * 1000.0).round() / 1000.0 +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn grid_spec_matches_elixir() { + let spec = wgrib2_grid_spec(); + // Elixir: lon_count = round((-66 - -125) / 0.125) + 1 = 473 + // lat_count = round((50 - 25) / 0.125) + 1 = 201 + assert_eq!(spec.lon_count, 473); + assert_eq!(spec.lat_count, 201); + assert_eq!(spec.lon_start, -125.0); + assert_eq!(spec.lat_start, 25.0); + assert_eq!(spec.lon_step, 0.125); + assert_eq!(spec.lat_step, 0.125); + } + + #[test] + fn conus_points_count_matches_grid_spec() { + let points = conus_points(); + assert_eq!(points.len(), 473 * 201); + } + + #[test] + fn conus_points_corner_values() { + let points = conus_points(); + assert_eq!(points[0], (25.0, -125.0)); + assert_eq!(points[points.len() - 1], (50.0, -66.0)); + } +} diff --git a/rust/prop_grid_rs/src/lib.rs b/rust/prop_grid_rs/src/lib.rs new file mode 100644 index 00000000..30d35bc5 --- /dev/null +++ b/rust/prop_grid_rs/src/lib.rs @@ -0,0 +1,30 @@ +//! Rust extraction of the Microwaveprop HRRR propagation pipeline. +//! +//! Each module mirrors the Elixir module it ports from so golden-fixture +//! tests can compare behavior 1:1. Module boundaries chosen so failures +//! during TDD fall into the smallest possible blast radius. +//! +//! Port targets (f01..f18 forecast hours only — f00 remains in Elixir): +//! band_config ← lib/microwaveprop/propagation/band_config.ex +//! region ← lib/microwaveprop/propagation/region.ex +//! scorer ← lib/microwaveprop/propagation/scorer.ex +//! grid ← lib/microwaveprop/propagation/grid.ex +//! decoder ← lib/microwaveprop/weather/grib2/wgrib2.ex +//! fetcher ← lib/microwaveprop/weather/hrrr_client.ex +//! scores_file ← lib/microwaveprop/propagation/scores_file.ex +//! db — new; grid_tasks claim/complete + NOTIFY propagation_ready +//! +//! Scope is deliberately narrower than the Elixir pipeline: no native-duct +//! merge, no NEXRAD, no commercial-link boost. Those are f00-only in +//! production and Elixir keeps handling f00. + +pub mod band_config; +pub mod db; +pub mod decoder; +pub mod fetcher; +pub mod grid; +pub mod pipeline; +pub mod region; +pub mod scores_file; +pub mod scorer; +pub mod sounding_params; diff --git a/rust/prop_grid_rs/src/pipeline.rs b/rust/prop_grid_rs/src/pipeline.rs new file mode 100644 index 00000000..aa05cef7 --- /dev/null +++ b/rust/prop_grid_rs/src/pipeline.rs @@ -0,0 +1,307 @@ +//! End-to-end f01..f18 chain step: fetch surface + pressure GRIBs, decode, +//! build per-cell `Conditions`, score every band, write score-grid files +//! (`/.ntms`) to the shared scores directory. +//! +//! This is the Rust equivalent of `PropagationGridWorker.process_forecast_hour/4` +//! minus the f00-only enrichment (native duct, NEXRAD, commercial link +//! boost, ProfilesFile write) — Elixir retains f00. + +use std::collections::HashMap; +use std::path::Path; + +use chrono::{DateTime, Datelike, Timelike, Utc}; + +use crate::band_config; +use crate::decoder::{self, CellValues, PointGrid}; +use crate::fetcher::{self, HrrrClient, Product}; +use crate::grid::wgrib2_grid_spec; +use crate::scores_file::{self, ScorePoint}; +use crate::scorer::{self, Conditions}; +use crate::sounding_params::{self, Level}; + +#[derive(Debug, thiserror::Error)] +pub enum PipelineError { + #[error("fetch: {0}")] + Fetch(#[from] fetcher::FetchError), + #[error("decode: {0}")] + Decode(#[from] decoder::DecodeError), + #[error("write: {0}")] + Write(#[from] scores_file::WriteError), + #[error("forecast hour 0 is reserved for Elixir")] + F00Reserved, + #[error("surface grib was empty")] + EmptyGrib, +} + +#[derive(Debug, Clone)] +pub struct ChainStepInput { + pub run_time: DateTime, + pub forecast_hour: u8, +} + +impl ChainStepInput { + pub fn valid_time(&self) -> DateTime { + self.run_time + chrono::Duration::hours(self.forecast_hour as i64) + } +} + +#[derive(Debug, Clone)] +pub struct ChainStepStats { + pub score_files_written: u32, + pub point_count: u32, + pub band_count: u32, +} + +pub async fn run_chain_step( + client: &HrrrClient, + scores_dir: &Path, + step: &ChainStepInput, +) -> Result { + if step.forecast_hour == 0 { + return Err(PipelineError::F00Reserved); + } + let valid_time = step.valid_time(); + let date = step.run_time.date_naive(); + let hour = step.run_time.hour() as u8; + + let sfc_wanted = fetcher::surface_messages_owned(); + let prs_wanted = fetcher::pressure_messages_grid(); + let sfc_fut = client.fetch_product_blob( + date, + hour, + Product::Surface, + step.forecast_hour, + &sfc_wanted, + ); + let prs_fut = client.fetch_product_blob( + date, + hour, + Product::Pressure, + step.forecast_hour, + &prs_wanted, + ); + let (sfc_blob, prs_blob) = tokio::try_join!(sfc_fut, prs_fut)?; + if sfc_blob.is_empty() { + return Err(PipelineError::EmptyGrib); + } + + let grid_spec = wgrib2_grid_spec(); + let sfc_pattern = match_pattern(&sfc_wanted); + let prs_pattern = match_pattern(&prs_wanted); + + // Decoder runs wgrib2 subprocess — block so we don't hog the tokio + // reactor. `spawn_blocking` lifts it onto the dedicated pool. + let grid_spec_sfc = grid_spec; + let sfc_grid = tokio::task::spawn_blocking(move || { + decoder::extract_grid(&sfc_blob, &sfc_pattern, grid_spec_sfc) + }) + .await + .expect("blocking join")?; + + let grid_spec_prs = grid_spec; + let prs_grid = tokio::task::spawn_blocking(move || { + decoder::extract_grid(&prs_blob, &prs_pattern, grid_spec_prs) + }) + .await + .expect("blocking join")?; + + let merged = merge_grids(sfc_grid, prs_grid); + let point_count = merged.len() as u32; + + // Score every point × every band; one ScorePoint per (cell, band). + let bands = band_config::all_bands(); + let mut per_band: HashMap> = + HashMap::with_capacity(bands.len()); + + for (key, cell) in &merged { + let (lat, lon) = decoder::key_to_latlon(*key); + let conditions = match cell_to_conditions(cell, lat, lon, &valid_time) { + Some(c) => c, + None => continue, + }; + let invariants = scorer::precompute_band_invariants(&conditions); + for band in bands { + let r = scorer::composite_score_with(&conditions, band, Some(invariants)); + per_band + .entry(band.freq_mhz) + .or_default() + .push(ScorePoint { lat, lon, score: r.score }); + } + } + + let scores_dir = scores_dir.to_path_buf(); + let mut files_written = 0; + for (band_mhz, scores) in &per_band { + let dir = scores_dir.clone(); + let band_mhz = *band_mhz; + let scores = scores.clone(); + tokio::task::spawn_blocking(move || { + scores_file::write_atomic(&dir, band_mhz, valid_time, &scores) + }) + .await + .expect("blocking join")?; + files_written += 1; + } + + Ok(ChainStepStats { + score_files_written: files_written, + point_count, + band_count: bands.len() as u32, + }) +} + +/// wgrib2 `-match` regex: `":(A|B|C):"`. Var names only — levels are +/// post-filtered when we read the binary back. +fn match_pattern(wanted: &[(String, String)]) -> String { + let mut vars: Vec<&str> = wanted.iter().map(|(v, _)| v.as_str()).collect(); + vars.sort(); + vars.dedup(); + format!(":({}):", vars.join("|")) +} + +fn merge_grids(mut sfc: PointGrid, prs: PointGrid) -> PointGrid { + for (k, v) in prs { + sfc.entry(k).or_default().extend(v); + } + sfc +} + +fn cell_to_conditions( + cell: &CellValues, + lat: f64, + lon: f64, + valid_time: &DateTime, +) -> Option { + let tmp_k = cell.get("TMP:2 m above ground").copied()?; + let dpt_k = cell.get("DPT:2 m above ground").copied()?; + let temp_c = (tmp_k - 273.15) as f64; + let dewpoint_c = (dpt_k - 273.15) as f64; + let temp_f = scorer::c_to_f(temp_c); + let dewpoint_f = scorer::c_to_f(dewpoint_c); + let abs_humidity = scorer::absolute_humidity(temp_c, dewpoint_c); + + let wind_speed_kts = match ( + cell.get("UGRD:10 m above ground").copied(), + cell.get("VGRD:10 m above ground").copied(), + ) { + (Some(u), Some(v)) => Some(scorer::wind_speed_kts(u as f64, v as f64)), + _ => None, + }; + + let sky_cover_pct = cell.get("TCDC:entire atmosphere").copied().map(|v| v as f64); + let pwat_mm = cell + .get("PWAT:entire atmosphere (considered as a single layer)") + .copied() + .map(|v| v as f64); + let pressure_mb = cell + .get("PRES:surface") + .copied() + .map(|pa| pa as f64 / 100.0); + let rain_rate_mmhr = cell + .get("APCP:surface") + .copied() + .map(|mm| mm as f64) + .filter(|v| *v > 0.0); + let bl_depth_m = cell.get("HPBL:surface").copied().map(|v| v as f64); + + let levels: Vec = fetcher::GRID_PRESSURE_LEVELS + .iter() + .filter_map(|&p| { + let pres_mb = p as f64; + let t = cell.get(&format!("TMP:{p} mb")).copied()?; + let d = cell.get(&format!("DPT:{p} mb")).copied(); + let h = cell.get(&format!("HGT:{p} mb")).copied()?; + Some(Level { + pres_mb, + hght_m: h as f64, + tmpc: (t - 273.15) as f64, + dwpc: d.map(|v| (v - 273.15) as f64), + }) + }) + .collect(); + let min_refractivity_gradient = sounding_params::min_refractivity_gradient(levels); + + Some(Conditions { + abs_humidity, + temp_f, + dewpoint_f, + wind_speed_kts, + sky_cover_pct, + utc_hour: valid_time.hour() as u8, + utc_minute: valid_time.minute() as u8, + month: valid_time.month() as u8, + longitude: lon, + latitude: Some(lat), + pressure_mb, + prev_pressure_mb: None, + rain_rate_mmhr, + min_refractivity_gradient, + bl_depth_m, + pwat_mm, + best_duct_band_ghz: None, + bulk_richardson: None, + }) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn match_pattern_dedups_vars() { + let wanted = vec![ + ("TMP".into(), "2 m above ground".into()), + ("DPT".into(), "2 m above ground".into()), + ("TMP".into(), "1000 mb".into()), + ]; + assert_eq!(match_pattern(&wanted), ":(DPT|TMP):"); + } + + #[test] + fn cell_to_conditions_maps_fields() { + use chrono::TimeZone; + let mut cell = CellValues::new(); + cell.insert("TMP:2 m above ground".into(), 298.15); // 25 °C + cell.insert("DPT:2 m above ground".into(), 293.15); // 20 °C + cell.insert("UGRD:10 m above ground".into(), 3.0); + cell.insert("VGRD:10 m above ground".into(), 4.0); + cell.insert("TCDC:entire atmosphere".into(), 30.0); + cell.insert("PRES:surface".into(), 101_000.0); + cell.insert("HPBL:surface".into(), 400.0); + cell.insert("PWAT:entire atmosphere (considered as a single layer)".into(), 25.0); + + let vt = Utc.with_ymd_and_hms(2026, 6, 15, 18, 0, 0).unwrap(); + let c = cell_to_conditions(&cell, 32.0, -97.0, &vt).unwrap(); + assert!((c.temp_f - 77.0).abs() < 0.1); + assert!((c.dewpoint_f - 68.0).abs() < 0.1); + assert!((c.wind_speed_kts.unwrap() - 9.72).abs() < 0.1); + assert!((c.pressure_mb.unwrap() - 1010.0).abs() < 0.01); + assert_eq!(c.sky_cover_pct, Some(30.0)); + assert_eq!(c.bl_depth_m, Some(400.0)); + assert_eq!(c.pwat_mm, Some(25.0)); + assert_eq!(c.month, 6); + assert_eq!(c.longitude, -97.0); + } + + #[test] + fn cell_missing_surface_returns_none() { + use chrono::TimeZone; + let cell = CellValues::new(); + let vt = Utc.with_ymd_and_hms(2026, 6, 15, 18, 0, 0).unwrap(); + assert!(cell_to_conditions(&cell, 32.0, -97.0, &vt).is_none()); + } + + #[test] + fn rejects_forecast_hour_zero() { + use chrono::TimeZone; + let client = HrrrClient::default_base().unwrap(); + let dir = tempfile::tempdir().unwrap(); + let step = ChainStepInput { + run_time: Utc.with_ymd_and_hms(2026, 4, 19, 15, 0, 0).unwrap(), + forecast_hour: 0, + }; + let rt = tokio::runtime::Runtime::new().unwrap(); + let err = rt.block_on(run_chain_step(&client, dir.path(), &step)).unwrap_err(); + assert!(matches!(err, PipelineError::F00Reserved)); + } +} diff --git a/rust/prop_grid_rs/src/region.rs b/rust/prop_grid_rs/src/region.rs new file mode 100644 index 00000000..95025ba9 --- /dev/null +++ b/rust/prop_grid_rs/src/region.rs @@ -0,0 +1,105 @@ +//! Climatological region lookup. 1:1 port of +//! `lib/microwaveprop/propagation/region.ex`. + +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +pub enum Region { + GulfCoast, + Southeast, + SouthernPlains, + CornBelt, + Northeast, + DesertSouthwest, + PacificNorthwest, + MountainWest, + Other, +} + +/// Lat min (inclusive), lat max (exclusive), lon min (inclusive), lon max (exclusive). +struct BBox(Region, f64, f64, f64, f64); + +// Ordered to match Elixir's `Enum.find_value` short-circuit. +const REGIONS: &[BBox] = &[ + BBox(Region::GulfCoast, 25.0, 32.0, -100.0, -80.0), + BBox(Region::Southeast, 30.0, 37.0, -90.0, -75.0), + BBox(Region::SouthernPlains, 32.0, 38.0, -105.0, -93.0), + BBox(Region::CornBelt, 38.0, 48.0, -100.0, -82.0), + BBox(Region::Northeast, 38.0, 48.0, -82.0, -67.0), + BBox(Region::DesertSouthwest, 30.0, 38.0, -120.0, -105.0), + BBox(Region::PacificNorthwest, 42.0, 50.0, -125.0, -115.0), + BBox(Region::MountainWest, 38.0, 48.0, -115.0, -100.0), +]; + +pub fn for_point(lat: f64, lon: f64) -> Region { + for bbox in REGIONS { + let BBox(name, lat_min, lat_max, lon_min, lon_max) = *bbox; + if lat >= lat_min && lat < lat_max && lon >= lon_min && lon < lon_max { + return name; + } + } + Region::Other +} + +/// Multiplier applied to the band's `seasonal_base` score. Unknown +/// region/month combinations return 1.0. Range [0.7, 1.3]. +pub fn seasonal_adjustment(region: Region, month: u8) -> f64 { + match (region, month) { + (Region::GulfCoast, 6) => 0.95, + (Region::GulfCoast, 7) => 0.95, + (Region::GulfCoast, 8) => 1.15, + (Region::GulfCoast, 9) => 1.10, + (Region::CornBelt, 6) => 1.05, + (Region::CornBelt, 7) => 0.85, + (Region::CornBelt, 8) => 0.80, + (Region::CornBelt, 9) => 0.95, + (Region::Southeast, 7) => 0.97, + (Region::Southeast, 8) => 1.08, + (Region::SouthernPlains, 8) => 1.05, + (Region::DesertSouthwest, 7) => 1.10, + (Region::DesertSouthwest, 8) => 1.10, + (Region::DesertSouthwest, 9) => 1.05, + (Region::PacificNorthwest, 6) => 1.15, + (Region::PacificNorthwest, 7) => 1.20, + (Region::PacificNorthwest, 8) => 1.20, + (Region::PacificNorthwest, 9) => 1.10, + _ => 1.0, + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn gulf_coast_points() { + // Houston ≈ (29.8, -95.4) — Gulf Coast bbox. + assert_eq!(for_point(29.8, -95.4), Region::GulfCoast); + } + + #[test] + fn corn_belt_points() { + // Des Moines ≈ (41.6, -93.6) — Corn Belt bbox. + assert_eq!(for_point(41.6, -93.6), Region::CornBelt); + } + + #[test] + fn non_conus_returns_other() { + // Alaska (61.2, -149.9) — outside every bbox. + assert_eq!(for_point(61.2, -149.9), Region::Other); + } + + #[test] + fn adjustments_match_elixir_table() { + assert_eq!(seasonal_adjustment(Region::GulfCoast, 8), 1.15); + assert_eq!(seasonal_adjustment(Region::CornBelt, 7), 0.85); + assert_eq!(seasonal_adjustment(Region::PacificNorthwest, 7), 1.20); + assert_eq!(seasonal_adjustment(Region::Other, 8), 1.0); + assert_eq!(seasonal_adjustment(Region::CornBelt, 1), 1.0); + } + + #[test] + fn precedence_matches_elixir_ordering() { + // (30.5, -90.0) is inside BOTH gulf_coast (25..32, -100..-80) and + // southeast (30..37, -90..-75). Elixir hits gulf_coast first. + assert_eq!(for_point(30.5, -90.0), Region::GulfCoast); + } +} diff --git a/rust/prop_grid_rs/src/scorer.rs b/rust/prop_grid_rs/src/scorer.rs new file mode 100644 index 00000000..afc364ac --- /dev/null +++ b/rust/prop_grid_rs/src/scorer.rs @@ -0,0 +1,949 @@ +//! Propagation scorer — 1:1 port of `lib/microwaveprop/propagation/scorer.ex`. +//! +//! Every factor returns a 0..=100 integer score. The composite is +//! `round(Σ factor · weight)` with weights from `band_config`. All +//! thresholds live in `band_config` / `region` — nothing magic here. +//! +//! Behavior parity tests mirror the Elixir `ScorerTest` suite line-by-line; +//! integer scores match exactly. +//! +//! Elixir `Kernel.round/1` and Rust `f64::round` both use round-half-away- +//! from-zero, so no custom rounding helper is needed. + +use crate::band_config::{ + BandConfig, HumidityEffect, Weights, DEFAULT_WEIGHTS, + HUMIDITY_BENEFICIAL_DEFAULT, HUMIDITY_BENEFICIAL_THRESHOLDS, + REFRACTIVITY_DEFAULT, REFRACTIVITY_THRESHOLDS, SUNRISE_TABLE, +}; +use crate::region; + +const BULK_RICHARDSON_STABLE_MAX: f64 = 25.0; + +/// Inputs to `composite_score`. All f64 everywhere to stay close to +/// Erlang's single-float world. +#[derive(Debug, Clone, Default)] +pub struct Conditions { + pub abs_humidity: f64, + pub temp_f: f64, + pub dewpoint_f: f64, + pub wind_speed_kts: Option, + pub sky_cover_pct: Option, + pub utc_hour: u8, + pub utc_minute: u8, + pub month: u8, + pub longitude: f64, + pub latitude: Option, + pub pressure_mb: Option, + pub prev_pressure_mb: Option, + pub rain_rate_mmhr: Option, + pub min_refractivity_gradient: Option, + pub bl_depth_m: Option, + pub pwat_mm: Option, + pub best_duct_band_ghz: Option, + pub bulk_richardson: Option, +} + +#[derive(Debug, Clone, Copy)] +pub struct BandInvariants { + pub tod: i32, + pub sky: i32, + pub wind: i32, + pub pressure: i32, +} + +#[derive(Debug, Clone)] +pub struct Factors { + pub humidity: i32, + pub time_of_day: i32, + pub td_depression: i32, + pub refractivity: i32, + pub sky: i32, + pub season: i32, + pub wind: i32, + pub rain: i32, + pub pwat: i32, + pub pressure: i32, +} + +#[derive(Debug, Clone)] +pub struct Composite { + pub score: i32, + pub factors: Factors, +} + +// ── Helpers ────────────────────────────────────────────────────────── + +pub fn f_to_c(f: f64) -> f64 { + (f - 32.0) * 5.0 / 9.0 +} + +pub fn c_to_f(c: f64) -> f64 { + c * 9.0 / 5.0 + 32.0 +} + +pub fn absolute_humidity(temp_c: f64, dewpoint_c: f64) -> f64 { + let e_sat = 6.112 * (17.67 * dewpoint_c / (dewpoint_c + 243.5)).exp(); + 217.0 * e_sat / (temp_c + 273.15) +} + +pub fn wind_speed_kts(u_ms: f64, v_ms: f64) -> f64 { + (u_ms * u_ms + v_ms * v_ms).sqrt() * 1.94384 +} + +pub fn precip_to_rate_mmhr(mm: Option) -> f64 { + match mm { + Some(v) if v > 0.0 => v, + _ => 0.0, + } +} + +/// Marshall-Palmer Z-R: `Z = 200 · R^1.6` → `R = (Z/200)^(1/1.6)`, `Z = 10^(dBZ/10)`. +/// Clips below 5 dBZ to 0 (ground clutter) and above 150 mm/hr (hail). +pub fn dbz_to_rain_rate_mmhr(dbz: Option) -> f64 { + match dbz { + None => 0.0, + Some(v) if v < 5.0 => 0.0, + Some(v) => { + let z = 10f64.powf(v / 10.0); + (z / 200.0).powf(1.0 / 1.6).min(150.0) + } + } +} + +fn clamp_score_f(v: f64) -> i32 { + (v.round() as i64).clamp(0, 100) as i32 +} + +fn clamp_score(v: i32) -> i32 { + v.clamp(0, 100) +} + +// ── Factor 1: humidity ─────────────────────────────────────────────── + +pub fn score_humidity(abs_humidity: f64, band: &BandConfig) -> i32 { + match band.humidity_effect { + HumidityEffect::Beneficial => HUMIDITY_BENEFICIAL_THRESHOLDS + .iter() + .find(|(max, _)| abs_humidity < *max as f64) + .map(|(_, s)| *s) + .unwrap_or(HUMIDITY_BENEFICIAL_DEFAULT), + HumidityEffect::Harmful => { + let r = abs_humidity * band.humidity_penalty; + if r <= 6.0 { + 100 + } else if r <= 9.0 { + (95.0 - (r - 6.0) / 3.0 * 20.0).round() as i32 + } else if r <= 13.0 { + (75.0 - (r - 9.0) / 4.0 * 30.0).round() as i32 + } else if r <= 18.0 { + (45.0 - (r - 13.0) / 5.0 * 35.0).round() as i32 + } else { + ((10.0 - (r - 18.0) * 2.0).round() as i32).max(0) + } + } + } +} + +// ── Factor 2: time of day ──────────────────────────────────────────── + +pub fn score_time_of_day( + utc_hour: u8, + utc_minute: u8, + month: u8, + longitude: f64, +) -> (i32, &'static str) { + let offset = longitude / 15.0; + let raw = utc_hour as f64 + utc_minute as f64 / 60.0 + offset + 24.0; + // Match Elixir :math.fmod/2 — same semantics as fmod. + let local = raw.rem_euclid(24.0); + let sunrise = SUNRISE_TABLE[(month - 1) as usize]; + let d = local - sunrise; + + if (-1.5..=1.5).contains(&d) { + (100, "Peak — inversion maximum") + } else if d > 1.5 && d <= 3.0 { + (78, "Good — inversion eroding") + } else if d > -3.0 && d < -1.5 { + (82, "Pre-dawn — inversion building") + } else if d > 3.0 && d <= 6.0 { + (38, "Marginal — boundary layer mixing") + } else if local >= 20.0 || local <= 1.0 { + (72, "Evening — cooling, inversion reforming") + } else if d > 6.0 { + (18, "Afternoon — full convective mixing") + } else { + (55, "Night — gradual cooling") + } +} + +// ── Factor 3: T-Td depression ──────────────────────────────────────── + +pub fn score_td_depression(temp_f: f64, dewpoint_f: f64, band: &BandConfig) -> i32 { + let dep = temp_f - dewpoint_f; + match band.humidity_effect { + HumidityEffect::Beneficial => { + if dep < 3.0 { + 40 + } else if dep < 8.0 { + 75 + } else if dep < 14.0 { + 85 + } else if dep < 22.0 { + 70 + } else { + 55 + } + } + HumidityEffect::Harmful => { + if dep > 22.0 { + 96 + } else if dep > 14.0 { + 80 + } else if dep > 8.0 { + 60 + } else if dep > 4.0 { + 38 + } else { + 18 + } + } + } +} + +// ── Factor 4: refractivity gradient (+ HPBL multiplier + native duct boost) ── + +pub fn score_refractivity( + min_gradient: Option, + bl_depth_m: Option, + best_duct_band_ghz: Option, + bulk_richardson: Option, + band: &BandConfig, +) -> i32 { + let Some(gradient) = min_gradient else { + return 50; + }; + + let base_match = REFRACTIVITY_THRESHOLDS + .iter() + .find(|(max, _, _)| gradient < *max as f64); + + let base = match base_match { + Some((_, b, h)) => match band.humidity_effect { + HumidityEffect::Beneficial => *b, + HumidityEffect::Harmful => *h, + }, + None => { + let (b, h) = REFRACTIVITY_DEFAULT; + if band.humidity_effect == HumidityEffect::Beneficial { + b + } else { + h + } + } + }; + + let with_hpbl = apply_hpbl_multiplier(base, bl_depth_m); + apply_native_duct_boost(with_hpbl, best_duct_band_ghz, bulk_richardson, band.freq_mhz) +} + +fn apply_hpbl_multiplier(base: i32, hpbl: Option) -> i32 { + let mul = match hpbl { + None => return base, + Some(v) if v < 200.0 => 1.10, + Some(v) if v < 500.0 => 1.05, + Some(v) if v < 1500.0 => 1.0, + Some(v) if v < 2000.0 => 0.92, + Some(_) => 0.78, + }; + clamp_score_f(base as f64 * mul) +} + +fn apply_native_duct_boost( + base: i32, + best_duct_band_ghz: Option, + bulk_richardson: Option, + freq_mhz: u32, +) -> i32 { + let Some(duct_band_ghz) = best_duct_band_ghz else { + return base; + }; + let target_ghz = freq_mhz as f64 / 1000.0; + let stable = match bulk_richardson { + None => true, + Some(r) => r < BULK_RICHARDSON_STABLE_MAX, + }; + if duct_band_ghz >= target_ghz && stable { + clamp_score_f(base as f64 * 1.15) + } else { + base + } +} + +// ── Factor 5: sky cover ────────────────────────────────────────────── + +pub fn score_sky(pct: Option) -> i32 { + match pct { + None => 50, + Some(p) if p <= 6.0 => 100, + Some(p) if p <= 25.0 => 88, + Some(p) if p <= 50.0 => 60, + Some(p) if p <= 87.0 => 25, + Some(_) => 5, + } +} + +// ── Factor 6: season ───────────────────────────────────────────────── + +pub fn score_season(month: u8, lat: Option, lon: Option, band: &BandConfig) -> i32 { + let idx = (month - 1) as usize; + let base = band.seasonal_base[idx]; + let adj = band.seasonal_adj[idx]; + + let region_mult = match (lat, lon) { + (Some(la), Some(lo)) => region::seasonal_adjustment(region::for_point(la, lo), month), + _ => 1.0, + }; + + let raw = (base + adj) as f64 * region_mult; + clamp_score_f(raw) +} + +// ── Factor 7: wind ─────────────────────────────────────────────────── + +pub fn score_wind(speed_kts: Option) -> i32 { + match speed_kts { + None => 50, + Some(s) if s < 5.0 => 100, + Some(s) if s < 10.0 => 90, + Some(s) if s < 15.0 => 75, + Some(s) if s < 20.0 => 55, + Some(s) if s < 25.0 => 35, + Some(_) => 15, + } +} + +// ── Factor 8: rain attenuation (ITU-R P.838) ──────────────────────── + +pub fn score_rain(rate_mmhr: Option, band: &BandConfig) -> i32 { + match rate_mmhr { + None => 100, + Some(0.0) => 100, + Some(v) => { + let gamma = band.rain_k * v.powf(band.rain_alpha); + if gamma < 0.1 { + 95 + } else if gamma < 0.5 { + 75 + } else if gamma < 1.0 { + 50 + } else if gamma < 2.0 { + 25 + } else if gamma < 5.0 { + 10 + } else { + 0 + } + } + } +} + +// ── Factor 9: precipitable water ──────────────────────────────────── + +pub fn score_pwat(pwat_mm: Option, band: &BandConfig) -> i32 { + let Some(v) = pwat_mm else { return 60 }; + match band.humidity_effect { + HumidityEffect::Beneficial => { + if v < 10.0 { + 55 + } else if v < 20.0 { + 75 + } else if v < 30.0 { + 90 + } else if v < 40.0 { + 70 + } else { + 50 + } + } + HumidityEffect::Harmful => { + if v < 10.0 { + 95 + } else if v < 20.0 { + 80 + } else if v < 30.0 { + 60 + } else if v < 40.0 { + 35 + } else { + 15 + } + } + } +} + +// ── Factor 10: pressure ───────────────────────────────────────────── + +pub fn score_pressure(current_mb: Option, previous_mb: Option) -> i32 { + let Some(current) = current_mb else { return 50 }; + match previous_mb { + None => { + if current < 980.0 { + 88 + } else if current < 990.0 { + 82 + } else if current < 1000.0 { + 70 + } else if current < 1010.0 { + 55 + } else if current < 1020.0 { + 40 + } else { + 30 + } + } + Some(prev) => { + let delta = current - prev; + if delta > 2.5 { + 80 + } else if delta > 0.8 { + 70 + } else if delta > -0.5 { + 60 + } else if delta > -2.0 { + 65 + } else { + 45 + } + } + } +} + +// ── Composite ─────────────────────────────────────────────────────── + +pub fn precompute_band_invariants(c: &Conditions) -> BandInvariants { + let (tod, _) = score_time_of_day(c.utc_hour, c.utc_minute, c.month, c.longitude); + BandInvariants { + tod, + sky: score_sky(c.sky_cover_pct), + wind: score_wind(c.wind_speed_kts), + pressure: score_pressure(c.pressure_mb, c.prev_pressure_mb), + } +} + +pub fn composite_score(c: &Conditions, band: &BandConfig) -> Composite { + composite_score_with(c, band, None) +} + +pub fn composite_score_with( + c: &Conditions, + band: &BandConfig, + precomputed: Option, +) -> Composite { + let inv = precomputed.unwrap_or_else(|| precompute_band_invariants(c)); + + let factors = Factors { + humidity: score_humidity(c.abs_humidity, band), + time_of_day: inv.tod, + td_depression: score_td_depression(c.temp_f, c.dewpoint_f, band), + refractivity: score_refractivity( + c.min_refractivity_gradient, + c.bl_depth_m, + c.best_duct_band_ghz, + c.bulk_richardson, + band, + ), + sky: inv.sky, + season: score_season(c.month, c.latitude, Some(c.longitude).filter(|_| c.latitude.is_some()), band), + wind: inv.wind, + rain: score_rain(c.rain_rate_mmhr, band), + pwat: score_pwat(c.pwat_mm, band), + pressure: inv.pressure, + }; + + let w = band.weights.unwrap_or(DEFAULT_WEIGHTS); + let weighted = weighted_sum(&factors, &w); + Composite { + score: clamp_score_f(weighted), + factors, + } +} + +fn weighted_sum(f: &Factors, w: &Weights) -> f64 { + f.humidity as f64 * w.humidity + + f.time_of_day as f64 * w.time_of_day + + f.td_depression as f64 * w.td_depression + + f.refractivity as f64 * w.refractivity + + f.sky as f64 * w.sky + + f.season as f64 * w.season + + f.wind as f64 * w.wind + + f.rain as f64 * w.rain + + f.pressure as f64 * w.pressure + + f.pwat as f64 * w.pwat +} + +/// Commercial-link inverse-sensor boost. Not used in the grid hot path +/// (f00-only — Elixir keeps that) but ported so unit-level correctness +/// stays testable from the Rust side. +pub fn commercial_link_boost(score: i32, n_links: u32, degradation_db: f64) -> i32 { + if n_links == 0 || degradation_db < 3.0 { + return clamp_score(score); + } + if degradation_db < 8.0 { + let bonus = 2.0 + (degradation_db - 3.0) * 8.0 / 5.0; + clamp_score_f(score as f64 + bonus) + } else { + let bonus = (10.0 + (degradation_db - 8.0) * 15.0 / 8.0).min(25.0); + clamp_score_f(score as f64 + bonus) + } +} + +// ── Tests (mirror Elixir ScorerTest) ──────────────────────────────── + +#[cfg(test)] +mod tests { + use super::*; + use crate::band_config; + + fn b10g() -> &'static BandConfig { + band_config::get(10_000).unwrap() + } + fn b24g() -> &'static BandConfig { + band_config::get(24_000).unwrap() + } + fn b75g() -> &'static BandConfig { + band_config::get(75_000).unwrap() + } + + const EAST_LON: f64 = -75.0; + + #[test] + fn f_to_c_boundaries() { + assert!((f_to_c(32.0) - 0.0).abs() < 0.01); + assert!((f_to_c(212.0) - 100.0).abs() < 0.01); + } + + #[test] + fn c_to_f_boundaries() { + assert!((c_to_f(0.0) - 32.0).abs() < 0.01); + assert!((c_to_f(100.0) - 212.0).abs() < 0.01); + } + + #[test] + fn absolute_humidity_typical_summer() { + let ah = absolute_humidity(25.0, 20.0); + assert!(ah > 15.0 && ah < 20.0, "{ah}"); + } + + #[test] + fn absolute_humidity_cold_dry() { + let ah = absolute_humidity(0.0, -5.0); + assert!(ah > 2.0 && ah < 5.0, "{ah}"); + } + + #[test] + fn wind_speed_3_4_kts() { + assert!((wind_speed_kts(3.0, 4.0) - 9.72).abs() < 0.1); + } + + #[test] + fn precip_to_rate_handles_nil_zero_negative() { + assert_eq!(precip_to_rate_mmhr(Some(2.5)), 2.5); + assert_eq!(precip_to_rate_mmhr(Some(0.0)), 0.0); + assert_eq!(precip_to_rate_mmhr(Some(-1.0)), 0.0); + assert_eq!(precip_to_rate_mmhr(None), 0.0); + } + + #[test] + fn dbz_to_rain_rate_clips_and_interpolates() { + assert_eq!(dbz_to_rain_rate_mmhr(None), 0.0); + assert_eq!(dbz_to_rain_rate_mmhr(Some(3.0)), 0.0); + assert!((dbz_to_rain_rate_mmhr(Some(20.0)) - 0.66).abs() < 0.05); + assert!((dbz_to_rain_rate_mmhr(Some(30.0)) - 2.7).abs() < 0.2); + assert!((dbz_to_rain_rate_mmhr(Some(45.0)) - 23.7).abs() < 1.0); + assert!(dbz_to_rain_rate_mmhr(Some(55.0)) <= 150.0); + assert!(dbz_to_rain_rate_mmhr(Some(65.0)) <= 150.0); + } + + // ── humidity ───────────────────────────────────────────────── + + #[test] + fn humidity_beneficial_table() { + assert_eq!(score_humidity(3.0, b10g()), 55); + assert_eq!(score_humidity(9.0, b10g()), 82); + assert_eq!(score_humidity(16.0, b10g()), 95); + assert_eq!(score_humidity(20.0, b10g()), 88); + assert_eq!(score_humidity(25.0, b10g()), 75); + } + + #[test] + fn humidity_harmful_piecewise() { + assert_eq!(score_humidity(2.0, b24g()), 100); + assert_eq!(score_humidity(5.0, b24g()), 82); + assert_eq!(score_humidity(10.0, b24g()), 24); + assert_eq!(score_humidity(20.0, b24g()), 0); + } + + // ── time of day ────────────────────────────────────────────── + + #[test] + fn time_of_day_dawn_peak() { + let (s, l) = score_time_of_day(11, 15, 6, EAST_LON); + assert_eq!(s, 100); + assert!(l.contains("Peak")); + } + + #[test] + fn time_of_day_afternoon() { + let (s, _) = score_time_of_day(22, 0, 6, EAST_LON); + assert_eq!(s, 18); + } + + #[test] + fn time_of_day_pre_dawn() { + let (s, l) = score_time_of_day(9, 0, 6, EAST_LON); + assert_eq!(s, 82); + assert!(l.contains("Pre-dawn")); + } + + #[test] + fn time_of_day_evening() { + let (s, l) = score_time_of_day(1, 0, 6, EAST_LON); + assert_eq!(s, 72); + assert!(l.contains("Evening")); + } + + #[test] + fn time_of_day_western_longitude_shifts_earlier() { + let (s, _) = score_time_of_day(13, 24, 1, -90.0); + assert_eq!(s, 100); + } + + #[test] + fn time_of_day_same_utc_different_longitudes() { + let (east, _) = score_time_of_day(18, 0, 6, -75.0); + let (west, _) = score_time_of_day(18, 0, 6, -120.0); + assert!(west > east); + } + + // ── td depression ──────────────────────────────────────────── + + #[test] + fn td_beneficial() { + assert_eq!(score_td_depression(72.0, 70.0, b10g()), 40); + assert_eq!(score_td_depression(80.0, 70.0, b10g()), 85); + assert_eq!(score_td_depression(100.0, 50.0, b10g()), 55); + } + + #[test] + fn td_harmful() { + assert_eq!(score_td_depression(72.0, 70.0, b24g()), 18); + assert_eq!(score_td_depression(80.0, 70.0, b24g()), 60); + assert_eq!(score_td_depression(100.0, 50.0, b24g()), 96); + } + + // ── refractivity ───────────────────────────────────────────── + + const BASELINE_BL: Option = Some(750.0); + + #[test] + fn refractivity_strong_gradient_beneficial() { + assert_eq!(score_refractivity(Some(-600.0), BASELINE_BL, None, None, b10g()), 98); + } + + #[test] + fn refractivity_strong_gradient_harmful() { + assert_eq!(score_refractivity(Some(-250.0), BASELINE_BL, None, None, b24g()), 85); + } + + #[test] + fn refractivity_moderate_gradient_beneficial() { + assert_eq!(score_refractivity(Some(-160.0), BASELINE_BL, None, None, b10g()), 92); + } + + #[test] + fn refractivity_nil_gradient_returns_50() { + assert_eq!(score_refractivity(None, BASELINE_BL, None, None, b10g()), 50); + } + + #[test] + fn refractivity_nil_bl_no_multiplier() { + assert_eq!(score_refractivity(Some(-160.0), None, None, None, b10g()), 92); + } + + #[test] + fn shallow_bl_boosts_score() { + let shallow = score_refractivity(Some(-100.0), Some(150.0), None, None, b10g()); + let baseline = score_refractivity(Some(-100.0), BASELINE_BL, None, None, b10g()); + assert!(shallow > baseline); + assert!(shallow <= 100); + } + + #[test] + fn deep_bl_penalises_score() { + let deep = score_refractivity(Some(-100.0), Some(2200.0), None, None, b10g()); + let baseline = score_refractivity(Some(-100.0), BASELINE_BL, None, None, b10g()); + assert!(deep < baseline); + assert!(deep >= 0); + } + + #[test] + fn shallow_bl_also_lifts_default_fallback() { + let shallow = score_refractivity(Some(-30.0), Some(150.0), None, None, b10g()); + let baseline = score_refractivity(Some(-30.0), BASELINE_BL, None, None, b10g()); + assert!(shallow > baseline); + } + + #[test] + fn native_duct_boosts_matching_band() { + let boosted = score_refractivity(Some(-80.0), Some(800.0), Some(15.0), None, b10g()); + let plain = score_refractivity(Some(-80.0), Some(800.0), None, None, b10g()); + assert!(boosted > plain); + assert!(boosted <= 100); + } + + #[test] + fn native_duct_below_target_no_boost() { + let unchanged = score_refractivity(Some(-80.0), Some(800.0), Some(3.0), None, b10g()); + let plain = score_refractivity(Some(-80.0), Some(800.0), None, None, b10g()); + assert_eq!(unchanged, plain); + } + + #[test] + fn richardson_gates_the_boost() { + let stable = score_refractivity(Some(-80.0), Some(800.0), Some(15.0), Some(12.0), b10g()); + let plain = score_refractivity(Some(-80.0), Some(800.0), None, None, b10g()); + assert!(stable > plain); + + let turbulent = + score_refractivity(Some(-80.0), Some(800.0), Some(15.0), Some(40.0), b10g()); + assert_eq!(turbulent, plain); + + let nil_r = score_refractivity(Some(-80.0), Some(800.0), Some(15.0), None, b10g()); + let four_arity_equiv = + score_refractivity(Some(-80.0), Some(800.0), Some(15.0), None, b10g()); + assert_eq!(nil_r, four_arity_equiv); + + let boundary = + score_refractivity(Some(-80.0), Some(800.0), Some(15.0), Some(25.0), b10g()); + assert_eq!(boundary, plain); + } + + // ── commercial link boost ──────────────────────────────────── + + #[test] + fn commercial_link_noop_cases() { + assert_eq!(commercial_link_boost(75, 0, 10.0), 75); + assert_eq!(commercial_link_boost(75, 3, 2.0), 75); + } + + #[test] + fn commercial_link_mild_boost() { + let b = commercial_link_boost(75, 3, 5.0); + assert!(b > 75 && b < 90, "{b}"); + } + + #[test] + fn commercial_link_strong_boost_capped() { + let b = commercial_link_boost(75, 3, 12.0); + assert!(b > 85 && b <= 100, "{b}"); + } + + // ── sky ────────────────────────────────────────────────────── + + #[test] + fn sky_table() { + assert_eq!(score_sky(Some(5.0)), 100); + assert_eq!(score_sky(Some(20.0)), 88); + assert_eq!(score_sky(Some(40.0)), 60); + assert_eq!(score_sky(Some(75.0)), 25); + assert_eq!(score_sky(Some(95.0)), 5); + assert_eq!(score_sky(None), 50); + } + + // ── season ─────────────────────────────────────────────────── + + #[test] + fn season_table_basic() { + assert_eq!(score_season(7, None, None, b10g()), 95); + assert_eq!(score_season(3, None, None, b10g()), 22); + assert_eq!(score_season(11, None, None, b24g()), 96); + assert_eq!(score_season(7, None, None, b24g()), 8); + } + + #[test] + fn season_gulf_coast_august_boost() { + let no_region = score_season(8, None, None, b10g()); + let gulf = score_season(8, Some(29.0), Some(-95.0), b10g()); + assert!(gulf > no_region); + } + + #[test] + fn season_corn_belt_august_penalty() { + let no_region = score_season(8, None, None, b10g()); + let iowa = score_season(8, Some(42.0), Some(-93.0), b10g()); + assert!(iowa < no_region); + } + + // ── wind ───────────────────────────────────────────────────── + + #[test] + fn wind_table() { + assert_eq!(score_wind(Some(3.0)), 100); + assert_eq!(score_wind(Some(8.0)), 90); + assert_eq!(score_wind(Some(12.0)), 75); + assert_eq!(score_wind(Some(22.0)), 35); + assert_eq!(score_wind(Some(30.0)), 15); + assert_eq!(score_wind(None), 50); + } + + // ── rain ───────────────────────────────────────────────────── + + #[test] + fn rain_zero_and_nil_full_score() { + assert_eq!(score_rain(Some(0.0), b24g()), 100); + assert_eq!(score_rain(None, b24g()), 100); + } + + #[test] + fn rain_24g_light() { + // gamma = 0.070 * 2.0^1.07 ≈ 0.147 → 75 + assert_eq!(score_rain(Some(2.0), b24g()), 75); + } + + #[test] + fn rain_10g_heavy_still_high() { + // gamma = 0.010 * 5.0^1.28 ≈ 0.076 → 95 + assert_eq!(score_rain(Some(5.0), b10g()), 95); + } + + #[test] + fn rain_75g_heavy_drops() { + // gamma = 0.345 * 10^0.84 ≈ 2.39 → 10 + assert_eq!(score_rain(Some(10.0), b75g()), 10); + } + + // ── pwat ───────────────────────────────────────────────────── + + #[test] + fn pwat_beneficial_table() { + assert_eq!(score_pwat(Some(5.0), b10g()), 55); + assert_eq!(score_pwat(Some(15.0), b10g()), 75); + assert_eq!(score_pwat(Some(25.0), b10g()), 90); + assert_eq!(score_pwat(Some(35.0), b10g()), 70); + assert_eq!(score_pwat(Some(45.0), b10g()), 50); + } + + #[test] + fn pwat_harmful_table() { + assert_eq!(score_pwat(Some(5.0), b24g()), 95); + assert_eq!(score_pwat(Some(15.0), b24g()), 80); + assert_eq!(score_pwat(Some(25.0), b24g()), 60); + assert_eq!(score_pwat(Some(35.0), b24g()), 35); + assert_eq!(score_pwat(Some(45.0), b24g()), 15); + } + + #[test] + fn pwat_nil_returns_60() { + assert_eq!(score_pwat(None, b10g()), 60); + assert_eq!(score_pwat(None, b24g()), 60); + } + + // ── pressure ───────────────────────────────────────────────── + + #[test] + fn pressure_standalone_table() { + assert_eq!(score_pressure(Some(1028.0), None), 30); + assert_eq!(score_pressure(Some(1020.0), None), 30); + assert_eq!(score_pressure(Some(1000.0), None), 55); + } + + #[test] + fn pressure_deltas() { + assert_eq!(score_pressure(Some(1020.0), Some(1015.0)), 80); + assert_eq!(score_pressure(Some(1016.0), Some(1015.0)), 70); + assert_eq!(score_pressure(Some(1015.0), Some(1015.3)), 60); + assert_eq!(score_pressure(Some(1014.0), Some(1015.0)), 65); + assert_eq!(score_pressure(Some(1010.0), Some(1015.0)), 45); + } + + // ── composite ──────────────────────────────────────────────── + + fn canonical_conditions() -> Conditions { + Conditions { + abs_humidity: 10.0, + temp_f: 80.0, + dewpoint_f: 70.0, + wind_speed_kts: Some(5.0), + sky_cover_pct: Some(20.0), + utc_hour: 11, + utc_minute: 15, + month: 6, + longitude: -75.0, + latitude: None, + pressure_mb: Some(1020.0), + prev_pressure_mb: Some(1018.0), + rain_rate_mmhr: Some(0.0), + min_refractivity_gradient: Some(-350.0), + bl_depth_m: Some(400.0), + pwat_mm: Some(25.0), + best_duct_band_ghz: None, + bulk_richardson: None, + } + } + + #[test] + fn composite_returns_0_100_score() { + let r = composite_score(&canonical_conditions(), b10g()); + assert!(r.score >= 0 && r.score <= 100); + } + + #[test] + fn composite_all_factors_populated() { + let r = composite_score(&canonical_conditions(), b10g()); + let f = &r.factors; + for s in [ + f.humidity, f.time_of_day, f.td_depression, f.refractivity, + f.sky, f.season, f.wind, f.rain, f.pwat, f.pressure, + ] { + assert!((0..=100).contains(&s), "factor out of range: {s}"); + } + } + + #[test] + fn precomputed_invariants_match_fresh() { + let c = canonical_conditions(); + let inv = precompute_band_invariants(&c); + let fresh = composite_score(&c, b10g()); + let reused = composite_score_with(&c, b10g(), Some(inv)); + assert_eq!(fresh.factors.time_of_day, reused.factors.time_of_day); + assert_eq!(fresh.factors.sky, reused.factors.sky); + assert_eq!(fresh.factors.wind, reused.factors.wind); + assert_eq!(fresh.factors.pressure, reused.factors.pressure); + assert_eq!(fresh.score, reused.score); + } + + #[test] + fn composite_uses_band_weights() { + let r = composite_score(&canonical_conditions(), b10g()); + let w = DEFAULT_WEIGHTS; + let expected = r.factors.humidity as f64 * w.humidity + + r.factors.time_of_day as f64 * w.time_of_day + + r.factors.td_depression as f64 * w.td_depression + + r.factors.refractivity as f64 * w.refractivity + + r.factors.sky as f64 * w.sky + + r.factors.season as f64 * w.season + + r.factors.wind as f64 * w.wind + + r.factors.rain as f64 * w.rain + + r.factors.pwat as f64 * w.pwat + + r.factors.pressure as f64 * w.pressure; + assert!((r.score as f64 - expected.round()).abs() <= 1.0); + } + + #[test] + fn composite_10g_vs_24g_differ() { + let c = canonical_conditions(); + let r10 = composite_score(&c, b10g()); + let r24 = composite_score(&c, b24g()); + assert_ne!(r10.score, r24.score); + } +} diff --git a/rust/prop_grid_rs/src/scores_file.rs b/rust/prop_grid_rs/src/scores_file.rs new file mode 100644 index 00000000..c5a42663 --- /dev/null +++ b/rust/prop_grid_rs/src/scores_file.rs @@ -0,0 +1,284 @@ +//! Score-grid file format (v1). 1:1 port of +//! `lib/microwaveprop/propagation/scores_file.ex`. +//! +//! Layout (all little-endian): +//! magic : 4 bytes "NTMS" (literal already on disk) +//! version : 1 byte 0x01 +//! band_mhz : 4 bytes uint32 +//! valid_time : 8 bytes int64 unix seconds +//! lat_min : 4 bytes float32 +//! lon_min : 4 bytes float32 +//! step_deg : 4 bytes float32 +//! n_rows : 2 bytes uint16 (lat) +//! n_cols : 2 bytes uint16 (lon) +//! scores : n_rows × n_cols bytes (uint8, 0-100 or 255 = no-data) +//! +//! Writes go through `rename(2)` — we write to `path.tmp.>` +//! then atomically rename to the final path. On the shared NFSv4 mount +//! this is safe for concurrent readers. + +use std::fs::OpenOptions; +use std::io::{BufWriter, Write}; +use std::path::{Path, PathBuf}; +use std::sync::atomic::{AtomicU64, Ordering}; +use std::time::{SystemTime, UNIX_EPOCH}; + +use chrono::{DateTime, Utc}; + +use crate::grid; + +pub const MAGIC: &[u8; 4] = b"NTMS"; +pub const VERSION: u8 = 1; +pub const NO_DATA: u8 = 255; + +static UNIQUE: AtomicU64 = AtomicU64::new(1); + +/// Absolute path `//.ntms`. +pub fn path_for(base_dir: &Path, band_mhz: u32, valid_time: DateTime) -> PathBuf { + let iso = valid_time + .format("%Y-%m-%dT%H:%M:%SZ") + .to_string(); + base_dir + .join(band_mhz.to_string()) + .join(format!("{iso}.ntms")) +} + +#[derive(Debug, thiserror::Error)] +pub enum WriteError { + #[error("io: {0}")] + Io(#[from] std::io::Error), + #[error("grid dimensions exceed uint16 (rows={rows}, cols={cols})")] + GridTooLarge { rows: usize, cols: usize }, +} + +/// Encode the full on-disk representation into a `Vec`. Separated +/// from the file I/O so tests can round-trip without a tempdir. +pub fn encode( + band_mhz: u32, + valid_time: DateTime, + scores: &[ScorePoint], +) -> Result, WriteError> { + let spec = grid::wgrib2_grid_spec(); + let n_rows: u16 = spec + .lat_count + .try_into() + .map_err(|_| WriteError::GridTooLarge { + rows: spec.lat_count, + cols: spec.lon_count, + })?; + let n_cols: u16 = spec + .lon_count + .try_into() + .map_err(|_| WriteError::GridTooLarge { + rows: spec.lat_count, + cols: spec.lon_count, + })?; + + let row_count = n_rows as usize; + let col_count = n_cols as usize; + let mut body = vec![NO_DATA; row_count * col_count]; + + for s in scores { + let row = (((s.lat - spec.lat_start) / spec.lat_step).round()) as isize; + let col = (((s.lon - spec.lon_start) / spec.lon_step).round()) as isize; + if row < 0 || col < 0 || row as usize >= row_count || col as usize >= col_count { + continue; + } + body[(row as usize) * col_count + (col as usize)] = clamp_score(s.score); + } + + let mut out = + Vec::with_capacity(4 + 1 + 4 + 8 + 4 + 4 + 4 + 2 + 2 + body.len()); + out.extend_from_slice(MAGIC); + out.push(VERSION); + out.extend_from_slice(&band_mhz.to_le_bytes()); + out.extend_from_slice(&valid_time.timestamp().to_le_bytes()); + out.extend_from_slice(&(spec.lat_start as f32).to_le_bytes()); + out.extend_from_slice(&(spec.lon_start as f32).to_le_bytes()); + out.extend_from_slice(&(spec.lon_step as f32).to_le_bytes()); + out.extend_from_slice(&n_rows.to_le_bytes()); + out.extend_from_slice(&n_cols.to_le_bytes()); + out.extend_from_slice(&body); + Ok(out) +} + +/// Atomic write to `//.ntms`. Creates the band +/// subdirectory on demand. +pub fn write_atomic( + base_dir: &Path, + band_mhz: u32, + valid_time: DateTime, + scores: &[ScorePoint], +) -> Result<(), WriteError> { + let bytes = encode(band_mhz, valid_time, scores)?; + let final_path = path_for(base_dir, band_mhz, valid_time); + let parent = final_path + .parent() + .ok_or_else(|| std::io::Error::other("path has no parent"))?; + std::fs::create_dir_all(parent)?; + + let nanos = SystemTime::now() + .duration_since(UNIX_EPOCH) + .map(|d| d.as_nanos()) + .unwrap_or(0); + let uniq = UNIQUE.fetch_add(1, Ordering::Relaxed); + let tmp_path = final_path.with_extension(format!("ntms.tmp.{nanos}.{uniq}")); + + { + let file = OpenOptions::new() + .write(true) + .create_new(true) + .open(&tmp_path)?; + let mut w = BufWriter::new(file); + w.write_all(&bytes)?; + w.flush()?; + } + + match std::fs::rename(&tmp_path, &final_path) { + Ok(()) => Ok(()), + Err(e) => { + let _ = std::fs::remove_file(&tmp_path); + Err(WriteError::Io(e)) + } + } +} + +#[derive(Debug, Clone, Copy)] +pub struct ScorePoint { + pub lat: f64, + pub lon: f64, + pub score: i32, +} + +fn clamp_score(s: i32) -> u8 { + if s < 0 { + 0 + } else if s > 100 { + 100 + } else { + s as u8 + } +} + +/// Minimal decoder used only in tests + the shadow comparator. Returns +/// the raw row-major body plus the metadata. Mirrors the Elixir +/// `decode/1` sans Access-behavior niceties. +pub fn decode(bytes: &[u8]) -> Option { + use byteorder::{ByteOrder, LittleEndian}; + if bytes.len() < 4 + 1 + 4 + 8 + 4 + 4 + 4 + 2 + 2 { + return None; + } + if &bytes[0..4] != MAGIC { + return None; + } + if bytes[4] != VERSION { + return None; + } + let band_mhz = LittleEndian::read_u32(&bytes[5..9]); + let valid_time_unix = LittleEndian::read_i64(&bytes[9..17]); + let lat_min = LittleEndian::read_f32(&bytes[17..21]); + let lon_min = LittleEndian::read_f32(&bytes[21..25]); + let step = LittleEndian::read_f32(&bytes[25..29]); + let n_rows = LittleEndian::read_u16(&bytes[29..31]); + let n_cols = LittleEndian::read_u16(&bytes[31..33]); + let body_len = (n_rows as usize) * (n_cols as usize); + if bytes.len() < 33 + body_len { + return None; + } + let valid_time = DateTime::::from_timestamp(valid_time_unix, 0)?; + Some(Decoded { + band_mhz, + valid_time, + lat_min, + lon_min, + step, + n_rows, + n_cols, + body: bytes[33..33 + body_len].to_vec(), + }) +} + +#[derive(Debug)] +pub struct Decoded { + pub band_mhz: u32, + pub valid_time: DateTime, + pub lat_min: f32, + pub lon_min: f32, + pub step: f32, + pub n_rows: u16, + pub n_cols: u16, + pub body: Vec, +} + +#[cfg(test)] +mod tests { + use super::*; + use chrono::TimeZone; + + #[test] + fn round_trip_header() { + let scores = vec![ScorePoint { + lat: 32.0, + lon: -97.0, + score: 73, + }]; + let ts = Utc.with_ymd_and_hms(2026, 4, 19, 15, 0, 0).unwrap(); + let bytes = encode(10_000, ts, &scores).unwrap(); + let decoded = decode(&bytes).unwrap(); + assert_eq!(decoded.band_mhz, 10_000); + assert_eq!(decoded.valid_time, ts); + assert_eq!(decoded.n_rows, 201); + assert_eq!(decoded.n_cols, 473); + // Score at (32, -97): row = (32-25)/0.125 = 56, col = (-97 - -125)/0.125 = 224 + let idx = 56 * 473 + 224; + assert_eq!(decoded.body[idx], 73); + } + + #[test] + fn missing_cells_use_no_data_sentinel() { + let scores: Vec = vec![]; + let ts = Utc.with_ymd_and_hms(2026, 4, 19, 15, 0, 0).unwrap(); + let bytes = encode(10_000, ts, &scores).unwrap(); + let decoded = decode(&bytes).unwrap(); + assert!(decoded.body.iter().all(|&b| b == NO_DATA)); + } + + #[test] + fn clamps_out_of_range_scores() { + let scores = vec![ + ScorePoint { lat: 25.0, lon: -125.0, score: -5 }, + ScorePoint { lat: 25.125, lon: -125.0, score: 150 }, + ]; + let ts = Utc.with_ymd_and_hms(2026, 4, 19, 15, 0, 0).unwrap(); + let bytes = encode(10_000, ts, &scores).unwrap(); + let decoded = decode(&bytes).unwrap(); + assert_eq!(decoded.body[0], 0); + // row = 1, col = 0 → idx = 1 * 473 + assert_eq!(decoded.body[473], 100); + } + + #[test] + fn path_for_layout() { + let ts = Utc.with_ymd_and_hms(2026, 4, 19, 15, 0, 0).unwrap(); + let p = path_for(Path::new("/data/scores"), 10_000, ts); + assert_eq!( + p.to_str().unwrap(), + "/data/scores/10000/2026-04-19T15:00:00Z.ntms" + ); + } + + #[test] + fn atomic_write_and_decode() { + let dir = tempfile::tempdir().unwrap(); + let ts = Utc.with_ymd_and_hms(2026, 4, 19, 15, 0, 0).unwrap(); + let scores = vec![ScorePoint { lat: 32.0, lon: -97.0, score: 73 }]; + + write_atomic(dir.path(), 10_000, ts, &scores).unwrap(); + + let path = path_for(dir.path(), 10_000, ts); + let bytes = std::fs::read(&path).unwrap(); + let decoded = decode(&bytes).unwrap(); + assert_eq!(decoded.band_mhz, 10_000); + assert_eq!(decoded.body[56 * 473 + 224], 73); + } +} diff --git a/rust/prop_grid_rs/src/sounding_params.rs b/rust/prop_grid_rs/src/sounding_params.rs new file mode 100644 index 00000000..cbc73231 --- /dev/null +++ b/rust/prop_grid_rs/src/sounding_params.rs @@ -0,0 +1,125 @@ +//! Minimum-refractivity-gradient derivation from pressure-level +//! profiles. 1:1 port of the subset of +//! `lib/microwaveprop/weather/sounding_params.ex` needed by the +//! propagation grid scorer: `min_refractivity_gradient` per cell. +//! +//! The full Elixir module derives CAPE/LI/K-index/ducts — those are +//! used for contact enrichment and f00's native-duct merge, neither of +//! which is in the Rust f01..f18 scope. + +#[derive(Debug, Clone)] +pub struct Level { + pub pres_mb: f64, + pub hght_m: f64, + pub tmpc: f64, + pub dwpc: Option, +} + +/// Buck equation for saturation vapor pressure (hPa) at temperature in °C. +pub fn sat_vap_pres(t_c: f64) -> f64 { + 6.1121 * ((18.678 - t_c / 234.5) * (t_c / (257.14 + t_c))).exp() +} + +/// Minimum refractivity gradient (dN/dh, N-units per km) from a pressure +/// profile. Returns `None` if fewer than 3 usable levels or adjacent +/// pairs too close in height. Levels are internally sorted descending by +/// pressure (surface first) to match the Elixir orientation. +pub fn min_refractivity_gradient(mut levels: Vec) -> Option { + levels.retain(|l| l.dwpc.is_some()); + if levels.len() < 3 { + return None; + } + levels.sort_by(|a, b| { + b.pres_mb + .partial_cmp(&a.pres_mb) + .unwrap_or(std::cmp::Ordering::Equal) + }); + let sfc_hght = levels[0].hght_m; + + let refract: Vec<(f64, f64)> = levels + .iter() + .map(|l| { + let t_k = l.tmpc + 273.15; + let e = sat_vap_pres(l.dwpc.expect("filtered above")); + let n = 77.6 * l.pres_mb / t_k + 3.73e5 * e / (t_k * t_k); + let h_agl = l.hght_m - sfc_hght; + (h_agl, n) + }) + .collect(); + + let mut min_grad: Option = None; + for pair in refract.windows(2) { + let (h0, n0) = pair[0]; + let (h1, n1) = pair[1]; + let dh_km = (h1 - h0) / 1000.0; + if dh_km.abs() < 0.01 { + continue; + } + let g = (n1 - n0) / dh_km; + min_grad = Some(match min_grad { + Some(prev) if prev <= g => prev, + _ => g, + }); + } + min_grad +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn buck_sat_vap_at_freezing() { + // At 0 °C, Buck gives ~6.112 hPa. + let e = sat_vap_pres(0.0); + assert!((e - 6.112).abs() < 0.02, "{e}"); + } + + #[test] + fn nil_for_too_few_levels() { + let levels = vec![Level { + pres_mb: 1000.0, + hght_m: 0.0, + tmpc: 25.0, + dwpc: Some(20.0), + }]; + assert!(min_refractivity_gradient(levels).is_none()); + } + + #[test] + fn typical_tropospheric_gradient_is_negative() { + // Synthetic profile: refractivity decreases with altitude → negative + // dN/dh. Realistic numbers from a standard atmosphere. + let levels = vec![ + Level { pres_mb: 1000.0, hght_m: 100.0, tmpc: 25.0, dwpc: Some(20.0) }, + Level { pres_mb: 925.0, hght_m: 800.0, tmpc: 20.0, dwpc: Some(14.0) }, + Level { pres_mb: 850.0, hght_m: 1500.0, tmpc: 15.0, dwpc: Some(8.0) }, + Level { pres_mb: 700.0, hght_m: 3000.0, tmpc: 5.0, dwpc: Some(-5.0) }, + ]; + let g = min_refractivity_gradient(levels).unwrap(); + assert!(g < 0.0, "gradient should be negative: {g}"); + assert!(g > -500.0, "no duct expected: {g}"); + } + + #[test] + fn surface_temperature_inversion_yields_stronger_gradient() { + // Surface inversion: cold moist near the ground, warm dry above — + // strong negative refractivity gradient. + let inversion = vec![ + Level { pres_mb: 1000.0, hght_m: 100.0, tmpc: 18.0, dwpc: Some(17.0) }, + Level { pres_mb: 990.0, hght_m: 300.0, tmpc: 22.0, dwpc: Some(5.0) }, + Level { pres_mb: 950.0, hght_m: 700.0, tmpc: 20.0, dwpc: Some(3.0) }, + Level { pres_mb: 850.0, hght_m: 1500.0, tmpc: 15.0, dwpc: Some(0.0) }, + ]; + let strong = min_refractivity_gradient(inversion).unwrap(); + + let neutral = vec![ + Level { pres_mb: 1000.0, hght_m: 100.0, tmpc: 25.0, dwpc: Some(18.0) }, + Level { pres_mb: 925.0, hght_m: 800.0, tmpc: 20.0, dwpc: Some(14.0) }, + Level { pres_mb: 850.0, hght_m: 1500.0, tmpc: 15.0, dwpc: Some(8.0) }, + ]; + let baseline = min_refractivity_gradient(neutral).unwrap(); + + assert!(strong < baseline, "inversion {strong} vs baseline {baseline}"); + } +} diff --git a/rust/prop_grid_rs/tests/scorer_golden.rs b/rust/prop_grid_rs/tests/scorer_golden.rs new file mode 100644 index 00000000..fb300b70 --- /dev/null +++ b/rust/prop_grid_rs/tests/scorer_golden.rs @@ -0,0 +1,84 @@ +//! Golden-fixture regression test for the Rust scorer. +//! +//! Reads `tests/scores.bincode` (produced by `mix rust.golden` from the +//! Elixir scorer) and asserts every (conditions, band) → score tuple +//! matches. Regenerate after any scorer or band_config change: +//! +//! mix rust.golden +//! cp priv/rust_golden/scores.bincode rust/prop_grid_rs/tests/ +//! +//! The format is documented in `lib/mix/tasks/rust.golden.ex`. + +use std::io::{Cursor, Read}; + +use byteorder::{LittleEndian, ReadBytesExt}; +use prop_grid_rs::{band_config, scorer}; + +fn opt(v: f64) -> Option { + if v.is_nan() { + None + } else { + Some(v) + } +} + +fn read_f64(r: &mut Cursor<&[u8]>) -> f64 { + r.read_f64::().expect("f64") +} + +fn read_u8(r: &mut Cursor<&[u8]>) -> u8 { + let mut buf = [0u8; 1]; + r.read_exact(&mut buf).expect("u8"); + buf[0] +} + +#[test] +fn matches_elixir_golden_fixture() { + let bytes = std::fs::read("tests/scores.bincode") + .expect("tests/scores.bincode — run `mix rust.golden` first"); + let mut r = Cursor::new(bytes.as_slice()); + + let n = r.read_u32::().expect("n_samples"); + assert!(n > 0, "empty fixture"); + + let mut mismatches: Vec = Vec::new(); + for i in 0..n { + let c = scorer::Conditions { + abs_humidity: read_f64(&mut r), + temp_f: read_f64(&mut r), + dewpoint_f: read_f64(&mut r), + wind_speed_kts: opt(read_f64(&mut r)), + sky_cover_pct: opt(read_f64(&mut r)), + utc_hour: read_u8(&mut r), + utc_minute: read_u8(&mut r), + month: read_u8(&mut r), + longitude: read_f64(&mut r), + latitude: opt(read_f64(&mut r)), + pressure_mb: opt(read_f64(&mut r)), + prev_pressure_mb: opt(read_f64(&mut r)), + rain_rate_mmhr: opt(read_f64(&mut r)), + min_refractivity_gradient: opt(read_f64(&mut r)), + bl_depth_m: opt(read_f64(&mut r)), + pwat_mm: opt(read_f64(&mut r)), + best_duct_band_ghz: opt(read_f64(&mut r)), + bulk_richardson: opt(read_f64(&mut r)), + }; + let band_mhz = r.read_u32::().expect("band_mhz"); + let expected = r.read_i32::().expect("expected_score"); + + let band = band_config::get(band_mhz).expect("band in config"); + let got = scorer::composite_score(&c, band).score; + if got != expected { + mismatches.push(format!( + "sample {i} band {band_mhz}: elixir={expected} rust={got}" + )); + } + } + + assert!( + mismatches.is_empty(), + "{n} samples checked, {} mismatches:\n{}", + mismatches.len(), + mismatches.join("\n") + ); +} diff --git a/rust/prop_grid_rs/tests/scores.bincode b/rust/prop_grid_rs/tests/scores.bincode new file mode 100644 index 00000000..1a8be7f1 Binary files /dev/null and b/rust/prop_grid_rs/tests/scores.bincode differ diff --git a/test/microwaveprop/propagation/grid_task_enqueuer_test.exs b/test/microwaveprop/propagation/grid_task_enqueuer_test.exs new file mode 100644 index 00000000..1d037191 --- /dev/null +++ b/test/microwaveprop/propagation/grid_task_enqueuer_test.exs @@ -0,0 +1,53 @@ +defmodule Microwaveprop.Propagation.GridTaskEnqueuerTest do + use Microwaveprop.DataCase, async: true + + import Ecto.Query + + alias Microwaveprop.Propagation.GridTaskEnqueuer + alias Microwaveprop.Repo + + test "seeds one row per fh=1..18" do + run_time = ~U[2026-04-19 15:00:00Z] + assert {:ok, 18} = GridTaskEnqueuer.seed(run_time) + + rows = + Repo.all( + from(g in "grid_tasks", + where: g.run_time == ^run_time, + select: %{forecast_hour: g.forecast_hour, status: g.status, valid_time: g.valid_time} + ) + ) + + assert length(rows) == 18 + assert rows |> Enum.map(& &1.forecast_hour) |> Enum.sort() == Enum.to_list(1..18) + assert Enum.all?(rows, &(&1.status == "queued")) + + # Raw schemaless selects return NaiveDateTime; compare against the + # equivalent naive form. + expected_naive = DateTime.to_naive(run_time) + + Enum.each(rows, fn r -> + expected = NaiveDateTime.add(expected_naive, r.forecast_hour * 3600, :second) + assert NaiveDateTime.compare(r.valid_time, expected) == :eq + end) + end + + test "is idempotent: reseeding the same run_time inserts nothing" do + run_time = ~U[2026-04-19 16:00:00Z] + assert {:ok, 18} = GridTaskEnqueuer.seed(run_time) + assert {:ok, 0} = GridTaskEnqueuer.seed(run_time) + + count = Repo.one(from(g in "grid_tasks", where: g.run_time == ^run_time, select: count())) + + assert count == 18 + end + + test "never emits a row for fh=0 — Elixir keeps that chain step" do + run_time = ~U[2026-04-19 17:00:00Z] + assert {:ok, 18} = GridTaskEnqueuer.seed(run_time) + + f0_count = Repo.one(from(g in "grid_tasks", where: g.run_time == ^run_time and g.forecast_hour == 0, select: count())) + + assert f0_count == 0 + end +end