gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r14402 - gauger


From: gnunet
Subject: [GNUnet-SVN] r14402 - gauger
Date: Mon, 14 Feb 2011 20:43:48 +0100

Author: bartpolot
Date: 2011-02-14 20:43:48 +0100 (Mon, 14 Feb 2011)
New Revision: 14402

Modified:
   gauger/explore.php
   gauger/params.php
   gauger/plot.php
   gauger/template_graph.php
   gauger/template_host.php
Log:
Added unit indentification and labeling


Modified: gauger/explore.php
===================================================================
--- gauger/explore.php  2011-02-14 18:06:36 UTC (rev 14401)
+++ gauger/explore.php  2011-02-14 19:43:48 UTC (rev 14402)
@@ -1,4 +1,16 @@
 <?php
+
+function get_counter_name($s) {
+    return preg_replace('/([^_]+).*/', '\1', $s);
+}
+
+function get_counter_unit($s) {
+    if(strpos($s, '_') !== FALSE)
+        return preg_replace('/.+_([^_]+)/', '\1', $s);
+    else
+        return "";
+}
+
 $d = dir(".");
 $hosts = array();
 while (false !== ($entry = $d->read())) {
@@ -12,4 +24,7 @@
         }
     }
 }
-$d->close();
\ No newline at end of file
+$d->close();
+// echo '<pre>';
+// print_r($hosts);
+// die('end');
\ No newline at end of file

Modified: gauger/params.php
===================================================================
--- gauger/params.php   2011-02-14 18:06:36 UTC (rev 14401)
+++ gauger/params.php   2011-02-14 19:43:48 UTC (rev 14402)
@@ -2,12 +2,16 @@
 
 // TODO: refactor into get_param function
 function get_param($name) {
-
+    if (array_key_exists($name, $_REQUEST)) {
+        return $_REQUEST[$name];
+    } else {
+        return "";
+    }
 }
 
 session_start();
 
-if (array_key_exists('logout', $_REQUEST)) {
+if (get_param('logout')) {
     session_unset();
     header("Location: " . preg_replace("/\?.*/", "", $_SERVER["REQUEST_URI"]));
     die();
@@ -16,26 +20,10 @@
 $mode_host = FALSE;
 $mode_graph = FALSE;
 
-if (array_key_exists('host', $_REQUEST)) {
-    $_SESSION['host'] = $_REQUEST['host'];
-    $current = $_REQUEST['host'];
+if ($current = get_param('host')) {
     $mode_host = TRUE;
-} /*else {
-    if (array_key_exists('host', $_SESSION)) {
-        $current = $_SESSION['host'];
-    } else {
-        $current = "";
-    }
-}*/
+}
 
-if (array_key_exists('graph', $_REQUEST)) {
-    $_SESSION['graph'] = $_REQUEST['graph'];
-    $currentg = $_REQUEST['graph'];
+if ($currentg = get_param('graph')) {
     $mode_graph = TRUE;
-} /*else {
-    if (array_key_exists('graph', $_SESSION)) {
-        $currentg = $_SESSION['graph'];
-    } else {
-        $currentg = "";
-    }
-}*/
+}
\ No newline at end of file

Modified: gauger/plot.php
===================================================================
--- gauger/plot.php     2011-02-14 18:06:36 UTC (rev 14401)
+++ gauger/plot.php     2011-02-14 19:43:48 UTC (rev 14402)
@@ -6,29 +6,37 @@
  * @return: stream representing a png graph
  */
 function plot($g = array(), $h = array()) {
+    global $hosts;
+
     $cmd =  'load "header.gp";';
+    if(!empty($g)) $cmd .=  ' set ylabel "' . get_counter_unit($g[0]) . '";';
     $cmd .= ' plot';
-    global $hosts;
 
     $ch = count($h);
-    $cg = count($g);
-
     if($ch == 0){
         $h = array_keys($hosts);
     }
+    $cg = count($g);
 
+    $units = Array();
     $c = 0;
     foreach($h as $host) {
         $counters = $hosts[$host];
         if($cg == 0) $g = $counters;
         foreach($g as $graph) {
             if(array_search($graph, $counters) === FALSE) continue;
+            $unit = get_counter_unit($graph);
+            $units[$unit] = 1;
+            if(count($units) > 2) {
+                die('TOOMANYUNITS');
+            }
+            $counter = get_counter_name($graph);
             if($c) $cmd .= ',';
             $cmd .= " \"$host/$graph.dat\"";
             $cmd .= " title \"";
             if($ch != 1) $cmd .= $host;
             if($ch != 1 && $cg != 1) $cmd .= " - ";
-            if($cg != 1) $cmd .= $graph;
+            if($cg != 1) $cmd .= $counter;
             $cmd .= "\"";
             $cmd .= " with lines lw 2";
             if($ch == 1 && $cg == 1) $cmd .= ", \"$host/$graph.dat\" notitle 
with yerrorbars lw 1";
@@ -36,11 +44,14 @@
         }
     }
 
+// echo '<pre>';
+// print_r($hosts);
+// print_r($h);
+// print_r($g);
+// die($cmd);
+
     if(!$c) die('NODATA');
 
-//print_r($h);
-//print_r($g);
-//die($cmd);
     $cmd = "echo '$cmd' | gnuplot";
     $out = shell_exec($cmd);
 
@@ -48,15 +59,18 @@
 }
 
 include "explore.php";
+include "params.php";
 
-$h = array();
-if (array_key_exists('h', $_REQUEST)) {
-    $h = explode(',', $_REQUEST['h']);
+if ($h = get_param('h')) {
+    $h = explode(',', $h);
+} else {
+    $h = array();
 }
 
-$g = array();
-if (array_key_exists('g', $_REQUEST)) {
-    $g = explode(',', $_REQUEST['g']);
+if ($g = get_param('g')) {
+    $g = explode(',', $g);
+} else {
+    $g = array();
 }
 
 $out = plot($g, $h);

Modified: gauger/template_graph.php
===================================================================
--- gauger/template_graph.php   2011-02-14 18:06:36 UTC (rev 14401)
+++ gauger/template_graph.php   2011-02-14 19:43:48 UTC (rev 14402)
@@ -1,3 +1,3 @@
-<h1>SHOWING GRAPH: <?php echo $currentg ?></h1>
+<h1>SHOWING GRAPH: <?php echo get_counter_name($currentg) ?></h1>
 <img src="plot.php?g=<?php echo $currentg ?>" alt="PNG not found :("/>
 <p>TODO: Select hosts | Range | Normalize </p>

Modified: gauger/template_host.php
===================================================================
--- gauger/template_host.php    2011-02-14 18:06:36 UTC (rev 14401)
+++ gauger/template_host.php    2011-02-14 19:43:48 UTC (rev 14402)
@@ -9,11 +9,11 @@
         <?php foreach ($hosts[$current] as $counter): ?>
         <tr>
             <th>
-                <?php echo $counter ?><br/><br/>
+                <?php echo get_counter_name($counter) ?><br/><br/>
                 <a href="?graph=<?php echo $counter ?>">Compare</a><br/>
                 <br/>TODO:<br/>Range<br/>Add counter<br/>Colors
             </th>
-            <td><img src="<?php echo 'plot.php?h='. $current . '&g=' . 
$counter ?>" alt="PNG not found :("/></td>
+            <td><img src="plot.php?h=<?php echo "$current&g=$counter" ?>" 
alt="PNG not found :("/></td>
         </tr>
         <?php endforeach; ?>
     </table>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]