diff --git a/lib/microwaveprop_web/live/contact_live/show.ex b/lib/microwaveprop_web/live/contact_live/show.ex index 14676741..7affd5c7 100644 --- a/lib/microwaveprop_web/live/contact_live/show.ex +++ b/lib/microwaveprop_web/live/contact_live/show.ex @@ -38,6 +38,7 @@ defmodule MicrowavepropWeb.ContactLive.Show do terrain = Terrain.get_terrain_profile(contact.id) contact = maybe_enqueue_terrain(terrain, contact) contact = maybe_enqueue_weather(weather, contact) + iemre = load_iemre(contact) elevation_profile = compute_elevation_profile(contact, hrrr_path, weather.soundings) propagation_analysis = build_propagation_analysis(contact, hrrr, terrain, elevation_profile, weather.soundings) data_sources = build_data_sources(hrrr, hrrr_path, terrain, weather, elevation_profile) @@ -50,6 +51,7 @@ defmodule MicrowavepropWeb.ContactLive.Show do soundings: weather.soundings, solar: solar, hrrr: hrrr, + iemre: iemre, terrain: terrain, elevation_profile: elevation_profile, propagation_analysis: propagation_analysis, @@ -254,6 +256,18 @@ defmodule MicrowavepropWeb.ContactLive.Show do defp sounding_sort_key("lifted_index"), do: &(&1.lifted_index || 0) defp sounding_sort_key(_), do: fn s -> s.station.name || s.station.station_code end + defp load_iemre(contact) do + case Weather.iemre_for_contact(contact) do + %{hourly: hourly} = obs when is_list(hourly) and hourly != [] -> + qso_hour = contact.qso_timestamp.hour + nearest = Enum.min_by(hourly, fn h -> abs((h["utc_hour"] || 0) - qso_hour) end) + %{observation: obs, nearest_hour: nearest} + + _ -> + nil + end + end + defp load_weather(contact) do lat1 = contact.pos1 && contact.pos1["lat"] lon1 = contact.pos1 && (contact.pos1["lon"] || contact.pos1["lng"]) @@ -799,6 +813,47 @@ defmodule MicrowavepropWeb.ContactLive.Show do
+