moved InterpreterInterface to own file

updated several interpreters
This commit is contained in:
Steffen Vogel 2010-09-22 02:29:15 +02:00
parent 208f8ad12b
commit f697228f97
5 changed files with 70 additions and 20 deletions

View file

@ -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(); }
}

View file

@ -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(); }
}
?>

View file

@ -0,0 +1,37 @@
<?php
/**
* @copyright Copyright (c) 2010, The volkszaehler.org project
* @package default
* @license http://www.opensource.org/licenses/gpl-license.php GNU Public License
*/
/*
* This file is part of volkzaehler.org
*
* volkzaehler.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* volkzaehler.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with volkszaehler.org. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Volkszaehler\Interpreter;
/**
*
* @author Steffen Vogel <info@steffenvogel.de>
*
*/
interface InterpreterInterface {
function getConsumption();
function getValues();
function getMin();
function getMax();
function getAverage();
}

View file

@ -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
);
}

View file

@ -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() {