{ "cells": [ { "cell_type": "markdown", "id": "098625d0", "metadata": {}, "source": [ "# GAWD Language Usage\n", "\n", "[](https://colab.research.google.com/github/SwareUG/gh-aw-dataset-builder/blob/main/data_analysis/language_usage.ipynb)\n", "\n", "Language usage summary for **A Dataset of GitHub Agentic Workflow Histories: Early Adopters**.\n", "\n", "This follows the compact structure of the AIDev `language_usage.ipynb`: load repository and event data, compute language counts/percentages, and produce language-focused figures.\n" ] }, { "cell_type": "code", "execution_count": 1, "id": "752a0d71", "metadata": {}, "outputs": [], "source": [ "from __future__ import annotations\n", "\n", "import importlib.util\n", "import subprocess\n", "import sys\n", "from io import BytesIO\n", "from pathlib import Path\n", "from urllib.request import urlopen\n", "\n", "REQUIRED_PACKAGES = {\n", " \"pandas\": \"pandas\",\n", " \"pyarrow\": \"pyarrow\",\n", " \"matplotlib\": \"matplotlib\",\n", " \"seaborn\": \"seaborn\",\n", "}\n", "\n", "if \"google.colab\" in sys.modules:\n", " missing = [\n", " package\n", " for package, import_name in REQUIRED_PACKAGES.items()\n", " if importlib.util.find_spec(import_name) is None\n", " ]\n", " if missing:\n", " subprocess.check_call([sys.executable, \"-m\", \"pip\", \"install\", \"-q\", *missing])\n", "\n", "import matplotlib as mpl\n", "import matplotlib.pyplot as plt\n", "import pandas as pd\n", "import seaborn as sns\n", "from IPython.display import Image, display\n", "\n", "DATASET_ID = \"pavtch/gawd\"\n", "DATASET_REVISION = \"main\"\n", "LOCAL_RELEASE_CANDIDATES = [\n", " Path(\"..\"),\n", " Path(\".\"),\n", " Path(\"../releases/gh-aw-early-adopters-source-history-2026-06-26\"),\n", " Path(\"releases/gh-aw-early-adopters-source-history-2026-06-26\"),\n", " Path(\"../releases/gawd\"),\n", " Path(\"releases/gawd\"),\n", "]\n", "LOCAL_RELEASE_MIRROR = next(\n", " (\n", " path.resolve()\n", " for path in LOCAL_RELEASE_CANDIDATES\n", " if (path / \"data\").is_dir() and any((path / \"data\").glob(\"*.parquet\"))\n", " ),\n", " None,\n", ")\n", "USE_LOCAL_MIRROR = \"google.colab\" not in sys.modules and LOCAL_RELEASE_MIRROR is not None\n", "\n", "\n", "def remote_parquet_url(table_name: str) -> str:\n", " return (\n", " f\"https://huggingface.co/datasets/{DATASET_ID}/resolve/\"\n", " f\"{DATASET_REVISION}/data/{table_name}.parquet\"\n", " )\n", "\n", "\n", "def local_parquet_path(table_name: str) -> Path:\n", " if LOCAL_RELEASE_MIRROR is None:\n", " raise FileNotFoundError(\"No local release mirror with a data/ directory was found.\")\n", " return LOCAL_RELEASE_MIRROR / \"data\" / f\"{table_name}.parquet\"\n", "\n", "\n", "def parquet_path(table_name: str) -> str:\n", " if USE_LOCAL_MIRROR:\n", " return str(local_parquet_path(table_name))\n", " return remote_parquet_url(table_name)\n", "\n", "\n", "def read_parquet_table(table_name: str) -> pd.DataFrame:\n", " if USE_LOCAL_MIRROR:\n", " return pd.read_parquet(local_parquet_path(table_name))\n", "\n", " try:\n", " with urlopen(remote_parquet_url(table_name)) as response:\n", " return pd.read_parquet(BytesIO(response.read()))\n", " except Exception:\n", " if LOCAL_RELEASE_MIRROR is not None:\n", " return pd.read_parquet(local_parquet_path(table_name))\n", " raise\n", "\n", "mpl.rcParams.update(\n", " {\n", " \"font.family\": \"serif\",\n", " \"font.serif\": [\"Times New Roman\", \"Times\", \"DejaVu Serif\"],\n", " \"mathtext.fontset\": \"stix\",\n", " \"axes.linewidth\": 1.0,\n", " \"axes.labelsize\": 14,\n", " \"axes.titlesize\": 15,\n", " \"xtick.major.size\": 4,\n", " \"ytick.major.size\": 4,\n", " \"xtick.labelsize\": 12,\n", " \"ytick.labelsize\": 12,\n", " \"legend.fontsize\": 11,\n", " \"legend.title_fontsize\": 11,\n", " \"figure.dpi\": 160,\n", " }\n", ")\n", "sns.set_style(\"whitegrid\")\n", "\n", "NOTEBOOK_DIR = Path(\"data_analysis\") if Path(\"data_analysis\").is_dir() else Path(\".\")\n", "FIG_DIR = NOTEBOOK_DIR / \"figs\"\n", "FIG_DIR.mkdir(parents=True, exist_ok=True)\n", "\n", "TOP_N = 10\n", "\n", "import matplotlib.dates as mdates\n", "repository_df = read_parquet_table(\"repository\")\n", "source_snapshot_df = read_parquet_table(\"source_markdown_file_snapshot\")\n", "source_version_df = read_parquet_table(\"source_markdown_file_version\")\n", "\n", "def save_and_show(fig: plt.Figure, out: Path) -> None:\n", " png_out = out.with_suffix(\".png\")\n", " pdf_out = out.with_suffix(\".pdf\")\n", " fig.savefig(png_out, bbox_inches=\"tight\", dpi=300)\n", " fig.savefig(pdf_out, bbox_inches=\"tight\")\n", " plt.close(fig)\n", " display(Image(filename=str(png_out)))\n", " print(\"Wrote\", png_out)\n", " print(\"Wrote\", pdf_out)\n" ] }, { "cell_type": "code", "execution_count": 2, "id": "dd2677bb", "metadata": {}, "outputs": [], "source": [ "# %%\n", "def build_adoption_table() -> pd.DataFrame:\n", " events = (\n", " source_version_df.merge(\n", " source_snapshot_df,\n", " on=\"source_markdown_file_snapshot_id\",\n", " how=\"inner\",\n", " validate=\"many_to_one\",\n", " )\n", " .merge(repository_df, on=\"repository_id\", how=\"left\", validate=\"many_to_one\")\n", " )\n", " events[\"committed_at\"] = pd.to_datetime(events[\"committed_at\"], utc=True, errors=\"coerce\")\n", " events = events.dropna(subset=[\"committed_at\"]).sort_values(\n", " [\"repository_id\", \"committed_at\", \"rank\"]\n", " )\n", " adoption = (\n", " events.groupby(\"repository_id\", as_index=False)\n", " .agg(\n", " repo_full_name=(\"repo_full_name\", \"first\"),\n", " main_language=(\"main_language\", \"first\"),\n", " stars=(\"stars\", \"first\"),\n", " forks=(\"forks\", \"first\"),\n", " adoption_date=(\"committed_at\", \"first\"),\n", " observed_versions=(\"source_markdown_file_version_id\", \"count\"),\n", " )\n", " .sort_values(\"adoption_date\")\n", " )\n", " adoption[\"language\"] = adoption[\"main_language\"].fillna(\"Unknown\")\n", " adoption[\"adoption_month\"] = (\n", " adoption[\"adoption_date\"].dt.tz_convert(None).dt.to_period(\"M\").dt.to_timestamp()\n", " )\n", " return adoption\n", "\n", "\n", "def language_counts(adoption: pd.DataFrame) -> pd.DataFrame:\n", " counts = adoption[\"language\"].value_counts(dropna=False).reset_index()\n", " counts.columns = [\"language\", \"repositories\"]\n", " counts[\"percentage\"] = counts[\"repositories\"] / counts[\"repositories\"].sum() * 100\n", " return counts\n", "\n", "\n", "def plot_total_language_percentages(counts: pd.DataFrame, top_n: int = TOP_N) -> None:\n", " plot_df = counts.head(top_n).copy()\n", " fig, ax = plt.subplots(figsize=(7, 0.45 * len(plot_df) + 1.4))\n", " sns.barplot(\n", " data=plot_df,\n", " y=\"language\",\n", " x=\"percentage\",\n", " orient=\"h\",\n", " color=\"#1C3F60\",\n", " ax=ax,\n", " )\n", " ax.set_xlabel(\"Percentage of Repositories (%)\")\n", " ax.set_ylabel(None)\n", " ax.set_title(\"Top Languages Used by Observed GH-AW Adopters\", weight=\"bold\")\n", " ax.set_xlim(0, plot_df[\"percentage\"].max() * 1.15)\n", " ax.grid(False)\n", " sns.despine(ax=ax)\n", " fig.tight_layout()\n", " out = FIG_DIR / \"gawd_total_language_percentages_top.png\"\n", " save_and_show(fig, out)\n", "\n", "\n", "def plot_language_cumulative(adoption: pd.DataFrame, top_n: int = 8) -> None:\n", " top_languages = adoption[\"language\"].value_counts().head(top_n).index\n", " plot_df = adoption.copy()\n", " plot_df[\"language_group\"] = plot_df[\"language\"].where(\n", " plot_df[\"language\"].isin(top_languages), \"Other\"\n", " )\n", " monthly = (\n", " plot_df.groupby([\"language_group\", \"adoption_month\"], as_index=False)\n", " .agg(new_repositories=(\"repository_id\", \"count\"))\n", " .sort_values([\"language_group\", \"adoption_month\"])\n", " )\n", " all_months = pd.date_range(\n", " adoption[\"adoption_month\"].min(), adoption[\"adoption_month\"].max(), freq=\"MS\"\n", " )\n", " complete_index = pd.MultiIndex.from_product(\n", " [sorted(monthly[\"language_group\"].unique()), all_months],\n", " names=[\"language_group\", \"adoption_month\"],\n", " )\n", " monthly = (\n", " monthly.set_index([\"language_group\", \"adoption_month\"])\n", " .reindex(complete_index, fill_value=0)\n", " .reset_index()\n", " )\n", " monthly[\"cumulative_repositories\"] = monthly.groupby(\"language_group\")[\n", " \"new_repositories\"\n", " ].cumsum()\n", "\n", " fig, ax = plt.subplots(figsize=(12, 7))\n", " sns.lineplot(\n", " data=monthly,\n", " x=\"adoption_month\",\n", " y=\"cumulative_repositories\",\n", " hue=\"language_group\",\n", " marker=\"o\",\n", " linewidth=2.2,\n", " palette=\"tab10\",\n", " ax=ax,\n", " )\n", " ax.set_title(\"Cumulative Observed GH-AW Adoption by Main Language\", weight=\"bold\")\n", " ax.set_xlabel(\"First observed adoption month\")\n", " ax.set_ylabel(\"Cumulative repositories\")\n", " ax.xaxis.set_major_locator(mdates.AutoDateLocator())\n", " ax.xaxis.set_major_formatter(mdates.ConciseDateFormatter(ax.xaxis.get_major_locator()))\n", " ax.legend(title=\"Main language\", bbox_to_anchor=(1.02, 1), loc=\"upper left\")\n", " sns.despine(ax=ax)\n", " fig.tight_layout()\n", " out = FIG_DIR / \"gawd_cumulative_language_usage.png\"\n", " save_and_show(fig, out)\n" ] }, { "cell_type": "code", "execution_count": 3, "id": "016cf9c4", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
| \n", " | language | \n", "repositories | \n", "percentage | \n", "
|---|---|---|---|
| 0 | \n", "TypeScript | \n", "52 | \n", "19.847328 | \n", "
| 1 | \n", "Go | \n", "41 | \n", "15.648855 | \n", "
| 2 | \n", "C# | \n", "32 | \n", "12.213740 | \n", "
| 3 | \n", "Python | \n", "29 | \n", "11.068702 | \n", "
| 4 | \n", "Makefile | \n", "21 | \n", "8.015267 | \n", "
| 5 | \n", "F# | \n", "18 | \n", "6.870229 | \n", "
| 6 | \n", "Rust | \n", "13 | \n", "4.961832 | \n", "
| 7 | \n", "JavaScript | \n", "11 | \n", "4.198473 | \n", "
| 8 | \n", "Java | \n", "10 | \n", "3.816794 | \n", "
| 9 | \n", "C++ | \n", "7 | \n", "2.671756 | \n", "
| 10 | \n", "Shell | \n", "5 | \n", "1.908397 | \n", "
| 11 | \n", "Kotlin | \n", "4 | \n", "1.526718 | \n", "
| 12 | \n", "C | \n", "3 | \n", "1.145038 | \n", "
| 13 | \n", "HTML | \n", "2 | \n", "0.763359 | \n", "
| 14 | \n", "Vue | \n", "2 | \n", "0.763359 | \n", "
| 15 | \n", "Ruby | \n", "2 | \n", "0.763359 | \n", "
| 16 | \n", "Elixir | \n", "1 | \n", "0.381679 | \n", "
| 17 | \n", "Dart | \n", "1 | \n", "0.381679 | \n", "
| 18 | \n", "Erlang | \n", "1 | \n", "0.381679 | \n", "
| 19 | \n", "Swift | \n", "1 | \n", "0.381679 | \n", "
| 20 | \n", "Jupyter Notebook | \n", "1 | \n", "0.381679 | \n", "
| 21 | \n", "PHP | \n", "1 | \n", "0.381679 | \n", "
| 22 | \n", "Lua | \n", "1 | \n", "0.381679 | \n", "
| 23 | \n", "R | \n", "1 | \n", "0.381679 | \n", "
| 24 | \n", "Julia | \n", "1 | \n", "0.381679 | \n", "
| 25 | \n", "Unknown | \n", "1 | \n", "0.381679 | \n", "