bblanchon / ArduinoStreamUtils

💪 Power-ups for Arduino streams
MIT License
257 stars 21 forks source link

Feature request: Calculate statistics on a (wrapped) stream #24

Open vshymanskyy opened 2 years ago

vshymanskyy commented 2 years ago

Could be interesting to be able to grab some stats of the stream usage:

The only difficulty I see here: Some functions (i.e. readBytes) could be implemented via read() on some streams, but it can also be implemented directly by other implementations. Not sure if there's a clean way to handle it.

bblanchon commented 2 years ago

Hi @vshymanskyy,

Thank you for this suggestion; I think this is a good idea.

We could name the new classes:

The members could be:

How does that sound?

Best regards, Benoit

vshymanskyy commented 2 years ago

Sounds cool. But some names may be ambiguous esp. readBytes(). Maybe prefix all of them with total, min, max, avg ?

bblanchon commented 2 years ago

You're right! Maybe something like this, then:

read write
readCount() writeCount()
avgReadSize() avgWriteSize()
maxReadSize() maxWriteSize()
minReadSize() minWriteSize()
totalReadSize() totalWriteSize()
bblanchon commented 2 years ago

I'm not sure how to handle error cases: should we count them, or ignore them?

For example, if upstream's write() function returns 0, should I increment writeCount? should I set minWriteSize to 0?

dpharris commented 1 year ago

Maybe readErrors() and writeErrors()?

mhaberler commented 1 year ago

for such jobs I like the header-only stats classes by https://www.johndcook.com/blog/skewness_kurtosis/

he has several such classes on his website, real collectors items - I collect them here plus my adaptations: https://github.com/mhaberler/Stats