Socket
Socket
Sign inDemoInstall

node-red-contrib-boolean-logic-ultimate

Package Overview
Dependencies
Maintainers
1
Versions
86
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-red-contrib-boolean-logic-ultimate - npm Package Compare versions

Comparing version 1.1.3 to 1.1.5

53

boolean-logic-ultimate/SumUltimate.js

@@ -7,3 +7,3 @@ module.exports = function (RED) {

node.math = config.math === undefined ? "sum" : config.math;
this.topics = {};
node.topics = [];

@@ -35,3 +35,3 @@ function setNodeStatus({ fill, shape, text }) {

if (msg.hasOwnProperty("reset")) {
node.topics = {};
node.topics = [];
setNodeStatus({ fill: "grey", shape: "ring", text: "Reset" });

@@ -55,11 +55,13 @@ return;

if (!isNaN(ret) && isFinite(ret)) {
node.topics[msg.topic.toString()] = ret;
if (node.topics.find(a => a.id === msg.topic.toString()) === undefined) {
node.topics.push({ id: msg.topic.toString(), val: ret });
}
var quantita = 0;
let somma = 0;
if (node.math === "sum") {
let somma = Object.keys(node.topics).reduce(function (a, b) {
node.topics.forEach((item) => {
somma += item.val;
++quantita;
return a + node.topics[b];
}, 0);
});
msg.payload = somma; // Sum

@@ -69,30 +71,22 @@ msg.average = somma / quantita; // Average

} else if (node.math === "multiply") {
let moltiplicazione = Object.keys(node.topics).reduce(function (a, b) {
try {
let moltiplicazione = 1;
node.topics.forEach((item) => {
if (item.val !== 0) {
moltiplicazione *= item.val;
++quantita;
return (a > 0 ? a : 1) * node.topics[b]; // Avoid returning zero everytime
} catch (error) {
setNodeStatus({ fill: "red", shape: "ring", text: "Error " + error.message });
return 0;
}
}, 0);
});
msg.payload = moltiplicazione; // Sum
msg.average = undefined; // Average
msg.average = moltiplicazione / quantita; // Average
msg.measurements = quantita; // Topics
} else if (node.math === "subtract") {
let values = []
for (let row in node.topics) {
if (node.topics.hasOwnProperty(row)) {
++quantita;
values.push(node.topics[row]);
}
let risultato = node.topics[0].val;
quantita = 1;
for (let index = 1; index < node.topics.length; index++) {
risultato -= node.topics[index].val;
++quantita;
}
function orderReverseNumbers(a, b) {
return b - a;
}
values.sort(orderReverseNumbers)
let risultato = values[0]
for (let index = 1; index < values.length; index++) {
risultato -= values[index];
}
msg.payload = risultato; // Sum

@@ -102,3 +96,2 @@ msg.average = risultato / quantita; // Average

}
// overwrite topic if configured

@@ -105,0 +98,0 @@ if (config.name) {

@@ -7,2 +7,6 @@ # node-red-contrib-boolean-logic-ultimate

<p>
<b>Version 1.1.5</b> April 2024<br/>
- Math node: fixed an issue with the "subtract" operator. See contestual help in the node-red help tab.</br>
</p>
<p>
<b>Version 1.1.3</b> March 2024<br/>

@@ -9,0 +13,0 @@ - Comparator node: NEW: you can now reset both input values to *undefined*, by sending **msg.reset = true**.</br>

{
"name": "node-red-contrib-boolean-logic-ultimate",
"version": "1.1.3",
"version": "1.1.5",
"description": "A set of Node-RED enhanced boolean logic and utility nodes, flow interruption, blinker, invert, filter, toggle etc.., with persistent values after reboot. Compatible also with Homeassistant values.",

@@ -5,0 +5,0 @@ "author": "Supergiovane (https://github.com/Supergiovane)",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc