Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QueryProfiler UI Pages - Combined download buttons for tar file + html report #267

Merged
merged 3 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 38 additions & 51 deletions project/ui/qprof-ui.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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\"<a href='{url1}' style='text-decoration: none; padding: 8px; background-color: #007bff; color: white; border-radius: 5px; margin-right: 10px;'><i class='fa fa-home'></i></a>\"\n",
"button_html2 = f\"<a href='{url2}' style='text-decoration: none; padding: 8px; background-color: #007bff; color: white; border-radius: 5px;'>{button_label2}</a>\"\n",
"button_html3 = f\"<a href='{url3}' style='text-decoration: none; padding: 8px; background-color: #007bff; color: white; border-radius: 5px; margin-right: 5px;'><i class='fa fa-arrow-left'></i></a>\"\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"
]
},
{
Expand Down Expand Up @@ -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])"
]
},
{
Expand All @@ -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",
Expand All @@ -251,7 +251,7 @@
" clear_output()\n",
" display(HTML(f'<script>{js_code}</script>'))\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",
Expand All @@ -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",
Expand All @@ -279,50 +280,36 @@
" 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'<script>{js_code}</script>'))\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)"
]
},
{
"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\"<a href='{url1}' style='text-decoration: none; padding: 5px; background-color: #007bff; color: white; border-radius: 5px; margin-right: 5px;'><i class='fa fa-arrow-left'></i></a>\"\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)"
]
},
{
Expand Down Expand Up @@ -687,7 +674,7 @@
"</head>\n",
"<body>\n",
" <div class=\"version\">\n",
" Page version update date: 6/3/2024\n",
" Page version update date: 6/4/2024\n",
" </div>\n",
"</body>\n",
"</html>"
Expand Down
2 changes: 1 addition & 1 deletion project/ui/qprof_main.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@
" sql_query = f\"SELECT * from query_requests WHERE request_type = 'QUERY' AND request_label LIKE '{request_label_wild_card}{request_label_input.value}{request_label_wild_card}' AND request LIKE '{query_search_wild_card}{query_search_input.value}{query_search_wild_card}' ORDER BY request_duration_ms DESC LIMIT 6;\"\n",
" result = vp.vDataFrame(sql_query)\n",
" logging.info('[Query Profile Main Page] Successfully fetched the queries from query_request table')\n",
" result.idisplay(checkboxes=True)\n",
" result.idisplay()\n",
" \n",
"logging.info('Trying to display Query Request Table button [Query Profile Main Page]')\n",
"button_01.on_click(on_button_clicked_01)\n",
Expand Down
Loading