{
  "metadata": {
    "kernelspec": {
      "name": "py-dku-venv-ver-solution_streaming-pqc-sol_streaming_pqc-v1-0-2",
      "display_name": "Python (version SOL_STREAMING_PQC.v1-0-2 of env solution_streaming-PQC)",
      "language": "python"
    },
    "creator": "romain.menini@dataiku.com",
    "createdOn": 1673511206853,
    "tags": [],
    "customFields": {},
    "hide_input": false,
    "language_info": {
      "name": "python",
      "version": "3.6.8",
      "mimetype": "text/x-python",
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "pygments_lexer": "ipython3",
      "nbconvert_exporter": "python",
      "file_extension": ".py"
    },
    "modifiedBy": "romain.menini@dataiku.com"
  },
  "nbformat": 4,
  "nbformat_minor": 1,
  "cells": [
    {
      "execution_count": 0,
      "cell_type": "code",
      "metadata": {},
      "source": [
        "%pylab inline"
      ],
      "outputs": []
    },
    {
      "execution_count": 0,
      "cell_type": "code",
      "metadata": {},
      "source": [
        "import dataiku\nfrom dataiku import pandasutils as pdu\nimport pandas as pd"
      ],
      "outputs": []
    },
    {
      "execution_count": 0,
      "cell_type": "code",
      "metadata": {},
      "source": [
        "# Example: load a DSS dataset as a Pandas dataframe\nmydataset \u003d dataiku.Dataset(\"mydataset\")\nmydataset_df \u003d mydataset.get_dataframe()"
      ],
      "outputs": []
    },
    {
      "execution_count": 11,
      "cell_type": "code",
      "metadata": {},
      "source": [
        "import dataiku\nfrom dataiku.scenario import Trigger\nfrom datetime import datetime\n\n#Get last and previous values of dataset metric (COUNT_RECORDS):\nds \u003d dataiku.Dataset(\"enriched-process-data\")\nmetrics \u003d ds.get_metric_history(\"records:COUNT_RECORDS\")\nlast_value \u003d metrics[\u0027lastValue\u0027][\u0027value\u0027]\nprevious_value \u003d metrics[\u0027values\u0027][-2][\u0027value\u0027]"
      ],
      "outputs": []
    },
    {
      "execution_count": 13,
      "cell_type": "code",
      "metadata": {},
      "source": [
        "previous_value"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 13,
          "data": {
            "text/plain": "27"
          },
          "metadata": {}
        }
      ]
    },
    {
      "execution_count": 7,
      "cell_type": "code",
      "metadata": {},
      "source": [
        "ds \u003d dataiku.Dataset(\"enriched-process-data\")\n"
      ],
      "outputs": []
    },
    {
      "execution_count": 22,
      "cell_type": "code",
      "metadata": {},
      "source": [
        "import dataiku\nfrom dataiku.scenario import Trigger\nfrom datetime import datetime\n\n\n#Get last and previous values of dataset metric (COUNT_RECORDS):\nds \u003d dataiku.Dataset(\"enriched-process-data\")\nmetrics \u003d ds.get_metric_history(\"records:COUNT_RECORDS\")\nlast_value \u003d metrics[\u0027lastValue\u0027][\u0027value\u0027]\nprevious_value \u003d metrics[\u0027values\u0027][-2][\u0027value\u0027]\n\n\nif last_value !\u003d previous_value:\n    print(\"pouet\")\nelse: print(\"non\")"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "text": "pouet\n",
          "name": "stdout"
        }
      ]
    },
    {
      "execution_count": 16,
      "cell_type": "code",
      "metadata": {},
      "source": [
        "t \u003d Trigger()"
      ],
      "outputs": [
        {
          "output_type": "error",
          "ename": "TypeError",
          "evalue": "the JSON object must be str, bytes or bytearray, not \u0027NoneType\u0027",
          "traceback": [
            "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
            "\u001b[0;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
            "\u001b[0;32m\u003cipython-input-16-ccf3b7504612\u003e\u001b[0m in \u001b[0;36m\u003cmodule\u003e\u001b[0;34m\u001b[0m\n\u001b[0;32m----\u003e 1\u001b[0;31m \u001b[0mt\u001b[0m \u001b[0;34m\u003d\u001b[0m \u001b[0mTrigger\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
            "\u001b[0;32m/opt/dataiku-dss-11.0.3/python/dataiku/scenario/trigger.py\u001b[0m in \u001b[0;36m__init__\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m     20\u001b[0m     \"\"\"\n\u001b[1;32m     21\u001b[0m     \u001b[0;32mdef\u001b[0m \u001b[0m__init__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---\u003e 22\u001b[0;31m         \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtrigger\u001b[0m \u001b[0;34m\u003d\u001b[0m \u001b[0mjson\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mloads\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mremoterun\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_env_var\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\u0027DKU_TRIGGER\u0027\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     23\u001b[0m         \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtrigger_state\u001b[0m \u001b[0;34m\u003d\u001b[0m \u001b[0mremoterun\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_env_var\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\u0027DKU_TRIGGER_STATE\u0027\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     24\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
            "\u001b[0;32m/usr/lib64/python3.6/json/__init__.py\u001b[0m in \u001b[0;36mloads\u001b[0;34m(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)\u001b[0m\n\u001b[1;32m    346\u001b[0m         \u001b[0;32mif\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0ms\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mbytes\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mbytearray\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    347\u001b[0m             raise TypeError(\u0027the JSON object must be str, bytes or bytearray, \u0027\n\u001b[0;32m--\u003e 348\u001b[0;31m                             \u0027not {!r}\u0027.format(s.__class__.__name__))\n\u001b[0m\u001b[1;32m    349\u001b[0m         \u001b[0ms\u001b[0m \u001b[0;34m\u003d\u001b[0m \u001b[0ms\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdecode\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdetect_encoding\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0ms\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\u0027surrogatepass\u0027\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    350\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
            "\u001b[0;31mTypeError\u001b[0m: the JSON object must be str, bytes or bytearray, not \u0027NoneType\u0027"
          ]
        }
      ]
    },
    {
      "execution_count": 0,
      "cell_type": "code",
      "metadata": {},
      "source": [
        ""
      ],
      "outputs": []
    }
  ]
}