I have this array of objects coming in on a msg.payload.
(the actual array has lots of other key:value pairs that I'm not interested in
[
{
"id": "99999",
"signal": "voltage1",
"timeseries": [
{
"time": 1664553600000,
"value": 2
},
{
"time": 1664553700000,
"value": 4
}]
},
{
"id": "99999",
"signal": "voltage2",
"timeseries": [
{
"time": 1664553600000,
"value": 3
},
{
"time": 1664553700000,
"value": 1
}]
},
{
"id": "99999",
"signal": "current",
"timeseries": [
{
"time": 1664553600000,
"value": 5
},
{
"time": 1664553700000,
"value": 4
}]
}
]
I want to match up the timestamps and do ("voltage1" + "voltage2") * "current"
Then I want to output a new array that has the result for each timestamp.
I started with the map() function, and got here:
const input = msg.payload;
const output = input.map(signal => {
const container = {};
container["id"] = signal.id;
container["signal"] = signal.signal;
container["timeseries"] = signal.timeseries;
return container;
});
msg.payload = output;
return msg;
this does return me new arrays with only the information I'm interested in. But I'm a bit lost on how to do the math operations. I've found math.max() math.sum(), but nothing much more complex.
Anyone have pointers?