Fix position computation, grid truncation, and status resets
- Truncate odd-length grids to nearest valid even length (FN03c → FN03) - Handle lng/lon key inconsistency in haversine distance calculation - Reset unavailable statuses to pending when positions are computed - Rename backfill queue column to "Pending"
This commit is contained in:
parent
33171ab32e
commit
a8920e9480
2 changed files with 40 additions and 4 deletions
|
|
@ -228,8 +228,11 @@ defmodule Microwaveprop.Radio do
|
|||
|
||||
distance =
|
||||
if pos1 && pos2 do
|
||||
lon1 = pos1["lon"] || pos1["lng"]
|
||||
lon2 = pos2["lon"] || pos2["lng"]
|
||||
|
||||
pos1["lat"]
|
||||
|> haversine_km(pos1["lon"], pos2["lat"], pos2["lon"])
|
||||
|> haversine_km(lon1, pos2["lat"], lon2)
|
||||
|> round()
|
||||
|> Decimal.new()
|
||||
else
|
||||
|
|
@ -245,6 +248,27 @@ defmodule Microwaveprop.Radio do
|
|||
if changes == %{} do
|
||||
contact
|
||||
else
|
||||
# Reset unavailable statuses to pending now that positions exist
|
||||
new_pos1 = Map.get(changes, :pos1)
|
||||
new_pos2 = Map.get(changes, :pos2)
|
||||
|
||||
changes =
|
||||
if new_pos1 do
|
||||
changes
|
||||
|> maybe_reset_status(:hrrr_status, contact.hrrr_status)
|
||||
|> maybe_reset_status(:weather_status, contact.weather_status)
|
||||
|> maybe_reset_status(:iemre_status, contact.iemre_status)
|
||||
else
|
||||
changes
|
||||
end
|
||||
|
||||
changes =
|
||||
if new_pos1 && (new_pos2 || contact.pos2) do
|
||||
maybe_reset_status(changes, :terrain_status, contact.terrain_status)
|
||||
else
|
||||
changes
|
||||
end
|
||||
|
||||
contact
|
||||
|> Ecto.Changeset.change(changes)
|
||||
|> Repo.update!()
|
||||
|
|
@ -254,12 +278,24 @@ defmodule Microwaveprop.Radio do
|
|||
end
|
||||
end
|
||||
|
||||
defp maybe_reset_status(changes, field, :unavailable), do: Map.put(changes, field, :pending)
|
||||
defp maybe_reset_status(changes, _field, _status), do: changes
|
||||
|
||||
defp latlon_from_grid(nil), do: nil
|
||||
|
||||
defp latlon_from_grid(grid) do
|
||||
case Maidenhead.to_latlon(grid) do
|
||||
{:ok, {lat, lon}} -> %{"lat" => lat, "lon" => lon}
|
||||
_ -> nil
|
||||
{:ok, {lat, lon}} ->
|
||||
%{"lat" => lat, "lon" => lon}
|
||||
|
||||
_ ->
|
||||
# Try truncating to nearest valid even length (e.g. "FN03c" → "FN03")
|
||||
truncated = String.slice(grid, 0, div(String.length(grid), 2) * 2)
|
||||
|
||||
case Maidenhead.to_latlon(truncated) do
|
||||
{:ok, {lat, lon}} -> %{"lat" => lat, "lon" => lon}
|
||||
_ -> nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -343,7 +343,7 @@ defmodule MicrowavepropWeb.BackfillLive do
|
|||
<tr>
|
||||
<th>Worker</th>
|
||||
<th>Executing</th>
|
||||
<th>Available</th>
|
||||
<th>Pending</th>
|
||||
<th>Retryable</th>
|
||||
<th>Total</th>
|
||||
</tr>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue