some fixes for average calculation

This commit is contained in:
Steffen Vogel 2011-07-31 19:10:45 +02:00
parent f7b7c710e7
commit d510f7047d
2 changed files with 6 additions and 7 deletions

View file

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

View file

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