diff --git a/backend/lib/DataAggregationIterator.php b/backend/lib/Interpreter/DataAggregationIterator.php
similarity index 92%
rename from backend/lib/DataAggregationIterator.php
rename to backend/lib/Interpreter/DataAggregationIterator.php
index cb2dac9..635bbe3 100644
--- a/backend/lib/DataAggregationIterator.php
+++ b/backend/lib/Interpreter/DataAggregationIterator.php
@@ -21,7 +21,7 @@
* along with volkszaehler.org. If not, see .
*/
-namespace Volkszaehler;
+namespace Volkszaehler\Interpreter;
use Doctrine\DBAL;
@@ -75,8 +75,8 @@ class DataAggregationIterator extends DataIterator {
$this->aggregatedKey++;
$this->current = $current;
- $this->current[0] = $tuple[0];
- $this->current[2] = $this->packageSize;
+ $this->current[0] = $tuple[0]; // the last timestamp of a package
+ $this->current[2] = $this->packageSize; // how many pulses do we have aggregated? how accurate is our result?
}
/**
diff --git a/backend/lib/DataIterator.php b/backend/lib/Interpreter/DataIterator.php
similarity index 98%
rename from backend/lib/DataIterator.php
rename to backend/lib/Interpreter/DataIterator.php
index f9dbc64..17257dd 100644
--- a/backend/lib/DataIterator.php
+++ b/backend/lib/Interpreter/DataIterator.php
@@ -21,7 +21,7 @@
* along with volkszaehler.org. If not, see .
*/
-namespace Volkszaehler;
+namespace Volkszaehler\Interpreter;
use Doctrine\DBAL;
diff --git a/backend/lib/Interpreter/GroupInterpreter.php b/backend/lib/Interpreter/GroupInterpreter.php
index 3276de6..607a6bf 100644
--- a/backend/lib/Interpreter/GroupInterpreter.php
+++ b/backend/lib/Interpreter/GroupInterpreter.php
@@ -42,7 +42,7 @@ class GroupInterpreter {
/**
* Constructor
*
- * @param Model\Group $group should only contain channels with the same indicator
+ * @param Model\Group $group should only contain channels of the same indicator
* @param ORM\EntityManager $em
* @param integer $from timestamp in ms since 1970
* @param integer $to timestamp in ms since 1970
diff --git a/backend/lib/Interpreter/Interpreter.php b/backend/lib/Interpreter/Interpreter.php
index adb6a07..b833d5b 100644
--- a/backend/lib/Interpreter/Interpreter.php
+++ b/backend/lib/Interpreter/Interpreter.php
@@ -98,16 +98,19 @@ abstract class Interpreter implements InterpreterInterface {
$sqlFields = ' timestamp, value';
}
+ // get total row count for grouping
$rowCount = $conn->fetchColumn($sqlRowCount, $params, 0);
+ // query for data
$stmt = $conn->executeQuery('SELECT ' . $sqlFields . $sqlFrom . $sqlWhere . $sqlGroupBy . $sqlOrderBy, $params);
+ // return iterators
if ($sqlGroupBy || is_null($groupBy)) { // aggregation by sql or skip it
- return new Volkszaehler\DataIterator($stmt, $rowCount);
+ return new DataIterator($stmt, $rowCount);
}
elseif (is_numeric($groupBy) ) { // aggregation by php
$tuples = (int) $groupBy;
- return new Volkszaehler\DataAggregationIterator($stmt, $rowCount, $tuples);
+ return new DataAggregationIterator($stmt, $rowCount, $tuples);
}
else {
throw new \Exception('invalid groupBy parameter');
diff --git a/backend/lib/Interpreter/MeterInterpreter.php b/backend/lib/Interpreter/MeterInterpreter.php
index a8babf2..afd4cbf 100644
--- a/backend/lib/Interpreter/MeterInterpreter.php
+++ b/backend/lib/Interpreter/MeterInterpreter.php
@@ -105,19 +105,12 @@ class MeterInterpreter extends Interpreter {
*/
public function getValues($groupBy = NULL) {
$pulses = parent::getData($groupBy);
- $count = $pulses->count();
$values = array();
foreach ($pulses as $pulse) {
if (isset($last)) {
- $delta = $pulse[0] - $last[0];
+ $values[] = $this->raw2differential($last, $pulse);
$last = $pulse;
-
- $values[] = array(
- (int) ($pulse[0] - $delta / 2), // timestamp
- $pulse[1] * (3600000 / (($this->channel->getResolution() / 1000) * $delta)), // value
- (isset($pulse[2])) ? $pulse[2] : 1
- );
}
else {
$last = $pulse;
@@ -126,6 +119,22 @@ class MeterInterpreter extends Interpreter {
return $values;
}
+
+ /**
+ * Calculates the differential quotient of two consecutive pulses
+ *
+ * @param array $last the last pulse
+ * @param array $next the next pulse
+ */
+ protected function raw2differential(array $last, array $next) {
+ $delta = $next[0] - $last[0];
+
+ return array(
+ (int) ($next[0] - $delta / 2), // timestamp
+ $next[1] * (3600000 / (($this->channel->getResolution() / 1000) * $delta)), // value
+ (isset($next[2])) ? $next[2] : 1
+ );
+ }
}
?>
\ No newline at end of file