diff --git a/fhem/CHANGED b/fhem/CHANGED index eebd260c4..3a8aa647d 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,6 @@ # Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # Do not insert empty lines here, update check depends on it. + - bugfix: TimeSeries: fix for calculation of standard deviation - feature: 76_SMAPortal: new relative time arguments for attr balanceDay, balanceMonth, balanceYear, new attribute useRelativeNames diff --git a/fhem/FHEM/TimeSeries.pm b/fhem/FHEM/TimeSeries.pm index cf304d9a6..ee226fc1f 100644 --- a/fhem/FHEM/TimeSeries.pm +++ b/fhem/FHEM/TimeSeries.pm @@ -44,6 +44,9 @@ # modified: method elapsed reverted to version from 2015-01-31 to provide downsampling and buffering through fhem.pl # modified: method _housekeeping does not reset time series if hold time is specified # +# 17.10.2020 Boris Neubert +# modified: fix for calculation of standard deviation +# ############################################################################## package TimeSeries; @@ -240,12 +243,13 @@ sub trimToHoldTime() { sub _updatestat($$) { my ($self, $V)= @_; - # see Donald Knuth, The Art of Computer Programming, ch. 4.2.2, formulas 14ff. + # see Donald Knuth, The Art of Computer Programming, ch. 4.2.2, p. 232ff, formulas 14ff. + # https://doc.lagout.org/science/0_Computer%20Science/2_Algorithms/The%20Art%20of%20Computer%20Programming%20%28vol.%202_%20Seminumerical%20Algorithms%29%20%283rd%20ed.%29%20%5BKnuth%201997-11-14%5D.pdf my $n= ++$self->{n}; if($n> 1) { my $M= $self->{_M}; $self->{_M}= $M + ($V - $M) / $n; - $self->{_S}= $self->{_S} + ($V - $M) * ($V - $M); + $self->{_S}= $self->{_S} + ($V - $M) * ($V - $self->{_M}); $self->{integral}+= $V; #main::Debug("V= $V M= $M _M= ".$self->{_M}." _S= " .$self->{_S}." int= ".$self->{integral}); } else {