1 <!doctype html public "-//w3c//dtd html 4.0 transitional//en">
4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
5 <meta name="GENERATOR" content="Mozilla/4.72 [cp1251] (X11; U; Linux 2.2.12-20smp i686) [Netscape]">
6 <title>WeatherMon (архив)</title>
7 <link rel="icon" href="favicon.png" />
9 <body text="black" bgcolor="silver" link="blue" vlink="#000080" alink="#FF0000">
12 include('config_local.php');
13 include('calendar.php');
15 $year = $_REQUEST['year'];
16 $month = $_REQUEST['month'];
17 $day = $_REQUEST['day'];
19 if (! ($db = new PDO("mysql:host=$mysql_host;port=$mysql_port;dbname=$mysql_schema",$mysql_user,$mysql_pwd,array( PDO::ATTR_PERSISTENT => false)))) {
23 $db -> exec('SET CHARACTER SET utf8');
29 date_format(timestamp,\'%Y\') as year
36 <h1>Архив метеоданных</h1>
38 while ($row = $q -> fetch(PDO::FETCH_ASSOC)) {
40 <a href="?year=<?php echo $row['year']; ?>">Данные за <?php echo $row['year']; ?> год</a><br>
49 $year = sprintf('%04d',$year);
50 $next_year = sprintf('%04d',$next_year);
53 date_format(timestamp,\'%m\') as month,
54 date_format(timestamp,\'%d\') as day
58 timestamp>=str_to_date(\''.$year.'-01-01\',\'%Y-%m-%d\') and
59 timestamp<str_to_date(\''.$next_year.'-01-01\',\'%Y-%m-%d\')
65 <h1 align="center"><?php echo $year; ?> год</h1>
67 $data = $q -> fetchAll(PDO::FETCH_ASSOC);
69 foreach ($data as $row) {
70 $days [$year.$row['month'].$row['day']] = '&month='.$row['month'].'&day='.$row['day'];
71 $months[$row['month']]=1;
74 echo '<table align="center">';
75 for ($i=1; $i<=3; $i++) {
77 for ($j=1; $j<=4; $j++) {
78 echo '<td valign="top">';
79 $month=sprintf('%02d',$m);
80 $month_name = strftime('%B',mktime(0,0,0,$month,1,$year));
81 if (!empty($months[$month])) {
82 echo '<h3 align="center"><a href="?year='.$year.'&month='.$month.'">'.$month_name.'</a></h3>';
84 echo '<h3 align="center">'.$month_name.'</h3>';
86 calendar($year,$month,$days,'?year='.$year.'%s',0);
98 s.id sensor,p.id param,s.s_description sensor_name,p.st_description param_name,
99 count(distinct date_format(v.timestamp,\'%d\')) cnt,
100 round(min(v.value),1) min_value,
101 round(max(v.value),1) max_value,
104 sensor_values v,sensors s,st_parameters p,units u
107 v.parameter_id=p.id and
109 v.timestamp>=str_to_date(\''.$year.'-01-01\',\'%Y-%m-%d\') and
110 v.timestamp<str_to_date(\''.$next_year.'-01-01\',\'%Y-%m-%d\')
111 group by s.id,p.id,s.s_description,p.st_description
116 $sensors = $q -> fetchAll(PDO::FETCH_ASSOC);
118 foreach ($sensors as $sensor) {
120 echo '<h3 align="center">'.$sensor['param_name'].'('.$sensor['sensor_name'].')</h3>';
121 echo '<table align="center">';
123 echo 'Минимальное значение за год <b>'.$sensor['min_value'].' '.$sensor['unit'].'</b><br>';
124 echo 'Максимальное значение за год <b>'.$sensor['max_value'].' '.$sensor['unit'].'</b><br>';
128 if ($sensor['cnt']>1) {
130 echo '<center><img src="image_minmax.php?sensor='.$sensor['sensor'].'¶m='.$sensor['param'].
131 '&type=year&year='.$year.'"></center>';
143 $next_month = $month+1;
145 if ($next_month == 13) {
147 $next_year = $next_year+1;
150 $next_month = sprintf('%02d',$next_month);
151 $next_year = sprintf('%04d',$next_year);
152 $month = sprintf('%02d',$month);
153 $year = sprintf('%04d',$year);
157 date_format(timestamp,\'%d\') as day
161 timestamp>=str_to_date(\''.$year.'-'.$month.'-01\',\'%Y-%m-%d\') and
162 timestamp<str_to_date(\''.$next_year.'-'.$next_month.'-01\',\'%Y-%m-%d\')
168 $data = $q -> fetchAll(PDO::FETCH_ASSOC);
170 $month_name = strftime('%B %Y',mktime(0,0,0,$month,1,$year));
173 <h1 align="center"><?php echo 'Данные за '.$month_name; ?></h1>
175 foreach ($data as $row) {
176 $days [$year.$month.$row['day']] = $row['day'];
179 calendar($year,$month,$days,'?year='.$year.'&month='.$month.'&day=%s',3);
181 $q = $db -> prepare (
183 s.id sensor,p.id param,s.s_description sensor_name,p.st_description param_name,
184 count(distinct date_format(v.timestamp,\'%d\')) cnt,
185 round(min(v.value),1) min_value,
186 round(max(v.value),1) max_value,
189 sensor_values v,sensors s,st_parameters p,units u
192 v.parameter_id=p.id and
194 v.timestamp>=str_to_date(\''.$year.'-'.$month.'-01\',\'%Y-%m-%d\') and
195 v.timestamp<str_to_date(\''.$next_year.'-'.$next_month.'-01\',\'%Y-%m-%d\')
196 group by s.id,p.id,s.s_description,p.st_description
201 $sensors = $q -> fetchAll(PDO::FETCH_ASSOC);
203 foreach ($sensors as $sensor) {
205 echo '<h3 align="center">'.$sensor['param_name'].'('.$sensor['sensor_name'].')</h3>';
206 echo '<table align="center">';
208 echo 'Минимальное значение за месяц <b>'.$sensor['min_value'].' '.$sensor['unit'].'</b><br>';
209 echo 'Максимальное значение за месяц <b>'.$sensor['max_value'].' '.$sensor['unit'].'</b><br>';
213 if ($sensor['cnt']>1) {
215 echo '<center><img src="image_minmax.php?sensor='.$sensor['sensor'].'¶m='.$sensor['param'].
216 '&type=month&year='.$year.'&month='.$month.'"></center>';
224 $month = sprintf('%02d',$month);
225 $year = sprintf('%04d',$year);
226 $day = sprintf('%02d',$day);
230 distinct v.sensor_id,s.s_description,p.id as param_id,p.st_description
232 sensor_values v,st_parameters p,sensors s
234 v.timestamp>=str_to_date(\''.$year.'-'.$month.'-'.$day.'\',\'%Y-%m-%d\') and
235 v.timestamp<date_add(str_to_date(\''.$year.'-'.$month.'-'.$day.'\',\'%Y-%m-%d\'),interval 1 day)
241 while ($row = $q -> fetch(PDO::FETCH_ASSOC)) {
243 echo '<h3 align="center">'.$row['s_description'].'/'.$row['st_description'].'</h3>';
245 <center><img src="image.php?sensor=<?php echo $row['sensor_id']; ?>¶m=<?php echo $row['param_id']?>&type=range&fromdate=<?php echo $year.$month.$day.'000000'; ?>&todate=<?php echo $year.$month.$day.'235959'?>"></center>