It wouldn't be rocket science, but I don't want to reinvent the wheel if I can avoid it.
You are receiving a series of messages (values).
The node "splits" the values to 3 outputs:
Maximum value received.
Average value received.
Minimum value received.
(If a reset message is received all stored values are wiped)
Would such a node exist?
Update:
The calculate node NEARLY does this. node-red-contrib-calculate
But lacks the ability to be reset by a message.
And yes, I would need 3 nodes to do what I want, but that doesn't mean I couldn't use it.
I just ..... wasn't sure that was.... coacher in doing it that way. (Legal - if you will)
It isn't like I am talking squillions of messages.
24 * 60 * ...... 2 -ish.
90,000 I think is there about.
While sleeping between those posts and now I thought:
(I'm asking for a sanity check on this option)
As I am wanting Max, Min and AVG (as opposed to Mean and all the other things offered by those nodes.
How about this code in a function node:
var MAX = context.get("MAX") || 0;
var COUNTER = context.get("COUNTER") || 0;
var MIN = context.get("MIN") || null;
var AVG = context.get("AVG") || null;
var TOTAL = context.get("TOTAL") || null;
var NEW = msg.payload;
msg1 = {};
msg2 = {};
if (msg.reset == true)
{
// Reset all things
node.warn("RESET");
context.set("MAX",0);
context.set("COUNTER",0);
context.set("MIN",null);
context.set("AVG",null);
context.set("TOTAL",null);
return;
}
if (COUNTER == 0)
{
// First pass
MIN = msg.payload;
}
NEW = msg.payload;
if (MAX > NEW)
{
MAX = NEW;
context.set("MAX",NEW);
}
if (MIN < NEW)
{
MIN = NEW;
context.set("MIN",NEW);
}
COUNTER = COUNTER + 1;
context.set("COUNTER",COUNTER);
TOTAL = TOTAL + NEW;
context.set("TOTAL",TOTAL);
AVG = parseInt((TOTAL / COUNTER));
msg.payload = "My calculated average is " + AVG;
msg1.payload = MAX;
msg2.payload = MIN;
return [msg,msg1,msg2];
No offence on the offers.
But the overhead of the 3 nodes to do a simple thing over a 24 hour time....
Their stacks (?) would/could get quite big because they offer so much more that I don't need.
This way it gets rid of a lot of that kind of stuff.