Переделка веб-интерфейса
authorRoman Bazalevsky <rvb@rvb.name>
Tue, 21 Oct 2014 10:55:30 +0000 (14:55 +0400)
committerRoman Bazalevsky <rvb@rvb.name>
Tue, 21 Oct 2014 10:55:30 +0000 (14:55 +0400)
web/archive.php
web/graphs.php [new file with mode: 0644]
web/image.php
web/index.php
web/units.php [new file with mode: 0644]

index 031bce768e2208451d8da000d84b8dbfde2a7eb4..c40386389e5a7e5bea9d368c16ee2b31ed688369 100644 (file)
 
 include('config_local.php');
 include('calendar.php');
-
-function get_unit($db,$param) {
-
-  $qug = $db -> prepare(
-    'select u.id,u.unit_group from st_parameters st,units u where st.id='.$param.' and st.st_unit=u.id'
-  );
-  $qug -> execute();
-                                    
-  while ($row = $qug -> fetch(PDO::FETCH_ASSOC)) {
-    $from_unit = $row['id'];
-    $unit_group = $row['unit_group'];
-  }
-                                                                       
-  if (!empty($_COOKIE['unit_'.$unit_group])) {
-    $to_unit=intval($_COOKIE['unit_'.$unit_group]);
-  } else {
-    $to_unit=$from_unit;
-  }
-                                                                                                                
-  $qu = $db -> prepare(
-    'select u.name_short from units u where u.id='.$to_unit
-  );
-  $qu -> execute();
-                                                                                                                                                                 
-  while ($row = $qu -> fetch(PDO::FETCH_ASSOC)) {
-    $param_unit = $row['name_short'];
-  }
-  return Array(
-    'from' => $from_unit,
-    'to' => $to_unit,
-    'name' => $param_unit
-  );                                                                                                                                                                                    
-
-}
-
-function convert_unit($db,$value,$from,$to) {
-
-  if ($from==$to) {
-
-    $val = $value;
-
-  } else {
-
-    $qv = $db -> prepare(
-      'select round(unitconv('.$value.','.$from.','.$to.'),2) res'
-    );
-    $qv -> execute();
-                            
-    while ($row = $qv -> fetch(PDO::FETCH_ASSOC)) {
-      $val = $row['res'];
-    }
-
-  }
-                                                        
-  return $val;
-
-}
+include('units.php');
 
 $year = $_REQUEST['year']; 
 $month = $_REQUEST['month'];
diff --git a/web/graphs.php b/web/graphs.php
new file mode 100644 (file)
index 0000000..dfc7450
--- /dev/null
@@ -0,0 +1,53 @@
+<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
+<html>
+<head>
+  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
+  <meta name="GENERATOR" content="Mozilla/4.72 (X11; U; Linux 2.2.12-20smp i686) [Netscape]">    
+  <title>WeatherMon (Последние 24 часа)</title>                      
+  <link rel="icon" href="favicon.png" />
+  <style type="text/css">
+     a:visited { text-decoration: none; color:darkblue; }
+     a:link { text-decoration: none; color:blue; }
+     a:hover { text-decoration: none; color:navy; }
+  </style>
+</head>
+<body text="black" bgcolor="silver" link="blue" vlink="#000080" alink="#FF0000">         
+<?php
+
+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($err);
+  }  
+
+$db -> exec('SET CHARACTER SET utf8');
+
+$q = $db -> prepare(
+  'select 
+    distinct v.sensor_id,s.s_description,p.id as param_id,p.st_description 
+  from 
+    sensor_values v,st_parameters p,sensors s 
+  where 
+    v.timestamp>adddate(now(), -1) 
+    and v.sensor_id=s.id 
+    and s.st_id=p.st_id
+    and p.id>=0
+  order by s_description,st_description'
+  );
+$q -> execute();
+
+while ($row = $q -> fetch(PDO::FETCH_ASSOC)) {
+
+  echo '<h3 align="center">'.$row['s_description'].'/'.$row['st_description'].'</h3>';
+?>
+<center><img src="image.php?sensor=<?php echo $row['sensor_id']; ?>&param=<?php echo $row['param_id']?>&type=last24"></center>
+<?php  
+
+}                                                            
+  
+?>
+<a href="archive.php">Архивные данные</a>
+<br>
+<a href="setup.php">Настройки</a>
+</body>
+      
\ No newline at end of file
index 0e513a1e2fe2ff39f73a28b1b8e7fc2929911e74..16fbafb89f28de2b801b3c34d77564875159cf43 100644 (file)
@@ -82,7 +82,23 @@ if ($type and $param) {
       'select unix_timestamp(timestamp) as x,unitconv(value,'.$from_unit.','.$to_unit.') as y from sensor_values where timestamp>adddate(now(), -1) and sensor_id='.$sensor.' and parameter_id='.$param.' order by timestamp'
     );
 
-    $height = 130;
+    $bottomheight = 130;
+    $topheight = 40;
+    $sizex = 1000;
+    $sizey = 800;
+    $scale = True;
+    
+  } elseif ($type == 'last24small') {
+
+    $q = $db -> prepare(
+      'select unix_timestamp(timestamp) as x,unitconv(value,'.$from_unit.','.$to_unit.') as y from sensor_values where timestamp>adddate(now(), -1) and sensor_id='.$sensor.' and parameter_id='.$param.' order by timestamp'
+    );
+
+    $bottomheight = 20;
+    $topheight = 20;
+    $sizex = 400;
+    $sizey = 300;
+    $scale = False;
     
   } elseif ($type == 'range') {
 
@@ -101,11 +117,15 @@ if ($type and $param) {
       'select unix_timestamp(timestamp) as x,unitconv(value,'.$from_unit.','.$to_unit.') as y from sensor_values where timestamp>=str_to_date("'.$from.'","%Y%m%d%H%i%s") and timestamp<=str_to_date("'.$to.'","%Y%m%d%H%i%s") and sensor_id='.$sensor.' and parameter_id='.$param.' order by timestamp'
     );
   
-    $height = 60;
+    $bottomheight = 60;
+    $topheight = 40;
+    $sizex = 1000;
+    $sizey = 800;
+    $scale = True;
   
   }
 
-  $g = new Graph(640,480);
+  $g = new Graph($sizex,$sizey);
   
   if ($cachefilename) {
       if ($g->cache->IsValid($cachefilename)) {
@@ -172,9 +192,13 @@ if ($type and $param) {
   // We need a datlin scale since we provide both
   // x and y coordinates for the data points, but x is unix timestamp.
   $g->SetScale('datlin');
-  $g->xaxis->SetLabelAngle(90);
+  if ($scale) {
+    $g->xaxis->SetLabelAngle(90);
+  } else {
+    $g->xaxis->HideLabels(True);
+  }
   $g->xaxis->SetPos("min");
-  $g->xaxis->scale->SetTimeAlign( HOURADJ_1 );
+#  $g->xaxis->scale->SetTimeAlign( HOURADJ_1 );
 
   // We use a scatterplot to illustrate the original
   // contro points.
@@ -192,10 +216,12 @@ if ($type and $param) {
   $fplot->SetColor($line_color);
   $fplot->SetWeight(2);
 
-  $g->SetMargin(50,30,40,$height);
-  $g->title->Set($sensor_name.'/'.$param_name.', '.$param_unit);
-  $g->title->SetFont(FF_DV_SANSSERIF,FS_BOLD,12);
-  $g->SetMarginColor('silver');
+  $g->SetMargin(50,30,$topheight,$bottomheight);
+  if ($scale) {
+    $g->title->Set($sensor_name.'/'.$param_name.', '.$param_unit);
+    $g->title->SetFont(FF_DV_SANSSERIF,FS_BOLD,12);
+  }  
+  $g->SetMarginColor('lightgray');
 
   $g->xgrid->Show();
   $g->xgrid->SetLineStyle('dotted');
index dfc7450d7463a2cdafaed2c21458f068bcb4bdeb..37251e653214c0b70ed45d4e11408103d0fe3f1b 100644 (file)
@@ -2,6 +2,7 @@
 <html>
 <head>
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
+  <meta http-equiv="Refresh" content="60"> 
   <meta name="GENERATOR" content="Mozilla/4.72 (X11; U; Linux 2.2.12-20smp i686) [Netscape]">    
   <title>WeatherMon (Последние 24 часа)</title>                      
   <link rel="icon" href="favicon.png" />
      a:visited { text-decoration: none; color:darkblue; }
      a:link { text-decoration: none; color:blue; }
      a:hover { text-decoration: none; color:navy; }
+     .header { font-size: 16; float: left; margin: 10px;}
+     .timestamp { font-size: 16; margin: 10px;}
+     .value { font-size: 60; margin: 10px; }
+     .block { float: left; margin: 20px; }
+     .container { clear: both; }
+     .footer { clear: both; margin: 20px; font-size: 20; }
   </style>
 </head>
-<body text="black" bgcolor="silver" link="blue" vlink="#000080" alink="#FF0000">         
+<body>         
+<div class="container">
 <?php
 
 include('config_local.php');
+include('units.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($err);
@@ -38,16 +47,57 @@ $q -> execute();
 
 while ($row = $q -> fetch(PDO::FETCH_ASSOC)) {
 
-  echo '<h3 align="center">'.$row['s_description'].'/'.$row['st_description'].'</h3>';
+  echo '<div class="block">';
+  echo '<div class="header">'.$row['s_description'].'/'.$row['st_description'].'</div>';
+
+$ql =  $db -> prepare(
+  '
+    SELECT unix_timestamp(timestamp) timestamp,DATE_FORMAT(timestamp,"%H:%i") printable,value
+    FROM
+      meteo.sensor_values 
+    WHERE 
+      sensor_id='.$row['sensor_id'].' and parameter_id='.$row['param_id'].' and timestamp>addtime(now(), -3600)
+    ORDER BY 
+      timestamp desc
+  '
+   );
+
+$ql -> execute();
+
+$printable_ts = "?";
+$value = "?";
+
+if ($rowl = $ql -> fetch(PDO::FETCH_ASSOC)) {
+
+  $timestamp = $rowl['timestamp'];
+  $printable_ts = $rowl['printable'];
+  $value = $rowl['value'];
+
+  $units = get_unit($db,$row['param_id']);
+  $from_unit = $units['from'];
+  $to_unit = $units['to'];
+  $param_unit = $units['name'];
+                        
+  $val = convert_unit($db,$value,$from_unit,$to_unit);
+                              
+}
+                                  
+echo '<div class="timestamp">'.$printable_ts.'</div>';
+echo '<div class="value">'.$val.' '.$param_unit.'</div>';
 ?>
-<center><img src="image.php?sensor=<?php echo $row['sensor_id']; ?>&param=<?php echo $row['param_id']?>&type=last24"></center>
+<div class="graph"><img src="image.php?sensor=<?php echo $row['sensor_id']; ?>&param=<?php echo $row['param_id']?>&type=last24small"></div>
 <?php  
 
+echo "</div>";
+
 }                                                            
   
 ?>
+</div>
+<div class="footer">
 <a href="archive.php">Архивные данные</a>
-<br>
+<a href="graphs.php">Подробные графики</a>
 <a href="setup.php">Настройки</a>
+</div>
 </body>
       
\ No newline at end of file
diff --git a/web/units.php b/web/units.php
new file mode 100644 (file)
index 0000000..16ad227
--- /dev/null
@@ -0,0 +1,61 @@
+<?php
+
+function get_unit($db,$param) {
+
+  $qug = $db -> prepare(
+    'select u.id,u.unit_group from st_parameters st,units u where st.id='.$param.' and st.st_unit=u.id'
+  );
+  $qug -> execute();
+                                    
+  while ($row = $qug -> fetch(PDO::FETCH_ASSOC)) {
+    $from_unit = $row['id'];
+    $unit_group = $row['unit_group'];
+  }
+                                                                       
+  if (!empty($_COOKIE['unit_'.$unit_group])) {
+    $to_unit=intval($_COOKIE['unit_'.$unit_group]);
+  } else {
+    $to_unit=$from_unit;
+  }
+                                                                                                                
+  $qu = $db -> prepare(
+    'select u.name_short from units u where u.id='.$to_unit
+  );
+  $qu -> execute();
+                                                                                                                                                                 
+  while ($row = $qu -> fetch(PDO::FETCH_ASSOC)) {
+    $param_unit = $row['name_short'];
+  }
+  return Array(
+    'from' => $from_unit,
+    'to' => $to_unit,
+    'name' => $param_unit
+  );                                                                                                                                                                                    
+
+}
+
+function convert_unit($db,$value,$from,$to) {
+
+  if ($from==$to) {
+
+    $val = $value;
+
+  } else {
+
+    $qv = $db -> prepare(
+      'select round(unitconv('.$value.','.$from.','.$to.'),2) res'
+    );
+    $qv -> execute();
+                            
+    while ($row = $qv -> fetch(PDO::FETCH_ASSOC)) {
+      $val = $row['res'];
+    }
+
+  }
+                                                        
+  return $val;
+
+}
+
+?>
\ No newline at end of file