From 8d9076da15a9ea66ec07185cccbaad93cd9c7960 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Thu, 24 Feb 2011 18:07:18 +0100 Subject: [PATCH] removed trash --- lib/Interpreter/AggregatorInterpreter.php | 2 +- lib/Interpreter/Interpreter.php | 3 +- lib/Interpreter/InterpreterInterface.php | 39 ----------------------- lib/Interpreter/MeterInterpreter.php | 13 ++------ lib/Interpreter/SensorInterpreter.php | 9 ------ lib/View/JSON.php | 33 ++++++++----------- lib/View/JpGraph.php | 2 +- lib/View/XML.php | 2 +- 8 files changed, 20 insertions(+), 83 deletions(-) delete mode 100644 lib/Interpreter/InterpreterInterface.php diff --git a/lib/Interpreter/AggregatorInterpreter.php b/lib/Interpreter/AggregatorInterpreter.php index 08141a0..1d63c79 100644 --- a/lib/Interpreter/AggregatorInterpreter.php +++ b/lib/Interpreter/AggregatorInterpreter.php @@ -36,7 +36,7 @@ use Volkszaehler\Util; * @author Steffen Vogel * @package default */ -class AggregatorInterpreter implements InterpreterInterface { +class AggregatorInterpreter { /** * @var array of Interpreter */ diff --git a/lib/Interpreter/Interpreter.php b/lib/Interpreter/Interpreter.php index e6ba2f2..1b9bdd5 100644 --- a/lib/Interpreter/Interpreter.php +++ b/lib/Interpreter/Interpreter.php @@ -34,9 +34,8 @@ use Doctrine\ORM; * * @author Steffen Vogel * @package default - * */ -abstract class Interpreter implements InterpreterInterface { +abstract class Interpreter { protected $channel; /** @var Database connection */ diff --git a/lib/Interpreter/InterpreterInterface.php b/lib/Interpreter/InterpreterInterface.php deleted file mode 100644 index b7dc79c..0000000 --- a/lib/Interpreter/InterpreterInterface.php +++ /dev/null @@ -1,39 +0,0 @@ -. - */ - -namespace Volkszaehler\Interpreter; - -/** - * - * @author Steffen Vogel - * - */ -interface InterpreterInterface { - function getConsumption(); - function getValues($tuples = NULL, $groupBy = NULL); - function getMin(); - function getMax(); - function getAverage(); - function getLast(); - function getEntity(); -} diff --git a/lib/Interpreter/MeterInterpreter.php b/lib/Interpreter/MeterInterpreter.php index 89def8d..c8a5d10 100644 --- a/lib/Interpreter/MeterInterpreter.php +++ b/lib/Interpreter/MeterInterpreter.php @@ -80,19 +80,10 @@ class MeterInterpreter extends Interpreter { /** * @return float - * @todo reimplement according to new env */ public function getAverage() { - return round(3600*1000*1000*$this->getConsumption() / ($this->to - $this->from), 10); // return W - // 3600: 3600 s/h; 1000: ms -> s; 1000: KW -> W - } - - /** - * @return float - * @todo reimplement according to new env - */ - public function getLast() { - //return $this->getConsumption() / ($this->to - $this->from) / 1000; // return W + // 3600: 3600 s/h; 1000: ms -> s; 1000: KW -> W + return (3600 * 1000 * 1000 * $this->getConsumption()) / ($this->to - $this->from); } /** diff --git a/lib/Interpreter/SensorInterpreter.php b/lib/Interpreter/SensorInterpreter.php index 0761736..00fb815 100644 --- a/lib/Interpreter/SensorInterpreter.php +++ b/lib/Interpreter/SensorInterpreter.php @@ -81,15 +81,6 @@ class SensorInterpreter extends Interpreter { return (float) $this->conn->fetchColumn('SELECT AVG(value) FROM data WHERE channel_id = ?' . parent::buildDateTimeFilterSQL($this->from, $this->to), array($this->channel->getId()), 0); } - /** - * Fetch the average value from the database - * @internal doesn't fits the SQL standard - * @return float - */ - public function getLast() { - return (float) $this->conn->fetchColumn('SELECT value FROM data WHERE channel_id = ?' . parent::buildDateTimeFilterSQL($this->from, $this->to). ' ORDER BY timestamp DESC', array($this->channel->getId()), 0); - } - /** * @todo possible and/or required? * @return float diff --git a/lib/View/JSON.php b/lib/View/JSON.php index 478edfe..5ccf14c 100644 --- a/lib/View/JSON.php +++ b/lib/View/JSON.php @@ -57,6 +57,7 @@ class JSON extends View { $this->json = new Util\JSON(); $this->json['version'] = VZ_VERSION; + $this->response->setHeader('Content-type', 'application/json'); $this->setPadding($request->getParameter('padding')); } @@ -66,7 +67,7 @@ class JSON extends View { * @param mixed $data */ public function add($data) { - if ($data instanceof Interpreter\InterpreterInterface) { + if ($data instanceof Interpreter\Interpreter || $data instanceof Interpreter\AggregatorInterpreter) { $this->addData($data); } elseif ($data instanceof Model\Entity) { @@ -87,9 +88,7 @@ class JSON extends View { } /** - * Process, encode and print output - * - * @return string the output + * Process, encode and print output to stdout */ protected function render() { $json = $this->json->encode((Util\Debug::isActivated()) ? JSON_PRETTY : 0); @@ -97,8 +96,6 @@ class JSON extends View { if ($this->padding) { $json = 'if (' . $this->padding . ') { ' . $this->padding . '(' . $json . '); }'; } - - $this->response->setHeader('Content-type', 'application/json'); echo $json; } @@ -213,20 +210,18 @@ class JSON extends View { * * @param Interpreter\InterpreterInterface $interpreter */ - protected function addData(Interpreter\InterpreterInterface $interpreter) { - $data = $interpreter->getValues($this->request->getParameter('tuples'), $this->request->getParameter('group')); + protected function addData(Interpreter\Interpreter $interpreter) { + $this->json['data']['uuid'] = $interpreter->getEntity()->getUuid(); - $this->json['data'] = array( - 'uuid' => $interpreter->getEntity()->getUuid(), - 'count' => count($data), - 'first' => (isset($data[0][0])) ? $data[0][0] : NULL, - 'last' => (isset($data[count($data)-1][0])) ? $data[count($data)-1][0] : NULL, - 'min' => $interpreter->getMin(), - 'max' => $interpreter->getMax(), - 'average' => $interpreter->getAverage(), - 'last' => $interpreter->getLast(), - 'tuples' => $data - ); + $data = $interpreter->getValues($this->request->getParameter('tuples'), $this->request->getParameter('group')); + $min = $interpreter->getMin(); + $max = $interpreter->getMax(); + $average = $interpreter->getAverage(); + + if (isset($min)) $this->json['data']['min'] = $min; + if (isset($max)) $this->json['data']['max'] = $max; + if (isset($average)) $this->json['data']['average'] = $average; + if (count($data) > 0) $this->json['data']['tuples'] = $data; } /** diff --git a/lib/View/JpGraph.php b/lib/View/JpGraph.php index 63b595a..3a7edd4 100644 --- a/lib/View/JpGraph.php +++ b/lib/View/JpGraph.php @@ -123,7 +123,7 @@ class JpGraph extends View { * @param mixed $data */ public function add($data) { - if ($data instanceof Interpreter\Interpreter) { + if ($data instanceof Interpreter\Interpreter || $data instanceof Interpreter\AggregatorInterpreter) { $this->addData($data); } elseif($data instanceof Interpreter\AggregatorInterpreter) { diff --git a/lib/View/XML.php b/lib/View/XML.php index 75092b7..1fb1520 100644 --- a/lib/View/XML.php +++ b/lib/View/XML.php @@ -68,7 +68,7 @@ class XML extends View { * @param mixed $data */ public function add($data) { - if ($data instanceof Interpreter\InterpreterInterface) { + if ($data instanceof Interpreter\Interpreter || $data instanceof Interpreter\AggregatorInterpreter) { $this->addData($data); } elseif ($data instanceof Model\Entity) {