diff --git a/project/ui/qprof-ui.ipynb b/project/ui/qprof-ui.ipynb index 974ef31e..1dd8444b 100644 --- a/project/ui/qprof-ui.ipynb +++ b/project/ui/qprof-ui.ipynb @@ -8,27 +8,32 @@ "outputs": [], "source": [ "import ipywidgets as widgets\n", - "from IPython.display import display, HTML\n", + "from IPython.display import display, HTML, clear_output\n", "\n", "# Define the URLs for the links\n", "url1 = \"/lab/\"\n", "url2 = \"/voila/render/ui/conn.ipynb\"\n", + "url3 = \"/voila/render/ui/qprof_main.ipynb\"\n", "\n", "# Define the button labels\n", "button_label1 = \"Go to Home Page\"\n", "button_label2 = \"Go to Connection\"\n", + "button_label3 = \"Go Back\"\n", "\n", "# Define HTML links for buttons\n", "button_html1 = f\"\"\n", "button_html2 = f\"{button_label2}\"\n", + "button_html3 = f\"\"\n", "\n", "\n", "# Create HTML widgets\n", "html_button1 = widgets.HTML(value=button_html1)\n", "html_button2 = widgets.HTML(value=button_html2)\n", + "html_button3 = widgets.HTML(value=button_html3)\n", + "\n", "\n", "# Display buttons\n", - "display(widgets.HBox([html_button1, html_button2]))\n" + "display(widgets.HBox([html_button3, html_button1, html_button2]))\n" ] }, { @@ -192,34 +197,30 @@ "metadata": {}, "outputs": [], "source": [ - "button_qprof_save = widgets.Button(description=\"Save Query Plan\", layout=widgets.Layout(width='150px'))\n", + "button_qprof_save = widgets.Button(description=\"Save Qprof Information & Report\", layout=widgets.Layout(width='250px'))\n", "output_export = widgets.Output()\n", "\n", "def click_export_query(_):\n", " output_export.clear_output(wait=True)\n", " with output_export:\n", " print(\"Saving Query. It may take a while...\")\n", - " qprof.export_profile(filename=\"qprof.tar\")\n", - " print(\"Ready to Download\")\n", - " display(download_output)\n", - " display(btn)\n", - " \n", - "\n", - "button_qprof_save.on_click(click_export_query)\n", + " try:\n", + " logging.info('[Query Profile Tree Page] Trying to export qprof object to a \"qprof.tar\" file')\n", + " qprof.export_profile(filename=\"qprof.tar\")\n", + " print(\"Ready to Download\")\n", + " display(download_output)\n", + " display(btn)\n", + " except Exception as e:\n", + " logging.info(f'[Query Profile Tree Page] Failed to export qprof because of this error:{e}')\n", + " print(\"\\033[91mReport was not created successfully.\\033[0m\")\n", + " print(\"Error:\", e)\n", + " print(\"\\n Press the button below to generate and download the HTML report...\")\n", + " display(btn_report)\n", "\n", - "qpof_save = widgets.VBox([button_qprof_save, output_export])\n", "\n", - "button_download_report = widgets.Button(description=\"Download Report\", layout=widgets.Layout(width='150px'))\n", - "output_download_report = widgets.Output()\n", - "def click_download_report(_):\n", - " output_download_report.clear_output(wait=True)\n", - " with output_download_report:\n", - " print(\"Downloading report. It may take a while...\")\n", - " print(\"Ready to Download\")\n", - " display(download_report_output)\n", - " display(btn_report)\n", + "button_qprof_save.on_click(click_export_query)\n", "\n", - "button_download_report.on_click(click_download_report)\n" + "qprof_save = widgets.VBox([button_qprof_save, output_export])" ] }, { @@ -231,7 +232,6 @@ "source": [ "import tarfile\n", "from ipywidgets import Output, Button\n", - "from IPython.display import HTML, clear_output\n", "from base64 import b64encode\n", "\n", "download_output = Output()\n", @@ -251,7 +251,7 @@ " clear_output()\n", " display(HTML(f''))\n", "\n", - "btn = Button(description='Click to download')\n", + "btn = Button(description='Click to download the tar file', layout=widgets.Layout(width='250px'))\n", "\n", "def download_qprof(e=None):\n", " # Assuming 'qprof.tar' is stored in the file path 'qprof_path'\n", @@ -271,6 +271,7 @@ "outputs": [], "source": [ "def trigger_download_report(data, filename, file_type='text/html'):\n", + " logging.info(f'[Query Profile Tree Page] Trying to download HTML report.')\n", " content_b64 = b64encode(data).decode()\n", " data_url = f'data:{file_type};base64,{content_b64}'\n", " js_code = f\"\"\"\n", @@ -279,19 +280,23 @@ " a.setAttribute('href', '{data_url}');\n", " a.click();\n", " \"\"\"\n", - " with download_report_output:\n", + " with download_output:\n", " clear_output()\n", " display(HTML(f''))\n", "\n", "download_report_output = widgets.Output()\n", - "btn_report = Button(description='Click to download')\n", + "btn_report = Button(description='Click to download HTML report', layout=widgets.Layout(width='250px'))\n", "\n", "def download_html(e=None):\n", " global qprof\n", - " # Define the HTML content\n", - " html_content = qprof.to_html()\n", - " html_data = html_content.encode('utf-8')\n", - " trigger_download_report(html_data, 'sample.html')\n", + " with output_export:\n", + " print(\"Preparing files....\")\n", + " # Define the HTML content\n", + " html_content = qprof.to_html()\n", + " html_data = html_content.encode('utf-8')\n", + " trigger_download_report(html_data, 'sample.html') \n", + " print(\"Done\")\n", + "\n", "\n", "btn_report.on_click(download_html)" ] @@ -299,30 +304,12 @@ { "cell_type": "code", "execution_count": null, - "id": "da8af3a2-0c8c-4a82-a6ef-5edb15d53f72", - "metadata": {}, - "outputs": [], - "source": [ - "# Define the URLs for the links\n", - "url1 = \"/voila/render/ui/qprof_main.ipynb\"\n", - "# Define the button labels\n", - "button_label1 = \"Go Back\"\n", - "# Define HTML links for button\n", - "button_html1 = f\"\"\n", - "html_button1 = widgets.HTML(value=button_html1)\n", - "\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "47599ae0-6ffa-41d9-b16a-f346b3f52d72", + "id": "98ed0721-e8d8-4d88-ae93-2c4819f98974", "metadata": {}, "outputs": [], "source": [ - "logging.info(f'[Query Profile Tree Page] Trying to display the back and \"save query plan\" button')\n", - "display(widgets.HBox([html_button1,button_download_report, button_qprof_save ]))\n", - "display(output_export, output_download_report)" + "top_accordion = widgets.Accordion(children=[qprof_save], titles=('Downloads',))\n", + "display(top_accordion)" ] }, { @@ -687,7 +674,7 @@ "\n", "
\n", "