diff --git a/htdocs/frontend/javascripts/frontend.js b/htdocs/frontend/javascripts/frontend.js index ffdc021..f80898f 100644 --- a/htdocs/frontend/javascripts/frontend.js +++ b/htdocs/frontend/javascripts/frontend.js @@ -373,31 +373,22 @@ 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 + vz.options.plot.yaxis.min = entity.data.min; + } + + // update entity table // TODO add units - if (entity.data.min) { - if (entity.data.min < vz.options.plot.yaxis.min) { // allow negative values for temperature sensors - vz.options.plot.yaxis.min = entity.data.min; - } - - $('#entity-' + entity.uuid + ' .min') - .text(vz.wui.formatNumber(entity.data.min[1])) - .attr('title', $.plot.formatDate(new Date(entity.data.min[0]), '%d. %b %h:%M:%S', vz.options.plot.xaxis.monthNames)); - } - if (entity.data.max) { - $('#entity-' + entity.uuid + ' .max') - .text(vz.wui.formatNumber(entity.data.max[1])) - .attr('title', $.plot.formatDate(new Date(entity.data.max[0]), '%d. %b %h:%M:%S', vz.options.plot.xaxis.monthNames)); - } - if (entity.data.average) { - $('#entity-' + entity.uuid + ' .average').text(vz.wui.formatNumber(entity.data.average)); - } - if (entity.data.consumption) { - $('#entity-' + entity.uuid + ' .consumption').text(vz.wui.formatNumber(entity.data.consumption)); - } - if (entity.data.tuples) { - $('#entity-' + entity.uuid + ' .last').text(vz.wui.formatNumber(entity.data.tuples.last()[1])); - } + $('#entity-' + entity.uuid + ' .min') + .text((entity.data.min !== null) ? vz.wui.formatNumber(entity.data.min[1]) : '-') + .attr('title', (entity.data.min !== null) ? $.plot.formatDate(new Date(entity.data.min[0]), '%d. %b %h:%M:%S', vz.options.plot.xaxis.monthNames) : ''); + $('#entity-' + entity.uuid + ' .max') + .text((entity.data.max !== null) ? vz.wui.formatNumber(entity.data.max[1]) : '-') + .attr('title', (entity.data.max !== null) ? $.plot.formatDate(new Date(entity.data.max[0]), '%d. %b %h:%M:%S', vz.options.plot.xaxis.monthNames) : ''); + $('#entity-' + entity.uuid + ' .average').text((entity.data.average !== null) ? vz.wui.formatNumber(entity.data.average) : '-'); + $('#entity-' + entity.uuid + ' .consumption').text(vz.wui.formatNumber(entity.data.consumption)); + $('#entity-' + entity.uuid + ' .last').text((entity.data.tuples) ? vz.wui.formatNumber(entity.data.tuples.last()[1]) : '-'); }, vz.drawPlot, 'data') ); } diff --git a/lib/Interpreter/Interpreter.php b/lib/Interpreter/Interpreter.php index 72952ec..ca012d2 100644 --- a/lib/Interpreter/Interpreter.php +++ b/lib/Interpreter/Interpreter.php @@ -44,7 +44,8 @@ abstract class Interpreter { protected $from; protected $to; - protected $rows; + protected $rowCount = NULL; + protected $tupleCount = NULL; /** * Constructor @@ -92,17 +93,19 @@ abstract class Interpreter { } // get total row count for grouping - $this->rows = $this->conn->fetchColumn($sql['rowCount'], array($this->channel->getId()), 0); + $this->rowCount = $this->conn->fetchColumn($sql['rowCount'], array($this->channel->getId()), 0); // query for data $stmt = $this->conn->executeQuery('SELECT ' . $sql['fields'] . $sql['from'] . $sql['where'] . $sql['groupBy'] . $sql['orderBy'], array($this->channel->getId())); // return iterators - if ($sql['groupBy'] || is_null($count) || $this->rows < $count) { - return new Iterator\DataIterator($stmt, $this->rows); + if ($sql['groupBy'] || is_null($count) || $this->rowCount < $count) { + $this->tupleCount = $this->rowCount; + return new Iterator\DataIterator($stmt, $this->rowCount); } else { - return new Iterator\DataAggregationIterator($stmt, $this->rows, $count); + $this->tupleCount = $count; + return new Iterator\DataAggregationIterator($stmt, $this->rowCount, $count); } } @@ -198,6 +201,7 @@ abstract class Interpreter { */ public function getEntity() { return $this->channel; } + public function getTupleCount() { return $this->tupleCount; } } ?> diff --git a/lib/Interpreter/MeterInterpreter.php b/lib/Interpreter/MeterInterpreter.php index aec6dfe..f74e837 100644 --- a/lib/Interpreter/MeterInterpreter.php +++ b/lib/Interpreter/MeterInterpreter.php @@ -37,8 +37,7 @@ class MeterInterpreter extends Interpreter { protected $min = NULL; protected $max = NULL; - protected $consumption = NULL; - protected $tuples = NULL; + protected $pulses = NULL; protected $resolution; /** @@ -46,9 +45,9 @@ class MeterInterpreter extends Interpreter { * @return float total consumption */ public function getConsumption() { - if (is_null($this->consumption) && is_null($this->tuples)) throw new \Exception('Data has to be processed first!'); + if (is_null($this->pulses) && is_null($this->tupleCount)) throw new \Exception('Data has to be processed first!'); - return $this->consumption / $this->resolution; + return $this->pulses / $this->resolution; } /** @@ -56,7 +55,7 @@ class MeterInterpreter extends Interpreter { * @return array (0 => timestamp, 1 => value) */ public function getMin() { - if (is_null($this->min) && is_null($this->tuples)) throw new \Exception('Data has to be processed first!'); + if (is_null($this->min) && is_null($this->tupleCount)) throw new \Exception('Data has to be processed first!'); return $this->min; } @@ -66,7 +65,7 @@ class MeterInterpreter extends Interpreter { * @return array (0 => timestamp, 1 => value) */ public function getMax() { - if (is_null($this->max) && is_null($this->tuples)) throw new \Exception('Data has to be processed first!'); + if (is_null($this->max) && is_null($this->tupleCount)) throw new \Exception('Data has to be processed first!'); return $this->max; } @@ -89,9 +88,8 @@ class MeterInterpreter extends Interpreter { public function processData($count, $groupBy, $callback) { $pulses = parent::getData($count, $groupBy); - $this->tuples = count($pulses); $this->resolution = $this->channel->getProperty('resolution'); - $this->consumption = 0; + $this->pulses = 0; $tuples = array(); $last = $pulses->rewind(); @@ -109,7 +107,7 @@ class MeterInterpreter extends Interpreter { $this->min = $tuple; } - $this->consumption += $tuple[2]; + $this->pulses += $tuple[2]; $tuples[] = $tuple; $last = $next; diff --git a/lib/View/JSON.php b/lib/View/JSON.php index adb8c55..76dd67e 100644 --- a/lib/View/JSON.php +++ b/lib/View/JSON.php @@ -224,15 +224,12 @@ class JSON extends View { ); } ); - $min = $interpreter->getMin(); - $max = $interpreter->getMax(); - $average = $interpreter->getAverage(); - $consumption = $interpreter->getConsumption(); - - $this->json['data']['min'] = $min; - $this->json['data']['max'] = $max; - $this->json['data']['average'] = View::formatNumber($average); - $this->json['data']['consumption'] = View::formatNumber($consumption); + + $this->json['data']['min'] = $interpreter->getMin(); + $this->json['data']['max'] = $interpreter->getMax(); + $this->json['data']['average'] = View::formatNumber($interpreter->getAverage()); + $this->json['data']['consumption'] = View::formatNumber($interpreter->getConsumption()); + $this->json['data']['count'] = $interpreter->getTupleCount(); if (count($data) > 0) $this->json['data']['tuples'] = $data; }