I needed this week some very basic mathematic stuff, but I didn't want to create a function node for it. So I tried to find something on flows.nodered.org, however without success...
I'm pretty sure there must something exist already, but I gave up searching after some time and started creating my own node-red-contrib-math node. So if somebody now offers me a link to an existing node with similar functionality, I will most probably drop dead instantaneously
It allows you to do rounding, truncating, summing, subtracting, multiplying, finding maximums, finding minimums, ... It can do that on a single number, but also on all numbers in an array.
As usual, all 'constructive' feedback is more than welcome before I publish it on npm. You can install the current version directly from Github:
I assume this is some kind of catch-question, but I'm not sure which direction you go ...
This is 6 times 9 using the math-node:
Have asked my 3 year old son, I he agrees that this should be the correct result.
Did you have anything else in mind ? Perhaps "54" for the string-lovers among us?
Uh oh... In the past, I've used node-red-contrib-statistics to do things like sum, min, max, and mean on arrays of numbers. But there are lots of other supported functions that may or may not overlap with what you have -- according to the docs:
bernoulliDistribution
chunk
ckmeans
cumulativeStdNormalProbability
equalIntervalBreaks
errorFunction
extent
factorial
inverseErrorFunction
gamma
geometricMean
harmonicMean
interquartileRange
medianAbsoluteDeviation
max
mean
median
min
mode
poissonDistribution
probit
product
quantile
quantileRank
rootMeanSquare
sample
sampleWithReplacement
sampleKurtosis
sampleSkewness
sampleStandardDeviation
shuffle
standardDeviation
sum
sumNthPowerDeviations
tTest
uniqueCount
variance
But I do applaud you for seeing a need and jumping right on it!
I have been guessing who wanted to see me dropping dead instantaneously, by passing me a node name. But Steve, I had never expected it would be you
Seems there is a small overlap between our nodes, but yours is for users above 7 years old. Mine is aimed at the remaining user group ... But now at least they can compare both nodes here, when they search the forum for 'math'. Thanks for the link!
Simon, it looks to me that you have been waiting about 3 years (until somebody would release a node-red-contrib-math node) to post that link. But I'm very proud of you
the ability to multiply/divide/add/subtract the payload with a value that can be configured in the node.
1.1. this value can be a constant, but it can also be a flow or global context variable.
To round a number to configurable number of decimals.
Currently you are applying the math to the msg.payload. It would be interesting if you can specify the source for the math like is done in the change node. Especially it would be interesting if you could apply the math to a different field of the msg.
I also think that time arithmetic functions is an interesting area for extension or a separate node.
E.g. adding X minutes or Y hours to a certain timestamp.
This will be useful for "quick and dirty" situations when it's not worth bothering with JavaScript or JSONata. Two observations:
It would be good to have the option of getting the result in a message property other than payload, so that the incoming payload could be preserved for use downstream.
It would be really nice to be able to choose the operation to be performed with the incoming message (perhaps with msg.operation), so that the same math node could be used to process different messages differently.
Perhaps more effort than you want to invest, but since (based on the rest of this thread) your life seems to be in danger, why not?
Yes indeed I have seen that node a couple of days ago, but there was no readme and I couldn't find the repository anywhere. So I left it behind... But what is more worse: I completely forgot about it Damn, I have even forgotten to install it at have a look at the source code. I'm getting old ...
Thanks anyway, I will have to rename mine to e.g. node-red-contrib-basic-math, or node-red-contrib-mathematic....
Bart
@BartButenaers, I haven't installed this yet (I'm waiting for the name change & publication), but can each of the functions be changed dynamically by a corresponding msg property, instead of, or overriding the setting in the node config.
ie msg.maximum or msg.minimum.
When the operation dropdown is set to an empty value, the input message needs to have a msg.operation field (containing e.g. 'sqrt' for Square Root). That was already available in my first version, but I hadn't documented it yet in the readme and the info panel ...
Both the input and output field messages can now be changed on the config screen:
A new operation has been added to round the input number to a specified number of decimal places:
Examples have been added to the readme page
A link to the node-red-contrib-statistics node has been added to the readme page
I have added a field to the config screen, where a fixed constant number can be entered:
But that is not entirely complete yet ... @janvda: How it works now. For example you want to round number 1.23456 to 3 decimals:
Normally you need to apply an input message containing an array [ 1.23456 , 3 ]
However when you enter 3 in the constant field, the input message will only need to contain the number 1.23456 (and the calc-node will internally create an array [ 1.23456 , 3 ]. Is that sufficient ?
Well I'm not native English speaking, so let's try it again: I round the input number to get a an rounded output number. Don't forget that we have to learn the English language by looking at television shows from your country like Monty Python, Mister Bean and Fawlty Towers. I'm not from Barcelona, but I still know nothing