{"id": "D0I76cew5KOnlem0", "name": "Workflow stats", "nodes": [{"id": "b1a73981-db6a-4fd2-9cad-d02bfecc7d3d", "name": "When clicking \"Test workflow\"", "type": "n8n-nodes-base.manualTrigger", "position": [1060, 740], "parameters": {}, "typeVersion": 1}, {"id": "cbe2d1a8-51e9-4f3d-8ca5-321f3edf9a92", "name": "nodes-section", "type": "n8n-nodes-base.code", "position": [1900, 800], "parameters": {"jsCode": "// Initialize an empty object to hold the mapping between nodes and workflows\nconst nodeToWorkflowsMap = {};\n\n// Iterate over each workflow in the input\n$input.all().forEach(item => {\n const { wf_stats } = item.json;\n const { nodes_unique, wf_name, wf_url, wf_id } = wf_stats;\n\n // For each unique node in the workflow, update the mapping\n nodes_unique.forEach(node => {\n if (!nodeToWorkflowsMap[node]) {\n // If the node has not been added to the map, initialize it with the current workflow\n nodeToWorkflowsMap[node] = [{ wf_name, wf_url, wf_id }];\n } else {\n // If the node is already in the map, append the current workflow to its list\n nodeToWorkflowsMap[node].push({ wf_name, wf_url, wf_id });\n }\n });\n});\n\n// Convert the map into an array format suitable for n8n's output\nconst result = Object.keys(nodeToWorkflowsMap).map(node => ({\n json: {\n node,\n count: nodeToWorkflowsMap[node].length,\n workflows: nodeToWorkflowsMap[node]\n }\n}));\n\nreturn result;"}, "typeVersion": 2}, {"id": "49a10bf3-f2e6-4fe9-8390-2a266f1b52a9", "name": "workflows-section", "type": "n8n-nodes-base.set", "position": [1680, 640], "parameters": {"options": {}, "assignments": {"assignments": [{"id": "fd4aa80c-cd88-4a97-b943-dfcf1ab222ee", "name": "wf_stats", "type": "object", "value": "={{ { nodes_unique :[...new Set($json.nodes_array)],\n nodes_count_total:$json.nodes_array.length,\n nodes_count_uniq :[...new Set($json.nodes_array)].length,\n wf_created :DateTime.fromISO($json.createdAt).toFormat('yyyy-MM-dd HH:mm:ss'),\n wf_updated :DateTime.fromISO($json.updatedAt).toFormat('yyyy-MM-dd HH:mm:ss'),\n wf_name :$json.name,\n wf_id :`wf-${$json.id}`,\n wf_url :`${$json.instance_url}/workflow/${$json.id}`