diff --git a/htdocs/frontend/javascripts/frontend.js b/htdocs/frontend/javascripts/frontend.js index 511f816..5760d2f 100644 --- a/htdocs/frontend/javascripts/frontend.js +++ b/htdocs/frontend/javascripts/frontend.js @@ -368,10 +368,11 @@ vz.entities.loadData = function() { .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 + ' .average').text(Math.round(entity.data.average/vz.options.rounding)*vz.options.rounding); + // rounding: Math.round rounds to whole numbers; to round to one decimal (e.g. 15.2) we multiply by 10 (resp. divide through 0.1), round and reverse the multiplication again; therefore "vz.options.rounding" needs to be set to 0.1 in that case } if (entity.data.last) { - $('#entity-' + entity.uuid + ' .last').text(entity.data.last) + $('#entity-' + entity.uuid + ' .last').text(Math.round(entity.data.last/vz.options.rounding)*vz.options.rounding); } }, vz.drawPlot, 'data') ); diff --git a/htdocs/frontend/javascripts/options.js b/htdocs/frontend/javascripts/options.js index de66ab5..ca883e9 100644 --- a/htdocs/frontend/javascripts/options.js +++ b/htdocs/frontend/javascripts/options.js @@ -29,6 +29,7 @@ vz.options = { language: 'de', backendUrl: '../backend.php', tuples: 300, + rounding: 0.1, render: 'lines', refresh: false, refreshInterval: 5*1000, // 5 secs diff --git a/lib/Interpreter/SensorInterpreter.php b/lib/Interpreter/SensorInterpreter.php index e9bf148..0761736 100644 --- a/lib/Interpreter/SensorInterpreter.php +++ b/lib/Interpreter/SensorInterpreter.php @@ -87,7 +87,7 @@ class SensorInterpreter extends Interpreter { * @return float */ public function getLast() { - return round((float) $this->conn->fetchColumn('SELECT value FROM data WHERE channel_id = ?' . parent::buildDateTimeFilterSQL($this->from, $this->to). ' ORDER BY timestamp DESC', array($this->channel->getId()), 0), 1); + return (float) $this->conn->fetchColumn('SELECT value FROM data WHERE channel_id = ?' . parent::buildDateTimeFilterSQL($this->from, $this->to). ' ORDER BY timestamp DESC', array($this->channel->getId()), 0); } /**