From: Roman Bazalevsky Date: Mon, 30 May 2016 15:17:05 +0000 (+0300) Subject: Добавлено настраиваемое округление значений при выводе на графике. X-Git-Url: https://git.rvb.name/weathermon.git/commitdiff_plain/888e7fac57439dbb42864d77122a4cf551889477?hp=--cc Добавлено настраиваемое округление значений при выводе на графике. Добавлено "прореживание" исторических данных. --- 888e7fac57439dbb42864d77122a4cf551889477 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 false)))) { - die('Не могу подключиться к БД'); + die('Не могу подключиться к БД'); } @@ -65,12 +65,13 @@ if ($type and $param) { } $q = $db -> prepare( - 'select u.name_short from units u where u.id='.$to_unit + 'select u.name_short,u.prec from units u where u.id='.$to_unit ); $q -> execute(); while ($row = $q -> fetch(PDO::FETCH_ASSOC)) { $param_unit = $row['name_short']; + $precision = $row['prec']; } $xdata = array(); @@ -198,6 +199,7 @@ if ($type and $param) { $g->xaxis->HideLabels(True); } $g->xaxis->SetPos("min"); + $g->yaxis->SetLabelFormat("%0.".$precision."f"); # $g->xaxis->scale->SetTimeAlign( HOURADJ_1 ); @@ -239,7 +241,7 @@ if ($type and $param) { } else { header("Content-Type: text/html; charset=UTF-8"); - die('Сенсор не выбран!'); + die('Сенсор не выбран!'); } diff --git a/web/image_minmax.php b/web/image_minmax.php index 183942b..edc1708 100644 --- a/web/image_minmax.php +++ b/web/image_minmax.php @@ -48,8 +48,7 @@ if ($type and $param) { } $q = $db -> prepare( - 'select st.st_fill_color_top,st.st_fill_color_bottom,st.st_description,u.id,u.unit_group from st_parameters st,units u where st.id='.$param.' and st.st_unit=u.id -' + 'select st.st_fill_color_top,st.st_fill_color_bottom,st.st_description,u.id,u.unit_group from st_parameters st,units u where st.id='.$param.' and st.st_unit=u.id' ); $q -> execute(); @@ -100,8 +99,11 @@ if ($type and $param) { } + $datestr=sprintf("%04d%02d01",$year,$month); + $nextdatestr=sprintf("%04d%02d01",$next_year,$next_month); + $q = $db -> prepare( - ' + ' select x, unitconv(min(min),'.$from_unit.','.$to_unit.') min_value, @@ -114,14 +116,14 @@ if ($type and $param) { from sensors_ranges where - day>=str_to_date(\''.$year.$month.'\',\'%Y%m\') - and day=STR_TO_DATE(\''.$datestr.'\',\'%Y%m%d\') + and day prepare( ' select @@ -150,8 +155,8 @@ if ($type and $param) { from sensors_ranges where - day>=str_to_date(\''.$year.'\',\'%Y\') - and day=STR_TO_DATE(\''.$datestr.'\',\'%Y%m%d\') + and daygraph_theme = null;