/ examples / future_examples / upload_snapshots.ipynb
upload_snapshots.ipynb
  1  {
  2   "cells": [
  3    {
  4     "metadata": {},
  5     "cell_type": "code",
  6     "outputs": [],
  7     "execution_count": null,
  8     "source": [
  9      "\n",
 10      "import numpy as np"
 11     ],
 12     "id": "4370e2785ffb059a"
 13    },
 14    {
 15     "metadata": {},
 16     "cell_type": "code",
 17     "outputs": [],
 18     "execution_count": null,
 19     "source": [
 20      "\n",
 21      "from evidently.core.report import Report\n",
 22      "import pandas as pd\n",
 23      "from evidently.tests import lt"
 24     ],
 25     "id": "780617ac5fd23750"
 26    },
 27    {
 28     "metadata": {},
 29     "cell_type": "code",
 30     "outputs": [],
 31     "execution_count": null,
 32     "source": [
 33      "from evidently.presets import DataSummaryPreset\n",
 34      "\n",
 35      "num_rows = 20\n",
 36      "np.random.seed(42)\n",
 37      "\n",
 38      "# Generate numerical data with some missing values\n",
 39      "num_col1 = np.random.randint(1, 100, num_rows).astype(float)\n",
 40      "num_col2 = np.random.uniform(10, 500, num_rows)\n",
 41      "num_col1[5] = np.nan  \n",
 42      "num_col2[12] = np.nan  \n",
 43      "\n",
 44      "# Generate categorical data with some missing values\n",
 45      "cat_col1 = np.random.choice(['A', 'B', 'C'], num_rows)\n",
 46      "cat_col2 = np.random.choice(['X', 'Y', 'Z'], num_rows)\n",
 47      "cat_col1[3] = np.nan \n",
 48      "cat_col2[8] = np.nan \n",
 49      "\n",
 50      "# Generate text data with some missing values\n",
 51      "text_col = np.random.choice(['Hello world', 'Test string', 'Sample text', 'Random text'], num_rows)\n",
 52      "text_col[6] = np.nan \n",
 53      "\n",
 54      "# Generate datetime data with some missing values\n",
 55      "date_col = pd.date_range(start='2025-01-01', periods=num_rows, freq='D')\n",
 56      "date_col = date_col.to_series().astype(\"object\")  # Convert to object to allow NaNs\n",
 57      "date_col.iloc[10] = np.nan \n",
 58      "\n",
 59      "# Create DataFrame\n",
 60      "df = pd.DataFrame({\n",
 61      "    'Numerical_1': num_col1,\n",
 62      "    'Numerical_2': num_col2,\n",
 63      "    'Categorical_1': cat_col1,\n",
 64      "    'Categorical_2': cat_col2,\n",
 65      "    'Text': text_col,\n",
 66      "    'Datetime': date_col.values, \n",
 67      "    'Datetime2': date_col.values,\n",
 68      "    'Datetime3': date_col.values,\n",
 69      "})\n",
 70      "\n",
 71      "report = Report(\n",
 72      "    [\n",
 73      "        DataSummaryPreset(row_count_tests=[lt(1)])\n",
 74      "    ],\n",
 75      "    tags=[\"t2\"],\n",
 76      ")\n",
 77      "\n",
 78      "report.set_model_id(\"m2\")\n",
 79      "\n",
 80      "snapshot = report.run(df, None, metadata={\"metadata_item\": \"meta_value\"}, tags=[\"t3\"])"
 81     ],
 82     "id": "b7624167f44fe07"
 83    },
 84    {
 85     "metadata": {},
 86     "cell_type": "code",
 87     "source": "snapshot",
 88     "id": "4f09cb9ac4f36265",
 89     "outputs": [],
 90     "execution_count": null
 91    },
 92    {
 93     "metadata": {},
 94     "cell_type": "code",
 95     "outputs": [],
 96     "execution_count": null,
 97     "source": [
 98      "import uuid\n",
 99      "from evidently.legacy.ui.workspace import CloudWorkspace\n",
100      "\n",
101      "client = CloudWorkspace(token=\"\", url=\"http://localhost:8003\")\n",
102      "client.add_run(uuid.UUID(\"01956698-b6d3-7ab0-9add-776f1a77ba78\"), snapshot)"
103     ],
104     "id": "92265e3b48ed602a"
105    },
106    {
107     "metadata": {},
108     "cell_type": "code",
109     "outputs": [],
110     "execution_count": null,
111     "source": [
112      "from evidently.legacy.ui.workspace import CloudWorkspace\n",
113      "import uuid\n",
114      "\n",
115      "client = CloudWorkspace(token=\"\", url=\"http://localhost:8003\")\n",
116      "client.add_run(uuid.UUID(\"0195d6d0-ee9e-7b79-be49-a790c3a0692e\"), snapshot, include_data=True)"
117     ],
118     "id": "897a1efa82663a01"
119    },
120    {
121     "metadata": {},
122     "cell_type": "code",
123     "source": "",
124     "id": "2c13c4f2a9ffea3c",
125     "outputs": [],
126     "execution_count": null
127    },
128    {
129     "metadata": {},
130     "cell_type": "code",
131     "source": "",
132     "id": "1a74a64406ca5910",
133     "outputs": [],
134     "execution_count": null
135    }
136   ],
137   "metadata": {
138    "kernelspec": {
139     "display_name": "Python 3",
140     "language": "python",
141     "name": "python3"
142    },
143    "language_info": {
144     "codemirror_mode": {
145      "name": "ipython",
146      "version": 2
147     },
148     "file_extension": ".py",
149     "mimetype": "text/x-python",
150     "name": "python",
151     "nbconvert_exporter": "python",
152     "pygments_lexer": "ipython2",
153     "version": "2.7.6"
154    }
155   },
156   "nbformat": 4,
157   "nbformat_minor": 5
158  }