diff options
| author | Adam Janovsky | 2024-09-08 18:26:37 +0200 |
|---|---|---|
| committer | Adam Janovsky | 2024-09-08 18:26:37 +0200 |
| commit | 75d8412062ed1adead2f003a5ddb5010c99e69cc (patch) | |
| tree | a6f6047d61aed9977a5f3ee51970db32d4b9af1a | |
| parent | 64faf31e74d8e1cabfb6546981f2da522831eaf0 (diff) | |
| download | sec-certs-75d8412062ed1adead2f003a5ddb5010c99e69cc.tar.gz sec-certs-75d8412062ed1adead2f003a5ddb5010c99e69cc.tar.zst sec-certs-75d8412062ed1adead2f003a5ddb5010c99e69cc.zip | |
new plots for chain-of-trust extended paper
| -rw-r--r-- | notebooks/cc/chain_of_trust_plots.ipynb | 166 |
1 files changed, 162 insertions, 4 deletions
diff --git a/notebooks/cc/chain_of_trust_plots.ipynb b/notebooks/cc/chain_of_trust_plots.ipynb index 2d58af8b..2e5dd035 100644 --- a/notebooks/cc/chain_of_trust_plots.ipynb +++ b/notebooks/cc/chain_of_trust_plots.ipynb @@ -17,8 +17,10 @@ "from matplotlib import lines\n", "from sklearn import metrics\n", "\n", + "from sec_certs.dataset import CCDataset\n", + "\n", "# LaTeX plotting\n", - "matplotlib.use(\"pgf\")\n", + "# matplotlib.use(\"pgf\")\n", "sns.set_palette(\"Set2\")\n", "sns.set_context(\"paper\")\n", "\n", @@ -42,14 +44,15 @@ "plt.rcParams[\"ytick.major.width\"] = 0.5\n", "plt.rcParams[\"ytick.major.pad\"] = 0.1\n", "\n", - "plt.rcParams[\"legend.title_fontsize\"] = 12\n", - "plt.rcParams[\"legend.fontsize\"] = 12\n", + "plt.rcParams[\"legend.title_fontsize\"] = 10\n", + "plt.rcParams[\"legend.fontsize\"] = 10\n", "plt.rcParams[\"legend.handletextpad\"] = 0.3\n", "plt.rcParams[\"lines.markersize\"] = 0.5\n", "plt.rcParams[\"savefig.pad_inches\"] = 0.01\n", "\n", "INPUT_DIR = Path(\"./paper_artifacts/chain_of_trust/data/plots/\")\n", "OUTPUT_DIR = Path(\"./results/figures/\")\n", + "DATASET_PATH = Path(\"./dataset/cc_november_23/dataset.json\")\n", "INPUT_DIR.mkdir(exist_ok=True, parents=True)" ] }, @@ -57,6 +60,161 @@ "cell_type": "markdown", "metadata": {}, "source": [ + "## Ecosystem insights plots" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "figure_width = 3.5\n", + "figure_height = 2.5\n", + "\n", + "dset = CCDataset.from_json(DATASET_PATH)\n", + "df = dset.to_pandas()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Validity boxplot\n", + "df_validity = pd.read_csv(INPUT_DIR / \"df_validity.csv\")\n", + "fig = plt.figure(figsize=(figure_width, figure_height))\n", + "box = sns.boxplot(data=df_validity, x=\"year_from\", y=\"validity_period\", linewidth=0.75, flierprops={\"marker\": \"x\"})\n", + "box.set(xlabel=\"\", ylabel=\"\")\n", + "plt.xticks([5 * i for i in range(6)], [1997, 2002, 2007, 2012, 2017, 2022])\n", + "fig.savefig(OUTPUT_DIR / \"boxplot_validity.pdf\", bbox_inches=\"tight\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Average EAL level\n", + "\n", + "avg_levels = pd.read_csv(INPUT_DIR / \"avg_eal.csv\").loc[lambda _df: _df.year_from < 2023]\n", + "eal_to_num_mapping = {eal: index for index, eal in enumerate(df[\"eal\"].cat.categories)}\n", + "avg_levels[\"smartcard_category\"] = avg_levels.category.map(\n", + " lambda x: x if x == \"ICs, Smartcards\" else \"Other categories\"\n", + ")\n", + "line = sns.lineplot(\n", + " data=avg_levels,\n", + " x=\"year_from\",\n", + " y=\"eal_number\",\n", + " hue=\"smartcard_category\",\n", + " errorbar=None,\n", + " style=\"smartcard_category\",\n", + " markers=True,\n", + " linewidth=2,\n", + ")\n", + "line.set(xlabel=None, ylabel=None, title=None, xlim=(1999.6, 2023.4))\n", + "ymin = 1\n", + "ymax = 9\n", + "ylabels = [\n", + " x if \"+\" in x else x + r\"\\phantom{+}\" for x in list(eal_to_num_mapping.keys())[ymin : ymax + 1]\n", + "] # this also aligns the labels by adding phantom spaces\n", + "plt.yticks(range(ymin, ymax + 1), ylabels)\n", + "plt.xticks([1997, 2002, 2007, 2012, 2017, 2022])\n", + "line.legend(title=None, labels=avg_levels.smartcard_category.unique())\n", + "plt.legend(frameon=False)\n", + "\n", + "fig = matplotlib.pyplot.gcf()\n", + "fig.set_size_inches(figure_width, figure_height)\n", + "fig.tight_layout(pad=0.1)\n", + "fig.savefig(OUTPUT_DIR / \"temporal_trends_categories.pdf\")\n", + "plt.show()\n", + "plt.close()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Interesting schemes" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "interesting_schemes = pd.read_csv(INPUT_DIR / \"interesting_schemes.csv\")\n", + "\n", + "line = sns.lineplot(\n", + " data=interesting_schemes,\n", + " x=\"year_from\",\n", + " y=\"size\",\n", + " hue=\"scheme\",\n", + " style=\"scheme\",\n", + " markers=True,\n", + " dashes=True,\n", + " linewidth=2,\n", + ")\n", + "line.set(xlabel=None, ylabel=None, title=None, xlim=(1999.6, 2022.4), ylim=(0, 60))\n", + "line.set_xticks([1997, 2002, 2007, 2012, 2017, 2022])\n", + "line.legend(title=None)\n", + "fig = matplotlib.pyplot.gcf()\n", + "fig.set_size_inches(figure_width, figure_height)\n", + "fig.tight_layout(pad=0.1)\n", + "fig.savefig(OUTPUT_DIR / \"temporal_trends_schemes.pdf\")\n", + "plt.show()\n", + "plt.close()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Popular categories" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "n_certs = pd.read_csv(INPUT_DIR / \"popular_categories.csv\").astype({\"year_from\": \"category\"})\n", + "dct = {\n", + " \"ICs, Smart Cards and Smart Card-Related Devices and Systems\": \"ICs and Smart Cards\",\n", + " \"Network and Network-Related Devices and Systems\": \"Network-Related Devices\",\n", + " \"Other Devices and Systems\": \"Other Devices\",\n", + " \"One of 11 other categories\": \"11 Other Categories\",\n", + "}\n", + "n_certs.popular_categories = n_certs.popular_categories.map(lambda x: dct.get(x, x))\n", + "cats = n_certs.popular_categories.unique()\n", + "years = n_certs.year_from.cat.categories[:-1]\n", + "data = [n_certs.loc[n_certs.popular_categories == c, \"size\"].tolist()[:-1] for c in cats]\n", + "\n", + "plt.stackplot(\n", + " years,\n", + " data,\n", + " labels=cats,\n", + ")\n", + "plt.legend(frameon=False, loc=\"upper left\", bbox_to_anchor=(0, 1))\n", + "plt.xticks([1997, 2002, 2007, 2012, 2017, 2022])\n", + "plt.xlim(1997, 2022)\n", + "\n", + "fig = matplotlib.pyplot.gcf()\n", + "fig.set_size_inches(figure_width, figure_height)\n", + "fig.tight_layout(pad=0.1)\n", + "fig.savefig(OUTPUT_DIR / \"temporal_trends_stackplot.pdf\")\n", + "plt.show()\n", + "plt.close()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ "## Average number of transitive references over time" ] }, @@ -312,7 +470,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.5" + "version": "3.10.14" } }, "nbformat": 4, |
