{
  "name": "PROD_04_Data_Analytics_Workflow",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "hours",
              "hoursInterval": 1
            }
          ]
        },
        "options": {}
      },
      "id": "1",
      "name": "Schedule_Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "1",
              "name": "query_date",
              "value": "{{ $now.minus({hours:1}).toISO() }}",
              "type": "string"
            },
            {
              "id": "2",
              "name": "source",
              "value": "analytics_db",
              "type": "string"
            }
          ]
        }
      },
      "id": "2",
      "name": "Set_Params",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3,
      "position": [
        450,
        300
      ]
    },
    {
      "parameters": {
        "method": "GET",
        "url": "https://api.example.com/analytics/data",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "from",
              "value": "={{ $json.query_date }}"
            }
          ]
        },
        "options": {}
      },
      "id": "3",
      "name": "Fetch_Analytics",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        650,
        300
      ]
    },
    {
      "parameters": {
        "jsCode": "const data = $input.first().json;\nconst metrics = data.metrics || [];\nconst summary = {\n  total_records: metrics.length,\n  avg_value: metrics.reduce((a,b)=>a+b.value,0)/metrics.length,\n  max_value: Math.max(...metrics.map(m=>m.value)),\n  min_value: Math.min(...metrics.map(m=>m.value)),\n  processed_at: new Date().toISOString()\n};\nreturn { summary, raw_data: data };"
      },
      "id": "4",
      "name": "Calculate_Metrics",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        850,
        300
      ]
    },
    {
      "parameters": {
        "operation": "upsert",
        "tableId": "analytics_results",
        "columns": [
          "summary",
          "raw_data",
          "processed_at"
        ],
        "options": {}
      },
      "id": "5",
      "name": "Store_Results",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4,
      "position": [
        1050,
        300
      ]
    },
    {
      "parameters": {
        "to": "analytics_team",
        "text": "={{ 'Analytics Report Ready | Records: ' + $json.summary.total_records + ' | Avg: ' + $json.summary.avg_value.toFixed(2) }}",
        "additionalFields": {}
      },
      "id": "6",
      "name": "Telegram_Report",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1,
      "position": [
        1250,
        300
      ]
    }
  ],
  "connections": {
    "Schedule_Trigger": {
      "main": [
        [
          {
            "node": "Set_Params",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set_Params": {
      "main": [
        [
          {
            "node": "Fetch_Analytics",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch_Analytics": {
      "main": [
        [
          {
            "node": "Calculate_Metrics",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Calculate_Metrics": {
      "main": [
        [
          {
            "node": "Store_Results",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Store_Results": {
      "main": [
        [
          {
            "node": "Telegram_Report",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "prod-04-v1",
  "id": "PROD04DATAANALYTICS",
  "tags": [
    {
      "name": "production"
    },
    {
      "name": "analytics"
    }
  ]
}