diff --git a/SAS/TMSS/scripts/notebooks/project_report_poc.ipynb b/SAS/TMSS/scripts/notebooks/project_report_poc.ipynb index 9baf1d5ba803799da36b146cd76a52f6694ba906..96efdfd902d2f678053acafdb3424118dc10f002 100644 --- a/SAS/TMSS/scripts/notebooks/project_report_poc.ipynb +++ b/SAS/TMSS/scripts/notebooks/project_report_poc.ipynb @@ -7,7 +7,11 @@ "source": [ "# Project Report PoC - TMSS\n", "\n", - "This document shows how to generate a report for a project." + "This notebook shows how to generate a report for a project.\n", + "\n", + "The data is retrieved through the *TMSS APIs* and it is analysed and visualised using the *Pandas* library.\n", + "\n", + "---" ] }, { @@ -17,13 +21,23 @@ "source": [ "### Prerequirements\n", "\n", - "The following modules are needed before proceeding:" + "Before proceeding you need to import some modules, as well as specify some configurations." + ] + }, + { + "cell_type": "markdown", + "id": "e36852c6", + "metadata": {}, + "source": [ + "#### Imports\n", + "\n", + "The Pandas and Requests libraries are required." ] }, { "cell_type": "code", "execution_count": 1, - "id": "48b766e7", + "id": "ae6bff14", "metadata": {}, "outputs": [], "source": [ @@ -31,6 +45,35 @@ "import requests" ] }, + { + "cell_type": "markdown", + "id": "6ada730f", + "metadata": {}, + "source": [ + "#### Configs\n", + "\n", + "Your authentication credentials are needed to perform HTTP requests to the TMSS APIs." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "48b766e7", + "metadata": {}, + "outputs": [], + "source": [ + "BASE_URL = 'http://localhost:8000/api' # TMSS API endpoint\n", + "auth = ('test', 'test') # username and password" + ] + }, + { + "cell_type": "markdown", + "id": "340c050b", + "metadata": {}, + "source": [ + "---" + ] + }, { "cell_type": "markdown", "id": "9812780a", @@ -40,7 +83,7 @@ "\n", "To retrieve the data, you need to perform a GET request to the following endpoint: `http://127.0.0.1:8000/api/project/<project>/report`\n", "\n", - "This can be done by using the `requests` module. You need to provide your authentication credentials in the `auth` parameter. Since the response will be a JSON object, you can simply store the result of `response.json()` as follows:" + "This can be done by using the `requests` module. To perform the request, you need to provide your target project, by specifying its *id* in the `project` variable, and to pass your authentication credentials in the `auth` parameter. Since the response will be a JSON object, you can simply store the result of `response.json()` in the `result` variable." ] }, { @@ -76,18 +119,17 @@ } ], "source": [ - "BASE_URL = 'http://localhost:8000/api'\n", - "project = 'test_for_report' # project id\n", - "credentials = ('test', 'test') # username, password\n", + "project = 'high' # Specify your target project\n", "\n", - "response = requests.get(BASE_URL + '/project/%s/report' % project, auth=credentials)\n", + "# Retrieve the data related to project\n", + "response = requests.get(BASE_URL + '/project/%s/report' % project, auth=auth)\n", "result = response.json()\n", "result" ] }, { "cell_type": "code", - "execution_count": 134, + "execution_count": 3, "id": "3276ce6d", "metadata": {}, "outputs": [], @@ -162,14 +204,14 @@ "id": "1721b2bc", "metadata": {}, "source": [ - "## Manage the data\n", + "### Manage the data\n", "\n", - "Once you have retrieved the data, you need to apply some preprocessing. In the following snippet, we extract the data into variables that will be used afterwards." + "Once you have retrieved the data, you need to extract it in a proper way. In the following snippet, we do such operation by defining some variables that will be used afterwards." ] }, { "cell_type": "code", - "execution_count": 135, + "execution_count": 4, "id": "d1b58c3a", "metadata": {}, "outputs": [], @@ -188,7 +230,17 @@ "id": "883d53a9", "metadata": {}, "source": [ - "You can now use Pandas for the data analysis and visualisation parts." + "You can now use a library (i.e., Pandas) for the data analysis and visualisation parts.\n", + "\n", + "---" + ] + }, + { + "cell_type": "markdown", + "id": "d2e62c29", + "metadata": {}, + "source": [ + "## Create tables\n" ] }, { @@ -196,14 +248,14 @@ "id": "c9b7d51e", "metadata": {}, "source": [ - "## Create a report\n", + "### Summary Table\n", "\n", "You can create a unique table within all the data related to a project. It might be convenient to create a different `DataFrame` for each variable of the previous step, as they could be used for subsequent analysis later." ] }, { "cell_type": "code", - "execution_count": 136, + "execution_count": 5, "id": "8a0a7ed9", "metadata": { "scrolled": true @@ -213,22 +265,22 @@ "data": { "text/html": [ "<style type=\"text/css\" >\n", - "</style><table id=\"T_8b9a6fac_9d01_11eb_9243_000c299c9be6\" ><caption>Summary Table</caption><thead> <tr> <th class=\"blank level0\" ></th> <th class=\"col_heading level0 col0\" >total</th> <th class=\"col_heading level0 col1\" >total_succeeded</th> <th class=\"col_heading level0 col2\" >total_not_cancelled</th> <th class=\"col_heading level0 col3\" >total_failed</th> <th class=\"col_heading level0 col4\" >size__sum</th> </tr></thead><tbody>\n", + "</style><table id=\"T_b5d46e6c_9d24_11eb_bb28_000c299c9be6\" ><caption>Summary Table</caption><thead> <tr> <th class=\"blank level0\" ></th> <th class=\"col_heading level0 col0\" >total</th> <th class=\"col_heading level0 col1\" >total_succeeded</th> <th class=\"col_heading level0 col2\" >total_not_cancelled</th> <th class=\"col_heading level0 col3\" >total_failed</th> <th class=\"col_heading level0 col4\" >size__sum</th> </tr></thead><tbody>\n", " <tr>\n", - " <th id=\"T_8b9a6fac_9d01_11eb_9243_000c299c9be6level0_row0\" class=\"row_heading level0 row0\" >test_for_report</th>\n", - " <td id=\"T_8b9a6fac_9d01_11eb_9243_000c299c9be6row0_col0\" class=\"data row0 col0\" >2800.000012</td>\n", - " <td id=\"T_8b9a6fac_9d01_11eb_9243_000c299c9be6row0_col1\" class=\"data row0 col1\" >1400.000006</td>\n", - " <td id=\"T_8b9a6fac_9d01_11eb_9243_000c299c9be6row0_col2\" class=\"data row0 col2\" >1400.000006</td>\n", - " <td id=\"T_8b9a6fac_9d01_11eb_9243_000c299c9be6row0_col3\" class=\"data row0 col3\" >800.000006</td>\n", - " <td id=\"T_8b9a6fac_9d01_11eb_9243_000c299c9be6row0_col4\" class=\"data row0 col4\" >246</td>\n", + " <th id=\"T_b5d46e6c_9d24_11eb_bb28_000c299c9be6level0_row0\" class=\"row_heading level0 row0\" >test_for_report</th>\n", + " <td id=\"T_b5d46e6c_9d24_11eb_bb28_000c299c9be6row0_col0\" class=\"data row0 col0\" >2800.000012</td>\n", + " <td id=\"T_b5d46e6c_9d24_11eb_bb28_000c299c9be6row0_col1\" class=\"data row0 col1\" >1400.000006</td>\n", + " <td id=\"T_b5d46e6c_9d24_11eb_bb28_000c299c9be6row0_col2\" class=\"data row0 col2\" >1400.000006</td>\n", + " <td id=\"T_b5d46e6c_9d24_11eb_bb28_000c299c9be6row0_col3\" class=\"data row0 col3\" >800.000006</td>\n", + " <td id=\"T_b5d46e6c_9d24_11eb_bb28_000c299c9be6row0_col4\" class=\"data row0 col4\" >246</td>\n", " </tr>\n", " </tbody></table>" ], "text/plain": [ - "<pandas.io.formats.style.Styler at 0x7f4c158faa90>" + "<pandas.io.formats.style.Styler at 0x7f6bb40e6f28>" ] }, - "execution_count": 136, + "execution_count": 5, "metadata": {}, "output_type": "execute_result" } @@ -245,16 +297,24 @@ }, { "cell_type": "markdown", - "id": "8f9b1da2", + "id": "ddfa7824", "metadata": {}, "source": [ - "For the other values, you can follow a similar procedure:" + "Note that for the other values, you can follow a similar procedure as illustrated by the following sections." + ] + }, + { + "cell_type": "markdown", + "id": "c2f231ba", + "metadata": {}, + "source": [ + "### Quota table\n" ] }, { "cell_type": "code", - "execution_count": 257, - "id": "aec5ebb1", + "execution_count": 6, + "id": "1b94ce76", "metadata": {}, "outputs": [ { @@ -309,20 +369,37 @@ "11 LTA Storage 2400.0" ] }, - "execution_count": 257, + "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ + "# Create a DataFrame for quota\n", "df_quota = pd.DataFrame(quota)\n", "df_quota.set_index('id')" ] }, + { + "cell_type": "markdown", + "id": "47f4503c", + "metadata": {}, + "source": [ + "### SchedulingUnitBlueprints\n" + ] + }, + { + "cell_type": "markdown", + "id": "93b336e7", + "metadata": {}, + "source": [ + "#### Finished SUBs\n" + ] + }, { "cell_type": "code", - "execution_count": 138, - "id": "a2621ab9", + "execution_count": 7, + "id": "10537659", "metadata": {}, "outputs": [ { @@ -346,52 +423,60 @@ " <thead>\n", " <tr style=\"text-align: right;\">\n", " <th></th>\n", - " <th>total_exposure</th>\n", + " <th>name</th>\n", + " <th>duration</th>\n", " </tr>\n", " <tr>\n", - " <th>sap_name</th>\n", + " <th>id</th>\n", + " <th></th>\n", " <th></th>\n", " </tr>\n", " </thead>\n", " <tbody>\n", " <tr>\n", - " <th>sap_1</th>\n", - " <td>340.0</td>\n", - " </tr>\n", - " <tr>\n", - " <th>sap_2</th>\n", - " <td>195.0</td>\n", + " <th>8</th>\n", + " <td>amazing_sub</td>\n", + " <td>600.000003</td>\n", " </tr>\n", " <tr>\n", - " <th>sap_3</th>\n", - " <td>235.0</td>\n", + " <th>21</th>\n", + " <td>another_amazing_sub</td>\n", + " <td>800.000003</td>\n", " </tr>\n", " </tbody>\n", "</table>\n", "</div>" ], "text/plain": [ - " total_exposure\n", - "sap_name \n", - "sap_1 340.0\n", - "sap_2 195.0\n", - "sap_3 235.0" + " name duration\n", + "id \n", + "8 amazing_sub 600.000003\n", + "21 another_amazing_sub 800.000003" ] }, - "execution_count": 138, + "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "df_saps = pd.DataFrame(saps)\n", - "df_saps.set_index('sap_name')" + "# Create a DataFrame for finished SUBs\n", + "df_subs_finished = pd.DataFrame(subs_finished)\n", + "df_subs_finished.set_index('id')" + ] + }, + { + "cell_type": "markdown", + "id": "c67ef360", + "metadata": {}, + "source": [ + "#### Failed SUBs\n" ] }, { "cell_type": "code", - "execution_count": 139, - "id": "192cea33", + "execution_count": 8, + "id": "6487f39e", "metadata": {}, "outputs": [ { @@ -426,40 +511,49 @@ " </thead>\n", " <tbody>\n", " <tr>\n", - " <th>8</th>\n", - " <td>amazing_sub</td>\n", + " <th>12</th>\n", + " <td>horrible_sub</td>\n", " <td>600.000003</td>\n", " </tr>\n", " <tr>\n", - " <th>21</th>\n", - " <td>another_amazing_sub</td>\n", - " <td>800.000003</td>\n", + " <th>36</th>\n", + " <td>another_horrible_sub</td>\n", + " <td>200.000003</td>\n", " </tr>\n", " </tbody>\n", "</table>\n", "</div>" ], "text/plain": [ - " name duration\n", - "id \n", - "8 amazing_sub 600.000003\n", - "21 another_amazing_sub 800.000003" + " name duration\n", + "id \n", + "12 horrible_sub 600.000003\n", + "36 another_horrible_sub 200.000003" ] }, - "execution_count": 139, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "df_subs_finished = pd.DataFrame(subs_finished)\n", - "df_subs_finished.set_index('id')" + "# Create a DataFrame for failed SUBs\n", + "df_subs_failed = pd.DataFrame(subs_failed)\n", + "df_subs_failed.set_index('id')" + ] + }, + { + "cell_type": "markdown", + "id": "265697ce", + "metadata": {}, + "source": [ + "### SAPs\n" ] }, { "cell_type": "code", - "execution_count": 140, - "id": "02d2a788", + "execution_count": 9, + "id": "669389c5", "metadata": {}, "outputs": [ { @@ -483,45 +577,55 @@ " <thead>\n", " <tr style=\"text-align: right;\">\n", " <th></th>\n", - " <th>name</th>\n", - " <th>duration</th>\n", + " <th>total_exposure</th>\n", " </tr>\n", " <tr>\n", - " <th>id</th>\n", - " <th></th>\n", + " <th>sap_name</th>\n", " <th></th>\n", " </tr>\n", " </thead>\n", " <tbody>\n", " <tr>\n", - " <th>12</th>\n", - " <td>horrible_sub</td>\n", - " <td>600.000003</td>\n", + " <th>sap_1</th>\n", + " <td>340.0</td>\n", " </tr>\n", " <tr>\n", - " <th>36</th>\n", - " <td>another_horrible_sub</td>\n", - " <td>200.000003</td>\n", + " <th>sap_2</th>\n", + " <td>195.0</td>\n", + " </tr>\n", + " <tr>\n", + " <th>sap_3</th>\n", + " <td>235.0</td>\n", " </tr>\n", " </tbody>\n", "</table>\n", "</div>" ], "text/plain": [ - " name duration\n", - "id \n", - "12 horrible_sub 600.000003\n", - "36 another_horrible_sub 200.000003" + " total_exposure\n", + "sap_name \n", + "sap_1 340.0\n", + "sap_2 195.0\n", + "sap_3 235.0" ] }, - "execution_count": 140, + "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "df_subs_failed = pd.DataFrame(subs_failed)\n", - "df_subs_failed.set_index('id')" + "# Create a DataFrame for SAPs\n", + "df_saps = pd.DataFrame(saps)\n", + "df_saps.set_index('sap_name')" + ] + }, + { + "cell_type": "markdown", + "id": "193c3998", + "metadata": {}, + "source": [ + "---" ] }, { @@ -529,23 +633,23 @@ "id": "b7a4b0b9", "metadata": {}, "source": [ - "### Create a plot\n", + "## Create a plot\n", "\n", "To better visualise the data, you could plot it in several ways. For example, you might want to observe the differences between all of the four durations retrieved, as follows:" ] }, { "cell_type": "markdown", - "id": "3425a1bd", + "id": "b5a0d68a", "metadata": {}, "source": [ - "#### Quota\n" + "### Quota\n" ] }, { "cell_type": "code", - "execution_count": 141, - "id": "c14dacaa", + "execution_count": 10, + "id": "8b6ad3ba", "metadata": {}, "outputs": [ { @@ -562,21 +666,21 @@ } ], "source": [ - "# Plot a horizontal bar graph\n", + "# Plot a bar graph\n", "ax_quota = df_quota.plot.bar(title='Quota', x='id', color=['#58a5f0'])" ] }, { "cell_type": "markdown", - "id": "cffa43f9", + "id": "619ec2aa", "metadata": {}, "source": [ - "#### Durations\n" + "### Durations\n" ] }, { "cell_type": "code", - "execution_count": 142, + "execution_count": 11, "id": "da3340db", "metadata": {}, "outputs": [ @@ -602,18 +706,26 @@ }, { "cell_type": "markdown", - "id": "f7eb2288", + "id": "982e28e7", "metadata": {}, "source": [ - "#### Scheduling Unit Blueprints\n", + "### Scheduling Unit Blueprints\n", "\n", "You can plot either the finished or the failed SUBs. In addiction, you can also plot a unified bar graph. Here all of the three options are shown." ] }, + { + "cell_type": "markdown", + "id": "07b8933f", + "metadata": {}, + "source": [ + "#### Finished SUBs" + ] + }, { "cell_type": "code", - "execution_count": 250, - "id": "c84e2c5e", + "execution_count": 12, + "id": "4835b891", "metadata": {}, "outputs": [ { @@ -630,17 +742,23 @@ } ], "source": [ - "# Plot a horizontal bar graph\n", + "# Plot a bar graph\n", "ax_subs_finished = df_subs_finished.plot.bar(title='Finished SUBs', x='id', color='#60ad5e')" ] }, + { + "cell_type": "markdown", + "id": "e385353c", + "metadata": {}, + "source": [ + "#### Failed SUBs" + ] + }, { "cell_type": "code", - "execution_count": 249, - "id": "2ae02964", - "metadata": { - "collapsed": true - }, + "execution_count": 13, + "id": "18074170", + "metadata": {}, "outputs": [ { "data": { @@ -656,24 +774,24 @@ } ], "source": [ - "# Plot a horizontal bar graph\n", + "# Plot a bar graph\n", "ax_subs_failed = df_subs_failed.plot.bar(title='Failed SUBs', x='id', color='#ff5f52')" ] }, { "cell_type": "markdown", - "id": "340f067d", + "id": "51e4faea", "metadata": {}, "source": [ - "##### SUBs Summary\n", + "#### SUBs Summary\n", "\n", "To summarise both finished and failed SchedulingUnitBlueprints, you can concatenate the prior DataFrames as well as adding a new column to distinguish them in the new DataFrame:" ] }, { "cell_type": "code", - "execution_count": 254, - "id": "a2e8f9cb", + "execution_count": 14, + "id": "d709f04e", "metadata": {}, "outputs": [ { @@ -746,7 +864,7 @@ "36 another_horrible_sub 200.000003 failed" ] }, - "execution_count": 254, + "execution_count": 14, "metadata": {}, "output_type": "execute_result" } @@ -762,7 +880,7 @@ }, { "cell_type": "markdown", - "id": "3be9b79e", + "id": "b7e56fc8", "metadata": {}, "source": [ "Then, you can plot a bar graph discriminting colors by status:" @@ -770,8 +888,8 @@ }, { "cell_type": "code", - "execution_count": 253, - "id": "117d845e", + "execution_count": 15, + "id": "0ed4233a", "metadata": {}, "outputs": [ { @@ -796,7 +914,7 @@ }, { "cell_type": "markdown", - "id": "f5be0a1d", + "id": "a2682239", "metadata": {}, "source": [ "#### SAPs" @@ -804,7 +922,7 @@ }, { "cell_type": "code", - "execution_count": 256, + "execution_count": 16, "id": "b323083e", "metadata": {}, "outputs": [ @@ -822,14 +940,22 @@ } ], "source": [ - "# Plot a horizontal bar graph\n", + "# Plot a bar graph\n", "ax_saps = df_saps.plot.bar(title='SAPs', x='sap_name', color=['#ffd95a'])" ] }, + { + "cell_type": "markdown", + "id": "9cc1a590", + "metadata": {}, + "source": [ + "---" + ] + }, { "cell_type": "code", "execution_count": null, - "id": "91042123", + "id": "a5d9b0db", "metadata": {}, "outputs": [], "source": []