[Reconnoiter-devel] [reconnoiter commit] r1479 - in trunk/ui/web: htdocs lib
svn-commit at lists.omniti.com
svn-commit at lists.omniti.com
Mon Nov 1 09:50:57 EDT 2010
Author: jesus
Date: 2010-11-01 09:50:56 -0400 (Mon, 01 Nov 2010)
New Revision: 1479
Modified:
trunk/ui/web/htdocs/json_graph_flot.php
trunk/ui/web/lib/Reconnoiter_DB.php
trunk/ui/web/lib/Reconnoiter_DataContainer.php
Log:
updates from Michal T?borsk?
The source field for guides now understands:
recognizes these patterns or keywords:
any number -> percentile (same as before)
avg, average -> obvious
min, minimum -> 0th percentile
max, maximum -> 100th percentile
med, median -> 50th percentile
stddev -> standard deviation
stddev+ -> average + standard deviation
stddev- -> average - standard deviation
refs #323
Modified: trunk/ui/web/htdocs/json_graph_flot.php
===================================================================
--- trunk/ui/web/htdocs/json_graph_flot.php 2010-10-30 19:45:30 UTC (rev 1478)
+++ trunk/ui/web/htdocs/json_graph_flot.php 2010-11-01 13:50:56 UTC (rev 1479)
@@ -19,20 +19,61 @@
$row = $db->getGraphByID($_GET['id']);
$graph = json_decode($row['json'], true);
-foreach($graph['datapoints'] as $d) {
+foreach($graph['datapoints'] as $k => $d) {
if($d['metric_type'] == 'guide') {
- $driver->calcPercentile($d['math2']);
+ if (preg_match('/\d+\%?/', $d['math2'])) {
+ // if the math field cotains just numbers or numbers with % sign, we want percentile
+ $driver->calcPercentile($d['math2']);
+ $guideType[$k]='percentile';
+ } else {
+ // if it is a string, see if we can recognize some aggregate aliases
+ switch ($d['math2']) {
+ case 'med':
+ case 'median':
+ $driver->calcPercentile(50);
+ $guideType[$k]='percentile';
+ $graph['datapoints'][$k]['math2']='50';
+ break;
+ case 'min':
+ case 'minimum':
+ $driver->calcPercentile(0);
+ $guideType[$k]='percentile';
+ $graph['datapoints'][$k]['math2']='0';
+ break;
+ case 'max':
+ case 'maximum':
+ $driver->calcPercentile(100);
+ $guideType[$k]='percentile';
+ $graph['datapoints'][$k]['math2']='100';
+ break;
+ case 'average':
+ $driver->calcAggregate('avg');
+ $guideType[$k]='aggregate';
+ $graph['datapoints'][$k]['math2']='avg';
+ break;
+ default:
+ // everything else is passed to aggregate calculator
+ $driver->calcAggregate($d['math2']);
+ $guideType[$k]='aggregate';
+ }
+ }
}
}
$i = 0;
$autounits = 0;
-foreach($graph['datapoints'] as $d) {
+foreach($graph['datapoints'] as $k => $d) {
if($d['metric_type'] == 'guide') {
$color = isset($d['color']) ? $d['color'] : '#ff0000';
+ if ($guideType[$k]=='percentile') {
$driver->addPercentileGuide($d['name'], $d['math2'],
array('expression' => $d['math1'],
'color' => $color));
+ } else {
+ $driver->addAggregateGuide($d['name'], $d['math2'],
+ array('expression' => $d['math1'],
+ 'color' => $color));
+ }
}
else if($d['metric_type'] == 'composite') {
$color = isset($d['color']) ? $d['color'] : '#ff0000';
Modified: trunk/ui/web/lib/Reconnoiter_DB.php
===================================================================
--- trunk/ui/web/lib/Reconnoiter_DB.php 2010-10-30 19:45:30 UTC (rev 1478)
+++ trunk/ui/web/lib/Reconnoiter_DB.php 2010-11-01 13:50:56 UTC (rev 1479)
@@ -130,7 +130,7 @@
$a = array();
while($row = $sth->fetch()) $a[] = $row;
return array('query' => $searchstring, 'limit' => $limit,
- 'offset' => $offset, count => $r['count'], 'results' => $a);
+ 'offset' => $offset, 'count' => $r['count'], 'results' => $a);
}
function get_worksheets($searchstring, $offset, $limit) {
return $this->run_tsearch($searchstring,
@@ -234,7 +234,7 @@
$ptr_groupby = ', ciamt.value';
$ptr_join = "
left join check_currently cia
- on ( $tblsrc.$want ::text = cia.target ::text
+ on ( $tblsrc.$want::text = cia.target::text
and cia.module='dns' and cia.name='in-addr.arpa')
left join metric_text_currently ciamt
on (cia.sid = ciamt.sid and ciamt.name='answer')";
@@ -344,6 +344,68 @@
}
return $rv;
}
+
+ function aggregate($arr, $p, $groupname = 'left', $attr=NULL) {
+
+ /* Calculate aggregate values
+ *
+ * Currently recognized aggregates:
+ * avg: average
+ * stddev: standard deviation
+ * stddev+: average + standard deviation
+ * stddev-: average - standard deviation
+ */
+
+ if(!is_array($arr) || !count($arr)) return array();
+ if(!is_array($p)) $p = array($p);
+ $full = array();
+ $rv=array();
+ foreach ($arr[0]->points() as $ts) {
+ $sum = 0;
+ $nonnull = 0;
+ foreach ($arr as $sets) {
+ if($sets->groupname() != $groupname) continue;
+ $value = $sets->data($ts, $attr);
+ if($value != "") $nonnull = 1;
+ $sum += $value;
+ }
+ if($nonnull == 1) $full[] = $sum;
+ }
+ if (in_array('avg',$p)) {
+ $rv['avg']=array_sum($full) / count($full);
+ }
+ if (in_array('stddev',$p) || in_array('stddev+',$p) || in_array('stddev-',$p)) {
+
+ function sd_square($x, $mean) { return pow($x - $mean,2); }
+
+ function sd($array) {
+ return sqrt(array_sum(array_map("sd_square", $array, array_fill(0,count($array), (array_sum($array) / count($array)) ) ) ) / (count($array)-1) );
+ }
+
+ $stddev=sd($full);
+ if (in_array('stddev', $p)) {
+ $rv['stddev']=$stddev;
+ }
+ if (in_array('stddev+', $p)) {
+ if (empty($rv['avg'])) {
+ $avg=array_sum($full) / count($full);
+ } else {
+ $avg = $rv['avg'];
+ }
+ $rv['stddev+']=$avg+$stddev;
+ }
+ if (in_array('stddev-', $p)) {
+ if (empty($rv['avg'])) {
+ $avg=array_sum($full) / count($full);
+ } else {
+ $avg = $rv['avg'];
+ }
+ $rv['stddev-']=$avg-$stddev;
+ }
+ }
+ return $rv;
+ }
+
function getWorksheetByID($id) {
$sth = $this->db->prepare("select w.sheetid, w.title, wd.graphid
from prism.saved_worksheets as w
Modified: trunk/ui/web/lib/Reconnoiter_DataContainer.php
===================================================================
--- trunk/ui/web/lib/Reconnoiter_DataContainer.php 2010-10-30 19:45:30 UTC (rev 1478)
+++ trunk/ui/web/lib/Reconnoiter_DataContainer.php 2010-11-01 13:50:56 UTC (rev 1479)
@@ -12,7 +12,9 @@
protected $end;
protected $cnt;
protected $ps_to_calc;
+ protected $agg_to_calc;
protected $percentile;
+ protected $aggregate;
protected $title;
protected $type;
@@ -76,12 +78,21 @@
$this->__calc();
$this->addGuide($name, $this->percentile[$p], $config);
}
+ function addAggregateGuide($name, $p, $config = array()) {
+ $this->__calc();
+ $this->addGuide($name, $this->aggregate[$p], $config);
+ }
+
function min() { $this->__calc(); return $this->percentile[0]; }
function max() { $this->__calc(); return $this->percentile[100]; }
function calcPercentile($p) {
if($this->units) throw new Exception("Already calculated percentiles");
$this->ps_to_calc[$p] = 'true';
}
+ function calcAggregate($p) {
+ if($this->units) throw new Exception("Already calculated percentiles");
+ $this->agg_to_calc[]=$p;
+ }
function __calc() {
if($this->units) return;
$db = Reconnoiter_DB::getDB();
@@ -89,6 +100,10 @@
array_keys($this->ps_to_calc)) as $p => $v) {
$this->percentile[$p] = $v;
}
+ foreach($db->aggregate(array_values($this->sets),
+ array_keys($this->agg_to_calc)) as $p => $v) {
+ $this->aggregate[$p] = $v;
+ }
$this->units = pow(1000,floor(log($this->percentile[100], 1000)));
if($this->units == 0) $this->units = 1;
}
More information about the Reconnoiter-devel
mailing list