Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
from flask import Flask, render_template
from flask import Flask, render_template, request
from mapping.folium_map import *

app = Flask(__name__)

@app.route("/")
def home():
def index():
return render_template("home.html")

gdf = create_gdf()
m = generate_map_from_gdf(gdf, w=800, h=600)

m.get_root().width = "800px"
m.get_root().height = "600px"
iframe = m.get_root()._repr_html_()

return render_template("home.html", iframe=iframe)
@app.route("/slider_update", methods=["POST"])
def slider():
received_data = request.data
return received_data
6 changes: 4 additions & 2 deletions config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# App configs
window_width: 800
window_height: 600
width: 800
width_px: "800px"
height: 600
height_px: "600px"
32 changes: 32 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from mapping.folium_map import *
import yaml

def main():
"""
Produce all required map iframes
"""
# Load config
with open("config.yaml") as f:
config = yaml.safe_load(f)

# Loop through required years
for i in range(2014, 2025):
file_extension = str(i)

# Create map
geo_df = create_gdf(i)
m = generate_map_from_gdf(geo_df, w=config["width"], h=config["height"])

# Serve map to iframe
m.get_root().width = config["width_px"]
m.get_root().height = config["height_px"]
iframe = m.get_root()._repr_html_()

# Write out iframe to HTML
filename = f"map_{file_extension}.html"
html_file = open(f"static/{filename}", "w")
html_file.write(iframe)
html_file.close

if __name__ == "__main__":
main()
17 changes: 9 additions & 8 deletions mapping/folium_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,30 @@
import json
from mapping.prep_data import *

def create_gdf():
def create_gdf(period: int):
"""
Function to create a GeoPandas DataFrame from the spatial data file
and then merge feature data into it
# Todo: Control for inflation on wage data
"""

# Get feature data
lad_df = get_df_from_db()

# Data cleaning
lad_df_2024 = lad_df[lad_df["year"]==2024]
lad_df_2024 = lad_df_2024.dropna()
lad_df_2024["median_ann_pay"] = lad_df_2024["median_ann_pay"].astype("int64")
lad_df_filtered = lad_df[lad_df["year"]==period]
lad_df_filtered = lad_df_filtered.dropna()
lad_df_filtered["median_ann_pay"] = lad_df_filtered["median_ann_pay"].astype("int64")

# Get spatial data
gdf = geopandas.read_file("data/local_authority_district_boundaries.geojson")

# Join feature data on spatial data
gdf = gdf.merge(
lad_df_2024,
how="left",
left_on="LAD24NM",
right_on="lad"
lad_df_filtered,
how="left",
left_on="LAD24NM",
right_on="lad"
)

return gdf
Expand Down
187 changes: 187 additions & 0 deletions static/map_2014.html

Large diffs are not rendered by default.

187 changes: 187 additions & 0 deletions static/map_2015.html

Large diffs are not rendered by default.

187 changes: 187 additions & 0 deletions static/map_2016.html

Large diffs are not rendered by default.

187 changes: 187 additions & 0 deletions static/map_2017.html

Large diffs are not rendered by default.

187 changes: 187 additions & 0 deletions static/map_2018.html

Large diffs are not rendered by default.

187 changes: 187 additions & 0 deletions static/map_2019.html

Large diffs are not rendered by default.

187 changes: 187 additions & 0 deletions static/map_2020.html

Large diffs are not rendered by default.

187 changes: 187 additions & 0 deletions static/map_2021.html

Large diffs are not rendered by default.

187 changes: 187 additions & 0 deletions static/map_2022.html

Large diffs are not rendered by default.

187 changes: 187 additions & 0 deletions static/map_2023.html

Large diffs are not rendered by default.

187 changes: 187 additions & 0 deletions static/map_2024.html

Large diffs are not rendered by default.

Loading