{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "initial_id",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-11-15T12:33:47.372994Z",
     "start_time": "2024-11-15T12:33:47.370080Z"
    }
   },
   "outputs": [],
   "source": [
    "import collections\n",
    "from functools import reduce\n",
    "import json\n",
    "import operator\n",
    "import os\n",
    "\n",
    "import pandas as pd\n",
    "\n",
    "from common import *"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "f4f962a27d9e4a44",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-11-15T16:59:29.653421Z",
     "start_time": "2024-11-15T16:59:28.811266Z"
    }
   },
   "outputs": [],
   "source": [
    "# File generated with\n",
    "# python analyze_bundle_dataset.py --total 100000 --worker $(nproc) -s identify_bundler $DATASETS/bundles-daily/results-*\n",
    "# mv results.json bundlers.json\n",
    "with open(os.path.join(DATASETS, \"bundlers.json\"), \"r\") as f:\n",
    "    data = json.load(f)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4ed7d3f57c77618e",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-11-15T17:01:36.275776Z",
     "start_time": "2024-11-15T17:01:35.682027Z"
    }
   },
   "outputs": [],
   "source": [
    "responsive_data = [d for d in data if len(d) > 0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "254587a9-69fa-45e7-89f6-719e15ec7040",
   "metadata": {},
   "outputs": [],
   "source": [
    "def new_bundlers_to_set(bundlers):\n",
    "    bs = set(b[0] for b in bundlers)\n",
    "    s = set(b[:7] for b in bs)\n",
    "    if \"webpack\" in bs:\n",
    "        s.add(\"webpackMain\")\n",
    "    if \"webpackChunk\" in bs:\n",
    "        s.add(\"webpackChunk\")\n",
    "    return s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "8250aa41825433f7",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-11-15T17:06:42.235598Z",
     "start_time": "2024-11-15T17:06:41.298259Z"
    }
   },
   "outputs": [],
   "source": [
    "bundler = collections.Counter(reduce(operator.iconcat, (b for b in [new_bundlers_to_set(d[\"bundlers\"]) for d in reduce(operator.iconcat, responsive_data)] if len(b) == 1 or all(b_.startswith(\"web\") for b_ in b)), []))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "118113a4-d9bf-4423-9d3b-1dfe07d13c57",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Counter({'webpack': 2843350,\n",
       "         'webpackChunk': 1490404,\n",
       "         'webpackMain': 1468081,\n",
       "         'rollup': 165608,\n",
       "         'browser': 141498,\n",
       "         'esbuild': 40187,\n",
       "         'parcel': 3344})"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bundler"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "d5ce88e941068b1c",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-11-15T17:06:43.328521Z",
     "start_time": "2024-11-15T17:06:43.233889Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>webpack</th>\n",
       "      <th>webpackChunk</th>\n",
       "      <th>webpackMain</th>\n",
       "      <th>rollup</th>\n",
       "      <th>browser</th>\n",
       "      <th>esbuild</th>\n",
       "      <th>parcel</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1.477261</td>\n",
       "      <td>0.774339</td>\n",
       "      <td>0.762741</td>\n",
       "      <td>0.086042</td>\n",
       "      <td>0.073515</td>\n",
       "      <td>0.020879</td>\n",
       "      <td>0.001737</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    webpack  webpackChunk  webpackMain    rollup   browser   esbuild    parcel\n",
       "0  1.477261      0.774339     0.762741  0.086042  0.073515  0.020879  0.001737"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame({k: [v / len(responsive_data)] for k, v in bundler.most_common()})\n",
    "df"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
