{
  "format": "rpai-station-workflow",
  "version": 1,
  "name": "CSV sales summary",
  "variables": [
    {
      "id": "var-folder",
      "name": "folder",
      "type": "string",
      "value": "~/Documents/Station Academy"
    },
    {
      "id": "var-0",
      "name": "region",
      "type": "string",
      "value": "North"
    }
  ],
  "activities": [
    {
      "id": "academy-001",
      "type": "comment",
      "name": "About this workflow",
      "properties": {
        "text": "Station Academy, Level 4 and project. Reads sales.csv, keeps one region, adds up the value of its sales and writes a filtered CSV and a short text report. Put sales.csv into the practice folder first."
      }
    },
    {
      "id": "academy-002",
      "type": "file_operation",
      "name": "Make sure the practice folder exists",
      "properties": {
        "operation": "create_folder",
        "sourcePath": "{{folder}}"
      }
    },
    {
      "id": "academy-003",
      "type": "csv_operation",
      "name": "Read the sales",
      "properties": {
        "operation": "read",
        "filePath": "{{folder}}/sales.csv",
        "delimiter": ",",
        "variable": "sales"
      }
    },
    {
      "id": "academy-004",
      "type": "datatable_filter",
      "name": "Only one region",
      "properties": {
        "tableVariable": "sales",
        "column": "Region",
        "operator": "equals",
        "value": "{{region}}",
        "saveToVariable": "regionSales"
      }
    },
    {
      "id": "academy-005",
      "type": "set_variable",
      "name": "Start the total",
      "properties": {
        "variableName": "total",
        "valueType": "static",
        "value": "0"
      }
    },
    {
      "id": "academy-010",
      "type": "for_each_row",
      "name": "For each sale",
      "properties": {
        "tableVariable": "regionSales",
        "rowVariable": "sale",
        "indexVariable": "i"
      },
      "children": [
        {
          "id": "academy-006",
          "type": "dict_get_key",
          "name": "Units of this sale",
          "properties": {
            "dictVariable": "sale",
            "key": "Units",
            "saveToVariable": "units"
          }
        },
        {
          "id": "academy-007",
          "type": "dict_get_key",
          "name": "Price of this sale",
          "properties": {
            "dictVariable": "sale",
            "key": "UnitPrice",
            "saveToVariable": "price"
          }
        },
        {
          "id": "academy-008",
          "type": "math_operation",
          "name": "Value of this sale",
          "properties": {
            "operation": "multiply",
            "operand1": "units",
            "operand2": "price",
            "saveToVariable": "value"
          }
        },
        {
          "id": "academy-009",
          "type": "math_operation",
          "name": "Add to the total",
          "properties": {
            "operation": "add",
            "operand1": "total",
            "operand2": "value",
            "saveToVariable": "total"
          }
        }
      ]
    },
    {
      "id": "academy-011",
      "type": "csv_operation",
      "name": "Save the region's sales",
      "properties": {
        "operation": "write",
        "filePath": "{{folder}}/sales-{{region}}.csv",
        "delimiter": ",",
        "variable": "regionSales"
      }
    },
    {
      "id": "academy-012",
      "type": "write_file",
      "name": "Write the report",
      "properties": {
        "filePath": "{{folder}}/sales-{{region}}-report.txt",
        "content": "Sales report for {{region}}\nTotal value: {{total}} EUR",
        "mode": "overwrite"
      }
    },
    {
      "id": "academy-013",
      "type": "log",
      "name": "Result",
      "properties": {
        "message": "{{region}}: total value {{total}} EUR",
        "level": "info"
      }
    }
  ]
}
