diff --git a/project/ui/conn.ipynb b/project/ui/conn.ipynb index c0e346e6..2ddf520c 100644 --- a/project/ui/conn.ipynb +++ b/project/ui/conn.ipynb @@ -228,7 +228,12 @@ "cell_type": "code", "execution_count": 6, "id": "14e6b51c-72d8-4611-b991-47f9aeaa1473", - "metadata": {}, + "metadata": { + "collapsed": true, + "jupyter": { + "outputs_hidden": true + } + }, "outputs": [ { "data": { @@ -269,6 +274,71 @@ "# Display buttons\n", "display(widgets.HBox([html_button1, html_button2]))\n" ] + }, + { + "cell_type": "markdown", + "id": "32f3c37b-1446-4114-99a0-8dc62998ac5d", + "metadata": {}, + "source": [ + "____" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "id": "dd19b4c5-f99f-4467-b885-3cc34a58a7ae", + "metadata": {}, + "outputs": [], + "source": [ + "from verticapy._utils._sql._vertica_version import vertica_version\n", + "\n", + "button_version = widgets.Button(description=\"Click to refresh\")\n", + "output_version = widgets.Output()\n", + "\n", + "def on_button_clicked_version(b):\n", + " output_version.clear_output(wait=True) # Clear the output\n", + " with output_version:\n", + " print(\"Vertica version:\", vertica_version()[0], \".\", vertica_version()[1], \".\", vertica_version()[2], \".\", vertica_version()[3])\n", + " print(\"VerticaPy version:\", vp.__version__)\n", + " print(\"VerticaPy long version:\", vp.__long_version__)\n", + "button_version.on_click(on_button_clicked_version)\n", + "version_details = widgets.VBox([button_version, output_version])" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "id": "db3e615b-7ed6-4b14-a508-432a0e6735a5", + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "2100538297184c6494d87fa467acb6f5", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Accordion(children=(VBox(children=(Button(description='Click to display', style=ButtonStyle()), Output(outputs…" + ] + }, + "execution_count": 27, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "accordion = widgets.Accordion(children=[version_details], titles=('Version Details',))\n", + "accordion" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c7e6ed2f-af31-48a8-80fc-f5a9402647b4", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { diff --git a/project/ui/qprof-ui.ipynb b/project/ui/qprof-ui.ipynb index f438180b..7b6ea538 100644 --- a/project/ui/qprof-ui.ipynb +++ b/project/ui/qprof-ui.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 9, + "execution_count": null, "id": "0221f436-1e34-405a-b28c-293eac20c369", "metadata": { "scrolled": true @@ -50,24 +50,23 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "id": "b74b0305-6612-4f85-aa18-ff0b36e5cd80", "metadata": {}, "outputs": [], "source": [ - "button_qprof_save = widgets.Button(description=\"Save Query Plan\", \n", - " # button_style='warning', \n", - " # layout=widgets.Layout(background_color='#007bff')\n", - " )\n", + "button_qprof_save = widgets.Button(description=\"Save Query Plan\")\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", + " print(\"Saving Query. It may take a while...\")\n", " qprof.export_profile(filename=\"qprof.tar\")\n", " print(\"Ready to Download\")\n", - " display(download_button)\n", + " display(download_output)\n", + " display(btn)\n", + " \n", "\n", "button_qprof_save.on_click(click_export_query)\n", "\n", @@ -76,38 +75,47 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "id": "72beb96c-85b4-4331-8e92-c59be23ae5fb", "metadata": {}, "outputs": [], "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", "\n", - "from ipywidgets import HTML\n", - "from IPython.display import display\n", "\n", + "def trigger_download(data, filename, file_type='application/octet-stream'):\n", + " content_b64 = b64encode(data).decode()\n", + " data_url = f'data:{file_type};base64,{content_b64}'\n", + " js_code = f\"\"\"\n", + " var a = document.createElement('a');\n", + " a.setAttribute('download', '{filename}');\n", + " a.setAttribute('href', '{data_url}');\n", + " a.click();\n", + " \"\"\"\n", + " with download_output:\n", + " clear_output()\n", + " display(HTML(f''))\n", "\n", - "def create_download_link(filepath):\n", - " return f'''\n", - " \n", - "
\n", - " \n", - " \n", - " \n", - " \"\n", - " \n", - " \n", - " \n", - " \n", - " '''\n", + "btn = Button(description='Click to download')\n", "\n", - "# Example usage\n", - "filepath = 'qprof.tar'\n", - "download_button = HTML(create_download_link(filepath))" + "def download_qprof(e=None):\n", + " # Assuming 'qprof.tar' is stored in the file path 'qprof_path'\n", + " qprof_path = 'qprof.tar' # Replace 'qprof.tar' with the actual file path\n", + " with open(qprof_path, 'rb') as file:\n", + " qprof_data = file.read()\n", + " trigger_download(qprof_data, 'qprof.tar')\n", + "\n", + "btn.on_click(download_qprof)" ] }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "id": "da8af3a2-0c8c-4a82-a6ef-5edb15d53f72", "metadata": {}, "outputs": [], @@ -124,39 +132,10 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": null, "id": "47599ae0-6ffa-41d9-b16a-f346b3f52d72", "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "3e657ea4f8984752ba89a55c3ef66bc7", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "HBox(children=(HTML(value=\"\n", - "\n", - "\n", - "\n", - "\n" - ], - "text/plain": [ - "