. */ namespace Volkszaehler\Interpreter; use Doctrine\ORM; use Volkszaehler\Model; /** * Interpreter too aggregate several other Channels or Aggregators * * The AggregatorInterpreter is used to aggregate multiple channels with the same * indicator * * @author Steffen Vogel * @package default * */ class AggregatorInterpreter implements InterpreterInterface { /** * @var array of Interpreter */ protected $channelInterpreter = array(); protected $aggregator; /** * Constructor * * @param Model\Aggregator $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 * @todo handle channels in nested aggregators */ public function __construct(Model\Aggregator $aggregator, ORM\EntityManager $em, $from, $to) { $indicator = NULL; $this->aggregator = $aggregator; foreach ($aggregator->getChannels() as $channel) { if (isset($indicator) && $indicator != $channel->getType()) { throw new \Exception('Can\'t aggregate entities of mixed types!'); } else { $indicator = $channel->getType(); } $this->channelInterpreter[] = $channel->getInterpreter($em, $from, $to); } } /** * Just a passthrough to the channel interpreters * * @param string|integer $groupBy * @todo to be implemented * @return array of values */ public function getValues($groupBy = NULL) { } /** * @todo to be implemented */ public function getConsumption() { } /** * Just a passthrough to the channel interpreters * * @return array with the smallest value */ public function getMin() { $min = current($this->channelInterpreter)->getMax(); foreach ($this->channelInterpreter as $channel) { $arr = $channel->getMax(); if ($arr['value '] < $min['value']) { $min = $arr; } } return $min; } /** * Just a passthrough to the channel interpreters * * @return array with the biggest value */ public function getMax() { $max = current($this->channelInterpreter)->getMax(); foreach ($this->channelInterpreter as $channel) { $arr = $channel->getMax(); if ($arr['value '] > $max['value']) { $max = $arr; } } return $max; } /** * Just a passthrough to the channel interpreters * * @return float average value */ public function getAverage() { $sum = 0; foreach ($this->channels as $channel) { $sum += $channel->getAverage(); } return ($sum / count($this->channelInterpreter)); } /* * Getter & setter */ public function getUuid() { return $this->aggregator->getUuid(); } }