Ill describe the issue and welcome feedback.
Lets say I have:
Three stats, I pull the temps in as TS1, TS2, TS3. They all read 70F for this example.
10 AVGTEMP = AVG(TS1,TS2,TS3)
(result AVGTEMP = 70)
This works great. No problems.
But what if TS1 decides to falsely report 0 or it is unplugged… mouse chews a wire… worker smashes the stat, etc.
TS1 = 0 or null
TS2 = 70
TS3 = 70
10 AVGTEMP = AVG(TS1,TS2,TS3)
(result AVGTEMP = 46.6)
The average is going to be skewed all the way down to 46.6F
If im using that AVGTEMP to drive other functions all kinds of bad things will start happening. Sure I can bounds check the result and have code in place to make things work somewhat… but this isnt ideal.
Im thinking we need an average function that allows bounds setting or it will disregard the data. Something like this in use:
10 AVGTEMP = SAFEAVG(TS1,TS2,TS3,55,85)
Where the last two values are minimum and maximum acceptable values. The function should silently drop any passed value below 55 and higher than 85.
SO in my example if TS1 = 0, TS2 = 70, TS3 = 70… SAFEAVG used as above would return 70. Dropping TS1 and not using it in the average calculation. Hopefully I described this correctly.
Im aware this can be done in code. I could write a series of conditional statments to check the data before passing it to the AVG function. Honestly though, doing it in 2000 bytes is going to be difficult at best depending on how many stats I need to poll.
By all means if someone has a better way to do this “safe” average Im all ears.