some cosmetics & more performance enhancements
This commit is contained in:
parent
e8c47dc899
commit
6660456f5c
3 changed files with 27 additions and 22 deletions
|
@ -32,9 +32,9 @@ use Doctrine\DBAL;
|
|||
* @package default
|
||||
*/
|
||||
class DataAggregationIterator implements \Iterator, \Countable {
|
||||
protected $current;
|
||||
protected $key; // key
|
||||
protected $size; // total readings in PDOStatement
|
||||
protected $current; // the current data
|
||||
protected $key; // key
|
||||
protected $size; // total readings in PDOStatement
|
||||
protected $iterator; // subiterator
|
||||
|
||||
/**
|
||||
|
@ -44,30 +44,36 @@ class DataAggregationIterator implements \Iterator, \Countable {
|
|||
* @param integer $size
|
||||
* @param integer $tuples
|
||||
*/
|
||||
public function __construct(\PDOStatement $stmt, $size, $tuples) {
|
||||
$this->iterator = new DataIterator($stmt, $size);
|
||||
public function __construct(\PDOStatement $stmt, $rows, $count) {
|
||||
$this->iterator = new DataIterator($stmt, $rows);
|
||||
|
||||
$this->packageSize = floor($size / $tuples);
|
||||
$this->size = (int) $tuples;
|
||||
$this->packageSize = floor($rows / $count);
|
||||
$this->size = $count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Aggregate data
|
||||
*/
|
||||
public function next() {
|
||||
$current = array(0, 0, 0);
|
||||
for ($i = 0; $i < $this->packageSize && $this->iterator->valid(); $i++, $this->iterator->next()) {
|
||||
$this->current = array(0, 0, 0);
|
||||
for ($i = 0; $i < $this->packageSize; $i++, $this->iterator->next()) {
|
||||
$tuple = $this->iterator->current();
|
||||
|
||||
$current[0] = $tuple[0];
|
||||
$current[1] += $tuple[1];
|
||||
$current[2] += $tuple[2];
|
||||
$this->current[0] = $tuple[0];
|
||||
$this->current[1] += $tuple[1];
|
||||
$this->current[2] += $tuple[2];
|
||||
}
|
||||
|
||||
$this->key++;
|
||||
return $this->current = $current;
|
||||
return $this->current;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rewind the iterator
|
||||
*
|
||||
* Should only be called once
|
||||
* PDOStatement hasn't a rewind()
|
||||
*/
|
||||
public function rewind() {
|
||||
$this->iterator->rewind();
|
||||
// skip first readings to get an even divisor
|
||||
|
|
|
@ -31,10 +31,10 @@ use Doctrine\DBAL;
|
|||
* @package default
|
||||
*/
|
||||
class DataIterator implements \Iterator, \Countable {
|
||||
protected $current; // the current data
|
||||
protected $key; // key
|
||||
protected $stmt; // PDOStatement
|
||||
protected $size; // total readings in PDOStatement
|
||||
protected $current; // the current data
|
||||
protected $key; // key
|
||||
protected $stmt; // PDOStatement
|
||||
protected $size; // total readings in PDOStatement
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
|
@ -81,7 +81,7 @@ class DataIterator implements \Iterator, \Countable {
|
|||
* Rewind the iterator
|
||||
*
|
||||
* Should only be called once
|
||||
* PDOStatements doest support rewind()
|
||||
* PDOStatement hasn't a rewind() aquivalent
|
||||
*/
|
||||
public function rewind() {
|
||||
$this->key = 0;
|
||||
|
|
|
@ -45,7 +45,7 @@ class MeterInterpreter extends Interpreter {
|
|||
* @return float total consumption
|
||||
*/
|
||||
public function getConsumption() {
|
||||
if (is_null($this->consumption)) throw new \Excpetion('Data has to be processed first!');
|
||||
if (is_null($this->consumption)) throw new \Exception('Data has to be processed first!');
|
||||
|
||||
return $this->consumption / $this->resolution;
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ class MeterInterpreter extends Interpreter {
|
|||
* @return array (0 => timestamp, 1 => value)
|
||||
*/
|
||||
public function getMin() {
|
||||
if (is_null($this->min)) throw new \Excpetion('Data has to be processed first!');
|
||||
if (is_null($this->min)) throw new \Exception('Data has to be processed first!');
|
||||
|
||||
return $this->min;
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ class MeterInterpreter extends Interpreter {
|
|||
* @return array (0 => timestamp, 1 => value)
|
||||
*/
|
||||
public function getMax() {
|
||||
if (is_null($this->max)) throw new \Excpetion('Data has to be processed first!');
|
||||
if (is_null($this->max)) throw new \Exception('Data has to be processed first!');
|
||||
|
||||
return $this->max;
|
||||
}
|
||||
|
@ -97,7 +97,6 @@ class MeterInterpreter extends Interpreter {
|
|||
$next = $pulses->current();
|
||||
|
||||
while ($pulses->valid()) {
|
||||
Util\Debug::log('after valid()', $last, $next);
|
||||
$tuple = $callback($this->raw2differential($last, $next));
|
||||
|
||||
if (is_null($this->max) || $tuple[1] > $this->max[1]) {
|
||||
|
|
Loading…
Add table
Reference in a new issue