fixes #73 (wrong calculation of consumption & average)
This commit is contained in:
parent
993fbce82a
commit
6c8942c904
2 changed files with 11 additions and 5 deletions
|
@ -76,8 +76,8 @@ class MeterInterpreter extends Interpreter {
|
||||||
* @return float 3600: 3600 s/h; 1000: ms -> s
|
* @return float 3600: 3600 s/h; 1000: ms -> s
|
||||||
*/
|
*/
|
||||||
public function getAverage() {
|
public function getAverage() {
|
||||||
if ($consumption = $this->getConsumption()) {
|
if ($this->pulseCount) {
|
||||||
return (3600 * 1000 * $consumption) / ($this->last[0] - $this->first[0]);
|
return (1000 * $this->pulseCount / $this->resolution) / ($this->last[0] - $this->first[0]);
|
||||||
}
|
}
|
||||||
else { // prevents division by zero
|
else { // prevents division by zero
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -72,9 +72,9 @@ class SensorInterpreter extends Interpreter {
|
||||||
* @return float 3600: 3600 s/h; 1000: ms -> s
|
* @return float 3600: 3600 s/h; 1000: ms -> s
|
||||||
*/
|
*/
|
||||||
public function getAverage() {
|
public function getAverage() {
|
||||||
if ($consumption = $this->getConsumption()) {
|
if ($this->consumption) {
|
||||||
$delta = $this->last[0] - $this->first[0];
|
$delta = $this->last[0] - $this->first[0];
|
||||||
return (3600 * 1000 * $consumption) / $delta;
|
return $this->consumption / $delta;
|
||||||
}
|
}
|
||||||
else { // prevents division by zero
|
else { // prevents division by zero
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -103,7 +103,13 @@ class SensorInterpreter extends Interpreter {
|
||||||
$this->min = $tuple;
|
$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;
|
$tuples[] = $tuple;
|
||||||
$last = $next;
|
$last = $next;
|
||||||
|
|
Loading…
Add table
Reference in a new issue