From b3a2428b14863b9e03142fad791cdc7243b319b3 Mon Sep 17 00:00:00 2001 From: ReenigneArcher <42013603+ReenigneArcher@users.noreply.github.com> Date: Wed, 21 Aug 2024 21:23:53 -0400 Subject: [PATCH] fix(prs): use itables (#16) --- notebook/dashboard.ipynb | 300 ++++++--------------------------------- requirements.txt | 2 + 2 files changed, 45 insertions(+), 257 deletions(-) diff --git a/notebook/dashboard.ipynb b/notebook/dashboard.ipynb index 9164c49f..f042ecdc 100644 --- a/notebook/dashboard.ipynb +++ b/notebook/dashboard.ipynb @@ -84,6 +84,8 @@ "# lib imports\n", "from dotenv import load_dotenv\n", "from github import Github, UnknownObjectException\n", + "from IPython.display import HTML, display\n", + "from itables import init_notebook_mode, show\n", "import pandas as pd\n", "import plotly.express as px\n", "import plotly.graph_objects as go\n", @@ -413,7 +415,6 @@ " \"author\": pr_details.user.login,\n", " \"labels\": [label.name for label in pr_details.labels],\n", " \"assignees\": [assignee.login for assignee in pr_details.assignees],\n", - " \"ready\": not pr_details.draft,\n", " \"created_at\": pr_details.created_at,\n", " \"last_activity\": pr_details.updated_at,\n", " \"status\": \"Draft\" if pr_details.draft else \"Ready\",\n", @@ -437,14 +438,6 @@ "df_pr_counts['total_prs'] = df_pr_counts.groupby('repo')['pr_count'].transform('sum')\n", "df_pr_counts = df_pr_counts.sort_values(by='total_prs', ascending=False)\n", "\n", - "# Create PR Table\n", - "fig_table = go.Figure(data=[go.Table(\n", - " header=dict(values=list(df_pr_details.columns),\n", - " align='left'),\n", - " cells=dict(values=[df_pr_details[col] for col in df_pr_details.columns],\n", - " align='left'))\n", - "])\n", - "\n", "# Create Stacked Bar Chart\n", "fig_bar = px.bar(\n", " df_pr_counts,\n", @@ -457,252 +450,6 @@ " category_orders={'repo': df_pr_counts['repo'].tolist()},\n", ")\n", "\n", - "# common filter button properties\n", - "y_button_position = 1.1\n", - "x_button_factor = 0.15\n", - "bg_color = \"lightgray\"\n", - "font = {\"color\": \"black\"}\n", - "\n", - "# Add common dropdown filters for repository, status, author, labels, and assignees\n", - "updatemenus = [\n", - " {\n", - " \"buttons\": [\n", - " {\n", - " \"label\": \"All Repos\",\n", - " \"method\": \"update\",\n", - " \"args\": [\n", - " {\n", - " \"cells\": {\n", - " \"values\": [df_pr_details[col] for col in df_pr_details.columns],\n", - " },\n", - " },\n", - " {\n", - " \"x\": [df_pr_counts['repo']],\n", - " \"y\": [df_pr_counts['pr_count']],\n", - " \"text\": [df_pr_counts['pr_count']],\n", - " },\n", - " ],\n", - " },\n", - " ] + [\n", - " {\n", - " \"label\": repo,\n", - " \"method\": \"update\",\n", - " \"args\": [\n", - " {\n", - " \"cells\": {\n", - " \"values\": [df_pr_details[df_pr_details['repo'] == repo][col]\n", - " for col in df_pr_details.columns],\n", - " },\n", - " },\n", - " {\n", - " \"x\": [df_pr_counts[df_pr_counts['repo'] == repo]['repo']],\n", - " \"y\": [df_pr_counts[df_pr_counts['repo'] == repo]['pr_count']],\n", - " \"text\": [df_pr_counts[df_pr_counts['repo'] == repo]['pr_count']],\n", - " },\n", - " ],\n", - " } for repo in df_pr_details['repo'].unique()\n", - " ],\n", - " \"direction\": \"down\",\n", - " \"showactive\": True,\n", - " \"x\": x_button_factor,\n", - " \"xanchor\": \"left\",\n", - " \"y\": y_button_position,\n", - " \"yanchor\": \"top\",\n", - " \"bgcolor\": bg_color,\n", - " \"font\": font,\n", - " },\n", - " {\n", - " \"buttons\": [\n", - " {\n", - " \"label\": \"All Authors\",\n", - " \"method\": \"update\",\n", - " \"args\": [\n", - " {\n", - " \"cells\": {\n", - " \"values\": [df_pr_details[col] for col in df_pr_details.columns],\n", - " },\n", - " },\n", - " {\n", - " \"x\": [df_pr_counts['repo']],\n", - " \"y\": [df_pr_counts['pr_count']],\n", - " \"text\": [df_pr_counts['pr_count']],\n", - " },\n", - " ],\n", - " },\n", - " ] + [\n", - " {\n", - " \"label\": author,\n", - " \"method\": \"update\",\n", - " \"args\": [\n", - " {\n", - " \"cells\": {\n", - " \"values\": [df_pr_details[df_pr_details['author'] == author][col]\n", - " for col in df_pr_details.columns],\n", - " },\n", - " },\n", - " {\n", - " \"x\": [df_pr_counts[df_pr_counts['repo'] == repo]['repo']],\n", - " \"y\": [df_pr_counts[df_pr_counts['repo'] == repo]['pr_count']],\n", - " \"text\": [df_pr_counts[df_pr_counts['repo'] == repo]['pr_count']],\n", - " },\n", - " ],\n", - " } for author in df_pr_details['author'].unique()\n", - " ],\n", - " \"direction\": \"down\",\n", - " \"showactive\": True,\n", - " \"x\": x_button_factor * 2,\n", - " \"xanchor\": \"left\",\n", - " \"y\": y_button_position,\n", - " \"yanchor\": \"top\",\n", - " \"bgcolor\": bg_color,\n", - " \"font\": font,\n", - " },\n", - " {\n", - " \"buttons\": [\n", - " {\n", - " \"label\": \"All Labels\",\n", - " \"method\": \"update\",\n", - " \"args\": [\n", - " {\n", - " \"cells\": {\n", - " \"values\": [df_pr_details[col] for col in df_pr_details.columns],\n", - " },\n", - " },\n", - " {\n", - " \"x\": [df_pr_counts['repo']],\n", - " \"y\": [df_pr_counts['pr_count']],\n", - " \"text\": [df_pr_counts['pr_count']],\n", - " },\n", - " ],\n", - " },\n", - " ] + [\n", - " {\n", - " \"label\": label,\n", - " \"method\": \"update\",\n", - " \"args\": [\n", - " {\n", - " \"cells\": {\n", - " \"values\": [df_pr_details[df_pr_details['labels'].apply(\n", - " lambda x: label in x)][col] for col in df_pr_details.columns],\n", - " },\n", - " },\n", - " {\n", - " \"x\": [df_pr_counts[df_pr_counts['repo'] == repo]['repo']],\n", - " \"y\": [df_pr_counts[df_pr_counts['repo'] == repo]['pr_count']],\n", - " \"text\": [df_pr_counts[df_pr_counts['repo'] == repo]['pr_count']],\n", - " },\n", - " ],\n", - " } for label in set(label for labels in df_pr_details['labels'] for label in labels)\n", - " ],\n", - " \"direction\": \"down\",\n", - " \"showactive\": True,\n", - " \"x\": x_button_factor * 3,\n", - " \"xanchor\": \"left\",\n", - " \"y\": y_button_position,\n", - " \"yanchor\": \"top\",\n", - " \"bgcolor\": bg_color,\n", - " \"font\": font,\n", - " },\n", - " {\n", - " \"buttons\": [\n", - " {\n", - " \"label\": \"All Assignees\",\n", - " \"method\": \"update\",\n", - " \"args\": [\n", - " {\n", - " \"cells\": {\n", - " \"values\": [df_pr_details[col] for col in df_pr_details.columns],\n", - " },\n", - " },\n", - " {\n", - " \"x\": [df_pr_counts['repo']],\n", - " \"y\": [df_pr_counts['pr_count']],\n", - " \"text\": [df_pr_counts['pr_count']],\n", - " },\n", - " ],\n", - " },\n", - " ] + [\n", - " {\n", - " \"label\": assignee,\n", - " \"method\": \"update\",\n", - " \"args\": [\n", - " {\n", - " \"cells\": {\n", - " \"values\": [df_pr_details[df_pr_details['assignees'].apply(\n", - " lambda x: assignee in x)][col] for col in df_pr_details.columns],\n", - " },\n", - " },\n", - " {\n", - " \"x\": [df_pr_counts[df_pr_counts['repo'] == repo]['repo']],\n", - " \"y\": [df_pr_counts[df_pr_counts['repo'] == repo]['pr_count']],\n", - " \"text\": [df_pr_counts[df_pr_counts['repo'] == repo]['pr_count']],\n", - " },\n", - " ],\n", - " } for assignee in set(assignee for assignees in df_pr_details['assignees'] for assignee in assignees)\n", - " ],\n", - " \"direction\": \"down\",\n", - " \"showactive\": True,\n", - " \"x\": x_button_factor * 4,\n", - " \"xanchor\": \"left\",\n", - " \"y\": y_button_position,\n", - " \"yanchor\": \"top\",\n", - " \"bgcolor\": bg_color,\n", - " \"font\": font,\n", - " },\n", - " {\n", - " \"buttons\": [\n", - " {\n", - " \"label\": \"All Statuses\",\n", - " \"method\": \"update\",\n", - " \"args\": [\n", - " {\n", - " \"cells\": {\n", - " \"values\": [df_pr_details[col] for col in df_pr_details.columns],\n", - " },\n", - " },\n", - " {\n", - " \"x\": [df_pr_counts['repo']],\n", - " \"y\": [df_pr_counts['pr_count']],\n", - " \"text\": [df_pr_counts['pr_count']],\n", - " },\n", - " ],\n", - " },\n", - " ] + [\n", - " {\n", - " \"label\": status,\n", - " \"method\": \"update\",\n", - " \"args\": [\n", - " {\n", - " \"cells\": {\n", - " \"values\": [df_pr_details[df_pr_details['status'] == status][col]\n", - " for col in df_pr_details.columns],\n", - " },\n", - " },\n", - " {\n", - " \"x\": [df_pr_counts[df_pr_counts['status'] == status]['repo']],\n", - " \"y\": [df_pr_counts[df_pr_counts['status'] == status]['pr_count']],\n", - " \"text\": [df_pr_counts[df_pr_counts['status'] == status]['pr_count']],\n", - " },\n", - " ],\n", - " } for status in df_pr_details['status'].unique()\n", - " ],\n", - " \"direction\": \"down\",\n", - " \"showactive\": True,\n", - " \"x\": x_button_factor * 5,\n", - " \"xanchor\": \"left\",\n", - " \"y\": y_button_position,\n", - " \"yanchor\": \"top\",\n", - " \"bgcolor\": bg_color,\n", - " \"font\": font,\n", - " }\n", - "]\n", - "\n", - "fig_table.update_layout(\n", - " title='Pull Request Details',\n", - " height=800,\n", - " updatemenus=updatemenus,\n", - ")\n", - "\n", "fig_bar.update_layout(\n", " yaxis_title='Open PRs',\n", " xaxis_title='Repository',\n", @@ -711,11 +458,50 @@ " texttemplate=text_template,\n", " textposition='inside',\n", ")\n", - "\n", - "fig_table.show()\n", "fig_bar.show()" ] }, + { + "cell_type": "code", + "execution_count": null, + "id": "b416c3c48ae4e103", + "metadata": {}, + "outputs": [], + "source": [ + "# PR Table\n", + "\n", + "# darken the column filter inputs\n", + "css = \"\"\"\n", + ".dt-column-title input[type=\"text\"] {\n", + " background-color: var(--jp-layout-color0);\n", + " border-color: rgb(64,67,70);\n", + " border-width: 1px;\n", + "}\n", + "\"\"\"\n", + "display(HTML(f\"\"))\n", + "\n", + "init_notebook_mode(\n", + " all_interactive=True,\n", + " connected=False,\n", + ")\n", + "\n", + "# Display the DataFrame as an interactive table using itables\n", + "table_download_name = \"LizardByte-Pull-Requests\"\n", + "show(\n", + " df_pr_details,\n", + " buttons=[\n", + " \"pageLength\",\n", + " \"copyHtml5\",\n", + " {\"extend\": \"csvHtml5\", \"title\": table_download_name},\n", + " {\"extend\": \"excelHtml5\", \"title\": table_download_name},\n", + " ],\n", + " classes=\"display compact\",\n", + " column_filters=\"header\",\n", + " header=True,\n", + " layout={\"topEnd\": None},\n", + ")" + ] + }, { "cell_type": "markdown", "id": "3c067ce1b06d52da", diff --git a/requirements.txt b/requirements.txt index 744dbbca..3f0fcb52 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,5 @@ +ipython==8.26.0 +itables==2.1.4 notebook==7.2.1 pandas==2.2.2 plotly==5.23.0