[
  {
    "id": "taskRank01",
    "name": "Repetitive task prioritizer",
    "nodes": [
      {
        "parameters": {
          "httpMethod": "POST",
          "path": "add-task",
          "responseMode": "responseNode",
          "options": {}
        },
        "id": "p1",
        "name": "Add a task (webhook)",
        "type": "n8n-nodes-base.webhook",
        "typeVersion": 2,
        "position": [
          0,
          0
        ],
        "webhookId": "tp-add"
      },
      {
        "parameters": {
          "jsCode": "// Score one repetitive task: how much time it costs and how easy it is to automate\nconst b = $input.first().json.body || {};\nconst name = String(b.name || '').trim();\nif (!name) throw new Error('Send a task name, for example {\"name\":\"Weekly sales report\"}');\n\n// Settings you can change\nconst SAVINGS = 0.8;                       // share of the work automation removes (80%)\nconst BUILD_HOURS = { 1: 24, 2: 8, 3: 3 }; // hours to build: 1 = hard, 2 = medium, 3 = easy\nconst EASE_WEIGHT = { 1: 0.6, 2: 0.85, 3: 1 };\n\nconst runsPerWeek = Number(b.runs_per_week) || 0;\nconst minutes = Number(b.minutes_each) || 0;\nconst people = Number(b.people) || 1;\nconst hourly = Number(b.hourly_cost) || 30;\nconst ease = [1, 2, 3].includes(Number(b.ease)) ? Number(b.ease) : 2;\n\nconst hoursMonth = runsPerWeek * minutes * people * 4.33 / 60;   // 4.33 weeks per month\nconst hoursSaved = hoursMonth * SAVINGS;\nconst valueMonth = hoursSaved * hourly;\nconst paybackMonths = valueMonth > 0 ? (BUILD_HOURS[ease] * hourly) / valueMonth : null;\nconst priority = Math.round(valueMonth * (b.error_prone ? 1.25 : 1) * EASE_WEIGHT[ease]);\n\nconst sd = $getWorkflowStaticData('global');\nsd.tasks = sd.tasks || {};\nconst rec = { name, runs_per_week: runsPerWeek, minutes_each: minutes, people, ease, error_prone: !!b.error_prone,\n  hours_month: +hoursMonth.toFixed(1), hours_saved_month: +hoursSaved.toFixed(1), value_month: Math.round(valueMonth),\n  payback_months: paybackMonths === null ? null : +paybackMonths.toFixed(1), priority };\nsd.tasks[name] = rec;\nreturn [{ json: rec }];"
        },
        "id": "p2",
        "name": "Score the task",
        "type": "n8n-nodes-base.code",
        "typeVersion": 2,
        "position": [
          260,
          0
        ]
      },
      {
        "parameters": {
          "respondWith": "json",
          "responseBody": "={{ $json }}",
          "options": {}
        },
        "id": "p3",
        "name": "Return the score",
        "type": "n8n-nodes-base.respondToWebhook",
        "typeVersion": 1.4,
        "position": [
          520,
          0
        ]
      },
      {
        "parameters": {
          "httpMethod": "GET",
          "path": "rank-tasks",
          "responseMode": "responseNode",
          "options": {}
        },
        "id": "p4",
        "name": "Rank tasks (webhook)",
        "type": "n8n-nodes-base.webhook",
        "typeVersion": 2,
        "position": [
          0,
          260
        ],
        "webhookId": "tp-rank"
      },
      {
        "parameters": {
          "jsCode": "// Rank all saved tasks by priority and total the savings\nconst tasks = Object.values(($getWorkflowStaticData('global').tasks) || {}).sort((a, b) => b.priority - a.priority);\nconst top = tasks.slice(0, 5).map((t, i) => ({ rank: i + 1, ...t }));\nconst totalHours = tasks.reduce((s, t) => s + t.hours_saved_month, 0);\nconst totalValue = tasks.reduce((s, t) => s + t.value_month, 0);\nconst report = top.map(t => `${t.rank}. ${t.name}: saves ${t.hours_saved_month} h/month (about $${t.value_month}), pays back in ${t.payback_months} months`).join('\\n');\nreturn [{ json: { tasks_scored: tasks.length, total_hours_saved_month: +totalHours.toFixed(1), total_value_month: Math.round(totalValue), top, report } }];"
        },
        "id": "p5",
        "name": "Rank and total",
        "type": "n8n-nodes-base.code",
        "typeVersion": 2,
        "position": [
          260,
          260
        ]
      },
      {
        "parameters": {
          "respondWith": "json",
          "responseBody": "={{ $json }}",
          "options": {}
        },
        "id": "p6",
        "name": "Return the ranking",
        "type": "n8n-nodes-base.respondToWebhook",
        "typeVersion": 1.4,
        "position": [
          520,
          260
        ]
      },
      {
        "parameters": {
          "fromEmail": "planner@360automate.test",
          "toEmail": "team@360automate.test",
          "subject": "=Top automation candidates: {{ $json.tasks_scored }} tasks scored",
          "emailFormat": "text",
          "text": "=Together these tasks could save about {{ $json.total_hours_saved_month }} hours a month (about ${{ $json.total_value_month }}).\n\nBest first:\n{{ $json.report }}",
          "options": {
            "appendAttribution": false
          }
        },
        "id": "p7",
        "name": "Email the ranking",
        "type": "n8n-nodes-base.emailSend",
        "typeVersion": 2.1,
        "position": [
          520,
          440
        ],
        "credentials": {
          "smtp": {
            "id": "mailpitSmtp01",
            "name": "Local Mailpit SMTP"
          }
        }
      }
    ],
    "connections": {
      "Add a task (webhook)": {
        "main": [
          [
            {
              "node": "Score the task",
              "type": "main",
              "index": 0
            }
          ]
        ]
      },
      "Score the task": {
        "main": [
          [
            {
              "node": "Return the score",
              "type": "main",
              "index": 0
            }
          ]
        ]
      },
      "Rank tasks (webhook)": {
        "main": [
          [
            {
              "node": "Rank and total",
              "type": "main",
              "index": 0
            }
          ]
        ]
      },
      "Rank and total": {
        "main": [
          [
            {
              "node": "Return the ranking",
              "type": "main",
              "index": 0
            },
            {
              "node": "Email the ranking",
              "type": "main",
              "index": 0
            }
          ]
        ]
      }
    },
    "settings": {
      "executionOrder": "v1"
    },
    "active": false
  }
]