. */ namespace Volkszaehler\Interpreter; /** * Sensor interpreter * * @package default * @author Steffen Vogel */ class SensorInterpreter extends Interpreter { /** * @todo untested * @param string|integer $groupBy */ public function getValues($groupBy = NULL) { $data = parent::getData($groupBy); $values = array(); foreach ($data as $reading) { $values[] = array( $reading[0], $reading[1] / $reading[2], // calculate average (ungroup the sql sum() function) $reading[2] ); } return $values; } /** * @todo adapt to doctrine orm * @todo untested * @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(); } /** * @todo adapt to doctrine orm * @todo untested * @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(); } /** * @todo adapt to doctrine orm * @todo untested * @return float */ public function getAverage() { return $this->dbh->query('SELECT AVG(value) AS value FROM data WHERE channel_id = ' . (int) $this->id . self::buildFilterTime($this->from, $this->to))->current(); } /** * @todo to be implemented * @todo possible and/or required? * @return float */ public function getConsumption() { } } ?>