Example #1
0
 /**
  * Add an array of objects to the output
  */
 protected function addArray($data, &$refNode)
 {
     if (is_null($refNode)) {
         $refNode = array();
     }
     foreach ($data as $index => $value) {
         if (is_array($value)) {
             $this->addArray($value, $refNode[$index]);
         } elseif ($value instanceof Model\Entity) {
             $refNode[$index] = self::convertEntity($value);
         } elseif ($value instanceof Interpreter\Interpreter) {
             // special case: interpreters are always added to the root node
             if (!isset($this->json['data'])) {
                 $this->json['data'] = array();
             }
             $this->json['data'][] = $value;
         } elseif (is_numeric($value)) {
             $refNode[$index] = View::formatNumber($value);
         } else {
             $refNode[$index] = $value;
         }
     }
 }
Example #2
0
 /**
  * Add data to output queue
  *
  * @param Interpreter\InterpreterInterface $interpreter
  * @param boolean $children
  * @todo  Aggregate first is assumed- this deviates from json view behaviour
  */
 protected function addData(Interpreter\Interpreter $interpreter)
 {
     $this->response->headers->set('Content-Disposition', 'attachment; ' . 'filename="' . strtolower($interpreter->getEntity()->getProperty('title')) . '.csv" ');
     echo PHP_EOL;
     // UUID delimiter
     echo '# uuid:' . CSV::DELIMITER . $interpreter->getEntity()->getUuid() . PHP_EOL;
     echo '# title:' . CSV::DELIMITER . $interpreter->getEntity()->getProperty('title') . PHP_EOL;
     if ($interpreter instanceof Interpreter\AggregatorInterpreter) {
         // min/ max etc are not populated if $children->processData hasn't been called
         return;
     }
     $data = array();
     // iterate through PDO resultset
     foreach ($interpreter as $tuple) {
         $data[] = $tuple;
     }
     $min = $interpreter->getMin();
     $max = $interpreter->getMax();
     $average = $interpreter->getAverage();
     $consumption = $interpreter->getConsumption();
     $from = $this->formatTimestamp($interpreter->getFrom());
     $to = $this->formatTimestamp($interpreter->getTo());
     if (isset($from)) {
         echo '# from:' . CSV::DELIMITER . $from . PHP_EOL;
     }
     if (isset($to)) {
         echo '# to:' . CSV::DELIMITER . $to . PHP_EOL;
     }
     if (isset($min)) {
         echo '# min:' . CSV::DELIMITER . $this->formatTimestamp($min[0]) . CSV::DELIMITER . ' => ' . CSV::DELIMITER . View::formatNumber($min[1]) . PHP_EOL;
     }
     if (isset($max)) {
         echo '# max:' . CSV::DELIMITER . $this->formatTimestamp($max[0]) . CSV::DELIMITER . ' => ' . CSV::DELIMITER . View::formatNumber($max[1]) . PHP_EOL;
     }
     if (isset($average)) {
         echo '# average:' . CSV::DELIMITER . View::formatNumber($average) . PHP_EOL;
     }
     if (isset($consumption)) {
         echo '# consumption:' . CSV::DELIMITER . View::formatNumber($consumption) . PHP_EOL;
     }
     echo '# rows:' . CSV::DELIMITER . $interpreter->getRowCount() . PHP_EOL;
     if (isset($data)) {
         // Aggregators don't return data
         foreach ($data as $tuple) {
             echo $this->formatTimestamp($tuple[0]) . CSV::DELIMITER . View::formatNumber($tuple[1]) . CSV::DELIMITER . $tuple[2] . PHP_EOL;
         }
     }
 }
Example #3
0
 /**
  * Add data to output queue
  *
  * @param $interpreter
  */
 protected function addData($interpreter)
 {
     $xmlDoc = $this->xmlDoc;
     $xmlData = $this->xmlDoc->createElement('data');
     $xmlTuples = $this->xmlDoc->createElement('tuples');
     $data = $interpreter->processData(function ($tuple) use($xmlDoc, $xmlTuples) {
         $xmlTuple = $xmlDoc->createElement('tuple');
         $xmlTuple->setAttribute('timestamp', $tuple[0]);
         $xmlTuple->setAttribute('value', View::formatNumber($tuple[1]));
         $xmlTuple->setAttribute('count', $tuple[2]);
         $xmlTuples->appendChild($xmlTuple);
         return $tuple;
     });
     $from = $interpreter->getFrom();
     $to = $interpreter->getTo();
     $min = $interpreter->getMin();
     $max = $interpreter->getMax();
     $average = $interpreter->getAverage();
     $consumption = $interpreter->getConsumption();
     $xmlData->appendChild($this->xmlDoc->createElement('uuid', $interpreter->getEntity()->getUuid()));
     if (isset($from)) {
         $xmlData->appendChild($this->xmlDoc->createElement('from', $from));
     }
     if (isset($to)) {
         $xmlData->appendChild($this->xmlDoc->createElement('to', $to));
     }
     if (isset($min)) {
         $xmlMin = $this->xmlDoc->createElement('min');
         $xmlMin->setAttribute('timestamp', $min[0]);
         $xmlMin->setAttribute('value', $min[1]);
         $xmlData->appendChild($xmlMin);
     }
     if (isset($max)) {
         $xmlMax = $this->xmlDoc->createElement('max');
         $xmlMax->setAttribute('timestamp', $max[0]);
         $xmlMax->setAttribute('value', $max[1]);
         $xmlData->appendChild($xmlMax);
     }
     if (isset($average)) {
         $xmlData->appendChild($this->xmlDoc->createElement('average', View::formatNumber($average)));
     }
     if (isset($consumption)) {
         $xmlData->appendChild($this->xmlDoc->createElement('consumption', View::formatNumber($consumption)));
     }
     $xmlData->appendChild($this->xmlDoc->createElement('rows', $interpreter->getRowCount()));
     if (($interpreter->getTupleCount() > 0 || is_null($interpreter->getTupleCount())) && count($data) > 0) {
         $xmlData->appendChild($xmlTuples);
     }
     $this->xmlRoot->appendChild($xmlData);
 }
Example #4
0
 /**
  * Add data to output queue
  *
  * @param 	$interpreter
  * @param 	boolean $children
  */
 protected function addData($interpreter, $children = false)
 {
     $xmlDoc = $this->xmlDoc;
     $xmlData = $children ? $this->xmlDoc->createElement('data') : $this->obtainElementById('data');
     $xmlTuples = $this->xmlDoc->createElement('tuples');
     // iterate through PDO resultset
     foreach ($interpreter as $tuple) {
         $xmlTuple = $xmlDoc->createElement('tuple');
         $xmlTuple->setAttribute('timestamp', $tuple[0]);
         $xmlTuple->setAttribute('value', View::formatNumber($tuple[1]));
         $xmlTuple->setAttribute('count', $tuple[2]);
         $xmlTuples->appendChild($xmlTuple);
     }
     $from = $interpreter->getFrom();
     $to = $interpreter->getTo();
     $min = $interpreter->getMin();
     $max = $interpreter->getMax();
     $average = $interpreter->getAverage();
     $consumption = $interpreter->getConsumption();
     $xmlData->appendChild($this->xmlDoc->createElement('uuid', $interpreter->getEntity()->getUuid()));
     if (isset($from)) {
         $xmlData->appendChild($this->xmlDoc->createElement('from', $from));
     }
     if (isset($to)) {
         $xmlData->appendChild($this->xmlDoc->createElement('to', $to));
     }
     if (isset($min)) {
         $xmlMin = $this->xmlDoc->createElement('min');
         $xmlMin->setAttribute('timestamp', $min[0]);
         $xmlMin->setAttribute('value', $min[1]);
         $xmlData->appendChild($xmlMin);
     }
     if (isset($max)) {
         $xmlMax = $this->xmlDoc->createElement('max');
         $xmlMax->setAttribute('timestamp', $max[0]);
         $xmlMax->setAttribute('value', $max[1]);
         $xmlData->appendChild($xmlMax);
     }
     if (isset($average)) {
         $xmlData->appendChild($this->xmlDoc->createElement('average', View::formatNumber($average)));
     }
     if (isset($consumption)) {
         $xmlData->appendChild($this->xmlDoc->createElement('consumption', View::formatNumber($consumption)));
     }
     $xmlData->appendChild($this->xmlDoc->createElement('rows', $interpreter->getRowCount()));
     if (($interpreter->getTupleCount() > 0 || is_null($interpreter->getTupleCount())) && count($xmlTuples) > 0) {
         $xmlData->appendChild($xmlTuples);
     }
     if ($children) {
         $xmlChildren = $this->obtainElementById('children');
         $xmlChildren->appendChild($xmlData);
         $xmlParentData = $this->obtainElementById('data');
         $xmlParentData->appendChild($xmlChildren);
         $this->xmlRoot->appendChild($xmlParentData);
     } else {
         $this->xmlRoot->appendChild($xmlData);
     }
 }
Example #5
0
 protected function addArray($data, &$refNode)
 {
     if (is_null($refNode)) {
         $refNode = array();
     }
     foreach ($data as $index => $value) {
         if ($value instanceof Util\JSON || is_array($value)) {
             $this->addArray($value, $refNode[$index]);
         } elseif ($value instanceof Model\Entity) {
             $refNode[$index] = self::convertEntity($value);
         } elseif (is_numeric($value)) {
             $refNode[$index] = View::formatNumber($value);
         } else {
             $refNode[$index] = $value;
         }
     }
 }
Example #6
0
 /**
  * Add data to output queue
  *
  * @param Interpreter\InterpreterInterface $interpreter
  */
 protected function addData(Interpreter\Interpreter $interpreter)
 {
     $this->response->setHeader('Content-Disposition', 'attachment; ' . 'filename="' . strtolower($interpreter->getEntity()->getProperty('title')) . '.csv" ' . 'creation-date="' . date(DATE_RFC2822, $interpreter->getTo() / 1000) . '"');
     $tuples = $interpreter->processData(function ($tuple) {
         return array($tuple[0], View::formatNumber($tuple[1]), $tuple[2]);
     });
     $min = $interpreter->getMin();
     $max = $interpreter->getMax();
     $average = $interpreter->getAverage();
     $consumption = $interpreter->getConsumption();
     $from = $interpreter->getFrom();
     $to = $interpreter->getTo();
     echo '# uuid: ' . $interpreter->getEntity()->getUuid() . PHP_EOL;
     if (isset($from)) {
         echo '# from: ' . $from . PHP_EOL;
     }
     if (isset($to)) {
         echo '# to: ' . $to . PHP_EOL;
     }
     if (isset($min)) {
         echo '# min: ' . $min[0] . ' => ' . $min[1] . PHP_EOL;
     }
     if (isset($max)) {
         echo '# max: ' . $max[0] . ' => ' . $max[1] . PHP_EOL;
     }
     if (isset($average)) {
         echo '# average: ' . View::formatNumber($average) . PHP_EOL;
     }
     if (isset($consumption)) {
         echo '# consumption: ' . View::formatNumber($consumption) . PHP_EOL;
     }
     echo '# rows: ' . $interpreter->getRowCount() . PHP_EOL;
     foreach ($tuples as $tuple) {
         echo implode(CSV::DELIMITER, $tuple) . PHP_EOL;
     }
 }