X-Git-Url: https://git.rvb.name/weathermon.git/blobdiff_plain/42bd3e809b0fa95d3a463462e242caf40d98bf79..428b776c5748cdfe60245fba4336c01b4f62064b:/mysql/meteo_routines.sql?ds=inline diff --git a/mysql/meteo_routines.sql b/mysql/meteo_routines.sql index bf72780..5f819b3 100644 --- a/mysql/meteo_routines.sql +++ b/mysql/meteo_routines.sql @@ -128,4 +128,55 @@ DELIMITER ; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; +DELIMITER $$ +CREATE DEFINER=`admin`@`%` PROCEDURE `Reduce`(pUpTo datetime,pRID integer) +BEGIN + declare lNewRID integer; + declare lSeconds integer; + + declare lStart,lEnd timestamp; + + set lNewRID:=pRID+1; + select seconds into lSeconds from reduce_ranges where id=lNewRID; + + delete from tmp_sensor_values; + + insert into tmp_sensor_values(sensor_id,parameter_id,timestamp,value) + select sensor_id,parameter_id,from_unixtime(avg(unix_timestamp(timestamp))),avg(value) + from sensor_values + where timestamp=lStart and day<=lEnd; + + insert into sensors_ranges(day,sensor,parameter,timestamp,min,max) + select date(timestamp),sensor_id,parameter_id,max(timestamp),min(value),max(value) + from sensor_values + where timestamp>=lStart and timestamp