118 lines
2.1 KiB
Go
118 lines
2.1 KiB
Go
package postgres
|
|
|
|
const (
|
|
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,
|
|
AVG(dewpoint_c) AS dewpoint_c,
|
|
AVG(relative_humidity_percent) AS relative_humidity_percent,
|
|
AVG(wind_speed_kmh) AS wind_speed_kmh,
|
|
AVG(wind_direction_degrees) 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;
|
|
`
|
|
|
|
queryRecentObservations = `
|
|
SELECT
|
|
event_id,
|
|
station_id,
|
|
station_name,
|
|
observed_at,
|
|
condition_code,
|
|
is_day,
|
|
text_description,
|
|
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
|
|
ORDER BY observed_at DESC
|
|
LIMIT $1;
|
|
`
|
|
|
|
queryObservationPresentWeather = `
|
|
SELECT
|
|
event_id,
|
|
weather_index,
|
|
raw_text
|
|
FROM observation_present_weather
|
|
WHERE event_id = ANY($1)
|
|
ORDER BY event_id ASC, weather_index ASC;
|
|
`
|
|
|
|
queryForecastPeriodsAt = `
|
|
SELECT
|
|
period_index,
|
|
start_time,
|
|
end_time,
|
|
name,
|
|
is_day,
|
|
condition_code,
|
|
condition_text,
|
|
provider_raw_description,
|
|
text_description,
|
|
detailed_text,
|
|
icon_url,
|
|
temperature_c,
|
|
temperature_c_min,
|
|
temperature_c_max,
|
|
dewpoint_c,
|
|
relative_humidity_percent,
|
|
wind_direction_degrees,
|
|
wind_speed_kmh,
|
|
wind_gust_kmh,
|
|
barometric_pressure_pa,
|
|
visibility_meters,
|
|
apparent_temperature_c,
|
|
cloud_cover_percent,
|
|
probability_of_precipitation_percent,
|
|
precipitation_amount_mm,
|
|
snowfall_depth_mm,
|
|
uv_index
|
|
FROM forecast_periods
|
|
WHERE start_time < $1
|
|
AND end_time > $1
|
|
ORDER BY period_index ASC, start_time DESC
|
|
LIMIT $2;
|
|
`
|
|
|
|
queryCurrentAlerts = `
|
|
SELECT
|
|
effective,
|
|
expires,
|
|
severity,
|
|
event,
|
|
headline,
|
|
instruction,
|
|
description
|
|
FROM alerts
|
|
WHERE expires > CURRENT_TIMESTAMP;
|
|
`
|
|
)
|