diff --git a/lib/microwaveprop/propagation.ex b/lib/microwaveprop/propagation.ex index 0fd021e3..eb91a68c 100644 --- a/lib/microwaveprop/propagation.ex +++ b/lib/microwaveprop/propagation.ex @@ -121,18 +121,33 @@ defmodule Microwaveprop.Propagation do end end - @doc "Returns distinct valid_times for a band from now onward, ordered ascending." + @doc """ + Returns distinct valid_times for a band, ordered ascending. + Filters out times more than 1 hour in the past, but always includes + the most recent valid_time so there's always data to display. + """ def available_valid_times(band_mhz) do - now = DateTime.utc_now() |> DateTime.add(-1800, :second) + cutoff = DateTime.utc_now() |> DateTime.add(-3600, :second) - Repo.all( - from(gs in GridScore, - where: gs.band_mhz == ^band_mhz and gs.valid_time >= ^now, - select: gs.valid_time, - distinct: gs.valid_time, - order_by: [asc: gs.valid_time] + times = + Repo.all( + from(gs in GridScore, + where: gs.band_mhz == ^band_mhz and gs.valid_time >= ^cutoff, + select: gs.valid_time, + distinct: gs.valid_time, + order_by: [asc: gs.valid_time] + ) ) - ) + + if times == [] do + # No future times — return the single most recent as fallback + case latest_valid_time(band_mhz) do + nil -> [] + t -> [t] + end + else + times + end end @doc """