Skip to content

Commit

Permalink
Merge pull request #52 from the-scouts/misc-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
AA-Turner authored May 13, 2020
2 parents 6f6626b + c0193ab commit bdabcca
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
12 changes: 6 additions & 6 deletions src/data/ons_pd_may_19.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def __init__(self, ons_pd_csv_path, load_data=True):
"name": "oslaua",
"codes": {
"path": names_codes_root / "LA_UA names and codes UK as at 12_19.csv",
"key": "LAD19CD", "key_type": "object",
"key": "LAD19CD", "key_type": "string",
"name": "LAD19NM",
},
"boundary": {"shapefile": shapefile_paths["LADs"], "key": "lad19cd", "name": "lad19nm", },
Expand All @@ -90,7 +90,7 @@ def __init__(self, ons_pd_csv_path, load_data=True):
"name": "oslaua",
"codes": {
"path": names_codes_root / "LA_UA names and codes UK as at 12_19.csv",
"key": "LAD19CD", "key_type": "object",
"key": "LAD19CD", "key_type": "string",
"name": "LAD19NM",
},
"boundary": {"shapefile": shapefile_paths["County"], "key": "ctyua17cd", "name": "ctyua17nm", },
Expand All @@ -101,7 +101,7 @@ def __init__(self, ons_pd_csv_path, load_data=True):
"name": "osward",
"codes": {
"path": names_codes_root / "Ward names and codes UK as at 05_19_NSPD.csv",
"key": "WD19CD", "key_type": "object",
"key": "WD19CD", "key_type": "string",
"name": "WD19NM",
},
"boundary": {"shapefile": shapefile_paths["Ward"], "key": "wd19cd", "name": "wd19nm", },
Expand All @@ -112,7 +112,7 @@ def __init__(self, ons_pd_csv_path, load_data=True):
"name": "pcon",
"codes": {
"path": names_codes_root / "Westminster Parliamentary Constituency names and codes UK as at 12_14.csv",
"key": "PCON14CD", "key_type": "object",
"key": "PCON14CD", "key_type": "string",
"name": "PCON14NM",
},
"boundary": {"shapefile": shapefile_paths["PCon"], "key": "pcon17cd", "name": "pcon17nm", },
Expand All @@ -123,7 +123,7 @@ def __init__(self, ons_pd_csv_path, load_data=True):
"name": "lsoa11",
"codes": {
"path": names_codes_root / "LSOA (2011) names and codes UK as at 12_12.csv",
"key": "LSOA11CD", "key_type": "object",
"key": "LSOA11CD", "key_type": "string",
"name": "LSOA11NM",
},
"boundary": {"shapefile": shapefile_paths["LSOA"], "key": "LSOA11CD", "name": "LSOA11NM", },
Expand All @@ -134,7 +134,7 @@ def __init__(self, ons_pd_csv_path, load_data=True):
"name": "msoa",
"codes": {
"path": names_codes_root / "MSOA (2011) names and codes UK as at 12_12.csv",
"key": "MSOA11CD", "key_type": "object",
"key": "MSOA11CD", "key_type": "string",
"name": "MSOA11NM",
},
"boundary": {"shapefile": shapefile_paths["MSOA"], "key": "msoa11cd", "name": None, },
Expand Down
6 changes: 3 additions & 3 deletions src/maps/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ def add_meeting_places_to_map(self, sections: pd.DataFrame, colour, marker_data:
sections["marker_colour"] = colour

# Areas outside the region_of_colour have markers coloured grey
if self.region_of_colour:
sections.loc[~sections[self.region_of_colour["column"]].isin(self.region_of_colour["value_list"]), "marker_colour"] = "gray"
if self._region_of_colour:
sections.loc[~sections[self._region_of_colour["column"]].isin(self._region_of_colour["value_list"]), "marker_colour"] = "gray"

# fmt: off
sections_info_table = pd.DataFrame({
Expand Down Expand Up @@ -218,7 +218,7 @@ def add_meeting_places_to_map(self, sections: pd.DataFrame, colour, marker_data:

# Fixes physical size of popup
popup = folium.Popup(html, max_width=2650)
self._map_plotter.add_marker(lat, long, popup, marker_colour, layer)
self._map_plotter.add_marker(lat, long, popup, marker_colour, layer["name"])

def add_sections_to_map(self, scout_data_object: ScoutData, colour, marker_data: list, single_section: str = None, layer: str = "Sections", cluster_markers: bool = False):
"""Filter sections and add to map.
Expand Down
8 changes: 4 additions & 4 deletions src/maps/map_plotter.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from __future__ import annotations
import folium
from folium.plugins import MarkerCluster
from folium.map import FeatureGroup
import geopandas as gpd
import pandas as pd
import webbrowser
import os

from src.reports.reports import Reports
from src.base import Base
Expand Down Expand Up @@ -34,7 +34,7 @@ class MapPlotter(Base):
def __init__(self, out_file: Path):
super().__init__()

self.out_file: Path = out_file.with_suffix(".html")
self.out_file: Path = out_file.with_suffix(".html").resolve()

# Create folium map
self.map: folium.Map = folium.Map(location=[53.5, -1.49], zoom_start=6)
Expand Down Expand Up @@ -185,8 +185,8 @@ def save(self):
"""Saves the folium map to a HTML file """
# Add layer control to map
folium.LayerControl(collapsed=False).add_to(self.map)
self.map.save(self.out_file)
self.map.save(f"{self.out_file}")

def show(self):
"""Show the file at self.out_file in the default browser. """
webbrowser.open(self.out_file.resolve().as_uri())
webbrowser.open(self.out_file.as_uri())
3 changes: 2 additions & 1 deletion src/reports/reports.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import annotations
import pandas as pd
import collections

Expand Down Expand Up @@ -261,7 +262,7 @@ def _awards_per_region(district_records, district_nums) -> dict:

# areas_data holds area names and codes for each area
# Area names column is Name and area codes column is the geography type
areas_data: pd.DataFrame = (self.geography.geography_region_ids_mapping.copy().rename(columns=renamed_cols_dict).reset_index(drop=True))
areas_data: pd.DataFrame = self.geography.geography_region_ids_mapping.copy().rename(columns=renamed_cols_dict).reset_index(drop=True)

merged_dataframes = pd.concat(dataframes, axis=1)
output_data = areas_data.merge(merged_dataframes, how="left", left_on=geog_name, right_index=True, sort=False)
Expand Down

0 comments on commit bdabcca

Please sign in to comment.