diff --git a/lib/Interpreter/MeterInterpreter.php b/lib/Interpreter/MeterInterpreter.php index b242c1e..60dccfc 100644 --- a/lib/Interpreter/MeterInterpreter.php +++ b/lib/Interpreter/MeterInterpreter.php @@ -76,8 +76,8 @@ class MeterInterpreter extends Interpreter { * @return float 3600: 3600 s/h; 1000: ms -> s */ public function getAverage() { - if ($consumption = $this->getConsumption()) { - return (3600 * 1000 * $consumption) / ($this->last[0] - $this->first[0]); + if ($this->pulseCount) { + return (1000 * $this->pulseCount / $this->resolution) / ($this->last[0] - $this->first[0]); } else { // prevents division by zero return 0; diff --git a/lib/Interpreter/SensorInterpreter.php b/lib/Interpreter/SensorInterpreter.php index 675ea55..d5408d5 100644 --- a/lib/Interpreter/SensorInterpreter.php +++ b/lib/Interpreter/SensorInterpreter.php @@ -72,9 +72,9 @@ class SensorInterpreter extends Interpreter { * @return float 3600: 3600 s/h; 1000: ms -> s */ public function getAverage() { - if ($consumption = $this->getConsumption()) { + if ($this->consumption) { $delta = $this->last[0] - $this->first[0]; - return (3600 * 1000 * $consumption) / $delta; + return $this->consumption / $delta; } else { // prevents division by zero return 0; @@ -103,7 +103,13 @@ class SensorInterpreter extends Interpreter { $this->min = $tuple; } - $this->consumption += $next[1] * ($next[0] - $last[0]); + /* + * Workaround for #73 + * Due to the "overfetching"" at the boundary regions + */ + if ($last[0] > $this->from && $next[0] < $this->to) { + $this->consumption += $next[1] * ($next[0] - $last[0]); + } $tuples[] = $tuple; $last = $next;