. */ namespace Volkszaehler\Interpreter; use Doctrine\ORM; use Volkszaehler\Model; class GroupInterpreter { protected $channelInterpreter; public function __construct(Model\Group $group, ORM\EntityManager $em, $from, $to) { foreach ($group->getChannels() as $channel) { if (isset($indicator) && $indicator != $channel->getIndicator) { throw new \Exception('we only can aggregate channels of the same indicator'); } else { $indicator = $channel->getIndicator(); } $this->channelInterpreter[] = $channel->getInterpreter($em, $from, $to); } } /** * * @todo to be implemented */ public function getValues($groupBy = NULL) { } /** * */ 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; } /** * */ 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; } /** * */ public function getAverage() { $sum = 0; foreach ($this->channels as $channel) { $sum += $channel->getAverage(); } return ($sum / count($this->channelInterpreter)); } }