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
|
||||||
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
|
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(
|
times =
|
||||||
from(gs in GridScore,
|
Repo.all(
|
||||||
where: gs.band_mhz == ^band_mhz and gs.valid_time >= ^now,
|
from(gs in GridScore,
|
||||||
select: gs.valid_time,
|
where: gs.band_mhz == ^band_mhz and gs.valid_time >= ^cutoff,
|
||||||
distinct: gs.valid_time,
|
select: gs.valid_time,
|
||||||
order_by: [asc: 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
|
end
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue