From 2092a257f2a84ca2e569d6d109c5141c0bb25c1d Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Sun, 27 Feb 2011 15:08:06 +0100 Subject: [PATCH] fixed "Data has to be processed first!" exception when requesting a interval with no data --- lib/Interpreter/MeterInterpreter.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/Interpreter/MeterInterpreter.php b/lib/Interpreter/MeterInterpreter.php index 6cbf147..aec6dfe 100644 --- a/lib/Interpreter/MeterInterpreter.php +++ b/lib/Interpreter/MeterInterpreter.php @@ -38,6 +38,7 @@ class MeterInterpreter extends Interpreter { protected $min = NULL; protected $max = NULL; protected $consumption = NULL; + protected $tuples = NULL; protected $resolution; /** @@ -45,7 +46,7 @@ class MeterInterpreter extends Interpreter { * @return float total consumption */ public function getConsumption() { - if (is_null($this->consumption)) throw new \Exception('Data has to be processed first!'); + if (is_null($this->consumption) && is_null($this->tuples)) throw new \Exception('Data has to be processed first!'); return $this->consumption / $this->resolution; } @@ -55,7 +56,7 @@ class MeterInterpreter extends Interpreter { * @return array (0 => timestamp, 1 => value) */ public function getMin() { - if (is_null($this->min)) throw new \Exception('Data has to be processed first!'); + if (is_null($this->min) && is_null($this->tuples)) throw new \Exception('Data has to be processed first!'); return $this->min; } @@ -65,7 +66,7 @@ class MeterInterpreter extends Interpreter { * @return array (0 => timestamp, 1 => value) */ public function getMax() { - if (is_null($this->max)) throw new \Exception('Data has to be processed first!'); + if (is_null($this->max) && is_null($this->tuples)) throw new \Exception('Data has to be processed first!'); return $this->max; } @@ -86,10 +87,11 @@ class MeterInterpreter extends Interpreter { * @return array with timestamp, values, and pulse count */ public function processData($count, $groupBy, $callback) { + $pulses = parent::getData($count, $groupBy); + + $this->tuples = count($pulses); $this->resolution = $this->channel->getProperty('resolution'); $this->consumption = 0; - - $pulses = parent::getData($count, $groupBy); $tuples = array(); $last = $pulses->rewind();