mirror of
https://github.com/bellingcat/sugartrail.git
synced 2026-06-08 03:28:31 +03:00
added data accordian to dashboard
This commit is contained in:
278
dashboard/.ipynb_checkpoints/quickstart_voila-checkpoint.ipynb
Normal file
278
dashboard/.ipynb_checkpoints/quickstart_voila-checkpoint.ipynb
Normal file
@@ -0,0 +1,278 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "b6926e35",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# sugartrail "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "f17ebdd2",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from sugartrail import mapview, api, base\n",
|
||||
"import ipywidgets as widgets\n",
|
||||
"from IPython.display import display\n",
|
||||
"import requests"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "cbc5e202",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"%%capture\n",
|
||||
"network = base.Network()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "1704e377",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"1. Insert your [Companies House API](https://developer.company-information.service.gov.uk/how-to-create-an-application) key:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "0632780b",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"API_input = widgets.Text(\n",
|
||||
" value='',\n",
|
||||
" placeholder='Insert API Key',\n",
|
||||
" disabled=False\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"company_text = widgets.Text(\n",
|
||||
" value='',\n",
|
||||
" placeholder='Insert Company ID',\n",
|
||||
" disabled=True\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"auth_status = widgets.HTML(\n",
|
||||
" value=\"\",\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"auth_button = widgets.Button(description='Authenticate',button_style='success')\n",
|
||||
"auth_button.on_click(lambda bt: auth())\n",
|
||||
"\n",
|
||||
"init_button = widgets.Button(description='Initialise',button_style='success', disabled=True)\n",
|
||||
"init_button.on_click(lambda bt: init_network()) \n",
|
||||
"\n",
|
||||
"def auth():\n",
|
||||
" auth_button.disabled=True\n",
|
||||
" API_input.disabled=True\n",
|
||||
" api.basic_auth.username = API_input.value\n",
|
||||
" if api.test():\n",
|
||||
" auth_status.value = u'\\u2705: Login successful'\n",
|
||||
" company_text.disabled = False\n",
|
||||
" init_button.disabled = False\n",
|
||||
" else:\n",
|
||||
" auth_button.disabled=False\n",
|
||||
" API_input.disabled=False\n",
|
||||
" auth_status.value = u'\\u274c: Invalid API key'\n",
|
||||
"\n",
|
||||
"display(API_input, auth_button, auth_status)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "2bd8c5be",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"2. Insert the unique company registration number (CRN) for a company you would like to investigate:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "d5f9b6ad",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"<!-- Insert a valid [Companies House Public Data API key](https://developer.company-information.service.gov.uk/get-started/) as `username` string value below. If you don't want to use the API and would prefer loading a pre-built network, uncomment and run the cell below and then run the final cell to build and load the map. -->"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "128106c5",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"init_status = widgets.HTML(\n",
|
||||
" value=\"\",\n",
|
||||
") \n",
|
||||
"\n",
|
||||
"depth_selector = widgets.BoundedIntText(\n",
|
||||
" value=1,\n",
|
||||
" min=1,\n",
|
||||
" max=5,\n",
|
||||
" step=1,\n",
|
||||
" disabled=True\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"generate_network_button = widgets.Button(description='Build Network',button_style='success', disabled=True)\n",
|
||||
"generate_network_button.on_click(lambda bt: generate_network()) \n",
|
||||
"\n",
|
||||
"def init_network():\n",
|
||||
" init_button.disabled=True\n",
|
||||
" company_text.disabled=True\n",
|
||||
" api.basic_auth.username = API_input.value\n",
|
||||
" response = api.get_company(str(company_text.value))\n",
|
||||
" if response:\n",
|
||||
" network.company_id = str(company_text.value)\n",
|
||||
" init_status.value = u'\\u2705: Initialisation successful for ' + str(response['company_name']) \n",
|
||||
" depth_selector.disabled = False\n",
|
||||
" generate_network_button.disabled = False\n",
|
||||
" else:\n",
|
||||
" init_button.disabled=False\n",
|
||||
" company_text.disabled=False\n",
|
||||
" auth_button.disabled=False\n",
|
||||
" API_input.disabled=False\n",
|
||||
" init_status.value = u'\\u274c: Initialisation Failed. No records for company: ' + str(company_text.value) + ' found.'\n",
|
||||
"\n",
|
||||
"display(company_text, init_button, init_status)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "addafb36",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"3. Select the depth of the network you would like to build:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "ea0e8392",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"build_status = widgets.HTML(\n",
|
||||
" value=\"\",\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"build_map_button=widgets.Button(description='Build Map',button_style='success', disabled=True)\n",
|
||||
"build_map_button.on_click(lambda bt: generate_map()) \n",
|
||||
"\n",
|
||||
"def generate_network():\n",
|
||||
" with output_box:\n",
|
||||
" depth_selector.disabled = True\n",
|
||||
" generate_network_button.disabled = True\n",
|
||||
" network.perform_hop(depth_selector.value + 1)\n",
|
||||
" network.run_map_preprocessing()\n",
|
||||
" build_map_button.disabled = False\n",
|
||||
" \n",
|
||||
" \n",
|
||||
"output_box = widgets.Output()\n",
|
||||
"display(depth_selector, generate_network_button, build_status, output_box)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "03ffce05",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"4. Visualise network on a map:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "6449cd96",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"map_container = widgets.HTML(\n",
|
||||
" value=\"\",\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"map_data,path_table = mapview.build_map(network, clear_widget=False) \n",
|
||||
"hbox_map = widgets.HBox([path_table])\n",
|
||||
"vbox_map = widgets.VBox([map_data, hbox_map])\n",
|
||||
"\n",
|
||||
"accordion_map = widgets.Accordion(children=[vbox_map])\n",
|
||||
"accordion_map.set_title(0, 'Map')\n",
|
||||
"\n",
|
||||
"tabs = ['Companies', 'Addresses', 'Officers', 'Company Details']\n",
|
||||
"children = [widgets.Output() for tab in tabs]\n",
|
||||
"tab = widgets.Tab()\n",
|
||||
"tab.children = children\n",
|
||||
"for i,title in enumerate(tabs):\n",
|
||||
" tab.set_title(i, title)\n",
|
||||
"\n",
|
||||
"accordion_data = widgets.Accordion(children=[tab])\n",
|
||||
"accordion_data.set_title(0, 'Data')\n",
|
||||
"\n",
|
||||
"def generate_map():\n",
|
||||
" map_data,path_table = mapview.build_map(network, clear_widget=False) \n",
|
||||
" hbox_map = widgets.HBox([path_table])\n",
|
||||
" vbox_map.children = [map_data, hbox_map]\n",
|
||||
" accordion_map.selected_index=0\n",
|
||||
" accordion_data.selected_index=0\n",
|
||||
" build_map_button.disabled = True\n",
|
||||
" with tab.children[0]:\n",
|
||||
" display(network.company_ids)\n",
|
||||
" with tab.children[1]:\n",
|
||||
" display(network.addresses)\n",
|
||||
" with tab.children[2]:\n",
|
||||
" display(network.officer_ids)\n",
|
||||
" with tab.children[3]:\n",
|
||||
" display(network.companies) \n",
|
||||
"\n",
|
||||
"display(build_map_button, map_container)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "684a116e",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"accordion_map"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "1e328d41",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"accordion_data"
|
||||
]
|
||||
}
|
||||
],
|
||||
"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.9.15"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
||||
@@ -10,7 +10,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"execution_count": null,
|
||||
"id": "f17ebdd2",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
@@ -53,6 +53,12 @@
|
||||
" disabled=False\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"company_text = widgets.Text(\n",
|
||||
" value='',\n",
|
||||
" placeholder='Insert Company ID',\n",
|
||||
" disabled=True\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"auth_status = widgets.HTML(\n",
|
||||
" value=\"\",\n",
|
||||
")\n",
|
||||
@@ -60,6 +66,9 @@
|
||||
"auth_button = widgets.Button(description='Authenticate',button_style='success')\n",
|
||||
"auth_button.on_click(lambda bt: auth())\n",
|
||||
"\n",
|
||||
"init_button = widgets.Button(description='Initialise',button_style='success', disabled=True)\n",
|
||||
"init_button.on_click(lambda bt: init_network()) \n",
|
||||
"\n",
|
||||
"def auth():\n",
|
||||
" auth_button.disabled=True\n",
|
||||
" API_input.disabled=True\n",
|
||||
@@ -99,18 +108,20 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"company_text = widgets.Text(\n",
|
||||
" value='',\n",
|
||||
" placeholder='Insert Company ID',\n",
|
||||
"init_status = widgets.HTML(\n",
|
||||
" value=\"\",\n",
|
||||
") \n",
|
||||
"\n",
|
||||
"depth_selector = widgets.BoundedIntText(\n",
|
||||
" value=1,\n",
|
||||
" min=1,\n",
|
||||
" max=5,\n",
|
||||
" step=1,\n",
|
||||
" disabled=True\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"init_status = widgets.HTML(\n",
|
||||
" value=\"\",\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"init_button = widgets.Button(description='Initialise',button_style='success', disabled=True)\n",
|
||||
"init_button.on_click(lambda bt: init_network()) \n",
|
||||
"generate_network_button = widgets.Button(description='Build Network',button_style='success', disabled=True)\n",
|
||||
"generate_network_button.on_click(lambda bt: generate_network()) \n",
|
||||
"\n",
|
||||
"def init_network():\n",
|
||||
" init_button.disabled=True\n",
|
||||
@@ -123,6 +134,8 @@
|
||||
" depth_selector.disabled = False\n",
|
||||
" generate_network_button.disabled = False\n",
|
||||
" else:\n",
|
||||
" init_button.disabled=False\n",
|
||||
" company_text.disabled=False\n",
|
||||
" auth_button.disabled=False\n",
|
||||
" API_input.disabled=False\n",
|
||||
" init_status.value = u'\\u274c: Initialisation Failed. No records for company: ' + str(company_text.value) + ' found.'\n",
|
||||
@@ -145,22 +158,13 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"depth_selector = widgets.BoundedIntText(\n",
|
||||
" value=1,\n",
|
||||
" min=1,\n",
|
||||
" max=5,\n",
|
||||
" step=1,\n",
|
||||
" disabled=True\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"generate_network_button = widgets.Button(description='Build Network',button_style='success', disabled=True)\n",
|
||||
"generate_network_button.on_click(lambda bt: generate_network()) \n",
|
||||
"\n",
|
||||
"\n",
|
||||
"build_status = widgets.HTML(\n",
|
||||
" value=\"\",\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"build_map_button=widgets.Button(description='Build Map',button_style='success', disabled=True)\n",
|
||||
"build_map_button.on_click(lambda bt: generate_map()) \n",
|
||||
"\n",
|
||||
"def generate_network():\n",
|
||||
" with output_box:\n",
|
||||
" depth_selector.disabled = True\n",
|
||||
@@ -189,20 +193,42 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"build_map_button=widgets.Button(description='Build Map',button_style='success', disabled=True)\n",
|
||||
"build_map_button.on_click(lambda bt: generate_map()) \n",
|
||||
"\n",
|
||||
"map_container = widgets.HTML(\n",
|
||||
" value=\"\",\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"map_data,path_table = mapview.build_map(network, clear_widget=False) \n",
|
||||
"hbox_map = widgets.HBox([path_table])\n",
|
||||
"vbox_map = widgets.VBox([map_data, hbox_map])\n",
|
||||
"\n",
|
||||
"accordion_map = widgets.Accordion(children=[vbox_map])\n",
|
||||
"accordion_map.set_title(0, 'Map')\n",
|
||||
"\n",
|
||||
"tabs = ['Companies', 'Addresses', 'Officers', 'Company Details']\n",
|
||||
"children = [widgets.Output() for tab in tabs]\n",
|
||||
"tab = widgets.Tab()\n",
|
||||
"tab.children = children\n",
|
||||
"for i,title in enumerate(tabs):\n",
|
||||
" tab.set_title(i, title)\n",
|
||||
"\n",
|
||||
"accordion_data = widgets.Accordion(children=[tab])\n",
|
||||
"accordion_data.set_title(0, 'Data')\n",
|
||||
"\n",
|
||||
"def generate_map():\n",
|
||||
" map_data,path_table = mapview.build_map(network, clear_widget=False) \n",
|
||||
" hbox = widgets.HBox([path_table])\n",
|
||||
" vbox.children = [map_data, hbox]\n",
|
||||
" accordion.selected_index=0\n",
|
||||
" accordi0n.open(0)\n",
|
||||
" hbox_map = widgets.HBox([path_table])\n",
|
||||
" vbox_map.children = [map_data, hbox_map]\n",
|
||||
" accordion_map.selected_index=0\n",
|
||||
" accordion_data.selected_index=0\n",
|
||||
" build_map_button.disabled = True\n",
|
||||
" with tab.children[0]:\n",
|
||||
" display(network.company_ids)\n",
|
||||
" with tab.children[1]:\n",
|
||||
" display(network.addresses)\n",
|
||||
" with tab.children[2]:\n",
|
||||
" display(network.officer_ids)\n",
|
||||
" with tab.children[3]:\n",
|
||||
" display(network.companies) \n",
|
||||
"\n",
|
||||
"display(build_map_button, map_container)"
|
||||
]
|
||||
@@ -210,71 +236,21 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "a5a07e3b",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"%%capture\n",
|
||||
"empty_network = base.Network()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"id": "01dca0cf",
|
||||
"metadata": {
|
||||
"scrolled": true,
|
||||
"tags": [
|
||||
"7"
|
||||
]
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"map_data,path_table = mapview.build_map(network, clear_widget=False) \n",
|
||||
"hbox = widgets.HBox([path_table])\n",
|
||||
"vbox = widgets.VBox([map_data, hbox])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 10,
|
||||
"id": "684a116e",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"application/vnd.jupyter.widget-view+json": {
|
||||
"model_id": "08a9390c88cb49cfb5705f3a0b378ced",
|
||||
"version_major": 2,
|
||||
"version_minor": 0
|
||||
},
|
||||
"text/plain": [
|
||||
"Accordion(children=(VBox(children=(Map(bottom=87768.0, center=[51.27331450324598, -3.223454500000008], control…"
|
||||
]
|
||||
},
|
||||
"execution_count": 10,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"accordion = widgets.Accordion(children=[vbox])\n",
|
||||
"accordion.set_title(0, 'Map')\n",
|
||||
"# accordion.set_title(1, 'Text')\n",
|
||||
"accordion"
|
||||
"accordion_map"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "457bf4d0",
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "1e328d41",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"<!-- Each marker represents a company in the network. Green markers represent active companies based at the address, red markers represent active companies no longer based at the address and black markers represent dissolved companies once based at the address. \n",
|
||||
"\n",
|
||||
"Select a marker to display additional information: \n",
|
||||
"- pop-up with the selected company's name and address\n",
|
||||
"- table containing the most efficient paths from the origin to the selected company\n",
|
||||
"- antpaths for each company in the network. Red antpath represents the path through all the historic addresses for the selected company. Black antpath represents the path from the network origin through all the addresses in the path to the selected company as displayed in the table. -->"
|
||||
"accordion_data"
|
||||
]
|
||||
}
|
||||
],
|
||||
|
||||
172
notebooks/.ipynb_checkpoints/quickstart-checkpoint.ipynb
Normal file
172
notebooks/.ipynb_checkpoints/quickstart-checkpoint.ipynb
Normal file
@@ -0,0 +1,172 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "b6926e35",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"*Quickstart hands-on exercise. For in-depth intro checkout Tutorial 1:*"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "f17ebdd2",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from sugartrail import mapview, api, base\n",
|
||||
"from ipywidgets import VBox, HBox"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "d5f9b6ad",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Insert a valid [Companies House Public Data API key](https://developer.company-information.service.gov.uk/get-started/) as `username` string value below. If you don't want to use the API and would prefer loading a pre-built network, uncomment and run the cell below and then run the final cell to build and load the map. "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "4a9639e6",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# # network build from Domain Foundation, company_id = \"11951034\"\n",
|
||||
"# import pickle\n",
|
||||
"\n",
|
||||
"# with open('../assets/networks/domain_corp_network.pickle', 'rb') as handle:\n",
|
||||
"# network = pickle.load(handle)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "89b0082a",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"api.basic_auth.username = \"\""
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "63220f29",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Enter the company number (as string) for a company you would like to explore. Example value is provided: "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "8aca6a54",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"company_id = \"11951034\"\n",
|
||||
"network = base.Network(company_id=company_id)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "7de31e72",
|
||||
"metadata": {
|
||||
"tags": [
|
||||
"5"
|
||||
]
|
||||
},
|
||||
"source": [
|
||||
"Perform `n` number of hops (3 or less at first is advised to keep the network manageable in size):"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "d80be86d",
|
||||
"metadata": {
|
||||
"tags": [
|
||||
"6"
|
||||
]
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"n = 3\n",
|
||||
"network = base.Network(company_id=company_id)\n",
|
||||
"network.perform_hop(n)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "4481c80d",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Now lets visualise the connections:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "022f026e",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"network.run_map_preprocessing()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "01dca0cf",
|
||||
"metadata": {
|
||||
"scrolled": false,
|
||||
"tags": [
|
||||
"7"
|
||||
]
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"map_data,path_table = mapview.build_map(network) \n",
|
||||
"hbox = HBox([path_table])\n",
|
||||
"vbox = VBox([map_data, hbox])\n",
|
||||
"vbox"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "457bf4d0",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Each marker represents a company in the network. Green markers represent active companies based at the address, red markers represent active companies no longer based at the address and black markers represent dissolved companies once based at the address. \n",
|
||||
"\n",
|
||||
"Select a marker to display additional information: \n",
|
||||
"- pop-up with the selected company's name and address\n",
|
||||
"- table containing the most efficient paths from the origin to the selected company\n",
|
||||
"- antpaths for each company in the network. Red antpath represents the path through all the historic addresses for the selected company. Black antpath represents the path from the network origin through all the addresses in the path to the selected company as displayed in the table. "
|
||||
]
|
||||
}
|
||||
],
|
||||
"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.9.15"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
||||
@@ -12,10 +12,10 @@ pd.set_option('display.max_rows', 150)
|
||||
|
||||
class Network:
|
||||
def __init__(self, officer_id=None, company_id=None, address=None):
|
||||
self.addresses = pd.DataFrame(columns=['address','n','link_type','node_type','node','lat','lon'])
|
||||
self.addresses = pd.DataFrame(columns=['address','lat','lon','n','link_type','node_type','node'])
|
||||
self.officer_ids = pd.DataFrame(columns=['officer_id','name','n','link_type','node_type','node'])
|
||||
self.company_ids = pd.DataFrame(columns=['company_id','n','link_type','node_type','node',])
|
||||
self.companies = pd.DataFrame(columns=['company_number','n'])
|
||||
self.companies = pd.DataFrame(columns=['company_number'])
|
||||
self.address_history = pd.DataFrame(columns=['company_number', 'address', 'start_date', 'end_date', 'lat', 'lon'])
|
||||
self._officer_id = officer_id
|
||||
self._company_id = company_id
|
||||
@@ -70,7 +70,7 @@ class Network:
|
||||
elif self.company_id:
|
||||
self.company_ids = self.company_ids.append({'company_id': self._company_id, 'n':self.n, 'link_type': None, 'node_type': None, 'node': None}, ignore_index=True)
|
||||
company = api.get_company(self._company_id)
|
||||
company['n'] = self.n
|
||||
# company['n'] = self.n
|
||||
company['link_type'] = self.link_type
|
||||
self.companies = self.companies.append(pd.json_normalize(company), ignore_index=True)
|
||||
elif self._address:
|
||||
@@ -78,6 +78,12 @@ class Network:
|
||||
else:
|
||||
print("No input provided. Please provide either officer_id, company_id or address value as input.")
|
||||
|
||||
def add_company_names(self):
|
||||
self.company_ids['name'] = ''
|
||||
for i, row in self.company_ids.iterrows():
|
||||
self.company_ids['name'][i] = self.companies.loc[self.companies['company_number'] == self.company_ids['company_id'][i]]['company_name'].unique()[0]
|
||||
self.company_ids = self.company_ids[['company_id', 'name', 'n', 'link_type', 'node_type', 'node']]
|
||||
|
||||
def get_company_from_id(self, company_df=None, company_id=None, print_progress=True):
|
||||
company_list = []
|
||||
if company_id:
|
||||
@@ -111,6 +117,7 @@ class Network:
|
||||
|
||||
def run_map_preprocessing(self):
|
||||
self.get_company_from_id()
|
||||
self.add_company_names()
|
||||
self.get_coords()
|
||||
return
|
||||
|
||||
|
||||
Reference in New Issue
Block a user