diff --git a/dashboard/Sugartrail.ipynb b/dashboard/Sugartrail.ipynb index 27544a3..eac7d32 100644 --- a/dashboard/Sugartrail.ipynb +++ b/dashboard/Sugartrail.ipynb @@ -10,7 +10,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "id": "f17ebdd2", "metadata": {}, "outputs": [], @@ -24,7 +24,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "id": "cbc5e202", "metadata": {}, "outputs": [], @@ -43,10 +43,53 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 17, "id": "0632780b", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "4df7b16d214240ddbc7106f2e0120942", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Text(value='', placeholder='Insert API Key')" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "8f0467c4899241579255adfcd5d270db", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Button(description='Authenticate', style=ButtonStyle(button_color='#F5F5F5'))" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "f755529c26c44e8aa0a6c701f9270e0c", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "HTML(value='')" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "API_input = widgets.Text(\n", " value='',\n", @@ -64,10 +107,13 @@ " value=\"\",\n", ")\n", "\n", - "auth_button = widgets.Button(description='Authenticate',button_style='success')\n", + "\n", + "\n", + "auth_button = widgets.Button(description='Authenticate')\n", "auth_button.on_click(lambda bt: auth())\n", "\n", - "init_button = widgets.Button(description='Initialise',button_style='success', disabled=True)\n", + "init_button = widgets.Button(description='Initialise', disabled=True)\n", + "# init_button.style.button_color = '#696969'\n", "init_button.on_click(lambda bt: init_network()) \n", "\n", "def auth():\n", @@ -76,6 +122,7 @@ " api.basic_auth.username = API_input.value\n", " if api.test():\n", " auth_status.value = u'\\u2705: Login successful'\n", + " auth_button.button_style='success'\n", " company_text.disabled = False\n", " init_button.disabled = False\n", " else:\n", @@ -104,10 +151,53 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "id": "128106c5", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "09a265b50120419c83fbee18954959b8", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Text(value='', disabled=True, placeholder='Insert Company ID')" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "33909f0e627f48199089e9a66cb40e46", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Button(button_style='success', description='Initialise', disabled=True, style=ButtonStyle())" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "6cfca501106049db984df7a5edc72140", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "HTML(value='')" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "init_status = widgets.HTML(\n", " value=\"\",\n", @@ -116,37 +206,221 @@ "depth_selector = widgets.BoundedIntText(\n", " value=1,\n", " min=1,\n", - " max=5,\n", + " max=20,\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 = widgets.Button(description='Build Network', disabled=True)\n", "generate_network_button.on_click(lambda bt: generate_network()) \n", "\n", "def init_network():\n", " init_button.disabled=True\n", - " network.company_id = str(company_text.value)\n", - " response = api.get_company(network.company_id)\n", + " response = api.get_company(str(company_text.value))\n", " company_text.disabled=True\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", + " init_button.button_style='success'\n", + " navigation_button.disabled = False\n", " depth_selector.disabled = False\n", " generate_network_button.disabled = False\n", + " \n", " else:\n", " init_button.disabled=False\n", " company_text.disabled=False\n", - " init_status.value = u'\\u274c: Initialisation Failed. No records for company: ' + str(company_text.value) + ' found.'\n", + " init_status.value = u'\\u274c: Initialisation Failed. No records for company: ' + str(company_text.value)\n", "\n", "display(company_text, init_button, init_status)" ] }, + { + "cell_type": "markdown", + "id": "96ffe953", + "metadata": {}, + "source": [ + "3. Select the criteria you would like to build your network from (optional):" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "6eb9065a", + "metadata": {}, + "outputs": [], + "source": [ + "navigation_button = widgets.Button(description='Update', disabled=True)\n", + "navigation_button.on_click(lambda bt: config_network()) \n", + "\n", + "officers_for_company = widgets.Checkbox(\n", + " value=True,\n", + " description='Get officers for each company',\n", + " disabled=False,\n", + " indent=False\n", + ")\n", + "\n", + "historic_addresses = widgets.Checkbox(\n", + " value=True,\n", + " description='Get historic addresses for each company',\n", + " disabled=False,\n", + " indent=False\n", + ")\n", + "\n", + "psc_address = widgets.Checkbox(\n", + " value=True,\n", + " description='Get PSC addresses for each company',\n", + " disabled=False,\n", + " indent=False\n", + ")\n", + "\n", + "officer_appointments = widgets.Checkbox(\n", + " value=True,\n", + " description='Get appointments for each officer',\n", + " disabled=False,\n", + " indent=False\n", + ")\n", + "\n", + "max_appointments_inttext = widgets.IntText(\n", + " value=50,\n", + " disabled=False\n", + ")\n", + "\n", + "max_appointments = widgets.HBox([widgets.Label('Maximum number of appointments for each officer: '), max_appointments_inttext])\n", + "\n", + "officer_correspondance = widgets.Checkbox(\n", + " value=True,\n", + " description='Get correspondance address for each officer',\n", + " disabled=False,\n", + " indent=False\n", + ")\n", + "\n", + "duplicate_officers = widgets.Checkbox(\n", + " value=True,\n", + " description='Get duplicates for each officer',\n", + " disabled=False,\n", + " indent=False\n", + ")\n", + "\n", + "max_duplicates_inttext = widgets.IntText(\n", + " value=50,\n", + " disabled=False\n", + ")\n", + "\n", + "max_duplicates = widgets.HBox([widgets.Label('Maximum number of duplicate officers for each officer: '), max_duplicates_inttext])\n", + "\n", + "officers_for_address = widgets.Checkbox(\n", + " value=True,\n", + " description='Get officers at each address',\n", + " disabled=False,\n", + " indent=False\n", + ")\n", + "\n", + "max_officers_inttext = widgets.IntText(\n", + " value=50,\n", + " disabled=False\n", + ")\n", + "\n", + "max_officers_at_address = widgets.HBox([widgets.Label('Maximum number of officers corresponding from address: '), max_officers_inttext])\n", + "\n", + "companies_for_address = widgets.Checkbox(\n", + " value=True,\n", + " description='Get companies registered at each address',\n", + " disabled=False,\n", + " indent=False\n", + ")\n", + "\n", + "max_companies_inttext = widgets.IntText(\n", + " value=50,\n", + " disabled=False\n", + ")\n", + "\n", + "max_companies_at_address = widgets.HBox([widgets.Label('Maximum number of companies registered to address: '), max_companies_inttext])\n", + "\n", + "checkboxes = [officers_for_company, \n", + " historic_addresses, \n", + " psc_address, \n", + " officer_appointments, \n", + " max_appointments, \n", + " officer_correspondance,\n", + " duplicate_officers,\n", + " max_duplicates, \n", + " officers_for_address,\n", + " max_officers_at_address,\n", + " companies_for_address,\n", + " max_companies_at_address,\n", + " navigation_button\n", + " ]\n" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "7da39d70", + "metadata": {}, + "outputs": [], + "source": [ + "def config_network():\n", + " network.hop.get_company_officers = officers_for_company.value\n", + " network.hop.get_company_address_history = historic_addresses.value\n", + " network.hop.get_psc_correspondance_address = psc_address.value\n", + " network.hop.get_officer_appointments = officer_appointments.value\n", + " network.hop.officer_appointments_maxsize = max_appointments_inttext.value\n", + " network.hop.get_officer_correspondance_address = officer_correspondance.value\n", + " network.hop.get_officer_duplicates = duplicate_officers.value\n", + " network.hop.officer_duplicates_maxsize = max_duplicates_inttext.value\n", + " network.hop.get_officers_at_address = officers_for_address.value\n", + " network.hop.officers_at_address_maxsize = max_officers_inttext.value\n", + " network.hop.get_companies_at_address = companies_for_address.value\n", + " network.hop.companies_at_address_maxsize = max_companies_inttext.value\n", + " depth_selector.disabled = False\n", + " generate_network_button.disabled = False\n", + " navigation_button.disabled = True\n", + " navigation_button.button_style='success'" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "bec983fc", + "metadata": {}, + "outputs": [], + "source": [ + "accordion_config = widgets.Accordion(children=[widgets.VBox(checkboxes)])\n", + "accordion_config.set_title(0, 'Config')" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "1c68e6b4", + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "515ecf4ccec248a286bc98390cd9b90d", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Accordion(children=(VBox(children=(Checkbox(value=True, description='Get officers for each company', indent=Fa…" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "accordion_config" + ] + }, { "cell_type": "markdown", "id": "addafb36", "metadata": {}, "source": [ - "3. Select the depth of the network you would like to build:" + "4. Select the depth of the network you would like to build:" ] }, { @@ -160,7 +434,7 @@ " value=\"\",\n", ")\n", "\n", - "build_map_button=widgets.Button(description='Build Map',button_style='success', disabled=True)\n", + "build_map_button=widgets.Button(description='Build Map', disabled=True)\n", "build_map_button.on_click(lambda bt: generate_map()) \n", "\n", "def generate_network():\n", @@ -170,6 +444,7 @@ " network.perform_hop(depth_selector.value)\n", " network.run_map_preprocessing()\n", " build_map_button.disabled = False\n", + " generate_network_button.button_style = \"success\"\n", " \n", " \n", "output_box = widgets.Output()\n", @@ -181,7 +456,7 @@ "id": "03ffce05", "metadata": {}, "source": [ - "4. Visualise network on a map:" + "5. Visualise network on a map:" ] }, { @@ -231,6 +506,7 @@ " accordion_map.selected_index=0\n", " accordion_data.selected_index=0\n", " build_map_button.disabled = True\n", + " build_map_button.button_style = \"Success\"\n", " with tab.children[0]:\n", " display(pd.DataFrame(network.company_ids))\n", " with tab.children[1]:\n", @@ -296,7 +572,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.15" + "version": "3.10.4" } }, "nbformat": 4, diff --git a/sugartrail/base.py b/sugartrail/base.py index 71ed592..d922db7 100644 --- a/sugartrail/base.py +++ b/sugartrail/base.py @@ -168,6 +168,7 @@ class Network: self.companies.extend(companies) def run_map_preprocessing(self): + # merge some of these methods: self.update_address_history() self.get_company_from_id() self.add_company_names()