{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from seeq import spy\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"background-color: #EEFFEE;text-align: left;\">Logged in to <strong>http://localhost:34216/api</strong> successfully as <strong>agent_api_key</strong>.<br>Seeq Server Version: <strong>R21.0.44.04</strong><br>Seeq Python Module Version: <strong>0.44.4.136</strong></div>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Log into Seeq Server if you're not using Seeq Data Lab:\n",
    "spy.login(url='http://localhost:34216', credentials_file='../credentials.key', force=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# spy.push\n",
    "\n",
    "Uploads signals, conditions, scalars, and assets to the Seeq Server.\n",
    "\n",
    "There are two main types of information processed by Seeq: _Data_ and _metadata_:\n",
    "\n",
    "- **Data** is the time series and time interval information that is either collected or derived from sensor data. It consists of timestamps and values (samples), or time intervals and properties (capsules). This data can be plotted on a trend or used to train a neural network, for example.\n",
    "\n",
    "- **Metadata** is the information about the data, that is independent of a particular point in time or time interval. For example, a signal's _name_, _description_ and _unit of measure_ is classified as metadata; or the formula that is used to derive a new signal from one or more source signals; or the asset tree that is used to model similar equipment or industrial processes.\n",
    "\n",
    "The `spy.push()` command allows you to upload both types of information to Seeq Server. When you push _metadata_, you make entries in Seeq's data index, which allows you or other users to search for and find such entries. If you also push _data_, then samples or capsules or scalars will appear when the user selects those index entries for inclusion on a trend, scatter plot, scorecard or other visualization."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "```\n",
    "spy.push(data=None, metadata=None, item_type=None, workbook='Data Lab >> Data Lab Analysis',\n",
    "         worksheet='From Data Lab', datasource=None, archive=False, type_mismatches='raise', errors='catalog')\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Workbook scoping\n",
    "\n",
    "When you push any type of data, it is only available/discoverable within the workbook specified by the `workbook` argument. This allows you to _sandbox_ your activity by default, and only publish to your colleagues later when your experimentation is largely over."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Pushing signal data\n",
    "\n",
    "The simplest activity you can do with the `spy.push()` command is to read in a CSV file using Pandas and push it into Seeq. It will be stored in Seeq's internal time series database."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>BITDEP(ft)</th>\n",
       "      <th>BLOCKCOMP(ft)</th>\n",
       "      <th>DEP_RTN(ft)</th>\n",
       "      <th>DEPTH(ft)</th>\n",
       "      <th>FLOWIN(USgal/min)</th>\n",
       "      <th>FLOWOUTPC(%)</th>\n",
       "      <th>ROP_AVG(ft/h)</th>\n",
       "      <th>DIFP(psi)</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>TIME(unitless)</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2018-07-25 23:00:01-06:00</th>\n",
       "      <td>4630.217</td>\n",
       "      <td>74.813</td>\n",
       "      <td>4627.0</td>\n",
       "      <td>4630.217</td>\n",
       "      <td>799.857</td>\n",
       "      <td>40.799</td>\n",
       "      <td>142.698</td>\n",
       "      <td>454.214</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-07-25 23:00:03-06:00</th>\n",
       "      <td>4630.354</td>\n",
       "      <td>74.735</td>\n",
       "      <td>4627.5</td>\n",
       "      <td>4630.354</td>\n",
       "      <td>799.857</td>\n",
       "      <td>40.576</td>\n",
       "      <td>142.698</td>\n",
       "      <td>481.383</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-07-25 23:00:05-06:00</th>\n",
       "      <td>4630.470</td>\n",
       "      <td>74.619</td>\n",
       "      <td>4627.5</td>\n",
       "      <td>4630.470</td>\n",
       "      <td>799.857</td>\n",
       "      <td>39.929</td>\n",
       "      <td>142.698</td>\n",
       "      <td>487.502</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-07-25 23:00:07-06:00</th>\n",
       "      <td>4630.588</td>\n",
       "      <td>74.501</td>\n",
       "      <td>4627.5</td>\n",
       "      <td>4630.588</td>\n",
       "      <td>799.857</td>\n",
       "      <td>40.305</td>\n",
       "      <td>210.705</td>\n",
       "      <td>561.480</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-07-25 23:00:09-06:00</th>\n",
       "      <td>4630.699</td>\n",
       "      <td>74.390</td>\n",
       "      <td>4627.5</td>\n",
       "      <td>4630.699</td>\n",
       "      <td>799.292</td>\n",
       "      <td>40.245</td>\n",
       "      <td>210.705</td>\n",
       "      <td>610.968</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                           BITDEP(ft)  BLOCKCOMP(ft)  DEP_RTN(ft)  DEPTH(ft)  \\\n",
       "TIME(unitless)                                                                 \n",
       "2018-07-25 23:00:01-06:00    4630.217         74.813       4627.0   4630.217   \n",
       "2018-07-25 23:00:03-06:00    4630.354         74.735       4627.5   4630.354   \n",
       "2018-07-25 23:00:05-06:00    4630.470         74.619       4627.5   4630.470   \n",
       "2018-07-25 23:00:07-06:00    4630.588         74.501       4627.5   4630.588   \n",
       "2018-07-25 23:00:09-06:00    4630.699         74.390       4627.5   4630.699   \n",
       "\n",
       "                           FLOWIN(USgal/min)  FLOWOUTPC(%)  ROP_AVG(ft/h)  \\\n",
       "TIME(unitless)                                                              \n",
       "2018-07-25 23:00:01-06:00            799.857        40.799        142.698   \n",
       "2018-07-25 23:00:03-06:00            799.857        40.576        142.698   \n",
       "2018-07-25 23:00:05-06:00            799.857        39.929        142.698   \n",
       "2018-07-25 23:00:07-06:00            799.857        40.305        210.705   \n",
       "2018-07-25 23:00:09-06:00            799.292        40.245        210.705   \n",
       "\n",
       "                           DIFP(psi)  \n",
       "TIME(unitless)                        \n",
       "2018-07-25 23:00:01-06:00    454.214  \n",
       "2018-07-25 23:00:03-06:00    481.383  \n",
       "2018-07-25 23:00:05-06:00    487.502  \n",
       "2018-07-25 23:00:07-06:00    561.480  \n",
       "2018-07-25 23:00:09-06:00    610.968  "
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import csv\n",
    "csv_file = pd.read_csv('csv_import_example.csv', parse_dates=['TIME(unitless)'], index_col='TIME(unitless)')\n",
    "csv_file.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "When you want to push data, it must have an index with a datetime data type. That's why we used the `parse_dates` and `index_col` arguments for `Pandas.read_csv()`.\n",
    "\n",
    "Now you can just push it into Seeq:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"background-color: #EEFFEE;text-align: left;\">Pushed successfully to datasource <strong>Seeq Data Lab [Datasource ID: Seeq Data Lab]</strong> and scoped to workbook ID <strong>DD7F6F24-283C-4138-9195-F1077E4A3FFE</strong><br>Click the following link to see what you pushed in Seeq:<br><a href=\"http://localhost:34216/E75C3137-38F2-4E50-B872-CC897D7100F3/workbook/DD7F6F24-283C-4138-9195-F1077E4A3FFE/worksheet/06D22E34-1429-4539-868C-0F33DBC56542\" target=\"_new\">http://localhost:34216/E75C3137-38F2-4E50-B872-CC897D7100F3/workbook/DD7F6F24-283C-4138-9195-F1077E4A3FFE/worksheet/06D22E34-1429-4539-868C-0F33DBC56542</a></div><table><tr><td style=\"background-color: #EEFFEE;\"></td><td style=\"background-color: #EEFFEE;\">Count</td><td style=\"background-color: #EEFFEE;\">Result</td><td style=\"background-color: #EEFFEE;\">Time</td></tr><tr style=\"background-color: #EEFFEE;\"><td>BITDEP(ft)</td><td>11485</td><td>Success</td><td>00:00:06.43</td></tr><tr style=\"background-color: #EEFFEE;\"><td>BLOCKCOMP(ft)</td><td>11485</td><td>Success</td><td>00:00:05.09</td></tr><tr style=\"background-color: #EEFFEE;\"><td>DEP_RTN(ft)</td><td>11485</td><td>Success</td><td>00:00:04.73</td></tr><tr style=\"background-color: #EEFFEE;\"><td>DEPTH(ft)</td><td>11485</td><td>Success</td><td>00:00:05.90</td></tr><tr style=\"background-color: #EEFFEE;\"><td>FLOWIN(USgal/min)</td><td>11485</td><td>Success</td><td>00:00:05.25</td></tr><tr style=\"background-color: #EEFFEE;\"><td>FLOWOUTPC(%)</td><td>11485</td><td>Success</td><td>00:00:05.91</td></tr><tr style=\"background-color: #EEFFEE;\"><td>ROP_AVG(ft/h)</td><td>11485</td><td>Success</td><td>00:00:04.95</td></tr><tr style=\"background-color: #EEFFEE;\"><td>DIFP(psi)</td><td>11485</td><td>Success</td><td>00:00:04.33</td></tr></table>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Push Count</th>\n",
       "      <th>Push Time</th>\n",
       "      <th>Push Result</th>\n",
       "      <th>Name</th>\n",
       "      <th>ID</th>\n",
       "      <th>Type</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>BITDEP(ft)</th>\n",
       "      <td>11485.0</td>\n",
       "      <td>0:00:06.429804</td>\n",
       "      <td>Success</td>\n",
       "      <td>BITDEP(ft)</td>\n",
       "      <td>A2EE83F9-3881-4458-8A65-DCAA7897B636</td>\n",
       "      <td>StoredSignal</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>BLOCKCOMP(ft)</th>\n",
       "      <td>11485.0</td>\n",
       "      <td>0:00:05.086397</td>\n",
       "      <td>Success</td>\n",
       "      <td>BLOCKCOMP(ft)</td>\n",
       "      <td>56DB9BE5-4A33-4847-BA94-97C8BFB2C5CB</td>\n",
       "      <td>StoredSignal</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>DEP_RTN(ft)</th>\n",
       "      <td>11485.0</td>\n",
       "      <td>0:00:04.731346</td>\n",
       "      <td>Success</td>\n",
       "      <td>DEP_RTN(ft)</td>\n",
       "      <td>0FC7EAAF-C3E7-480F-8DE9-B0C7371BB2DB</td>\n",
       "      <td>StoredSignal</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>DEPTH(ft)</th>\n",
       "      <td>11485.0</td>\n",
       "      <td>0:00:05.899195</td>\n",
       "      <td>Success</td>\n",
       "      <td>DEPTH(ft)</td>\n",
       "      <td>1C6250DA-0A1C-46F0-A6C6-0F9D2693DF1A</td>\n",
       "      <td>StoredSignal</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>FLOWIN(USgal/min)</th>\n",
       "      <td>11485.0</td>\n",
       "      <td>0:00:05.250957</td>\n",
       "      <td>Success</td>\n",
       "      <td>FLOWIN(USgal/min)</td>\n",
       "      <td>013167A3-3ECE-4852-8541-E9E9ED483A90</td>\n",
       "      <td>StoredSignal</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>FLOWOUTPC(%)</th>\n",
       "      <td>11485.0</td>\n",
       "      <td>0:00:05.906205</td>\n",
       "      <td>Success</td>\n",
       "      <td>FLOWOUTPC(%)</td>\n",
       "      <td>89A1F851-2965-4909-B2C2-A4263F75BB50</td>\n",
       "      <td>StoredSignal</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ROP_AVG(ft/h)</th>\n",
       "      <td>11485.0</td>\n",
       "      <td>0:00:04.949735</td>\n",
       "      <td>Success</td>\n",
       "      <td>ROP_AVG(ft/h)</td>\n",
       "      <td>E7AC16B0-9534-450F-8CD6-DF3ABC530434</td>\n",
       "      <td>StoredSignal</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>DIFP(psi)</th>\n",
       "      <td>11485.0</td>\n",
       "      <td>0:00:04.331416</td>\n",
       "      <td>Success</td>\n",
       "      <td>DIFP(psi)</td>\n",
       "      <td>E64ECBFF-D5E0-4306-BCF2-AB33740C5D45</td>\n",
       "      <td>StoredSignal</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   Push Count       Push Time Push Result               Name  \\\n",
       "BITDEP(ft)            11485.0  0:00:06.429804     Success         BITDEP(ft)   \n",
       "BLOCKCOMP(ft)         11485.0  0:00:05.086397     Success      BLOCKCOMP(ft)   \n",
       "DEP_RTN(ft)           11485.0  0:00:04.731346     Success        DEP_RTN(ft)   \n",
       "DEPTH(ft)             11485.0  0:00:05.899195     Success          DEPTH(ft)   \n",
       "FLOWIN(USgal/min)     11485.0  0:00:05.250957     Success  FLOWIN(USgal/min)   \n",
       "FLOWOUTPC(%)          11485.0  0:00:05.906205     Success       FLOWOUTPC(%)   \n",
       "ROP_AVG(ft/h)         11485.0  0:00:04.949735     Success      ROP_AVG(ft/h)   \n",
       "DIFP(psi)             11485.0  0:00:04.331416     Success          DIFP(psi)   \n",
       "\n",
       "                                                     ID          Type  \n",
       "BITDEP(ft)         A2EE83F9-3881-4458-8A65-DCAA7897B636  StoredSignal  \n",
       "BLOCKCOMP(ft)      56DB9BE5-4A33-4847-BA94-97C8BFB2C5CB  StoredSignal  \n",
       "DEP_RTN(ft)        0FC7EAAF-C3E7-480F-8DE9-B0C7371BB2DB  StoredSignal  \n",
       "DEPTH(ft)          1C6250DA-0A1C-46F0-A6C6-0F9D2693DF1A  StoredSignal  \n",
       "FLOWIN(USgal/min)  013167A3-3ECE-4852-8541-E9E9ED483A90  StoredSignal  \n",
       "FLOWOUTPC(%)       89A1F851-2965-4909-B2C2-A4263F75BB50  StoredSignal  \n",
       "ROP_AVG(ft/h)      E7AC16B0-9534-450F-8CD6-DF3ABC530434  StoredSignal  \n",
       "DIFP(psi)          E64ECBFF-D5E0-4306-BCF2-AB33740C5D45  StoredSignal  "
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "push_results = spy.push(data=csv_file)\n",
    "push_results"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "NOTE: Pushing data can be relatively slow. This is an area that Seeq will be optimizing in future versions.\n",
    "\n",
    "You can push multiple times, and as long as the names are the same and the workbook hasn't changed, you'll just add to the existing signal."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Pushing metadata"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now let's try pushing just metadata. You can see that the column names from the CSV file contain the unit of measure in parentheses. Let's use Pandas to extract the name and the unit of measure as separate columns."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Push Count</th>\n",
       "      <th>Push Time</th>\n",
       "      <th>Push Result</th>\n",
       "      <th>Name</th>\n",
       "      <th>ID</th>\n",
       "      <th>Type</th>\n",
       "      <th>Original Name</th>\n",
       "      <th>Value Unit Of Measure</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>BITDEP(ft)</th>\n",
       "      <td>11485.0</td>\n",
       "      <td>0:00:06.429804</td>\n",
       "      <td>Success</td>\n",
       "      <td>BITDEP</td>\n",
       "      <td>A2EE83F9-3881-4458-8A65-DCAA7897B636</td>\n",
       "      <td>StoredSignal</td>\n",
       "      <td>BITDEP(ft)</td>\n",
       "      <td>ft</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>BLOCKCOMP(ft)</th>\n",
       "      <td>11485.0</td>\n",
       "      <td>0:00:05.086397</td>\n",
       "      <td>Success</td>\n",
       "      <td>BLOCKCOMP</td>\n",
       "      <td>56DB9BE5-4A33-4847-BA94-97C8BFB2C5CB</td>\n",
       "      <td>StoredSignal</td>\n",
       "      <td>BLOCKCOMP(ft)</td>\n",
       "      <td>ft</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>DEP_RTN(ft)</th>\n",
       "      <td>11485.0</td>\n",
       "      <td>0:00:04.731346</td>\n",
       "      <td>Success</td>\n",
       "      <td>DEP_RTN</td>\n",
       "      <td>0FC7EAAF-C3E7-480F-8DE9-B0C7371BB2DB</td>\n",
       "      <td>StoredSignal</td>\n",
       "      <td>DEP_RTN(ft)</td>\n",
       "      <td>ft</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>DEPTH(ft)</th>\n",
       "      <td>11485.0</td>\n",
       "      <td>0:00:05.899195</td>\n",
       "      <td>Success</td>\n",
       "      <td>DEPTH</td>\n",
       "      <td>1C6250DA-0A1C-46F0-A6C6-0F9D2693DF1A</td>\n",
       "      <td>StoredSignal</td>\n",
       "      <td>DEPTH(ft)</td>\n",
       "      <td>ft</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>FLOWIN(USgal/min)</th>\n",
       "      <td>11485.0</td>\n",
       "      <td>0:00:05.250957</td>\n",
       "      <td>Success</td>\n",
       "      <td>FLOWIN</td>\n",
       "      <td>013167A3-3ECE-4852-8541-E9E9ED483A90</td>\n",
       "      <td>StoredSignal</td>\n",
       "      <td>FLOWIN(USgal/min)</td>\n",
       "      <td>USgal/min</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>FLOWOUTPC(%)</th>\n",
       "      <td>11485.0</td>\n",
       "      <td>0:00:05.906205</td>\n",
       "      <td>Success</td>\n",
       "      <td>FLOWOUTPC</td>\n",
       "      <td>89A1F851-2965-4909-B2C2-A4263F75BB50</td>\n",
       "      <td>StoredSignal</td>\n",
       "      <td>FLOWOUTPC(%)</td>\n",
       "      <td>%</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ROP_AVG(ft/h)</th>\n",
       "      <td>11485.0</td>\n",
       "      <td>0:00:04.949735</td>\n",
       "      <td>Success</td>\n",
       "      <td>ROP_AVG</td>\n",
       "      <td>E7AC16B0-9534-450F-8CD6-DF3ABC530434</td>\n",
       "      <td>StoredSignal</td>\n",
       "      <td>ROP_AVG(ft/h)</td>\n",
       "      <td>ft/h</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>DIFP(psi)</th>\n",
       "      <td>11485.0</td>\n",
       "      <td>0:00:04.331416</td>\n",
       "      <td>Success</td>\n",
       "      <td>DIFP</td>\n",
       "      <td>E64ECBFF-D5E0-4306-BCF2-AB33740C5D45</td>\n",
       "      <td>StoredSignal</td>\n",
       "      <td>DIFP(psi)</td>\n",
       "      <td>psi</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   Push Count       Push Time Push Result       Name  \\\n",
       "BITDEP(ft)            11485.0  0:00:06.429804     Success     BITDEP   \n",
       "BLOCKCOMP(ft)         11485.0  0:00:05.086397     Success  BLOCKCOMP   \n",
       "DEP_RTN(ft)           11485.0  0:00:04.731346     Success    DEP_RTN   \n",
       "DEPTH(ft)             11485.0  0:00:05.899195     Success      DEPTH   \n",
       "FLOWIN(USgal/min)     11485.0  0:00:05.250957     Success     FLOWIN   \n",
       "FLOWOUTPC(%)          11485.0  0:00:05.906205     Success  FLOWOUTPC   \n",
       "ROP_AVG(ft/h)         11485.0  0:00:04.949735     Success    ROP_AVG   \n",
       "DIFP(psi)             11485.0  0:00:04.331416     Success       DIFP   \n",
       "\n",
       "                                                     ID          Type  \\\n",
       "BITDEP(ft)         A2EE83F9-3881-4458-8A65-DCAA7897B636  StoredSignal   \n",
       "BLOCKCOMP(ft)      56DB9BE5-4A33-4847-BA94-97C8BFB2C5CB  StoredSignal   \n",
       "DEP_RTN(ft)        0FC7EAAF-C3E7-480F-8DE9-B0C7371BB2DB  StoredSignal   \n",
       "DEPTH(ft)          1C6250DA-0A1C-46F0-A6C6-0F9D2693DF1A  StoredSignal   \n",
       "FLOWIN(USgal/min)  013167A3-3ECE-4852-8541-E9E9ED483A90  StoredSignal   \n",
       "FLOWOUTPC(%)       89A1F851-2965-4909-B2C2-A4263F75BB50  StoredSignal   \n",
       "ROP_AVG(ft/h)      E7AC16B0-9534-450F-8CD6-DF3ABC530434  StoredSignal   \n",
       "DIFP(psi)          E64ECBFF-D5E0-4306-BCF2-AB33740C5D45  StoredSignal   \n",
       "\n",
       "                       Original Name Value Unit Of Measure  \n",
       "BITDEP(ft)                BITDEP(ft)                    ft  \n",
       "BLOCKCOMP(ft)          BLOCKCOMP(ft)                    ft  \n",
       "DEP_RTN(ft)              DEP_RTN(ft)                    ft  \n",
       "DEPTH(ft)                  DEPTH(ft)                    ft  \n",
       "FLOWIN(USgal/min)  FLOWIN(USgal/min)             USgal/min  \n",
       "FLOWOUTPC(%)            FLOWOUTPC(%)                     %  \n",
       "ROP_AVG(ft/h)          ROP_AVG(ft/h)                  ft/h  \n",
       "DIFP(psi)                  DIFP(psi)                   psi  "
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "better_metadata = push_results.copy()\n",
    "better_metadata['Original Name'] = better_metadata.index\n",
    "better_metadata['Name'] = better_metadata['Original Name'].str.extract(r'(.*)\\(')\n",
    "better_metadata['Value Unit Of Measure'] = better_metadata['Original Name'].str.extract(r'.*\\((.*)\\)')\n",
    "better_metadata"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"background-color: #EEFFEE;text-align: left;\">Pushed successfully to datasource <strong>Seeq Data Lab [Datasource ID: Seeq Data Lab]</strong> and scoped to workbook ID <strong>DD7F6F24-283C-4138-9195-F1077E4A3FFE</strong><br>Click the following link to see what you pushed in Seeq:<br><a href=\"http://localhost:34216/E75C3137-38F2-4E50-B872-CC897D7100F3/workbook/DD7F6F24-283C-4138-9195-F1077E4A3FFE/worksheet/06D22E34-1429-4539-868C-0F33DBC56542\" target=\"_new\">http://localhost:34216/E75C3137-38F2-4E50-B872-CC897D7100F3/workbook/DD7F6F24-283C-4138-9195-F1077E4A3FFE/worksheet/06D22E34-1429-4539-868C-0F33DBC56542</a></div><table><tr><td style=\"background-color: #EEFFEE;\"></td><td style=\"background-color: #EEFFEE;\">Asset</td><td style=\"background-color: #EEFFEE;\">Condition</td><td style=\"background-color: #EEFFEE;\">Overall</td><td style=\"background-color: #EEFFEE;\">Relationship</td><td style=\"background-color: #EEFFEE;\">Scalar</td><td style=\"background-color: #EEFFEE;\">Signal</td><td style=\"background-color: #EEFFEE;\">Threshold Metric</td></tr><tr style=\"background-color: #EEFFEE;\"><td>Items pushed</td><td>0</td><td>0</td><td>8</td><td>0</td><td>0</td><td>8</td><td>0</td></tr></table>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Push Count</th>\n",
       "      <th>Push Time</th>\n",
       "      <th>Name</th>\n",
       "      <th>ID</th>\n",
       "      <th>Type</th>\n",
       "      <th>Original Name</th>\n",
       "      <th>Value Unit Of Measure</th>\n",
       "      <th>Push Result</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>BITDEP(ft)</th>\n",
       "      <td>11485.0</td>\n",
       "      <td>0:00:06.429804</td>\n",
       "      <td>BITDEP</td>\n",
       "      <td>A2EE83F9-3881-4458-8A65-DCAA7897B636</td>\n",
       "      <td>StoredSignal</td>\n",
       "      <td>BITDEP(ft)</td>\n",
       "      <td>ft</td>\n",
       "      <td>Success</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>BLOCKCOMP(ft)</th>\n",
       "      <td>11485.0</td>\n",
       "      <td>0:00:05.086397</td>\n",
       "      <td>BLOCKCOMP</td>\n",
       "      <td>56DB9BE5-4A33-4847-BA94-97C8BFB2C5CB</td>\n",
       "      <td>StoredSignal</td>\n",
       "      <td>BLOCKCOMP(ft)</td>\n",
       "      <td>ft</td>\n",
       "      <td>Success</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>DEP_RTN(ft)</th>\n",
       "      <td>11485.0</td>\n",
       "      <td>0:00:04.731346</td>\n",
       "      <td>DEP_RTN</td>\n",
       "      <td>0FC7EAAF-C3E7-480F-8DE9-B0C7371BB2DB</td>\n",
       "      <td>StoredSignal</td>\n",
       "      <td>DEP_RTN(ft)</td>\n",
       "      <td>ft</td>\n",
       "      <td>Success</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>DEPTH(ft)</th>\n",
       "      <td>11485.0</td>\n",
       "      <td>0:00:05.899195</td>\n",
       "      <td>DEPTH</td>\n",
       "      <td>1C6250DA-0A1C-46F0-A6C6-0F9D2693DF1A</td>\n",
       "      <td>StoredSignal</td>\n",
       "      <td>DEPTH(ft)</td>\n",
       "      <td>ft</td>\n",
       "      <td>Success</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>FLOWIN(USgal/min)</th>\n",
       "      <td>11485.0</td>\n",
       "      <td>0:00:05.250957</td>\n",
       "      <td>FLOWIN</td>\n",
       "      <td>013167A3-3ECE-4852-8541-E9E9ED483A90</td>\n",
       "      <td>StoredSignal</td>\n",
       "      <td>FLOWIN(USgal/min)</td>\n",
       "      <td>USgal/min</td>\n",
       "      <td>Success</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>FLOWOUTPC(%)</th>\n",
       "      <td>11485.0</td>\n",
       "      <td>0:00:05.906205</td>\n",
       "      <td>FLOWOUTPC</td>\n",
       "      <td>89A1F851-2965-4909-B2C2-A4263F75BB50</td>\n",
       "      <td>StoredSignal</td>\n",
       "      <td>FLOWOUTPC(%)</td>\n",
       "      <td>%</td>\n",
       "      <td>Success</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ROP_AVG(ft/h)</th>\n",
       "      <td>11485.0</td>\n",
       "      <td>0:00:04.949735</td>\n",
       "      <td>ROP_AVG</td>\n",
       "      <td>E7AC16B0-9534-450F-8CD6-DF3ABC530434</td>\n",
       "      <td>StoredSignal</td>\n",
       "      <td>ROP_AVG(ft/h)</td>\n",
       "      <td>ft/h</td>\n",
       "      <td>Success</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>DIFP(psi)</th>\n",
       "      <td>11485.0</td>\n",
       "      <td>0:00:04.331416</td>\n",
       "      <td>DIFP</td>\n",
       "      <td>E64ECBFF-D5E0-4306-BCF2-AB33740C5D45</td>\n",
       "      <td>StoredSignal</td>\n",
       "      <td>DIFP(psi)</td>\n",
       "      <td>psi</td>\n",
       "      <td>Success</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   Push Count       Push Time       Name  \\\n",
       "BITDEP(ft)            11485.0  0:00:06.429804     BITDEP   \n",
       "BLOCKCOMP(ft)         11485.0  0:00:05.086397  BLOCKCOMP   \n",
       "DEP_RTN(ft)           11485.0  0:00:04.731346    DEP_RTN   \n",
       "DEPTH(ft)             11485.0  0:00:05.899195      DEPTH   \n",
       "FLOWIN(USgal/min)     11485.0  0:00:05.250957     FLOWIN   \n",
       "FLOWOUTPC(%)          11485.0  0:00:05.906205  FLOWOUTPC   \n",
       "ROP_AVG(ft/h)         11485.0  0:00:04.949735    ROP_AVG   \n",
       "DIFP(psi)             11485.0  0:00:04.331416       DIFP   \n",
       "\n",
       "                                                     ID          Type  \\\n",
       "BITDEP(ft)         A2EE83F9-3881-4458-8A65-DCAA7897B636  StoredSignal   \n",
       "BLOCKCOMP(ft)      56DB9BE5-4A33-4847-BA94-97C8BFB2C5CB  StoredSignal   \n",
       "DEP_RTN(ft)        0FC7EAAF-C3E7-480F-8DE9-B0C7371BB2DB  StoredSignal   \n",
       "DEPTH(ft)          1C6250DA-0A1C-46F0-A6C6-0F9D2693DF1A  StoredSignal   \n",
       "FLOWIN(USgal/min)  013167A3-3ECE-4852-8541-E9E9ED483A90  StoredSignal   \n",
       "FLOWOUTPC(%)       89A1F851-2965-4909-B2C2-A4263F75BB50  StoredSignal   \n",
       "ROP_AVG(ft/h)      E7AC16B0-9534-450F-8CD6-DF3ABC530434  StoredSignal   \n",
       "DIFP(psi)          E64ECBFF-D5E0-4306-BCF2-AB33740C5D45  StoredSignal   \n",
       "\n",
       "                       Original Name Value Unit Of Measure Push Result  \n",
       "BITDEP(ft)                BITDEP(ft)                    ft     Success  \n",
       "BLOCKCOMP(ft)          BLOCKCOMP(ft)                    ft     Success  \n",
       "DEP_RTN(ft)              DEP_RTN(ft)                    ft     Success  \n",
       "DEPTH(ft)                  DEPTH(ft)                    ft     Success  \n",
       "FLOWIN(USgal/min)  FLOWIN(USgal/min)             USgal/min     Success  \n",
       "FLOWOUTPC(%)            FLOWOUTPC(%)                     %     Success  \n",
       "ROP_AVG(ft/h)          ROP_AVG(ft/h)                  ft/h     Success  \n",
       "DIFP(psi)                  DIFP(psi)                   psi     Success  "
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "spy.push(metadata=better_metadata)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Pushing condition and capsule data"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "You can also push capsules, which are time intervals of interest, to Seeq by supplying a DataFrame with `Capsule Start` and `Capsule End` columns. Any additional columns will be added as properties of the capsule."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Capsule End</th>\n",
       "      <th>Capsule Start</th>\n",
       "      <th>Operator On Duty</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2019-01-10 17:00:00+00:00</td>\n",
       "      <td>2019-01-10 09:00:00+00:00</td>\n",
       "      <td>Mark</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2019-01-11 17:00:00+00:00</td>\n",
       "      <td>2019-01-11 09:00:00+00:00</td>\n",
       "      <td>Hedwig</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                Capsule End             Capsule Start Operator On Duty\n",
       "0 2019-01-10 17:00:00+00:00 2019-01-10 09:00:00+00:00             Mark\n",
       "1 2019-01-11 17:00:00+00:00 2019-01-11 09:00:00+00:00           Hedwig"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "capsule_data = pd.DataFrame([{\n",
    "    'Capsule Start':    pd.to_datetime('2019-01-10T09:00:00.000Z'),\n",
    "    'Capsule End':      pd.to_datetime('2019-01-10T17:00:00.000Z'),\n",
    "    'Operator On Duty': 'Mark'\n",
    "}, {\n",
    "    'Capsule Start':    pd.to_datetime('2019-01-11T09:00:00.000Z'),\n",
    "    'Capsule End':      pd.to_datetime('2019-01-11T17:00:00.000Z'),\n",
    "    'Operator On Duty': 'Hedwig'\n",
    "}])\n",
    "\n",
    "capsule_data"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "When you push capsule data, you must supply a `metadata` DataFrame that is exactly 1 row and contains, at minimum, the `Name`, `Type` and `Maximum Duration` columns like so:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"background-color: #EEFFEE;text-align: left;\">Pushed successfully to datasource <strong>Seeq Data Lab [Datasource ID: Seeq Data Lab]</strong> and scoped to workbook ID <strong>DD7F6F24-283C-4138-9195-F1077E4A3FFE</strong><br>Click the following link to see what you pushed in Seeq:<br><a href=\"http://localhost:34216/E75C3137-38F2-4E50-B872-CC897D7100F3/workbook/DD7F6F24-283C-4138-9195-F1077E4A3FFE/worksheet/06D22E34-1429-4539-868C-0F33DBC56542\" target=\"_new\">http://localhost:34216/E75C3137-38F2-4E50-B872-CC897D7100F3/workbook/DD7F6F24-283C-4138-9195-F1077E4A3FFE/worksheet/06D22E34-1429-4539-868C-0F33DBC56542</a></div><table><tr><td style=\"background-color: #EEFFEE;\"></td><td style=\"background-color: #EEFFEE;\">ID</td><td style=\"background-color: #EEFFEE;\">Name</td><td style=\"background-color: #EEFFEE;\">Count</td><td style=\"background-color: #EEFFEE;\">Time</td><td style=\"background-color: #EEFFEE;\">Result</td></tr><tr style=\"background-color: #EEFFEE;\"><td>0</td><td>4C0A0639-677F-499D-BCB1-62815A0AB426</td><td>Operator Shifts</td><td>2</td><td>00:00:00.07</td><td>Success</td></tr></table>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Maximum Duration</th>\n",
       "      <th>Name</th>\n",
       "      <th>Type</th>\n",
       "      <th>Datasource Class</th>\n",
       "      <th>Datasource ID</th>\n",
       "      <th>Data ID</th>\n",
       "      <th>ID</th>\n",
       "      <th>Push Result</th>\n",
       "      <th>Push Count</th>\n",
       "      <th>Push Time</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2d</td>\n",
       "      <td>Operator Shifts</td>\n",
       "      <td>StoredCondition</td>\n",
       "      <td>Seeq Data Lab</td>\n",
       "      <td>Seeq Data Lab</td>\n",
       "      <td>[DD7F6F24-283C-4138-9195-F1077E4A3FFE] {Condit...</td>\n",
       "      <td>4C0A0639-677F-499D-BCB1-62815A0AB426</td>\n",
       "      <td>Success</td>\n",
       "      <td>2</td>\n",
       "      <td>0:00:00.065824</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  Maximum Duration             Name             Type Datasource Class  \\\n",
       "0               2d  Operator Shifts  StoredCondition    Seeq Data Lab   \n",
       "\n",
       "   Datasource ID                                            Data ID  \\\n",
       "0  Seeq Data Lab  [DD7F6F24-283C-4138-9195-F1077E4A3FFE] {Condit...   \n",
       "\n",
       "                                     ID Push Result  Push Count  \\\n",
       "0  4C0A0639-677F-499D-BCB1-62815A0AB426     Success           2   \n",
       "\n",
       "        Push Time  \n",
       "0  0:00:00.065824  "
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "spy.push(data=capsule_data,\n",
    "         metadata=pd.DataFrame([{\n",
    "             'Name': 'Operator Shifts',\n",
    "             'Type': 'Condition',\n",
    "             'Maximum Duration': '2d'\n",
    "         }]))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "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.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
