removed trash
This commit is contained in:
parent
cad41b1804
commit
8d9076da15
8 changed files with 20 additions and 83 deletions
|
@ -36,7 +36,7 @@ use Volkszaehler\Util;
|
|||
* @author Steffen Vogel <info@steffenvogel.de>
|
||||
* @package default
|
||||
*/
|
||||
class AggregatorInterpreter implements InterpreterInterface {
|
||||
class AggregatorInterpreter {
|
||||
/**
|
||||
* @var array of Interpreter
|
||||
*/
|
||||
|
|
|
@ -34,9 +34,8 @@ use Doctrine\ORM;
|
|||
*
|
||||
* @author Steffen Vogel <info@steffenvogel.de>
|
||||
* @package default
|
||||
*
|
||||
*/
|
||||
abstract class Interpreter implements InterpreterInterface {
|
||||
abstract class Interpreter {
|
||||
protected $channel;
|
||||
|
||||
/** @var Database connection */
|
||||
|
|
|
@ -1,39 +0,0 @@
|
|||
<?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($tuples = NULL, $groupBy = NULL);
|
||||
function getMin();
|
||||
function getMax();
|
||||
function getAverage();
|
||||
function getLast();
|
||||
function getEntity();
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Add table
Reference in a new issue