fixes #73 (wrong calculation of consumption & average)

This commit is contained in:
Steffen Vogel 2011-07-22 12:29:16 +02:00
parent 993fbce82a
commit 6c8942c904
2 changed files with 11 additions and 5 deletions

View file

@ -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;

View file

@ -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;