diff --git a/backend/lib/Interpreter/AggregatorInterpreter.php b/backend/lib/Interpreter/AggregatorInterpreter.php index 267e45d..1f4b03f 100644 --- a/backend/lib/Interpreter/AggregatorInterpreter.php +++ b/backend/lib/Interpreter/AggregatorInterpreter.php @@ -36,12 +36,14 @@ use Volkszaehler\Model; * @package default * */ -class AggregatorInterpreter { +class AggregatorInterpreter implements InterpreterInterface { /** * @var array of Interpreter */ protected $channelInterpreter = array(); + protected $aggregator; + /** * Constructor * @@ -53,13 +55,14 @@ class AggregatorInterpreter { */ public function __construct(Model\Aggregator $aggregator, ORM\EntityManager $em, $from, $to) { $indicator = NULL; + $this->aggregator = $aggregator; - foreach ($aggregator->getChannels() as $channels) { - if (isset($indicator) && $indicator != $channel->getIndicator()) { + foreach ($aggregator->getChannels() as $channel) { + if (isset($indicator) && $indicator != $channel->getType()) { throw new \Exception('Can\'t aggregate entities of mixed types!'); } else { - $indicator = $channel->getIndicator(); + $indicator = $channel->getType(); } $this->channelInterpreter[] = $channel->getInterpreter($em, $from, $to); @@ -77,6 +80,13 @@ class AggregatorInterpreter { } + /** + * @todo to be implemented + */ + public function getConsumption() { + + } + /** * Just a passthrough to the channel interpreters * @@ -122,4 +132,9 @@ class AggregatorInterpreter { } return ($sum / count($this->channelInterpreter)); } + + /* + * Getter & setter + */ + public function getUuid() { return $this->aggregator->getUuid(); } } \ No newline at end of file diff --git a/backend/lib/Interpreter/Interpreter.php b/backend/lib/Interpreter/Interpreter.php index 9e36054..042aa87 100644 --- a/backend/lib/Interpreter/Interpreter.php +++ b/backend/lib/Interpreter/Interpreter.php @@ -30,18 +30,9 @@ namespace Volkszaehler\Interpreter; * */ use Volkszaehler\Iterator; - use Volkszaehler; - use Doctrine\ORM\Query; -interface InterpreterInterface { - function getConsumption(); - function getValues(); - function getMin(); - function getMax(); - function getAverage(); -} /** * Interpreter superclass for all interpreters @@ -183,6 +174,11 @@ abstract class Interpreter implements InterpreterInterface { return $sql; } + + /* + * Getter & setter + */ + public function getUuid() { return $this->channel->getUuid(); } } ?> \ No newline at end of file diff --git a/backend/lib/Interpreter/InterpreterInterface.php b/backend/lib/Interpreter/InterpreterInterface.php new file mode 100644 index 0000000..6e79fa1 --- /dev/null +++ b/backend/lib/Interpreter/InterpreterInterface.php @@ -0,0 +1,37 @@ +. + */ + +namespace Volkszaehler\Interpreter; + +/** + * + * @author Steffen Vogel + * + */ +interface InterpreterInterface { + function getConsumption(); + function getValues(); + function getMin(); + function getMax(); + function getAverage(); +} \ No newline at end of file diff --git a/backend/lib/Interpreter/MeterInterpreter.php b/backend/lib/Interpreter/MeterInterpreter.php index 7e65396..adc0cf7 100644 --- a/backend/lib/Interpreter/MeterInterpreter.php +++ b/backend/lib/Interpreter/MeterInterpreter.php @@ -54,7 +54,7 @@ class MeterInterpreter extends Interpreter { } /** - * + * @return array (0 => timestamp, 1 => value) */ public function getMin() { $data = $this->getData(); @@ -69,7 +69,7 @@ class MeterInterpreter extends Interpreter { } /** - * @return array + * @return array (0 => timestamp, 1 => value) */ public function getMax() { $data = $this->getData(); @@ -84,7 +84,6 @@ class MeterInterpreter extends Interpreter { } /** - * @todo calculate timeinterval if no params were given * @return float */ public function getAverage() { @@ -93,6 +92,8 @@ class MeterInterpreter extends Interpreter { /** * Just a passthrough of raw data + * + * @deprecated */ public function getPulses($groupBy = NULL) { return parent::getData($groupBy); @@ -131,8 +132,8 @@ class MeterInterpreter extends Interpreter { $delta = $next[0] - $last[0]; return array( - ($next[0] - $delta / 2), // timestamp - $next[1] * (3600000 / (($this->channel->getProperty('resolution')->getValue() / 1000) * $delta)), // value + ($next[0] - $delta / 2), // timestamp + $next[1] * (3600000 / (($this->channel->getProperty('resolution') / 1000) * $delta)), // value (isset($next[2])) ? $next[2] : 1 ); } diff --git a/backend/lib/Interpreter/SensorInterpreter.php b/backend/lib/Interpreter/SensorInterpreter.php index 53bcb80..b8c0d4c 100644 --- a/backend/lib/Interpreter/SensorInterpreter.php +++ b/backend/lib/Interpreter/SensorInterpreter.php @@ -53,7 +53,7 @@ class SensorInterpreter extends Interpreter { /** * @todo adapt to doctrine orm * @todo untested - * @return array + * @return array (0 => timestamp, 1 => value) */ public function getMin() { return $this->dbh->query('SELECT value, timestamp FROM data WHERE channel_id = ' . (int) $this->id . self::buildFilterTime($this->from, $this->to) . ' ORDER BY value ASC', 1)->current(); @@ -62,7 +62,7 @@ class SensorInterpreter extends Interpreter { /** * @todo adapt to doctrine orm * @todo untested - * @return array + * @return array (0 => timestamp, 1 => value) */ public function getMax() { return $this->dbh->query('SELECT value, timestamp FROM data WHERE channel_id = ' . (int) $this->id . self::buildFilterTime($this->from, $this->to) . ' ORDER BY value DESC', 1)->current(); @@ -79,6 +79,7 @@ class SensorInterpreter extends Interpreter { /** * @todo to be implemented + * @todo possible and/or required? * @return float */ public function getConsumption() {