Added a /conditions/current endpoint with computed best-guess values for current conditions
All checks were successful
ci/woodpecker/push/build-image Pipeline was successful
All checks were successful
ci/woodpecker/push/build-image Pipeline was successful
This commit is contained in:
@@ -1,33 +1,80 @@
|
||||
package postgres
|
||||
|
||||
const (
|
||||
queryObservationSummary = `
|
||||
queryCurrentConditionsSummary = `
|
||||
WITH windowed AS (
|
||||
SELECT
|
||||
temperature_c,
|
||||
apparent_temperature_c,
|
||||
dewpoint_c,
|
||||
relative_humidity_percent,
|
||||
wind_speed_kmh,
|
||||
wind_direction_degrees,
|
||||
condition_code,
|
||||
is_day,
|
||||
observed_at
|
||||
FROM observations
|
||||
WHERE observed_at > CURRENT_TIMESTAMP - make_interval(mins => $1)
|
||||
)
|
||||
SELECT
|
||||
AVG(temperature_c) AS temperature_c,
|
||||
AVG(apparent_temperature_c) AS apparent_temperature_c
|
||||
FROM observations
|
||||
WHERE observed_at > CURRENT_TIMESTAMP - make_interval(mins => $1);
|
||||
AVG(apparent_temperature_c) AS apparent_temperature_c,
|
||||
AVG(dewpoint_c) AS dewpoint_c,
|
||||
AVG(relative_humidity_percent) AS relative_humidity_percent,
|
||||
AVG(wind_speed_kmh) AS wind_speed_kmh,
|
||||
CASE
|
||||
WHEN COUNT(wind_direction_degrees) FILTER (WHERE wind_direction_degrees IS NOT NULL) = 0 THEN NULL
|
||||
ELSE MOD(
|
||||
DEGREES(
|
||||
ATAN2(
|
||||
AVG(SIN(RADIANS(wind_direction_degrees))),
|
||||
AVG(COS(RADIANS(wind_direction_degrees)))
|
||||
)
|
||||
) + 360.0,
|
||||
360.0
|
||||
)
|
||||
END AS wind_direction_degrees,
|
||||
MAX(condition_code) AS condition_code,
|
||||
(
|
||||
SELECT is_day
|
||||
FROM windowed
|
||||
ORDER BY observed_at DESC
|
||||
LIMIT 1
|
||||
) AS is_day
|
||||
FROM windowed;
|
||||
`
|
||||
|
||||
queryObservationConditions = `
|
||||
queryRecentObservations = `
|
||||
SELECT
|
||||
event_id,
|
||||
station_id,
|
||||
station_name,
|
||||
observed_at,
|
||||
temperature_c,
|
||||
condition_code,
|
||||
is_day,
|
||||
text_description,
|
||||
provider_raw_description,
|
||||
condition_text
|
||||
temperature_c,
|
||||
dewpoint_c,
|
||||
wind_direction_degrees,
|
||||
wind_speed_kmh,
|
||||
wind_gust_kmh,
|
||||
barometric_pressure_pa,
|
||||
visibility_meters,
|
||||
relative_humidity_percent,
|
||||
apparent_temperature_c
|
||||
FROM observations
|
||||
WHERE observed_at > CURRENT_TIMESTAMP - make_interval(mins => $1)
|
||||
ORDER BY observed_at DESC;
|
||||
ORDER BY observed_at DESC
|
||||
LIMIT $1;
|
||||
`
|
||||
|
||||
queryObservationPrecipitation = `
|
||||
queryObservationPresentWeather = `
|
||||
SELECT
|
||||
event_id,
|
||||
weather_index,
|
||||
raw_text
|
||||
FROM observation_present_weather
|
||||
WHERE observed_at > CURRENT_TIMESTAMP - make_interval(mins => $1)
|
||||
ORDER BY observed_at DESC;
|
||||
WHERE event_id = ANY($1)
|
||||
ORDER BY event_id ASC, weather_index ASC;
|
||||
`
|
||||
|
||||
queryForecastPeriodsAt = `
|
||||
|
||||
Reference in New Issue
Block a user