Hi,
this is the list of nodes of a flow ...
can I know the number of the node? Or the number of node in (all) my project?
It's a simple curiosity ....
Hi,
this is the list of nodes of a flow ...
can I know the number of the node? Or the number of node in (all) my project?
It's a simple curiosity ....
Here is a little flow to count the number of nodes in all flows, by node type.
[{"id":"1918a51fd4dc2e4a","type":"group","z":"3378d78bb37c052e","name":"Counting nodes in flows.json all at once","style":{"label":true},"nodes":["02cf87c8d1cf30c1","6aa2c90239f6b087","ccd47e52b8a3a5c5","6800dfd62b817b01","d81b083e0d1de79e"],"x":14,"y":159,"w":832,"h":82},{"id":"02cf87c8d1cf30c1","type":"inject","z":"3378d78bb37c052e","g":"1918a51fd4dc2e4a","name":"go","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":110,"y":200,"wires":[["6aa2c90239f6b087"]]},{"id":"6aa2c90239f6b087","type":"file in","z":"3378d78bb37c052e","g":"1918a51fd4dc2e4a","name":"flows.json","filename":".node-red/flows.json","filenameType":"str","format":"utf8","chunk":false,"sendError":false,"encoding":"none","allProps":false,"x":260,"y":200,"wires":[["ccd47e52b8a3a5c5"]]},{"id":"ccd47e52b8a3a5c5","type":"json","z":"3378d78bb37c052e","g":"1918a51fd4dc2e4a","name":"","property":"payload","action":"","pretty":false,"x":410,"y":200,"wires":[["d81b083e0d1de79e"]]},{"id":"6800dfd62b817b01","type":"debug","z":"3378d78bb37c052e","g":"1918a51fd4dc2e4a","name":"Show","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":750,"y":200,"wires":[]},{"id":"d81b083e0d1de79e","type":"change","z":"3378d78bb37c052e","g":"1918a51fd4dc2e4a","name":"Count","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload { type: $count($) }","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":550,"y":200,"wires":[["6800dfd62b817b01"]]}]
Ok, thank you ...
@Giamma You should accept the solution by clicking the "Solved" checkbox.
With sort by type and total sum (code by ChatGPT)
[{"id":"02cf87c8d1cf30c1","type":"inject","z":"01760d4e9f96f88b","name":"go","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":190,"y":1780,"wires":[["6aa2c90239f6b087"]]},{"id":"6aa2c90239f6b087","type":"file in","z":"01760d4e9f96f88b","name":"flows.json","filename":".node-red/flows.json","filenameType":"str","format":"utf8","chunk":false,"sendError":false,"encoding":"none","allProps":false,"x":320,"y":1780,"wires":[["ccd47e52b8a3a5c5"]]},{"id":"ccd47e52b8a3a5c5","type":"json","z":"01760d4e9f96f88b","name":"","property":"payload","action":"","pretty":false,"x":450,"y":1780,"wires":[["d81b083e0d1de79e"]]},{"id":"6800dfd62b817b01","type":"debug","z":"01760d4e9f96f88b","name":"Show","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":890,"y":1780,"wires":[]},{"id":"d81b083e0d1de79e","type":"change","z":"01760d4e9f96f88b","name":"Count","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload { type: $count($) }","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":570,"y":1780,"wires":[["32c2180ed0fa9198","1938bf898cce916b"]]},{"id":"32c2180ed0fa9198","type":"function","z":"01760d4e9f96f88b","name":"function 16","func":"const output = [null];\n\nlet data = msg.payload;\nlet sortedKeys = Object.keys(data).sort();\n\nlet sortedObj = {};\nsortedKeys.forEach(key => {\n sortedObj[key] = data[key];\n});\n\noutput[0] = { payload: sortedObj }\n\nreturn output;\n","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":730,"y":1780,"wires":[["6800dfd62b817b01"]]},{"id":"1938bf898cce916b","type":"function","z":"01760d4e9f96f88b","name":"function 15","func":"const output = [null];\n\nlet data = msg.payload;\nlet sum = 0;\nfor (let key in data) {\n if (data.hasOwnProperty(key)) {\n sum += data[key];\n }\n}\n\noutput[0] = { payload: sum };\n\nreturn output;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":750,"y":1820,"wires":[["dabbc05ded7e6e42"]]},{"id":"dabbc05ded7e6e42","type":"debug","z":"01760d4e9f96f88b","name":"debug 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":900,"y":1820,"wires":[]}]
Or the whole thing in one change node, giving you a total count and ordering the type.
$merge(
[
{"total_nodes":$count($$.payload)},
$$.payload^(type){type:$count($)}
]
)
Ok, I prefer yours, thank you ....
That's an excellent example of grouping and subtotalling with Jsonata, thanks @E1cid.
Single and double dollars, round and squiggly brackets, carets, functions ...
It's gradually becoming nearly as intuitive as regular expressions!
This should go to FAQ + Flow examples.