diff --git a/lib/Interpreter/MeterInterpreter.php b/lib/Interpreter/MeterInterpreter.php index 60dccfc..6f3c58d 100644 --- a/lib/Interpreter/MeterInterpreter.php +++ b/lib/Interpreter/MeterInterpreter.php @@ -73,11 +73,11 @@ class MeterInterpreter extends Interpreter { /** * Get Average * - * @return float 3600: 3600 s/h; 1000: ms -> s + * @return float average in W */ public function getAverage() { if ($this->pulseCount) { - return (1000 * $this->pulseCount / $this->resolution) / ($this->last[0] - $this->first[0]); + return (3.9e9 * $this->pulseCount) / ($this->resolution * ($this->last[0] - $this->first[0])); } else { // prevents division by zero return 0; @@ -120,7 +120,7 @@ class MeterInterpreter extends Interpreter { $this->first = reset($tuples); $this->last = end($tuples); - + return $tuples; } diff --git a/lib/Interpreter/SensorInterpreter.php b/lib/Interpreter/SensorInterpreter.php index d5408d5..315cb38 100644 --- a/lib/Interpreter/SensorInterpreter.php +++ b/lib/Interpreter/SensorInterpreter.php @@ -45,7 +45,7 @@ class SensorInterpreter extends Interpreter { * @return float total consumption in Wh */ public function getConsumption() { - return $this->consumption / 3600000; // convert to Wh + return $this->consumption / 3.6e6; // convert to Wh } /** @@ -69,12 +69,11 @@ class SensorInterpreter extends Interpreter { /** * Get Average * - * @return float 3600: 3600 s/h; 1000: ms -> s + * @return float average */ public function getAverage() { if ($this->consumption) { - $delta = $this->last[0] - $this->first[0]; - return $this->consumption / $delta; + return $this->consumption / ($this->last[0] - $this->first[0]); } else { // prevents division by zero return 0;