[Reconnoiter-devel] [reconnoiter commit] r437 - in trunk/ui/web: htdocs lib

svn-commit at lists.omniti.com svn-commit at lists.omniti.com
Sun Sep 21 19:54:45 EDT 2008


Author: jesus
Date: 2008-09-21 19:54:44 -0400 (Sun, 21 Sep 2008)
New Revision: 437

Added:
   trunk/ui/web/lib/Reconnoiter_RPN.php
Modified:
   trunk/ui/web/htdocs/bw_settings.php
   trunk/ui/web/htdocs/generic_settings.php
   trunk/ui/web/lib/Reconnoiter_DataContainer.php
   trunk/ui/web/lib/Reconnoiter_DataSet.php
   trunk/ui/web/lib/Reconnoiter_amCharts_Driver.php
   trunk/ui/web/lib/Reconnoiter_amLine_Driver.php
Log:
as hard as we try, we cannot replace the elegance of reverse polish notation.  refs #22

Modified: trunk/ui/web/htdocs/bw_settings.php
===================================================================
--- trunk/ui/web/htdocs/bw_settings.php	2008-09-21 19:55:50 UTC (rev 436)
+++ trunk/ui/web/htdocs/bw_settings.php	2008-09-21 23:54:44 UTC (rev 437)
@@ -19,21 +19,21 @@
 $driver = new Reconnoiter_amLine_Driver($start, $end,
                                         isset($_GET['cnt']) ? $_GET['cnt'] : 400);
 $i = 0;
-$math = '$this->bw($value)';
+$math = 'auto,2,round';
 if($view == "packets") {
   $settings = $graph_settings[$i++];
-  $settings['expression'] = "0 - $math";
-  $driver->addDataSet($uuid, 'inucastpkts', true, '$value', $settings);
+  $settings['expression'] = "$math,-1,*";
+  $driver->addDataSet($uuid, 'inucastpkts', true, null, $settings);
   $settings = $graph_settings[$i++];
   $settings['expression'] = "$math";
-  $driver->addDataSet($uuid, 'outucastpkts', true, '$value', $settings);
+  $driver->addDataSet($uuid, 'outucastpkts', true, null, $settings);
 } else {
   $settings = $graph_settings[$i++];
-  $settings['expression'] = "0 - $math";
-  $driver->addDataSet($uuid, 'inoctets', true, '$value * 8', $settings);
+  $settings['expression'] = "$math,-1,*";
+  $driver->addDataSet($uuid, 'inoctets', true, '8,*', $settings);
   $settings = $graph_settings[$i++];
   $settings['expression'] = "$math";
-  $driver->addDataSet($uuid, 'outoctets', true, '$value * 8', $settings);
+  $driver->addDataSet($uuid, 'outoctets', true, '8,*', $settings);
   $driver->addChangeSet($uuid, 'alias');
   $driver->calcPercentile(95);
   $driver->addPercentileGuide('95th', 95, array('expression' => "$math"));

Modified: trunk/ui/web/htdocs/generic_settings.php
===================================================================
--- trunk/ui/web/htdocs/generic_settings.php	2008-09-21 19:55:50 UTC (rev 436)
+++ trunk/ui/web/htdocs/generic_settings.php	2008-09-21 23:54:44 UTC (rev 437)
@@ -24,7 +24,7 @@
   $settings = $graph_settings[$i++];
   if($matches[3] == '~') {
     $autounits = 1;
-    $settings['expression'] = '$this->autounits($value)';
+    $settings['expression'] = 'auto';
   }
   $settings['axis'] = ($matches[2] == 'l') ? 'left' : 'right';
   if($matches[1] == 'n')
@@ -32,7 +32,7 @@
   else if($matches[1] == 'd')
     $driver->addDataSet($matches[4], $matches[5], 'true', null, $settings);
   else if($matches[1] == 'D') {
-    $settings['expression'] = "((".$settings['expression']." > 0) ? (".$settings['expression'].") : 0)";
+    $settings['expression'] = $settings['expression'].",0,max";
     $driver->addDataSet($matches[4], $matches[5], 'true', null, $settings);
   }
   else

Modified: trunk/ui/web/lib/Reconnoiter_DataContainer.php
===================================================================
--- trunk/ui/web/lib/Reconnoiter_DataContainer.php	2008-09-21 19:55:50 UTC (rev 436)
+++ trunk/ui/web/lib/Reconnoiter_DataContainer.php	2008-09-21 23:54:44 UTC (rev 437)
@@ -3,8 +3,9 @@
 require_once('Reconnoiter_DB.php');
 require_once('Reconnoiter_DataSet.php');
 require_once('Reconnoiter_ChangeSet.php');
+require_once('Reconnoiter_RPN.php');
 
-class Reconnoiter_DataContainer {
+class Reconnoiter_DataContainer extends Reconnoiter_RPN {
   protected $units = 0;
   protected $start;
   protected $end;

Modified: trunk/ui/web/lib/Reconnoiter_DataSet.php
===================================================================
--- trunk/ui/web/lib/Reconnoiter_DataSet.php	2008-09-21 19:55:50 UTC (rev 436)
+++ trunk/ui/web/lib/Reconnoiter_DataSet.php	2008-09-21 23:54:44 UTC (rev 437)
@@ -1,6 +1,8 @@
 <?php
 
-class Reconnoiter_DataSet {
+require_once('Reconnoiter_RPN.php');
+
+class Reconnoiter_DataSet extends Reconnoiter_RPN {
   public $data;
   protected $expr;
   function __construct($uuid, $name, $derive, $expr, $start, $end, $cnt = 400) {
@@ -16,8 +18,6 @@
   }
   function data($ts, $attr = 'avg_value') {
     if(!$this->expr) return $this->data[$ts][$attr];
-    $value = $this->data[$ts][$attr];
-    eval("\$value = $this->expr;");
-    return $value;
+    return $this->rpn_eval($this->data[$ts][$attr], $this->expr);
   }
 }

Added: trunk/ui/web/lib/Reconnoiter_RPN.php
===================================================================
--- trunk/ui/web/lib/Reconnoiter_RPN.php	                        (rev 0)
+++ trunk/ui/web/lib/Reconnoiter_RPN.php	2008-09-21 23:54:44 UTC (rev 437)
@@ -0,0 +1,66 @@
+<?php
+
+class Reconnoiter_RPN {
+  function rpn_eval($value, $expr) {
+    $s = array();
+    $ops = explode(",", $expr);
+    array_unshift($s, $value);
+    foreach($ops as $op) {
+      switch($op) {
+        case 'ln':
+          array_unshift($s, log(array_shift($s))); break;
+        case 'round':
+          $r = array_shift($s);
+          $l = array_shift($s);
+          array_unshift($s, round($l,$r));
+          break;
+        case 'floor':
+          array_unshift($s, floor(array_shift($s))); break;
+        case 'ceil':
+          array_unshift($s, ceil(array_shift($s))); break;
+        case 'log':
+          $r = array_shift($s);
+          $l = array_shift($s);
+          array_unshift($s, log($l,$r));
+          break;
+        case 'e':
+          array_unshift($s, exp(1)); break;
+        case 'pi':
+          array_unshift($s, pi()); break;
+        case '^':
+          $r = array_shift($s);
+          $l = array_shift($s);
+          array_unshift($s, pow($l,$r));
+          break;
+        case '-':
+          $r = array_shift($s);
+          $l = array_shift($s);
+          array_unshift($s, $l-$r);
+          break;
+        case '/':
+          $r = array_shift($s);
+          $l = array_shift($s);
+          array_unshift($s, $l/$r);
+          break;
+        case '.':
+          array_unshift($s, $s[array_shift($s)]); break;
+        case '+':
+          array_unshift($s, array_shift($s) + array_shift($s)); break;
+        case '*':
+          array_unshift($s, array_shift($s) * array_shift($s)); break;
+        case 'auto':
+          array_unshift($s, $this->autounits(array_shift($s))); break;
+        case 'min':
+          array_unshift($s, min(array_shift($s),array_shift($s))); break;
+        case 'max':
+          array_unshift($s, max(array_shift($s),array_shift($s))); break;
+        default:
+          if(preg_match('/^-?\d+$/', $op)) {
+            array_unshift($s, $op);
+          }
+      }
+    }
+    $value = array_shift($s);
+    return $value;
+  }
+}

Modified: trunk/ui/web/lib/Reconnoiter_amCharts_Driver.php
===================================================================
--- trunk/ui/web/lib/Reconnoiter_amCharts_Driver.php	2008-09-21 19:55:50 UTC (rev 436)
+++ trunk/ui/web/lib/Reconnoiter_amCharts_Driver.php	2008-09-21 23:54:44 UTC (rev 437)
@@ -73,8 +73,7 @@
   function guideXML($value, $config) {
     if($value != "") {
       if(isset($config['expression'])) {
-        $expr = $config['expression'];
-        eval("\$value = $expr;");
+        $value = $this->rpn_eval($value, $config['expression']);
       }
     }
     print "<start_value>$value</start_value>\n";

Modified: trunk/ui/web/lib/Reconnoiter_amLine_Driver.php
===================================================================
--- trunk/ui/web/lib/Reconnoiter_amLine_Driver.php	2008-09-21 19:55:50 UTC (rev 436)
+++ trunk/ui/web/lib/Reconnoiter_amLine_Driver.php	2008-09-21 23:54:44 UTC (rev 437)
@@ -21,8 +21,7 @@
       $value = $set->data($ts);
       if($value != "") {
         if(isset($config['expression'])) {
-          $expr = $config['expression'];
-          eval("\$value = $expr;");
+          $value = $this->rpn_eval($value, $config['expression']);
         }
         $desc = $set->description($ts);
         if($desc) {



More information about the Reconnoiter-devel mailing list