adapted Views to new DataController

improved debugging and entity defintion
This commit is contained in:
Steffen Vogel 2011-03-16 14:45:43 +01:00
parent 71bfe883d6
commit d7192c2b7f
4 changed files with 64 additions and 63 deletions

View file

@ -178,9 +178,9 @@
}
},
{
"name" : "radition",
"name" : "radiation",
"required" : ["title"],
"optional" : ["description", "details:", "owner:", "address:", "tolerance", "public"],
"optional" : ["description", "details:", "owner:", "address:", "tolerance", "resolution", "public"],
"icon" : "radioactivity.png",
"unit" : "μSv",
"interpreter" : "Volkszaehler\\Interpreter\\SensorInterpreter",

View file

@ -64,12 +64,6 @@ class Debug {
throw new \Exception('Debugging has already been started. please use the static functions!');
}
self::$instance = $this;
// assert options
assert_options(ASSERT_ACTIVE, TRUE); // activate assertions
assert_options(ASSERT_BAIL, FALSE);
assert_options(ASSERT_WARNING, FALSE);
assert_options(ASSERT_CALLBACK, array($this, 'assertHandler'));
}
/*
@ -82,46 +76,27 @@ class Debug {
if (isset(self::$instance)) {
$trace = debug_backtrace(FALSE);
$info = $trace[0];
$level = self::$instance->level;
self::$instance->messages[] = array(
'message' => $message,
'file' => $info['file'],
'line' => $info['line'],
'args' => array_slice($info['args'], 1),
'trace' => array_slice($trace, 1)
);
$message = array('message' => $message);
if ($level > 2) {
$message['file'] = $info['file'];
$message['line'] = $info['line'];
}
if ($level > 4) {
$message['args'] = array_slice($info['args'], 1);
}
if ($level > 5) {
$message['trace'] = array_slice($trace, 1);
}
self::$instance->messages[] = $message;
}
}
/**
* simple assertion passthrough for future improvements
*
* @param string $code code to be evaluated
*/
public static function assert($code) {
return assert($code);
}
/**
* handles failed assertions
*
* @param string $file
* @param integer $line
* @param string $code code to be evaluated
*/
public function assertHandler($file, $line, $code) {
$trace = debug_backtrace();
$info = $trace[2];
$this->messages[] = array(
'message' => 'assertion failed: ' . $code,
'file' => $info['file'],
'line' => $info['line'],
'time' => date('r'),
'trace' => array_slice($trace, 3)
);
}
/**
* Is debugging enabled?
* @return boolean
@ -149,6 +124,11 @@ class Debug {
*/
public static function getInstance() { return self::$instance; }
/**
* @return integer current debug level
*/
public function getLevel() { return $this->level; }
/**
* Tries to determine the current SHA1 hash of your git commit
*

View file

@ -160,6 +160,7 @@ class JSON extends View {
*/
protected function addDebug(Util\Debug $debug) {
$jsonDebug['time'] = $debug->getExecutionTime();
$jsonDebug['level'] = $debug->getLevel();
$jsonDebug['messages'] = $debug->getMessages();
$jsonDebug['queries'] = array_values($debug->getQueries());
@ -210,25 +211,29 @@ class JSON extends View {
}
);
$this->json['data']['uuid'] = $interpreter->getEntity()->getUuid();
$this->json['data']['count'] = count($data);
$this->json['data']['rowCount'] = $interpreter->getRowCount();
$min = $interpreter->getMin();
$max = $interpreter->getMax();
$average = View::formatNumber($interpreter->getAverage());
$average = $interpreter->getAverage();
$from = $interpreter->getFrom();
$to = $interpreter->getTo();
$this->json['data']['uuid'] = $interpreter->getEntity()->getUuid();
if (isset($from))
$this->json['data']['from'] = $from;
if (isset($to))
$this->json['data']['to'] = $to;
if (isset($min))
$this->json['data']['min'] = $min;
$this->json['data']['min'] = $min;
if (isset($max))
$this->json['data']['max'] = $max;
$this->json['data']['max'] = $max;
if (isset($average))
$this->json['data']['average'] = $average;
$this->json['data']['average'] = View::formatNumber($average);
if ($interpreter instanceof Interpreter\MeterInterpreter)
$this->json['data']['consumption'] = View::formatNumber($interpreter->getConsumption());
if (count($data) > 0) {
$this->json['data']['tuples'] = $data;
}
$this->json['data']['count'] = count($data);
if (($interpreter->getTupleCount() > 0 || is_null($interpreter->getTupleCount())) && count($data) > 0)
$this->json['data']['tuples'] = $data;
}
/**

View file

@ -164,6 +164,7 @@ class XML extends View {
*/
protected function addDebug(Util\Debug $debug) {
$xmlDebug = $this->xmlDoc->createElement('debug');
$xmlDebug->setAttribute('level', $debug->getLevel());
$xmlDebug->appendChild($this->xmlDoc->createElement('time', $debug->getExecutionTime()));
$xmlMessages = $this->xmlDoc->createElement('messages');
@ -232,23 +233,38 @@ class XML extends View {
$xmlTuples = $this->xmlDoc->createElement('tuples');
$data = $interpreter->processData(
$this->request->getParameter('tuples'),
$this->request->getParameter('group'),
function($tuple) use ($xmlDoc, $xmlTuples) {
$xmlTuple = $xmlDoc->createElement('tuple');
$xmlTuple->setAttribute('timestamp', $tuple[0]); // hardcoded data fields for performance optimization
$xmlTuple->setAttribute('timestamp', $tuple[0]);
$xmlTuple->setAttribute('value', View::formatNumber($tuple[1]));
$xmlTuple->setAttribute('count', $tuple[2]);
$xmlTuples->appendChild($xmlTuple);
}
);
$min = $interpreter->getMin();
$max = $interpreter->getMax();
$average = $interpreter->getAverage();
$from = $interpreter->getFrom();
$to = $interpreter->getTo();
$xmlData->appendChild($this->xmlDoc->createElement('uuid', $interpreter->getEntity()->getUuid()));
$xmlData->appendChild($this->xmlDoc->createElement('min', $interpreter->getMin()));
$xmlData->appendChild($this->xmlDoc->createElement('max', $interpreter->getMax()));
$xmlData->appendChild($this->xmlDoc->createElement('average', self::formatNumber($interpreter->getAverage())));
$xmlData->appendChild($this->xmlDoc->createElement('consumption', self::formatNumber($interpreter->getConsumption())));
$xmlData->appendChild($xmlTuples);
if (isset($from))
$xmlData->appendChild($this->xmlDoc->createElement('from', $from));
if (isset($to))
$xmlData->appendChild($this->xmlDoc->createElement('to', $to));
if (isset($min))
$xmlData->appendChild($this->xmlDoc->createElement('min', $min));
if (isset($max))
$xmlData->appendChild($this->xmlDoc->createElement('max', $max));
if (isset($average))
$xmlData->appendChild($this->xmlDoc->createElement('average', View::formatNumber($average)));
if ($interpreter instanceof Interpreter\MeterInterpreter)
$xmlData->appendChild($this->xmlDoc->createElement('consumption', View::formatNumber($interpreter->getConsumption())));
$xmlData->appendChild($this->xmlDoc->createElement('count', count($data)));
if (($interpreter->getTupleCount() > 0 || is_null($interpreter->getTupleCount())) && count($data) > 0)
$xmlData->appendChild($xmlTuples);
$this->xmlRoot->appendChild($xmlData);
}