From 9d962df9ac6ecda687115992d951fad47f9e3937 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Mon, 7 Mar 2011 02:34:21 +0100 Subject: [PATCH] fixes #62 (yet another autoscaling issue) --- htdocs/frontend/javascripts/frontend.js | 10 +++++----- lib/Interpreter/MeterInterpreter.php | 19 +++++++++---------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/htdocs/frontend/javascripts/frontend.js b/htdocs/frontend/javascripts/frontend.js index c7ccc51..f8f5d0f 100644 --- a/htdocs/frontend/javascripts/frontend.js +++ b/htdocs/frontend/javascripts/frontend.js @@ -363,11 +363,11 @@ vz.entities.loadData = function() { vz.wui.updateHeadline(); $('#overlay').html('loading...

loading...

'); this.each(function(entity, parent) { + //var delta = vz.options.plot.xaxis.max - vz.options.plot.xaxis.min; + //var offset = delta * 0.1; + var offset = 1000*60*60; // load additional data to avoid paddings + if (entity.active && entity.type != 'group') { // TODO add group data aggregation - //var delta = vz.options.plot.xaxis.max - vz.options.plot.xaxis.min; - //var offset = delta * 0.1; - var offset = 1000*60*60; - vz.load('data', entity.uuid, { from: Math.floor(vz.options.plot.xaxis.min - offset), // fuzy-logic to get enough data @@ -377,7 +377,7 @@ vz.entities.loadData = function() { waitAsync(function(json) { entity.data = json.data; - if (entity.data.min !== null && entity.data.min < vz.options.plot.yaxis.min) { // allow negative values for temperature sensors + if (entity.data.min !== null && entity.data.min[1] < vz.options.plot.yaxis.min) { // allow negative values for temperature sensors vz.options.plot.yaxis.min = null; } diff --git a/lib/Interpreter/MeterInterpreter.php b/lib/Interpreter/MeterInterpreter.php index f74e837..95a9232 100644 --- a/lib/Interpreter/MeterInterpreter.php +++ b/lib/Interpreter/MeterInterpreter.php @@ -37,7 +37,7 @@ class MeterInterpreter extends Interpreter { protected $min = NULL; protected $max = NULL; - protected $pulses = NULL; + protected $pulseCount = NULL; protected $resolution; /** @@ -45,9 +45,9 @@ class MeterInterpreter extends Interpreter { * @return float total consumption */ public function getConsumption() { - if (is_null($this->pulses) && is_null($this->tupleCount)) throw new \Exception('Data has to be processed first!'); + if (is_null($this->tupleCount)) throw new \Exception('Data has to be processed first!'); - return $this->pulses / $this->resolution; + return $this->pulseCount / $this->resolution; } /** @@ -55,9 +55,9 @@ class MeterInterpreter extends Interpreter { * @return array (0 => timestamp, 1 => value) */ public function getMin() { - if (is_null($this->min) && is_null($this->tupleCount)) throw new \Exception('Data has to be processed first!'); + if (is_null($this->tupleCount)) throw new \Exception('Data has to be processed first!'); - return $this->min; + return ($this->min) ? array_map('floatval', array_slice($this->min, 0 , 2)) : NULL; } /** @@ -65,9 +65,9 @@ class MeterInterpreter extends Interpreter { * @return array (0 => timestamp, 1 => value) */ public function getMax() { - if (is_null($this->max) && is_null($this->tupleCount)) throw new \Exception('Data has to be processed first!'); + if (is_null($this->tupleCount)) throw new \Exception('Data has to be processed first!'); - return $this->max; + return ($this->max) ? array_map('floatval', array_slice($this->max, 0 , 2)) : NULL; } /** @@ -89,12 +89,11 @@ class MeterInterpreter extends Interpreter { $pulses = parent::getData($count, $groupBy); $this->resolution = $this->channel->getProperty('resolution'); - $this->pulses = 0; + $this->pulseCount = 0; $tuples = array(); $last = $pulses->rewind(); $next = $pulses->next(); - $next = $pulses->current(); while ($pulses->valid()) { $tuple = $callback($this->raw2differential($last, $next)); @@ -107,7 +106,7 @@ class MeterInterpreter extends Interpreter { $this->min = $tuple; } - $this->pulses += $tuple[2]; + $this->pulseCount += $tuple[2]; $tuples[] = $tuple; $last = $next;