{ "cells": [ { "cell_type": "code", "execution_count": 55, "id": "af118d77-d87a-4687-be5b-e810a24c403e", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "2024-06-26 13:01:06 +0000 | io:INFO | Loaded TOML config file successfully.\n" ] } ], "source": [ "from lang_main import io\n", "\n", "from pathlib import Path\n", "import pickle\n", "import base64" ] }, { "cell_type": "code", "execution_count": 56, "id": "4256081a-6364-4e8f-8cfd-799912ca6b94", "metadata": {}, "outputs": [], "source": [ "res_path = Path(r'A:\\Arbeitsaufgaben\\lang-main\\scripts\\results\\test_20240619')\n", "assert res_path.exists()" ] }, { "cell_type": "code", "execution_count": 121, "id": "e9a92ad6-5e63-49c4-b9e7-9f81da8549fe", "metadata": {}, "outputs": [], "source": [ "# obj = 'TK-GRAPH_POSTPROCESSING.pkl'\n", "obj = 'TK-GRAPH_ANALYSIS.pkl'\n", "load_pth = res_path / obj\n", "assert load_pth.exists()" ] }, { "cell_type": "code", "execution_count": 122, "id": "c2421d89-ed8c-41dd-b363-ad5b5b716704", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "2024-06-26 13:22:38 +0000 | io:INFO | Loaded file successfully.\n" ] } ], "source": [ "ret = io.load_pickle(load_pth)" ] }, { "cell_type": "code", "execution_count": 123, "id": "ca25a7f2-84af-4b5e-89d6-b139fca35617", "metadata": {}, "outputs": [], "source": [ "tkg = ret[0]" ] }, { "cell_type": "code", "execution_count": 124, "id": "ff7e7ab6-67d9-4a2c-b668-cf10740f7542", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "TokenGraph(name: TokenGraph, number of nodes: 143, number of edges: 163)" ] }, "execution_count": 124, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tkg" ] }, { "cell_type": "code", "execution_count": 125, "id": "f0df3580-cea5-48cc-bdbc-2927dd446e1b", "metadata": {}, "outputs": [], "source": [ "import networkx as nx\n", "from alph import alph, layout\n", "import altair as alt" ] }, { "cell_type": "markdown", "id": "f042b302-fa3c-45b0-8d7a-7a68b66bf595", "metadata": {}, "source": [ "layout_fn=lambda g: nx.spring_layout(\n", " g,\n", " weight=\"weight\",\n", " k=20,\n", " iterations=5000,\n", " seed=42\n", " ),\n", "layout_fn=lambda g: layout.force_atlas_sknet(\n", " g,\n", " n_iter=100,\n", " gravity_factor=0.01,\n", " repulsive_factor=0.1,\n", " init_seed=42,\n", " )," ] }, { "cell_type": "code", "execution_count": 257, "id": "04d3d857-37cb-420e-8426-b1465d94efae", "metadata": {}, "outputs": [], "source": [ "alph_params = dict(\n", " weight_attr=\"weight\",\n", " layout_fn=lambda g: nx.nx_agraph.pygraphviz_layout(\n", " g,\n", " prog=\"fdp\",\n", " args='-GK=5'\n", " ),\n", " node_args=dict(\n", " size=alt.Size(\n", " \"degree_centrality\",\n", " scale=alt.Scale(domain=[0,1], range=[12**2, 40**2]),\n", " legend=None\n", " ),\n", " #fill=alt.Color(\n", " # \"degree_centrality\",\n", " # scale=alt.Scale(domain=companies, range=palette),\n", " #),\n", " stroke=\"#333\",\n", " strokeWidth=alt.Size(\n", " \"degree_centrality\",\n", " scale=alt.Scale(domain=[0,1], range=[2, 5]),\n", " legend=None\n", " ),\n", " tooltip_attrs=[\"id\"],\n", " label_attr=\"id\",\n", " ),\n", " edge_args=dict(\n", " color=\"#000\",\n", " ),\n", " width=800,\n", " height=600,\n", ")" ] }, { "cell_type": "code", "execution_count": 258, "id": "64e6a5c1-e42d-4ad2-8c32-5cf62bc75852", "metadata": {}, "outputs": [], "source": [ "nx.set_node_attributes(tkg, {\n", " n: {\n", " \"id\": n,\n", " } for n in tkg.nodes\n", "})" ] }, { "cell_type": "code", "execution_count": 259, "id": "7e895f70-74a2-433c-91c2-a440303ab81a", "metadata": {}, "outputs": [], "source": [ "nx.set_node_attributes(tkg, nx.degree_centrality(tkg), \"degree_centrality\")" ] }, { "cell_type": "code", "execution_count": 260, "id": "a13cc710-01d8-4f52-b066-3796b4609118", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", "" ], "text/plain": [ "alt.LayerChart(...)" ] }, "execution_count": 260, "metadata": {}, "output_type": "execute_result" } ], "source": [ "alph(tkg, **alph_params).configure_view(strokeWidth=0)" ] }, { "cell_type": "code", "execution_count": 261, "id": "842e01fa-29cd-4028-9461-c7af24e01c33", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'id': 'Wartungstätigkeit', 'degree_centrality': 0.04225352112676056}" ] }, "execution_count": 261, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tkg.nodes['Wartungstätigkeit']" ] }, { "cell_type": "code", "execution_count": null, "id": "8d36d22e-73fd-44fe-ab08-98f8186bc6b2", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "7f6d1b73-7378-4c98-aeed-b72bf27a942e", "metadata": {}, "outputs": [], "source": [] } ], "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.11.9" } }, "nbformat": 4, "nbformat_minor": 5 }