Добавлено "прореживание" исторических данных.
/*!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<pUpTo and reduced=pRID
+ group by sensor_id,parameter_id,floor(unix_timestamp(timestamp)/lSeconds);
+
+ select date(min(timestamp)),date(max(timestamp)) into lStart,lEnd from tmp_sensor_values;
+
+ delete from sensor_values where timestamp<pUpTo and reduced=pRID;
+
+ insert into sensor_values(sensor_id,parameter_id,timestamp,value,reduced)
+ select sensor_id,parameter_id,timestamp,value,lNewRID from tmp_sensor_values;
+
+ delete from sensors_ranges
+ where day>=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<date_add(lEnd, interval 1 day)
+ group by date(timestamp),sensor_id,parameter_id;
+
+ delete from tmp_sensor_values;
+
+END$$
+DELIMITER ;
+
+DELIMITER $$
+CREATE DEFINER=`admin`@`%` PROCEDURE `Cron_Reduce`(pMonths integer)
+BEGIN
+ declare lTime datetime;
+ select date_sub(date_format(now(),'%Y-%m-01'), interval pMonths month) into lTime;
+ call meteo.reduce(lTime,0);
+END$$
+DELIMITER ;
+
+
+
-- Dump completed on 2014-09-25 14:45:45
`name` varchar(32) CHARACTER SET utf8 NOT NULL,
`name_short` varchar(8) CHARACTER SET utf8 NOT NULL,
`unit_group` int(11) NOT NULL,
+ `prec` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `fk_units_group_idx` (`unit_group`),
CONSTRAINT `fk_units_group` FOREIGN KEY (`unit_group`) REFERENCES `unit_groups` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
--- /dev/null
+CREATE TABLE `tmp_sensor_values` (
+ `id` int(11) NOT NULL DEFAULT '0',
+ `sensor_id` int(11) NOT NULL,
+ `timestamp` datetime NOT NULL,
+ `value` float NOT NULL,
+ `parameter_id` int(11) NOT NULL,
+ `reduced` int(11) DEFAULT '0'
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
<?php // content="text/plain; charset=utf-8"
-error_reporting(E_ALL & ~E_STRICT & ~E_NOTICE);
+error_reporting(E_ALL & ~E_STRICT & ~E_NOTICE & ~E_DEPRECATED);
include ('config_local.php');
if (! ($db = new PDO("mysql:host=$mysql_host;port=$mysql_port;dbname=$mysql_schema",$mysql_user,$mysql_pwd,array( PDO::ATTR_PERSISTENT => false)))) {
- die('Не могу подключиться к БД');
+ die('Ð\9dе могу подключитьÑ\81Ñ\8f к БД');
}
}
$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();
$g->xaxis->HideLabels(True);
}
$g->xaxis->SetPos("min");
+ $g->yaxis->SetLabelFormat("%0.".$precision."f");
# $g->xaxis->scale->SetTimeAlign( HOURADJ_1 );
} else {
header("Content-Type: text/html; charset=UTF-8");
- die('СенÑ\81оÑ\80 не вÑ\8bбÑ\80ан!');
+ die('Ã\90¡Ã\90µÃ\90½Ã\91Â\81Ã\90¾Ã\91â\82¬ Ã\90½Ã\90µ Ã\90²Ã\91â\80¹Ã\90±Ã\91â\82¬Ã\90°Ã\90½!');
}
}
$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();
}
+ $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,
from
sensors_ranges
where
- day>=str_to_date(\''.$year.$month.'\',\'%Y%m\')
- and day<str_to_date(\''.$next_year.$next_month.'\',\'%Y%m\')
+ day>=STR_TO_DATE(\''.$datestr.'\',\'%Y%m%d\')
+ and day<STR_TO_DATE(\''.$nextdatestr.'\',\'%Y%m%d\')
and sensor='.$sensor.'
and parameter='.$param.'
) t group by x
order by x'
);
-
+
} elseif ($type == "year") {
$next_year = $year+1;
}
+ $datestr=sprintf("%04d0101",$year);
+ $nextdatestr=sprintf("%04d0101",$next_year);
+
$q = $db -> prepare(
'
select
from
sensors_ranges
where
- day>=str_to_date(\''.$year.'\',\'%Y\')
- and day<str_to_date(\''.$next_year.'\',\'%Y\')
+ day>=STR_TO_DATE(\''.$datestr.'\',\'%Y%m%d\')
+ and day<STR_TO_DATE(\''.$nextdatestr.'\',\'%Y%m%d\')
and sensor='.$sensor.'
and parameter='.$param.'
) t group by x
}
-
// Create the graph
$g->graph_theme = null;