Always show at least the most recent valid_time in timeline
This commit is contained in:
parent
b550f63005
commit
b11e0bac84
1 changed files with 24 additions and 9 deletions
|
|
@ -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 """
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue