fixed smaller issues, added comments
This commit is contained in:
parent
3aa02568ee
commit
2e48407cef
5 changed files with 69 additions and 44 deletions
|
@ -206,23 +206,33 @@ Entity.prototype.loadData = function() {
|
|||
success: function(json) {
|
||||
this.data = json.data;
|
||||
|
||||
if (this.data.min !== null && this.data.min[1] < vz.options.plot.yaxis.min) { // allow negative values for temperature sensors
|
||||
vz.options.plot.yaxis.min = null;
|
||||
}
|
||||
if (this.data.count > 0) {
|
||||
if (this.data.min[1] < vz.options.plot.yaxis.min) { // allow negative values for temperature sensors
|
||||
vz.options.plot.yaxis.min = null;
|
||||
}
|
||||
|
||||
// update entity table
|
||||
var unit = ' ' + this.definition.unit;
|
||||
$('#entity-' + this.uuid + ' .min')
|
||||
.text(
|
||||
(this.data.min !== null) ? vz.wui.formatNumber(this.data.min[1]) + unit : '-')
|
||||
.attr('title', (this.data.min !== null) ? $.plot.formatDate(new Date(this.data.min[0]), '%d. %b %h:%M:%S', vz.options.plot.xaxis.monthNames) : '');
|
||||
$('#entity-' + this.uuid + ' .max')
|
||||
.text((this.data.max !== null) ? vz.wui.formatNumber(this.data.max[1]) + unit : '-')
|
||||
.attr('title', (this.data.max !== null) ? $.plot.formatDate(new Date(this.data.max[0]), '%d. %b %h:%M:%S', vz.options.plot.xaxis.monthNames) : '');
|
||||
$('#entity-' + this.uuid + ' .average').text((this.data.average !== null) ? vz.wui.formatNumber(this.data.average) + unit : '');
|
||||
$('#entity-' + this.uuid + ' .last').text((this.data.tuples) ? vz.wui.formatNumber(this.data.tuples.last()[1]) + unit : '');
|
||||
if (this.definition.interpreter == 'Volkszaehler\\Interpreter\\MeterInterpreter') { // sensors have no consumption
|
||||
$('#entity-' + this.uuid + ' .consumption').text(vz.wui.formatNumber(this.data.consumption) + unit + 'h');
|
||||
// update entity table
|
||||
var unit = ' ' + this.definition.unit;
|
||||
$('#entity-' + this.uuid + ' .min')
|
||||
.text(vz.wui.formatNumber(this.data.min[1]) + unit)
|
||||
.attr('title', $.plot.formatDate(new Date(this.data.min[0]), '%d. %b %h:%M:%S', vz.options.plot.xaxis.monthNames));
|
||||
$('#entity-' + this.uuid + ' .max')
|
||||
.text(vz.wui.formatNumber(this.data.max[1]) + unit)
|
||||
.attr('title', $.plot.formatDate(new Date(this.data.max[0]), '%d. %b %h:%M:%S', vz.options.plot.xaxis.monthNames));
|
||||
$('#entity-' + this.uuid + ' .average')
|
||||
.text(vz.wui.formatNumber(this.data.average) + unit);
|
||||
$('#entity-' + this.uuid + ' .last')
|
||||
.text(vz.wui.formatNumber(this.data.tuples.last()[1]) + unit);
|
||||
if (this.definition.interpreter == 'Volkszaehler\\Interpreter\\MeterInterpreter') { // sensors have no consumption
|
||||
$('#entity-' + this.uuid + ' .consumption').text(vz.wui.formatNumber(this.data.consumption) + unit + 'h');
|
||||
}
|
||||
}
|
||||
else { // no data available, clear table
|
||||
$('#entity-' + this.uuid + ' .min').text('').attr('title', '');
|
||||
$('#entity-' + this.uuid + ' .max').text('').attr('title', '');
|
||||
$('#entity-' + this.uuid + ' .average').text('');
|
||||
$('#entity-' + this.uuid + ' .last').text('');
|
||||
$('#entity-' + this.uuid + ' .consumption').text('');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -55,12 +55,14 @@ class DataIterator implements \Iterator, \Countable {
|
|||
$this->stmt = $stmt;
|
||||
$this->stmt->setFetchMode(\PDO::FETCH_NUM);
|
||||
|
||||
if ($this->rowCount > $this->tupleCount) {
|
||||
if ($this->rowCount > $this->tupleCount) { // sumarize
|
||||
$this->packageSize = floor($this->rowCount / $this->tupleCount);
|
||||
$this->tupleCount = floor($this->rowCount / $this->packageSize) + 1;
|
||||
}
|
||||
else {
|
||||
else { // passthrough
|
||||
$this->packageSize = 1;
|
||||
$this->tupleCount = $this->rowCount;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -68,15 +70,20 @@ class DataIterator implements \Iterator, \Countable {
|
|||
* Aggregate data
|
||||
*/
|
||||
public function next() {
|
||||
$package = array(0, 0, 0);
|
||||
for ($i = 0; $i < $this->packageSize && $this->valid(); $i++) {
|
||||
$tuple = $this->stmt->fetch();
|
||||
if ( $this->packageSize == 1) { // return each row as single tuple
|
||||
$package = $this->stmt->fetch();
|
||||
}
|
||||
else { // summarize rows
|
||||
$package = array(0, 0, 0);
|
||||
for ($i = 0; $i < $this->packageSize && $this->rowKey < $this->rowCount; $i++) {
|
||||
$tuple = $this->stmt->fetch();
|
||||
|
||||
$package[0] = $tuple[0];
|
||||
$package[1] += $tuple[1];
|
||||
$package[2] += $tuple[2];
|
||||
$package[0] = $tuple[0];
|
||||
$package[1] += $tuple[1];
|
||||
$package[2] += $tuple[2];
|
||||
|
||||
$this->rowKey++;
|
||||
$this->rowKey++;
|
||||
}
|
||||
}
|
||||
|
||||
$this->key++;
|
||||
|
@ -91,11 +98,11 @@ class DataIterator implements \Iterator, \Countable {
|
|||
*/
|
||||
public function rewind() {
|
||||
$this->key = $this->rowKey = 0;
|
||||
return $this->next();
|
||||
return $this->next(); // fetch first tuple
|
||||
}
|
||||
|
||||
public function valid() {
|
||||
return $this->rowKey < $this->rowCount;
|
||||
return $this->key < $this->tupleCount;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -205,7 +205,6 @@ abstract class Interpreter {
|
|||
*/
|
||||
|
||||
public function getEntity() { return $this->channel; }
|
||||
public function getTupleCount() { return $this->tupleCount; }
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -92,8 +92,7 @@ class MeterInterpreter extends Interpreter {
|
|||
$this->pulseCount = 0;
|
||||
|
||||
$tuples = array();
|
||||
$pulses->rewind();
|
||||
$last = $pulses->next();
|
||||
$last = $pulses->rewind();
|
||||
$next = $pulses->next();
|
||||
|
||||
while ($pulses->valid()) {
|
||||
|
@ -127,9 +126,10 @@ class MeterInterpreter extends Interpreter {
|
|||
$delta = $next[0] - $last[0];
|
||||
|
||||
return array(
|
||||
($next[0] - $delta / 2), // timestamp
|
||||
$next[1] * (3600000 / (($this->resolution / 1000) * $delta)), // value
|
||||
$next[2] // num of pulses
|
||||
//($next[0] - $delta / 2), // timestamp in the middle
|
||||
$next[0], // timestamp at the end
|
||||
$next[1] * (3600000 / (($this->resolution / 1000) * $delta)), // value
|
||||
$next[2] // num of pulses
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -199,9 +199,7 @@ class JSON extends View {
|
|||
* @param $interpreter
|
||||
*/
|
||||
protected function addData($interpreter) {
|
||||
$this->json['data']['uuid'] = $interpreter->getEntity()->getUuid();
|
||||
|
||||
$data = $interpreter->processData(
|
||||
$data = $interpreter->processData( // iterate through PDO resultset
|
||||
function($tuple) {
|
||||
return array(
|
||||
$tuple[0],
|
||||
|
@ -210,17 +208,25 @@ class JSON extends View {
|
|||
);
|
||||
}
|
||||
);
|
||||
|
||||
$this->json['data']['uuid'] = $interpreter->getEntity()->getUuid();
|
||||
$this->json['data']['count'] = count($data);
|
||||
|
||||
$min = $interpreter->getMin();
|
||||
$max = $interpreter->getMax();
|
||||
$average = View::formatNumber($interpreter->getAverage());
|
||||
|
||||
$this->json['data']['min'] = $interpreter->getMin();
|
||||
$this->json['data']['max'] = $interpreter->getMax();
|
||||
$this->json['data']['average'] = View::formatNumber($interpreter->getAverage());
|
||||
|
||||
if ($interpreter instanceof Interpreter\MeterInterpreter) {
|
||||
if (isset($min))
|
||||
$this->json['data']['min'] = $min;
|
||||
if (isset($max))
|
||||
$this->json['data']['max'] = $max;
|
||||
if (isset($average))
|
||||
$this->json['data']['average'] = $average;
|
||||
if ($interpreter instanceof Interpreter\MeterInterpreter)
|
||||
$this->json['data']['consumption'] = View::formatNumber($interpreter->getConsumption());
|
||||
if (count($data) > 0) {
|
||||
$this->json['data']['tuples'] = $data;
|
||||
}
|
||||
|
||||
$this->json['data']['count'] = $interpreter->getTupleCount();
|
||||
if (count($data) > 0) $this->json['data']['tuples'] = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -234,6 +240,9 @@ class JSON extends View {
|
|||
elseif ($value instanceof Model\Entity) {
|
||||
$refNode[$index] = self::convertEntity($value);
|
||||
}
|
||||
elseif (is_numeric($value)) {
|
||||
$refNode[$index] = View::formatNumber($value);
|
||||
}
|
||||
else {
|
||||
$refNode[$index] = $value;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue