From b5f7ffcf35600f32bc8480f27f46b392af86e21e Mon Sep 17 00:00:00 2001 From: Justin Otherguy Date: Sat, 8 Jan 2011 01:43:16 +0100 Subject: [PATCH] filled display for "average" for meters --- htdocs/frontend/javascripts/frontend.js | 12 +++++++++--- lib/Interpreter/MeterInterpreter.php | 13 +++---------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/htdocs/frontend/javascripts/frontend.js b/htdocs/frontend/javascripts/frontend.js index a9603e3..511f816 100644 --- a/htdocs/frontend/javascripts/frontend.js +++ b/htdocs/frontend/javascripts/frontend.js @@ -357,15 +357,21 @@ vz.entities.loadData = function() { // update entity table // TODO add units - if (entity.data.min && entity.data.max && entity.data.min) { + if (entity.data.min) { $('#entity-' + entity.uuid + ' .min') .text(entity.data.min.value) .attr('title', $.plot.formatDate(new Date(entity.data.min.timestamp), '%d. %b %h:%M:%S', vz.options.plot.xaxis.monthNames)); + } + if (entity.data.max) { $('#entity-' + entity.uuid + ' .max') .text(entity.data.max.value) - .attr('title', $.plot.formatDate(new Date(entity.data.max.timestamp), '%d. %b %h:%M:%S', vz.options.plot.xaxis.monthNames)); + .attr('title', $.plot.formatDate(new Date(entity.data.max.timestamp), '%d. %b %h:%M:%S', vz.options.plot.xaxis.monthNames)); + } + if (entity.data.average) { $('#entity-' + entity.uuid + ' .average').text(entity.data.average); - $('#entity-' + entity.uuid + ' .last').text(entity.data.last); + } + if (entity.data.last) { + $('#entity-' + entity.uuid + ' .last').text(entity.data.last) } }, vz.drawPlot, 'data') ); diff --git a/lib/Interpreter/MeterInterpreter.php b/lib/Interpreter/MeterInterpreter.php index c67cdd6..8cadbcd 100644 --- a/lib/Interpreter/MeterInterpreter.php +++ b/lib/Interpreter/MeterInterpreter.php @@ -41,16 +41,9 @@ class MeterInterpreter extends Interpreter { * @todo reimplement according to new env */ public function getConsumption() { - /*$sql = 'SELECT SUM(value) AS count - FROM data - WHERE - channel_id = ' . (int) $this->id . ' && - ' . self::buildTimeFilterSQL($this->from, $this->to) . ' - GROUP BY channel_id'; + $sql = 'SELECT COUNT(*) FROM `data` WHERE `channel_id` = ' . $this->channel->getId() . parent::buildDateTimeFilterSQL($this->from, $this->to); - $result = $this->dbh->query($sql)->rewind(); - - return $result['count'] / $this->resolution / 1000; // returns Wh*/ + return $this->conn->fetchColumn($sql, array($this->channel->getId()), 0)*$this->channel->getProperty('resolution'); // return Wh } /** @@ -90,7 +83,7 @@ class MeterInterpreter extends Interpreter { * @todo reimplement according to new env */ public function getAverage() { - //return $this->getConsumption() / ($this->to - $this->from) / 1000; // return W + return $this->getConsumption() / ($this->to - $this->from) * 1000; // return W } /**