Always show at least the most recent valid_time in timeline

This commit is contained in:
Graham McIntire 2026-03-31 17:49:19 -05:00
parent b550f63005
commit b11e0bac84
No known key found for this signature in database
GPG key ID: F4ABF488E6029E59

View file

@ -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 """