Удалил барахло
[weathermon.git] / web / image.php
index 0e513a1e2fe2ff39f73a28b1b8e7fc2929911e74..9b6ca84e3209b5de7b07c08e83b292488f16dc2c 100644 (file)
@@ -1,6 +1,6 @@
 <?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');
 
@@ -12,7 +12,7 @@ require_once ('jpgraph/jpgraph_regstat.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 Ðº Ð‘Д');
 
 }  
 
@@ -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();
@@ -82,7 +83,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 +118,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,30 +193,42 @@ 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->yaxis->SetLabelFormat("%0.".$precision."f");
+#  $g->xaxis->scale->SetTimeAlign( HOURADJ_1 );
+
+
+  if ($type!="last24small") {
 
-  // We use a scatterplot to illustrate the original
-  // contro points.
-  $splot = new ScatterPlot($ydata,$xdata);
-  $g->Add($splot);
+    // We use a scatterplot to illustrate the original
+    // contro points.
+    $splot = new ScatterPlot($ydata,$xdata);
+    $g->Add($splot);
 
-  // 
-  $splot->mark->SetFillColor($dot_color);
-  $splot->mark->SetColor($dot_color);
-  $splot->mark->SetType(MARK_FILLEDCIRCLE);
-  $splot->mark->SetSize(2);
+    // 
+    $splot->mark->SetFillColor($dot_color);
+    $splot->mark->SetColor($dot_color);
+    $splot->mark->SetType(MARK_FILLEDCIRCLE);
+    $splot->mark->SetSize(2);
+
+  }
 
   $fplot = new LinePlot($f_ydata,$xdata);
   $g->Add($fplot);
   $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');
@@ -208,7 +241,7 @@ if ($type and $param) {
 } 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½!');
 
 }