Fix Faktiskā showing blank temperatures right after each new hour starts
queryLatestTemperatures picked the single most-recent row per city with no regard for whether that row's tempAvg was actually populated yet. The open-data source publishes fields on different schedules within the same hour (snow lands well before the hourly temperature aggregate), so the freshest row for a city routinely has a real dateTime but a still-null tempAvg while the previous hour's row has good data. Confirmed live on both Rocky and the VPS: every city's newest row had tempAvg null (but a real snowAvg=0), one hour after the actual last real reading. Fixed by requiring tempAvg IS NOT NULL in the WHERE clause, so DISTINCT ON's "most recent" pick skips a fresh partial row and finds the newest row that actually has a value. Checked before changing: this is the only caller of queryLatestTemperatures (Faktiskā's fixed-station lookup); a city with zero real temperature history ever now returns no row instead of a null-valued one, which the frontend already treats identically to a present-but-null observation (falls through to the same "Nav datu" missing state either way) -- confirmed via MapGraphics.tsx before shipping, not assumed.
This commit is contained in:
@@ -29,10 +29,17 @@ object PostgresService {
|
|||||||
|
|
||||||
class PostgresService(transactor: Transactor[IO], log: Logger[IO]) {
|
class PostgresService(transactor: Transactor[IO], log: Logger[IO]) {
|
||||||
def queryLatestTemperatures(cities: NonEmptyList[String]): IO[List[(String, LocalDateTime, Option[Double])]] = {
|
def queryLatestTemperatures(cities: NonEmptyList[String]): IO[List[(String, LocalDateTime, Option[Double])]] = {
|
||||||
|
// The open-data source publishes fields on different schedules within
|
||||||
|
// the same hour (e.g. snow arrives well before the hourly temperature
|
||||||
|
// aggregate), so the single newest row for a city can have a real
|
||||||
|
// dateTime but a still-null tempAvg. Skip straight to DISTINCT ON's
|
||||||
|
// "most recent" pick by requiring tempAvg itself to be present, so a
|
||||||
|
// fresh partial row never hides an older row that actually has data.
|
||||||
val query =
|
val query =
|
||||||
fr"SELECT DISTINCT ON (city) city, dateTime, tempAvg" ++
|
fr"SELECT DISTINCT ON (city) city, dateTime, tempAvg" ++
|
||||||
fr" FROM weather" ++
|
fr" FROM weather" ++
|
||||||
fr" WHERE " ++ Fragments.in(fr"city", cities) ++
|
fr" WHERE " ++ Fragments.in(fr"city", cities) ++
|
||||||
|
fr" AND tempAvg IS NOT NULL" ++
|
||||||
fr" ORDER BY city, dateTime DESC"
|
fr" ORDER BY city, dateTime DESC"
|
||||||
|
|
||||||
query.query[(String, LocalDateTime, Option[Double])]
|
query.query[(String, LocalDateTime, Option[Double])]
|
||||||
|
|||||||
Reference in New Issue
Block a user