{
  "type": "step_based",
  "name": "Alerting",
  "active": false,
  "runAsUser": "romain.menini@dataiku.com",
  "creationTag": {
    "versionNumber": 28,
    "lastModifiedBy": {
      "login": "romain.menini@dataiku.com"
    },
    "lastModifiedOn": 1666349157220
  },
  "versionTag": {
    "versionNumber": 28,
    "lastModifiedBy": {
      "login": "romain.menini@dataiku.com"
    },
    "lastModifiedOn": 1666349157220
  },
  "checklists": {
    "checklists": []
  },
  "delayedTriggersBehavior": {
    "delayWhileRunning": true,
    "squashDelayedTriggers": true,
    "suppressTriggersWhileRunning": true
  },
  "tags": [],
  "triggers": [
    {
      "id": "n0l6i1rv",
      "type": "ds_modified",
      "name": "Dataset modified",
      "delay": 900,
      "active": true,
      "params": {
        "watches": [
          {
            "type": "DATASET",
            "itemId": "quality-alerts_log",
            "partitionsSpec": ""
          }
        ],
        "triggerWhenAllFire": false
      },
      "graceDelaySettings": {
        "delay": 120,
        "checkAgainAfterGraceDelay": true
      }
    }
  ],
  "reporters": [],
  "params": {
    "steps": [
      {
        "id": "def_scenar_vars",
        "type": "define_vars",
        "name": "machine, defect_rate",
        "runConditionType": "RUN_IF_STATUS_MATCH",
        "runConditionStatuses": [
          "SUCCESS",
          "WARNING"
        ],
        "runConditionExpression": "",
        "resetScenarioStatus": false,
        "delayBetweenRetries": 10,
        "maxRetriesOnFail": 0,
        "params": {
          "variables": {
            "machine_name": "",
            "predicted_defect_rate": ""
          },
          "definitions": [],
          "evaluateValues": false
        }
      },
      {
        "id": "custom_python_+yxlMs5KPlJ/ilw/6YArSQ",
        "type": "custom_python",
        "name": "Set variables",
        "runConditionType": "RUN_IF_STATUS_MATCH",
        "runConditionStatuses": [
          "SUCCESS",
          "WARNING"
        ],
        "runConditionExpression": "",
        "resetScenarioStatus": false,
        "delayBetweenRetries": 10,
        "maxRetriesOnFail": 0,
        "params": {
          "script": "import dataiku\nfrom dataiku.scenario import Scenario\nimport pandas as pd\n\n\n#Load quality_alerts_log as df:\nquality_alerts_logs \u003d dataiku.Dataset(\"quality-alerts_log\")\nquality_alerts_df \u003d quality_alerts_logs.get_dataframe()\nquality_alerts_df \u003d quality_alerts_df.sort_values([\u0027alert_time\u0027])\n\n#Get the last alert machine name and predicted_defect_rate\nmachine_name \u003d quality_alerts_df[quality_alerts_df[\"alert_time\"] \u003d\u003d quality_alerts_df[\"alert_time\"].max()][\"press\"].item()\npredicted_defect_rate \u003d quality_alerts_df[quality_alerts_df[\"alert_time\"] \u003d\u003d quality_alerts_df[\"alert_time\"].max()][\"predicted_defect_rate\"].item()\n\nif\n\n#write in the scenario variables\nScenario().set_scenario_variables(machine_name\u003dmachine_name)\nScenario().set_scenario_variables(predicted_defect_rate\u003dpredicted_defect_rate)",
          "envSelection": {
            "envMode": "INHERIT"
          },
          "proceedOnFailure": false
        }
      },
      {
        "id": "report2272e5bc5c69f8d2c8bfef3b332efd20",
        "type": "send_report",
        "name": "Microsoft teams",
        "runConditionType": "RUN_IF_STATUS_MATCH",
        "runConditionStatuses": [
          "SUCCESS",
          "WARNING"
        ],
        "runConditionExpression": "",
        "resetScenarioStatus": false,
        "delayBetweenRetries": 10,
        "maxRetriesOnFail": 0,
        "params": {
          "failOnMessageNotSent": true,
          "messaging": {
            "type": "msft-teams-scenario",
            "configuration": {
              "message": "\u0026#9888; The machine ${machine_name} has a predicted defect rate of ${predicted_defect_rate} %!",
              "useProxy": true,
              "useGlobalChannel": true,
              "channelId": "Maintenance-team"
            }
          }
        }
      }
    ]
  },
  "automationLocal": false,
  "customFields": {}
}