{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Workspaces\n",
    "\n",
    "Workspaces are a centralized place for the management of models and pipelines. All models and pipelines are created and uploaded into the users current workspace."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Default Workspace\n",
    "\n",
    "Users are given a default workspace called \"My Workspace\" to store their models and pipelines."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'name': 'My Workspace', 'id': 1, 'archived': False, 'created_by': 'ccbb181a-bb4e-427f-a994-383b2e7ca43b', 'created_at': '2022-02-28T18:21:58.309248+00:00', 'models': [{'name': 'cc-freud', 'version': 'a4561db6-ae8a-417e-8633-a5862bbf1dbc', 'file_name': 'keras_ccfraud.onnx', 'last_update_time': datetime.datetime(2022, 2, 28, 18, 21, 58, 355806, tzinfo=tzutc())}, {'name': 'cc-freud', 'version': 'f26afd95-9a44-413e-8a72-b62537730cb3', 'file_name': 'keras_ccfraud.onnx', 'last_update_time': datetime.datetime(2022, 2, 28, 18, 22, 36, 328963, tzinfo=tzutc())}, {'name': 'cc-freud', 'version': 'bc5522ec-d220-4f11-9ba0-fe0bdf02ffbd', 'file_name': 'keras_ccfraud.onnx', 'last_update_time': datetime.datetime(2022, 2, 28, 18, 23, 12, 341141, tzinfo=tzutc())}, {'name': 'cc-freud', 'version': '73c0ccff-68d4-49f4-8e61-e0b5ee304c6c', 'file_name': 'keras_ccfraud.onnx', 'last_update_time': datetime.datetime(2022, 2, 28, 18, 25, 41, 303181, tzinfo=tzutc())}, {'name': 'ccfraud', 'version': 'd8b2a7dd-857a-4841-8354-3ce404f33184', 'file_name': 'keras_ccfraud.onnx', 'last_update_time': datetime.datetime(2022, 2, 28, 21, 16, 26, 655612, tzinfo=tzutc())}, {'name': 'ccfraud', 'version': '984c4055-30cc-4108-aed3-91f2c4026b5e', 'file_name': 'keras_ccfraud.onnx', 'last_update_time': datetime.datetime(2022, 2, 28, 21, 23, 49, 105535, tzinfo=tzutc())}, {'name': 'lazyadam', 'version': '2a652238-b8b4-40a9-82ba-475a2b702307', 'file_name': 'optimizers_lazyadam.zip', 'last_update_time': datetime.datetime(2022, 2, 28, 21, 32, 13, 345677, tzinfo=tzutc())}, {'name': 'lazyadam', 'version': '24b33450-c094-425f-8cbf-d58aebb70ddc', 'file_name': 'optimizers_lazyadam.zip', 'last_update_time': datetime.datetime(2022, 2, 28, 21, 33, 47, 423032, tzinfo=tzutc())}, {'name': 'lazyadam', 'version': 'ea7dd374-80ee-4117-b74d-3506cadcfe47', 'file_name': 'optimizers_lazyadam.zip', 'last_update_time': datetime.datetime(2022, 2, 28, 21, 34, 56, 205279, tzinfo=tzutc())}, {'name': 'lazyadam', 'version': 'c765bc19-c131-4a24-8815-9b9d08d9b3d0', 'file_name': 'optimizers_lazyadam.zip', 'last_update_time': datetime.datetime(2022, 2, 28, 21, 35, 58, 978677, tzinfo=tzutc())}, {'name': 'lazyadam', 'version': '6b519ec0-2adb-41e6-bfab-e7dd1840bc8a', 'file_name': 'optimizers_lazyadam.zip', 'last_update_time': datetime.datetime(2022, 2, 28, 21, 37, 39, 481968, tzinfo=tzutc())}, {'name': 'lazyadam', 'version': '478988b8-16ee-4a1d-994a-2cd4c54866e0', 'file_name': 'optimizers_lazyadam.zip', 'last_update_time': datetime.datetime(2022, 2, 28, 21, 38, 10, 220414, tzinfo=tzutc())}], 'pipelines': [{'name': 'ccfraud-9955c412-4f97-4352-a55f-c6ac1f50dfcb', 'create_time': datetime.datetime(2022, 2, 28, 21, 16, 26, 806320, tzinfo=tzutc()), 'definition': '[]'}, {'name': 'ccfraud', 'create_time': datetime.datetime(2022, 2, 28, 21, 23, 49, 243070, tzinfo=tzutc()), 'definition': '[]'}, {'name': 'lazyadam', 'create_time': datetime.datetime(2022, 2, 28, 21, 32, 13, 468334, tzinfo=tzutc()), 'definition': '[]'}]}"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import wallaroo\n",
    "\n",
    "wl = wallaroo.Client(auth_type=\"sso\")\n",
    "wl.get_current_workspace()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Create a Workspace\n",
    "\n",
    "A user may create a new workspace to collaborate with others at their company. After creating the workspace, you can add users and additional owners to the workspace by the user's email address."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "new_workspace = wl.create_workspace(\"Wallaroo Model Workspace\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Add a user\n",
    "\n",
    "This function can also be used to change an existing workspace owner to a user in a given workspace"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'name': 'Wallaroo Model Workspace', 'id': 3, 'archived': False, 'created_by': 'ccbb181a-bb4e-427f-a994-383b2e7ca43b', 'created_at': '2022-03-02T15:07:48.371521+00:00', 'models': [], 'pipelines': []}"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "new_workspace.add_user(\"user@company.com\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Add an owner\n",
    "\n",
    "This function can also be used to change an existing workspace user into an owner of a given workspace"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'name': 'Wallaroo Model Workspace', 'id': 3, 'archived': False, 'created_by': 'ccbb181a-bb4e-427f-a994-383b2e7ca43b', 'created_at': '2022-03-02T15:07:48.371521+00:00', 'models': [], 'pipelines': []}"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "new_workspace.add_owner(\"user@company.com\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Remove a user\n",
    "\n",
    "This function can be used to remove both users and owners from a workspace"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "new_workspace.remove_user(\"user@company.com\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Set Current Workspace\n",
    "\n",
    "The user can change which workspace models and pipelines are created in by setting the current workspace. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "_ = wl.set_current_workspace(new_workspace)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'name': 'Wallaroo Model Workspace', 'id': 3, 'archived': False, 'created_by': 'ccbb181a-bb4e-427f-a994-383b2e7ca43b', 'created_at': '2022-03-02T15:07:48.371521+00:00', 'models': [], 'pipelines': []}"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "wl.get_current_workspace()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## All new models and piplines will be uploaded to the current workspace"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## You can list workspaces and select from the returned array to switch workspaces"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "        <table>\n",
       "            <tr>\n",
       "                <th>Name</th>\n",
       "                <th>Created At</th>\n",
       "                <th>Users</th>\n",
       "                <th>Models</th>\n",
       "                <th>Pipelines</th>\n",
       "            </tr>\n",
       "            \n",
       "        <tr >\n",
       "            <td>My Workspace</td>\n",
       "            <td>2022-02-28 18:21:58</td>\n",
       "            <td>['admin@foo.com']</td>\n",
       "            <td>12</td>\n",
       "            <td>3</td>\n",
       "        </tr>\n",
       "        \n",
       "\n",
       "        <tr >\n",
       "            <td>Wallaroo Model Workspace</td>\n",
       "            <td>2022-03-01 21:18:47</td>\n",
       "            <td>['admin@foo.com', 'user@company.com']</td>\n",
       "            <td>0</td>\n",
       "            <td>0</td>\n",
       "        </tr>\n",
       "        \n",
       "\n",
       "        <tr >\n",
       "            <td>Wallaroo Model Workspace</td>\n",
       "            <td>2022-03-02 15:07:48</td>\n",
       "            <td>['admin@foo.com']</td>\n",
       "            <td>0</td>\n",
       "            <td>0</td>\n",
       "        </tr>\n",
       "        \n",
       "        </table>\n",
       "        "
      ],
      "text/plain": [
       "[{'name': 'My Workspace', 'id': 1, 'archived': False, 'created_by': 'ccbb181a-bb4e-427f-a994-383b2e7ca43b', 'created_at': '2022-02-28T18:21:58.309248+00:00', 'models': [{'name': 'cc-freud', 'version': 'a4561db6-ae8a-417e-8633-a5862bbf1dbc', 'file_name': 'keras_ccfraud.onnx', 'last_update_time': datetime.datetime(2022, 2, 28, 18, 21, 58, 355806, tzinfo=tzutc())}, {'name': 'cc-freud', 'version': 'f26afd95-9a44-413e-8a72-b62537730cb3', 'file_name': 'keras_ccfraud.onnx', 'last_update_time': datetime.datetime(2022, 2, 28, 18, 22, 36, 328963, tzinfo=tzutc())}, {'name': 'cc-freud', 'version': 'bc5522ec-d220-4f11-9ba0-fe0bdf02ffbd', 'file_name': 'keras_ccfraud.onnx', 'last_update_time': datetime.datetime(2022, 2, 28, 18, 23, 12, 341141, tzinfo=tzutc())}, {'name': 'cc-freud', 'version': '73c0ccff-68d4-49f4-8e61-e0b5ee304c6c', 'file_name': 'keras_ccfraud.onnx', 'last_update_time': datetime.datetime(2022, 2, 28, 18, 25, 41, 303181, tzinfo=tzutc())}, {'name': 'ccfraud', 'version': 'd8b2a7dd-857a-4841-8354-3ce404f33184', 'file_name': 'keras_ccfraud.onnx', 'last_update_time': datetime.datetime(2022, 2, 28, 21, 16, 26, 655612, tzinfo=tzutc())}, {'name': 'ccfraud', 'version': '984c4055-30cc-4108-aed3-91f2c4026b5e', 'file_name': 'keras_ccfraud.onnx', 'last_update_time': datetime.datetime(2022, 2, 28, 21, 23, 49, 105535, tzinfo=tzutc())}, {'name': 'lazyadam', 'version': '2a652238-b8b4-40a9-82ba-475a2b702307', 'file_name': 'optimizers_lazyadam.zip', 'last_update_time': datetime.datetime(2022, 2, 28, 21, 32, 13, 345677, tzinfo=tzutc())}, {'name': 'lazyadam', 'version': '24b33450-c094-425f-8cbf-d58aebb70ddc', 'file_name': 'optimizers_lazyadam.zip', 'last_update_time': datetime.datetime(2022, 2, 28, 21, 33, 47, 423032, tzinfo=tzutc())}, {'name': 'lazyadam', 'version': 'ea7dd374-80ee-4117-b74d-3506cadcfe47', 'file_name': 'optimizers_lazyadam.zip', 'last_update_time': datetime.datetime(2022, 2, 28, 21, 34, 56, 205279, tzinfo=tzutc())}, {'name': 'lazyadam', 'version': 'c765bc19-c131-4a24-8815-9b9d08d9b3d0', 'file_name': 'optimizers_lazyadam.zip', 'last_update_time': datetime.datetime(2022, 2, 28, 21, 35, 58, 978677, tzinfo=tzutc())}, {'name': 'lazyadam', 'version': '6b519ec0-2adb-41e6-bfab-e7dd1840bc8a', 'file_name': 'optimizers_lazyadam.zip', 'last_update_time': datetime.datetime(2022, 2, 28, 21, 37, 39, 481968, tzinfo=tzutc())}, {'name': 'lazyadam', 'version': '478988b8-16ee-4a1d-994a-2cd4c54866e0', 'file_name': 'optimizers_lazyadam.zip', 'last_update_time': datetime.datetime(2022, 2, 28, 21, 38, 10, 220414, tzinfo=tzutc())}], 'pipelines': [{'name': 'ccfraud-9955c412-4f97-4352-a55f-c6ac1f50dfcb', 'create_time': datetime.datetime(2022, 2, 28, 21, 16, 26, 806320, tzinfo=tzutc()), 'definition': '[]'}, {'name': 'ccfraud', 'create_time': datetime.datetime(2022, 2, 28, 21, 23, 49, 243070, tzinfo=tzutc()), 'definition': '[]'}, {'name': 'lazyadam', 'create_time': datetime.datetime(2022, 2, 28, 21, 32, 13, 468334, tzinfo=tzutc()), 'definition': '[]'}]},\n",
       " {'name': 'Wallaroo Model Workspace', 'id': 2, 'archived': False, 'created_by': 'ccbb181a-bb4e-427f-a994-383b2e7ca43b', 'created_at': '2022-03-01T21:18:47.358079+00:00', 'models': [], 'pipelines': []},\n",
       " {'name': 'Wallaroo Model Workspace', 'id': 3, 'archived': False, 'created_by': 'ccbb181a-bb4e-427f-a994-383b2e7ca43b', 'created_at': '2022-03-02T15:07:48.371521+00:00', 'models': [], 'pipelines': []}]"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "wl.list_workspaces()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "my_workspace = wl.list_workspaces()[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'name': 'My Workspace', 'id': 1, 'archived': False, 'created_by': 'ccbb181a-bb4e-427f-a994-383b2e7ca43b', 'created_at': '2022-02-28T18:21:58.309248+00:00', 'models': [{'name': 'cc-freud', 'version': 'a4561db6-ae8a-417e-8633-a5862bbf1dbc', 'file_name': 'keras_ccfraud.onnx', 'last_update_time': datetime.datetime(2022, 2, 28, 18, 21, 58, 355806, tzinfo=tzutc())}, {'name': 'cc-freud', 'version': 'f26afd95-9a44-413e-8a72-b62537730cb3', 'file_name': 'keras_ccfraud.onnx', 'last_update_time': datetime.datetime(2022, 2, 28, 18, 22, 36, 328963, tzinfo=tzutc())}, {'name': 'cc-freud', 'version': 'bc5522ec-d220-4f11-9ba0-fe0bdf02ffbd', 'file_name': 'keras_ccfraud.onnx', 'last_update_time': datetime.datetime(2022, 2, 28, 18, 23, 12, 341141, tzinfo=tzutc())}, {'name': 'cc-freud', 'version': '73c0ccff-68d4-49f4-8e61-e0b5ee304c6c', 'file_name': 'keras_ccfraud.onnx', 'last_update_time': datetime.datetime(2022, 2, 28, 18, 25, 41, 303181, tzinfo=tzutc())}, {'name': 'ccfraud', 'version': 'd8b2a7dd-857a-4841-8354-3ce404f33184', 'file_name': 'keras_ccfraud.onnx', 'last_update_time': datetime.datetime(2022, 2, 28, 21, 16, 26, 655612, tzinfo=tzutc())}, {'name': 'ccfraud', 'version': '984c4055-30cc-4108-aed3-91f2c4026b5e', 'file_name': 'keras_ccfraud.onnx', 'last_update_time': datetime.datetime(2022, 2, 28, 21, 23, 49, 105535, tzinfo=tzutc())}, {'name': 'lazyadam', 'version': '2a652238-b8b4-40a9-82ba-475a2b702307', 'file_name': 'optimizers_lazyadam.zip', 'last_update_time': datetime.datetime(2022, 2, 28, 21, 32, 13, 345677, tzinfo=tzutc())}, {'name': 'lazyadam', 'version': '24b33450-c094-425f-8cbf-d58aebb70ddc', 'file_name': 'optimizers_lazyadam.zip', 'last_update_time': datetime.datetime(2022, 2, 28, 21, 33, 47, 423032, tzinfo=tzutc())}, {'name': 'lazyadam', 'version': 'ea7dd374-80ee-4117-b74d-3506cadcfe47', 'file_name': 'optimizers_lazyadam.zip', 'last_update_time': datetime.datetime(2022, 2, 28, 21, 34, 56, 205279, tzinfo=tzutc())}, {'name': 'lazyadam', 'version': 'c765bc19-c131-4a24-8815-9b9d08d9b3d0', 'file_name': 'optimizers_lazyadam.zip', 'last_update_time': datetime.datetime(2022, 2, 28, 21, 35, 58, 978677, tzinfo=tzutc())}, {'name': 'lazyadam', 'version': '6b519ec0-2adb-41e6-bfab-e7dd1840bc8a', 'file_name': 'optimizers_lazyadam.zip', 'last_update_time': datetime.datetime(2022, 2, 28, 21, 37, 39, 481968, tzinfo=tzutc())}, {'name': 'lazyadam', 'version': '478988b8-16ee-4a1d-994a-2cd4c54866e0', 'file_name': 'optimizers_lazyadam.zip', 'last_update_time': datetime.datetime(2022, 2, 28, 21, 38, 10, 220414, tzinfo=tzutc())}], 'pipelines': [{'name': 'ccfraud-9955c412-4f97-4352-a55f-c6ac1f50dfcb', 'create_time': datetime.datetime(2022, 2, 28, 21, 16, 26, 806320, tzinfo=tzutc()), 'definition': '[]'}, {'name': 'ccfraud', 'create_time': datetime.datetime(2022, 2, 28, 21, 23, 49, 243070, tzinfo=tzutc()), 'definition': '[]'}, {'name': 'lazyadam', 'create_time': datetime.datetime(2022, 2, 28, 21, 32, 13, 468334, tzinfo=tzutc()), 'definition': '[]'}]}"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "wl.set_current_workspace(my_workspace)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
