Fix enrichment: check actual data presence, not just status flag
This commit is contained in:
parent
f897a9a321
commit
15a09f0d7b
1 changed files with 22 additions and 20 deletions
|
|
@ -183,26 +183,27 @@ defmodule MicrowavepropWeb.ContactLive.Show do
|
||||||
end
|
end
|
||||||
|
|
||||||
defp maybe_enqueue_weather(weather, contact) do
|
defp maybe_enqueue_weather(weather, contact) do
|
||||||
if contact.weather_status == :complete do
|
has_data = weather.surface_observations != [] or weather.soundings != []
|
||||||
contact
|
|
||||||
else
|
|
||||||
has_data = weather.surface_observations != [] or weather.soundings != []
|
|
||||||
|
|
||||||
cond do
|
cond do
|
||||||
has_data ->
|
has_data ->
|
||||||
|
if contact.weather_status != :complete do
|
||||||
Radio.set_enrichment_status!([contact.id], :weather_status, :complete)
|
Radio.set_enrichment_status!([contact.id], :weather_status, :complete)
|
||||||
%{contact | weather_status: :complete}
|
end
|
||||||
|
|
||||||
contact.pos1 && contact.weather_status in [:pending, :failed, :queued] ->
|
%{contact | weather_status: :complete}
|
||||||
jobs = ContactWeatherEnqueueWorker.build_weather_jobs([contact])
|
|
||||||
if jobs != [], do: Oban.insert_all(jobs)
|
|
||||||
Radio.set_enrichment_status!([contact.id], :weather_status, :queued)
|
|
||||||
%{contact | weather_status: :queued}
|
|
||||||
|
|
||||||
true ->
|
contact.pos1 && contact.weather_status not in [:queued, :unavailable] ->
|
||||||
Radio.set_enrichment_status!([contact.id], :weather_status, :unavailable)
|
jobs = ContactWeatherEnqueueWorker.build_weather_jobs([contact])
|
||||||
%{contact | weather_status: :unavailable}
|
if jobs != [], do: Oban.insert_all(jobs)
|
||||||
end
|
Radio.set_enrichment_status!([contact.id], :weather_status, :queued)
|
||||||
|
%{contact | weather_status: :queued}
|
||||||
|
|
||||||
|
is_nil(contact.pos1) ->
|
||||||
|
%{contact | weather_status: :unavailable}
|
||||||
|
|
||||||
|
true ->
|
||||||
|
contact
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -299,10 +300,11 @@ defmodule MicrowavepropWeb.ContactLive.Show do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp maybe_enqueue_hrrr(hrrr, %{hrrr_status: :complete} = contact), do: {hrrr, contact, 0}
|
|
||||||
|
|
||||||
defp maybe_enqueue_hrrr(hrrr, contact) when not is_nil(hrrr) do
|
defp maybe_enqueue_hrrr(hrrr, contact) when not is_nil(hrrr) do
|
||||||
Radio.set_enrichment_status!([contact.id], :hrrr_status, :complete)
|
if contact.hrrr_status != :complete do
|
||||||
|
Radio.set_enrichment_status!([contact.id], :hrrr_status, :complete)
|
||||||
|
end
|
||||||
|
|
||||||
{hrrr, %{contact | hrrr_status: :complete}, 0}
|
{hrrr, %{contact | hrrr_status: :complete}, 0}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -310,7 +312,7 @@ defmodule MicrowavepropWeb.ContactLive.Show do
|
||||||
lat = contact.pos1 && contact.pos1["lat"]
|
lat = contact.pos1 && contact.pos1["lat"]
|
||||||
lon = contact.pos1 && (contact.pos1["lon"] || contact.pos1["lng"])
|
lon = contact.pos1 && (contact.pos1["lon"] || contact.pos1["lng"])
|
||||||
|
|
||||||
if lat && lon && contact.hrrr_status in [:pending, :failed, :queued] do
|
if lat && lon && contact.hrrr_status not in [:queued, :unavailable] do
|
||||||
valid_time = HrrrClient.nearest_hrrr_hour(contact.qso_timestamp)
|
valid_time = HrrrClient.nearest_hrrr_hour(contact.qso_timestamp)
|
||||||
{rlat, rlon} = Weather.round_to_hrrr_grid(lat, lon)
|
{rlat, rlon} = Weather.round_to_hrrr_grid(lat, lon)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue