Skip to content

Commit

Permalink
feat: add max temperature
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaszkowic committed Jul 8, 2024
1 parent 4a6dc2e commit ceb5942
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions supabase/functions/gdk_stats/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ const getMonthlyWeather = async (): Promise<MonthlyWeather[]> => {
return data.map((month: any) => ({
month: month.month,
averageTemperatureCelsius: month.avg_temperature_celsius,
maximumTemperatureCelsius: month.max_temperature_celsius,
totalRainfallLiters: month.total_rainfall_liters,
}));
};
Expand Down
14 changes: 14 additions & 0 deletions supabase/migrations/20240708094214_fix_db_stats_function.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
drop function if exists get_monthly_weather();

CREATE OR REPLACE FUNCTION public.get_monthly_weather()
RETURNS TABLE(month text, avg_temperature_celsius double precision, max_temperature_celsius double precision, total_rainfall_liters double precision)
LANGUAGE plpgsql
AS $function$
BEGIN
RETURN QUERY
SELECT to_char(daily_weather_data.measure_day, 'yyyy-mm') AS month, AVG(daily_weather_data.avg_temperature_celsius) as avg_temperature_celsius, MAX(daily_weather_data.avg_temperature_celsius) as max_temperature_celsius, SUM(daily_weather_data.sum_precipitation_mm_per_sqm) as total_rainfall_liters
FROM daily_weather_data
GROUP BY to_char(daily_weather_data.measure_day, 'yyyy-mm')
ORDER BY to_char(daily_weather_data.measure_day, 'yyyy-mm') DESC;
END;
$function$

0 comments on commit ceb5942

Please sign in to comment.