Closed ghost closed 1 year ago
Think you need %ld instead of %f. (int instead of float) for the getCount() call.
Think you need %ld instead of %f. (int instead of float) for the getCount() call.
No matter what i use float or int, library work without getAverage on some esphome componet and not with others, maybe its esphome issue rather than library. Linking this issue with esphome https://github.com/esphome/issues/issues/4657
Think you need %ld instead of %f. (int instead of float) for the getCount() call.
ESP_LOGD("Stats", "%f %i", stats.getStandardDeviation(), stats.getCount());
[output]
[02:05:47][D][Stats:072]: nan 5
So count is 5, that means the NAN is not caused by divide by zero (_count is used in a division at some point)
What is the output if you swap the two parameters in the print? First count and then stddev?
Hypothesis 1 The order of the calls could initialize an internal variable needed by std dev.
test for hypothesis above.
if you change line 150 in RunningAverage.cpp
float average = getFastAverage();
into
float average = getAverage();
does your code print correctly then?
(I try to find out where the NAN is coming from, I cannot replicate so far on a "normal" Arduino).
Linking this issue with esphome https://github.com/esphome/issues/issues/4657
is closed without solution.
Esphome doc's already mentioned that external component can show unknown behaviour, that why they closed that https://github.com/esphome/issues/issues/4657. Maybe it was esphome issue, i have another proof this library also provide std_dev https://github.com/MajenkoLibraries/Average but after last Esphome update it's break and also return nan value. For last 2 Year i was using MajenkoLibraries/Average for std_dev calculation.
[optional]
Esphome doc's already mentioned that external component can show unknown behaviour
It means that fixing or adapting code gives no guarantees whatsoever for the future.
https://github.com/MajenkoLibraries/Average uses roughly the same method to calculate the stddev() (of course). So cause is likely to be similar. That is why I asked to change line 150.
Now you can only do modify RunningAverage to stricted class based ...
Feel free to make a PR.
I already request for standard deviation calculation in esphome
Good action.
Note: follow up of - https://github.com/RobTillaart/Statistic/issues/20
Get weird result when calculate standard deviation without average function in sketch.