diff --git a/dashboard_code/dashboard.py b/dashboard_code/dashboard.py index aa39baa1e7b8388e53639c3efb9c50330a724d0f..1014dec2b9099255dc43984723957aea02e51c79 100644 --- a/dashboard_code/dashboard.py +++ b/dashboard_code/dashboard.py @@ -61,7 +61,7 @@ class Dashboard: margin-top: 20px; }} iframe {{ - height: 800px; /* Set a fixed height for the iframe */ + height: 1000px; /* Increase the height for better legibility */ width: 100%; }} </style> diff --git a/data_code/querys.py b/data_code/querys.py index db4791569249812c4c5c598d5c2b3873fbf0624b..0d936ceb74609e315e9c8cdf4aadef894297ded2 100644 --- a/data_code/querys.py +++ b/data_code/querys.py @@ -99,11 +99,9 @@ def Government_education_spending(): def uk_education_expenditure(): - # Use COALESCE to select the non-NULL value between 't_expenditure_millions' and 't_expenditure' education_expenditure = """ - SELECT time_period, t_expenditure_millions - FROM data - WHERE education_function = 'Total' AND expenditure_type = 'Total' AND expenditure_level = 'Total'; + SELECT time_period,time_identifier,geographic_level,country_code,country_name,education_function,expenditure_type,expenditure_level,t_expenditure_millions + FROM data; """ return education_expenditure @@ -116,7 +114,7 @@ def school_funding_uk_county(): def UK_crime_data(): crime_data = """ - SELECT Year, Area_Code, "Total recorded crime (excluding fraud) [note 2]" + SELECT Year, Area_Code, Area_Name, "Total recorded crime (excluding fraud) [note 2]","Violence against the person","Homicide","Violence with injury","Violence without injury","Sexual offences","Robbery","Theft offences","Burglary","Domestic burglary","Non-domestic burglary","Vehicle offences","Theft from the person","Bicycle theft","Shoplifting","All other theft offences","Criminal damage and arson","Drug offences","Possession of weapon offences","Public order offences","Miscellaneous crimes against society","Death or serious injury - unlawful driving","Stalking and harassment","Residential burglary","Non-residential burglary","Other theft offences","Possession of weapons offences","Miscellaneous crimes" FROM data; """ return crime_data diff --git a/data_storage/UK/Crime/combined_crime_uk.db b/data_storage/UK/Crime/combined_crime_uk.db index 0615d7721e562c20efb042a9dafbe04158ec42b4..1fa931e47c5be68062228d24ea0bb16fa9906c24 100644 Binary files a/data_storage/UK/Crime/combined_crime_uk.db and b/data_storage/UK/Crime/combined_crime_uk.db differ diff --git a/data_storage/UK/Education/education-and-training-statistics-for-the-uk_2024/data/uk_expenditure.db b/data_storage/UK/Education/education-and-training-statistics-for-the-uk_2024/data/uk_expenditure.db index 7001c7828c24da8f7ee7370e506f3a9a6a893a59..401c2b9032375f9b3bcdeee5e7d1a26ae4705cf4 100644 Binary files a/data_storage/UK/Education/education-and-training-statistics-for-the-uk_2024/data/uk_expenditure.db and b/data_storage/UK/Education/education-and-training-statistics-for-the-uk_2024/data/uk_expenditure.db differ diff --git a/data_storage/UK/Education/education-and-training-statistics-for-the-uk_2024/data/uk_highest_qualifications_time_series_rounded.db b/data_storage/UK/Education/education-and-training-statistics-for-the-uk_2024/data/uk_highest_qualifications_time_series_rounded.db index 111c7b6ab9e611127107942f5da22f1338d115ad..c3fd6a9aeb651b4d8cfe4b9126377138f5ad3c3b 100644 Binary files a/data_storage/UK/Education/education-and-training-statistics-for-the-uk_2024/data/uk_highest_qualifications_time_series_rounded.db and b/data_storage/UK/Education/education-and-training-statistics-for-the-uk_2024/data/uk_highest_qualifications_time_series_rounded.db differ diff --git a/data_storage/UK/Education/education-and-training-statistics-for-the-uk_2024/data/uk_neet.db b/data_storage/UK/Education/education-and-training-statistics-for-the-uk_2024/data/uk_neet.db index 29040517378d9ca9d38caab1d00fe330f49e89cf..7f616ede93ab26edd2635b957fa0677edfca5a5c 100644 Binary files a/data_storage/UK/Education/education-and-training-statistics-for-the-uk_2024/data/uk_neet.db and b/data_storage/UK/Education/education-and-training-statistics-for-the-uk_2024/data/uk_neet.db differ diff --git a/data_storage/UK/Education/education-and-training-statistics-for-the-uk_2024/data/uk_post_compulsory_education_fe_students.db b/data_storage/UK/Education/education-and-training-statistics-for-the-uk_2024/data/uk_post_compulsory_education_fe_students.db index b64775fbe80acba757ed6625c49738c339627dfd..4be305e4cf25173865811f5d3d082666ef23e183 100644 Binary files a/data_storage/UK/Education/education-and-training-statistics-for-the-uk_2024/data/uk_post_compulsory_education_fe_students.db and b/data_storage/UK/Education/education-and-training-statistics-for-the-uk_2024/data/uk_post_compulsory_education_fe_students.db differ diff --git a/data_storage/UK/Education/education-and-training-statistics-for-the-uk_2024/data/uk_post_compulsory_education_he_students.db b/data_storage/UK/Education/education-and-training-statistics-for-the-uk_2024/data/uk_post_compulsory_education_he_students.db index 078b61a92066709d80b6f76acb31fc22826f55c7..da2f3f18a6e2d38b8c6df98fe50cb6057456a554 100644 Binary files a/data_storage/UK/Education/education-and-training-statistics-for-the-uk_2024/data/uk_post_compulsory_education_he_students.db and b/data_storage/UK/Education/education-and-training-statistics-for-the-uk_2024/data/uk_post_compulsory_education_he_students.db differ diff --git a/data_storage/UK/Education/education-and-training-statistics-for-the-uk_2024/data/uk_post_compulsory_education_institutions.db b/data_storage/UK/Education/education-and-training-statistics-for-the-uk_2024/data/uk_post_compulsory_education_institutions.db index 263adac80813f0b930df99c0dc27cd62e815a414..99816aaac3e7cd7c9754e0786e91eaee0416167d 100644 Binary files a/data_storage/UK/Education/education-and-training-statistics-for-the-uk_2024/data/uk_post_compulsory_education_institutions.db and b/data_storage/UK/Education/education-and-training-statistics-for-the-uk_2024/data/uk_post_compulsory_education_institutions.db differ diff --git a/data_storage/UK/Education/education-and-training-statistics-for-the-uk_2024/data/uk_pupil_teacher_ratios.db b/data_storage/UK/Education/education-and-training-statistics-for-the-uk_2024/data/uk_pupil_teacher_ratios.db index 9eafbe81c581327a45ec3e2e1fb07329a6ad0fec..20a1e7fffbdd98c07469fbb8d57e3fcbc4e7ee04 100644 Binary files a/data_storage/UK/Education/education-and-training-statistics-for-the-uk_2024/data/uk_pupil_teacher_ratios.db and b/data_storage/UK/Education/education-and-training-statistics-for-the-uk_2024/data/uk_pupil_teacher_ratios.db differ diff --git a/data_storage/UK/Education/education-and-training-statistics-for-the-uk_2024/data/uk_pupils_suppressed.db b/data_storage/UK/Education/education-and-training-statistics-for-the-uk_2024/data/uk_pupils_suppressed.db index 0e451dc5b496e04d9dd673e6a12b6bfeccb62e72..6c8a6c544737a3043a8a9e2e2cca11a636829751 100644 Binary files a/data_storage/UK/Education/education-and-training-statistics-for-the-uk_2024/data/uk_pupils_suppressed.db and b/data_storage/UK/Education/education-and-training-statistics-for-the-uk_2024/data/uk_pupils_suppressed.db differ diff --git a/data_storage/UK/Education/education-and-training-statistics-for-the-uk_2024/data/uk_schools.db b/data_storage/UK/Education/education-and-training-statistics-for-the-uk_2024/data/uk_schools.db index 49d9c0b800ccb5d8c101e288b35af604f57382c9..6bef7ae78dc80444a04dd1dedf1a808ce465d285 100644 Binary files a/data_storage/UK/Education/education-and-training-statistics-for-the-uk_2024/data/uk_schools.db and b/data_storage/UK/Education/education-and-training-statistics-for-the-uk_2024/data/uk_schools.db differ diff --git a/data_storage/UK/Education/education-and-training-statistics-for-the-uk_2024/data/uk_teachers_suppressed.db b/data_storage/UK/Education/education-and-training-statistics-for-the-uk_2024/data/uk_teachers_suppressed.db index 5c30189713d501fdd6516bc29e052501e329778e..83ebb2ce70d2f061e0271da1fb40d5538d2ee77e 100644 Binary files a/data_storage/UK/Education/education-and-training-statistics-for-the-uk_2024/data/uk_teachers_suppressed.db and b/data_storage/UK/Education/education-and-training-statistics-for-the-uk_2024/data/uk_teachers_suppressed.db differ diff --git a/data_storage/UK/Education/la-and-school-expenditure_2023-24/data/cfr_income_la_regional_national.db b/data_storage/UK/Education/la-and-school-expenditure_2023-24/data/cfr_income_la_regional_national.db index bcfaaf97444048555412d7882ceead7686f76beb..ba706a9a89788bfd3d386f684f73cd1d84fa8fa2 100644 Binary files a/data_storage/UK/Education/la-and-school-expenditure_2023-24/data/cfr_income_la_regional_national.db and b/data_storage/UK/Education/la-and-school-expenditure_2023-24/data/cfr_income_la_regional_national.db differ diff --git a/data_storage/UK/Education/la-and-school-expenditure_2023-24/data/cfr_income_national_summary.db b/data_storage/UK/Education/la-and-school-expenditure_2023-24/data/cfr_income_national_summary.db index 61ff3416b18a5c5cb313c6ba7221ce0c86bf9020..6addce62c01f6d2559a9a2cda2e6d20c54447b59 100644 Binary files a/data_storage/UK/Education/la-and-school-expenditure_2023-24/data/cfr_income_national_summary.db and b/data_storage/UK/Education/la-and-school-expenditure_2023-24/data/cfr_income_national_summary.db differ diff --git a/data_storage/UK/Education/la-and-school-expenditure_2023-24/data/cfr_revenue_reserve_la_regional_national_data.db b/data_storage/UK/Education/la-and-school-expenditure_2023-24/data/cfr_revenue_reserve_la_regional_national_data.db index db728a6e6deb9d84cd1af2adc30641234fd34976..86e4bb347fccf46b0a9270eb565bc62f7947bbfb 100644 Binary files a/data_storage/UK/Education/la-and-school-expenditure_2023-24/data/cfr_revenue_reserve_la_regional_national_data.db and b/data_storage/UK/Education/la-and-school-expenditure_2023-24/data/cfr_revenue_reserve_la_regional_national_data.db differ diff --git a/data_storage/UK/Education/la-and-school-expenditure_2023-24/data/cfr_revenue_reserves_national_rounded_data.db b/data_storage/UK/Education/la-and-school-expenditure_2023-24/data/cfr_revenue_reserves_national_rounded_data.db index a9193ff2d8b1addd2330601fac6f1b74ad6decc9..8ff5b8304650dc242439b59bcaa85752ee838684 100644 Binary files a/data_storage/UK/Education/la-and-school-expenditure_2023-24/data/cfr_revenue_reserves_national_rounded_data.db and b/data_storage/UK/Education/la-and-school-expenditure_2023-24/data/cfr_revenue_reserves_national_rounded_data.db differ diff --git a/data_storage/UK/Education/la-and-school-expenditure_2023-24/data/headline_key_figures.db b/data_storage/UK/Education/la-and-school-expenditure_2023-24/data/headline_key_figures.db index e92e9be3e15bec0105952b996013e3ba42978b31..320ad3e621648f7d1280c7bcfc36f738b1deebc3 100644 Binary files a/data_storage/UK/Education/la-and-school-expenditure_2023-24/data/headline_key_figures.db and b/data_storage/UK/Education/la-and-school-expenditure_2023-24/data/headline_key_figures.db differ diff --git a/data_storage/UK/Education/la-and-school-expenditure_2023-24/data/s251_childrens_young_peoples_services_la_regional_national.db b/data_storage/UK/Education/la-and-school-expenditure_2023-24/data/s251_childrens_young_peoples_services_la_regional_national.db index 3835a0dd115c55ec79bc2de61a34cc8cff2a93d2..9237dd9f835178017225ef0c5c6a82e87151fa38 100644 Binary files a/data_storage/UK/Education/la-and-school-expenditure_2023-24/data/s251_childrens_young_peoples_services_la_regional_national.db and b/data_storage/UK/Education/la-and-school-expenditure_2023-24/data/s251_childrens_young_peoples_services_la_regional_national.db differ diff --git a/data_storage/UK/Education/la-and-school-expenditure_2023-24/data/s251_childrens_young_peoples_services_national.db b/data_storage/UK/Education/la-and-school-expenditure_2023-24/data/s251_childrens_young_peoples_services_national.db index 051f02b40887f5b69decae3ce68d4338a76af4a8..319f300bd8e4ec72d9898bf8e1f1ea180c5f7422 100644 Binary files a/data_storage/UK/Education/la-and-school-expenditure_2023-24/data/s251_childrens_young_peoples_services_national.db and b/data_storage/UK/Education/la-and-school-expenditure_2023-24/data/s251_childrens_young_peoples_services_national.db differ diff --git a/data_storage/UK/Education/school-funding-statistics_2023-24/data/20240125_fig2.db b/data_storage/UK/Education/school-funding-statistics_2023-24/data/20240125_fig2.db index 1f7a70264693ff20f838c788d182484dbc2669fd..5b6509a28e58b2dba3efe95b1878a2e26ba2cf06 100644 Binary files a/data_storage/UK/Education/school-funding-statistics_2023-24/data/20240125_fig2.db and b/data_storage/UK/Education/school-funding-statistics_2023-24/data/20240125_fig2.db differ diff --git a/data_storage/UK/Education/school-funding-statistics_2023-24/data/20240125_school_level_data_csv.db b/data_storage/UK/Education/school-funding-statistics_2023-24/data/20240125_school_level_data_csv.db index 4d769a65f4a4f2bfb987a7e68c2dc6af98991f81..2ca3897c68d908e382e129c5e26230e39a4d22db 100644 Binary files a/data_storage/UK/Education/school-funding-statistics_2023-24/data/20240125_school_level_data_csv.db and b/data_storage/UK/Education/school-funding-statistics_2023-24/data/20240125_school_level_data_csv.db differ diff --git a/data_storage/UK/Education/school-funding-statistics_2023-24/data/20240125_tab1.db b/data_storage/UK/Education/school-funding-statistics_2023-24/data/20240125_tab1.db index 726d3dc00454eec4591610e66852c080a15cc73f..98ab82ed834f8c36b3e69833c28639e96e8ba6b8 100644 Binary files a/data_storage/UK/Education/school-funding-statistics_2023-24/data/20240125_tab1.db and b/data_storage/UK/Education/school-funding-statistics_2023-24/data/20240125_tab1.db differ diff --git a/data_storage/UN/Crime/SYB67_328_202411_Intentional homicides and other crimes.db b/data_storage/UN/Crime/SYB67_328_202411_Intentional homicides and other crimes.db index 369406d766e7136894581bf3c58c65be650d089d..62acbcaa03cdc4369423e94b4ad0333bc0ffe18c 100644 Binary files a/data_storage/UN/Crime/SYB67_328_202411_Intentional homicides and other crimes.db and b/data_storage/UN/Crime/SYB67_328_202411_Intentional homicides and other crimes.db differ diff --git a/data_storage/UN/Economy/Government_final_consumption_expenditure_by_function_at_current_prices.db b/data_storage/UN/Economy/Government_final_consumption_expenditure_by_function_at_current_prices.db index e526d48ab28d8bc1b84b84d2ea545adc13f58973..f2d38ae15b2ea0522cf6d2fae5403c243c77f2b5 100644 Binary files a/data_storage/UN/Economy/Government_final_consumption_expenditure_by_function_at_current_prices.db and b/data_storage/UN/Economy/Government_final_consumption_expenditure_by_function_at_current_prices.db differ diff --git a/data_storage/UN/Economy/SYB67_128_202411_Consumer Price Index.db b/data_storage/UN/Economy/SYB67_128_202411_Consumer Price Index.db index ee7474727d98c79900e5461ad6c216a487272fe6..9dede1162fbcf535175e3830c9477428cfa22c6b 100644 Binary files a/data_storage/UN/Economy/SYB67_128_202411_Consumer Price Index.db and b/data_storage/UN/Economy/SYB67_128_202411_Consumer Price Index.db differ diff --git a/data_storage/UN/Economy/SYB67_230_202411_GDP and GDP Per Capita.db b/data_storage/UN/Economy/SYB67_230_202411_GDP and GDP Per Capita.db index e4a71b9c9fd670988f3eafcaedea0891e652cc03..b5881ceecc6fa1f395d3b30543c2b6e3522a3920 100644 Binary files a/data_storage/UN/Economy/SYB67_230_202411_GDP and GDP Per Capita.db and b/data_storage/UN/Economy/SYB67_230_202411_GDP and GDP Per Capita.db differ diff --git a/data_storage/UN/Education/SYB67_245_202411_Public expenditure on education and access to computers.db b/data_storage/UN/Education/SYB67_245_202411_Public expenditure on education and access to computers.db index 4d62e02dffc33fa06cd307933b75969afb655765..cf517ea1e4f6a97222db59608d2b032380d9d1ca 100644 Binary files a/data_storage/UN/Education/SYB67_245_202411_Public expenditure on education and access to computers.db and b/data_storage/UN/Education/SYB67_245_202411_Public expenditure on education and access to computers.db differ diff --git a/data_storage/UN/Education/SYB67_309_202411_Education.db b/data_storage/UN/Education/SYB67_309_202411_Education.db index 6d62f3e4f23da7d616f4cfb4870445920c97fff2..ecdd1175f9badca82aae2e93a69759943bc93695 100644 Binary files a/data_storage/UN/Education/SYB67_309_202411_Education.db and b/data_storage/UN/Education/SYB67_309_202411_Education.db differ diff --git a/data_storage/UN/Education/SYB67_323_202411_Teaching Staff in education.db b/data_storage/UN/Education/SYB67_323_202411_Teaching Staff in education.db index dab483bbfa03b8937d7c9cc32f1697df3ce56cec..5dad2fc5f996cc85137162892b124e05dbd51912 100644 Binary files a/data_storage/UN/Education/SYB67_323_202411_Teaching Staff in education.db and b/data_storage/UN/Education/SYB67_323_202411_Teaching Staff in education.db differ diff --git a/data_storage/UN/Gender/SYB67_319_202411_Ratio of girls to boys in education.db b/data_storage/UN/Gender/SYB67_319_202411_Ratio of girls to boys in education.db index c3b395b4759559fe758ddef21d0a40252288636f..dedea0417b55292f91c8992b5d30f4465f5b0de3 100644 Binary files a/data_storage/UN/Gender/SYB67_319_202411_Ratio of girls to boys in education.db and b/data_storage/UN/Gender/SYB67_319_202411_Ratio of girls to boys in education.db differ diff --git a/data_storage/UN/Health/SYB67_154_202411_Health Personnel.db b/data_storage/UN/Health/SYB67_154_202411_Health Personnel.db index c3dbd60fdd70b14960fc1254be00a7d5dcd6f424..ffdfbcabbb0e282d6d42903dc4533dd16a9675ea 100644 Binary files a/data_storage/UN/Health/SYB67_154_202411_Health Personnel.db and b/data_storage/UN/Health/SYB67_154_202411_Health Personnel.db differ diff --git a/data_storage/UN/Health/SYB67_325_202411_Expenditure on health.db b/data_storage/UN/Health/SYB67_325_202411_Expenditure on health.db index 89f37d7a4cd3ad3349984bf2c1131c6efdd92997..b0623d80acf8e2c2971df9dcb0ccdae94fed0fab 100644 Binary files a/data_storage/UN/Health/SYB67_325_202411_Expenditure on health.db and b/data_storage/UN/Health/SYB67_325_202411_Expenditure on health.db differ diff --git a/data_storage/UN/Internet/SYB67_314_202411_Internet Usage.db b/data_storage/UN/Internet/SYB67_314_202411_Internet Usage.db index 9b5e6ddc08326dc8ddbc2f6003486fd79ae077ea..6d4fd3d6e6f951dc1eb4ed759a94f75558a495ab 100644 Binary files a/data_storage/UN/Internet/SYB67_314_202411_Internet Usage.db and b/data_storage/UN/Internet/SYB67_314_202411_Internet Usage.db differ diff --git a/data_storage/UN/Labour/SYB67_200_202411_Employment.db b/data_storage/UN/Labour/SYB67_200_202411_Employment.db index ec7c161ea6c2c0763268029bf35bff041b2b923d..a62a431708dcf8ecdc7454587d79cddae14b8316 100644 Binary files a/data_storage/UN/Labour/SYB67_200_202411_Employment.db and b/data_storage/UN/Labour/SYB67_200_202411_Employment.db differ diff --git a/data_storage/UN/Labour/SYB67_329_202411_Labour Force and Unemployment.db b/data_storage/UN/Labour/SYB67_329_202411_Labour Force and Unemployment.db index d3fda4ef93ba8794f72b46efa62bf5da451bcd84..28fe87461d33adddf9757e9d6afc4fc39d23bae3 100644 Binary files a/data_storage/UN/Labour/SYB67_329_202411_Labour Force and Unemployment.db and b/data_storage/UN/Labour/SYB67_329_202411_Labour Force and Unemployment.db differ diff --git a/data_storage/UN/Land/SYB67_145_202411_Land.db b/data_storage/UN/Land/SYB67_145_202411_Land.db index 2decbc93c86bbc0c1ad163be0a67a8eebc770d1e..72782573fe79abc40bf536b632d103d63b0fd2c5 100644 Binary files a/data_storage/UN/Land/SYB67_145_202411_Land.db and b/data_storage/UN/Land/SYB67_145_202411_Land.db differ diff --git a/graphs/graphs_display.html b/graphs/graphs_display.html index f90c0533bec1a30317c061cbc3e8ba9bb99ab195..534b003b085422104ea35cd598b56daa0b7fc06f 100644 Binary files a/graphs/graphs_display.html and b/graphs/graphs_display.html differ diff --git a/main.py b/main.py index 4c846809688e6e896279c508b46c3cd734a7c709..040d1ba45abd4a48aa862eff69eee9bf388d6c1d 100644 --- a/main.py +++ b/main.py @@ -10,6 +10,8 @@ import warnings import webbrowser import os import statsmodels.api as sm +import plotly.graph_objects as go + # Ignore deprecation warnings @@ -30,7 +32,6 @@ table_list_UK = sql_t_UK.list_db(verbose=False) def combined_graph(): - import plotly.graph_objects as go male_homicide_rate_query = querys.male_homicide_rate() @@ -320,126 +321,272 @@ def combined_choropleth(): def graph8(): - - - # Load the GeoJSON file - gpkg_path = "UK_Choropleth/Counties_and_Unitary_Authorities_May_2023_UK_BGC_-5421515367278074247.gpkg" - counties = gpd.read_file(gpkg_path) - #print(counties.head()) - - # Reproject to WGS 84 (EPSG:4326) - counties = counties.to_crs(epsg=4326) - - # Convert GeoDataFrame to GeoJSON - counties_json = json.loads(counties.to_json()) - - # Create a DataFrame with the necessary data - data = { - "CTYUA23CD": [feature["properties"]["CTYUA23CD"] for feature in counties_json["features"]], - "CTYUA23NM": [feature["properties"]["CTYUA23NM"] for feature in counties_json["features"]] - } - data = pd.DataFrame(data) - - # Join school funding on CTYUA23CD and la_name - school_funding_query = querys.school_funding_uk_county() - school_funding = sql_t_UK.query_db(school_funding_query, table_name="20240125_school_level_data_csv.db") - school_funding = school_funding.rename(columns={"new_la_code": "CTYUA23CD"}) - - school_funding = school_funding.groupby("CTYUA23CD", as_index=False)["total_funding"].mean() - - # Merge and keep all columns from the original data and add total_funding - data = data.merge(school_funding[['CTYUA23CD', 'total_funding']], on="CTYUA23CD", how="left") - - #print(data.head()) - - # Create Plotly choropleth map - fig = px.choropleth_mapbox( - data, - geojson=counties_json, - locations="CTYUA23CD", - featureidkey="properties.CTYUA23CD", - color="total_funding", # Change this to the column you want to color by - hover_name="CTYUA23NM", # Column to display on hover - hover_data=["CTYUA23CD", "total_funding"], # Additional data to display on hover - mapbox_style="carto-positron", # Use a less detailed mapbox style - title="Average Funding of Schools Per Local Area Code", # Title of the map - labels={"total_funding": "Average Funding Per School"}, # Label for the color scale - zoom=5, - center={"lat": 54.0, "lon": -2.0}, - opacity=1 + # Query the education expenditure data + education_expenditure_query = querys.uk_education_expenditure() + education_expenditure = sql_t_UK.query_db(education_expenditure_query, table_name="uk_expenditure.db") + + # Convert time_period to a standard year format + education_expenditure["time_period"] = education_expenditure["time_period"].astype(str).str[:4] + education_expenditure["time_period"] = pd.to_numeric(education_expenditure["time_period"], errors="coerce") + + # Filter only 'Total' expenditure type to avoid double-counting + education_expenditure = education_expenditure[education_expenditure["expenditure_type"] == "Total"] + + # Ensure the data is sorted by time_period + education_expenditure = education_expenditure.sort_values(by="time_period") + + # Remove non-numeric or missing values in t_expenditure_millions + education_expenditure["t_expenditure_millions"] = pd.to_numeric(education_expenditure["t_expenditure_millions"], errors="coerce") + education_expenditure = education_expenditure.dropna(subset=["t_expenditure_millions"]) + + # Group by time_period and education_function to get the total expenditure + grouped_df = education_expenditure.groupby(["time_period", "education_function"], as_index=False)["t_expenditure_millions"].sum() + + # Create a stacked bar chart by year + fig = px.bar( + grouped_df, + x="time_period", + y="t_expenditure_millions", + color="education_function", + barmode="stack", + labels={"time_period": "Year", "t_expenditure_millions": "Expenditure (Millions)"}, + title="UK Education Spending" + ) + + + # Update the y-axis to have regular intervals + fig.update_layout( + yaxis=dict( + tickmode='linear', + tick0=0, + dtick=100000 # Set the interval for y-axis ticks + ), + xaxis_title="Financial Year", + yaxis_title="Total Expenditure (Millions)" ) - - # # Show plot return fig - - -def graph9(): - - - # Load the GeoJSON file +def graph9(): # CRIME MAP + # Load GeoDataFrame gpkg_path = "UK_Choropleth/Police_Force_Areas_December_2022_EW_BFE_4519315402050042056.geojson" - counties = gpd.read_file(gpkg_path) - #print(counties.head()) - # Reproject to WGS 84 (EPSG:4326) - counties = counties.to_crs(epsg=4326) - - # Convert GeoDataFrame to GeoJSON + counties = gpd.read_file(gpkg_path).to_crs(epsg=4326) pfa_json = json.loads(counties.to_json()) - # Create a DataFrame with the necessary data - data = { - "PFA22CD": [feature["properties"]["PFA22CD"] for feature in pfa_json["features"]], - "PFA22NM": [feature["properties"]["PFA22NM"] for feature in pfa_json["features"]] - } - data = pd.DataFrame(data) - - # Get crime statistics + data = pd.DataFrame({ + "PFA22CD": [feat["properties"]["PFA22CD"] for feat in pfa_json["features"]], + "PFA22NM": [feat["properties"]["PFA22NM"] for feat in pfa_json["features"]] + }) + + # Query + rename crime_data_query = querys.UK_crime_data() crime_data = sql_t_UK.query_db(crime_data_query, table_name="combined_crime_uk.db") crime_data = crime_data.rename(columns={"Area_Code": "PFA22CD"}) - - # Clean up my crime_data before grouping - crime_data["Total recorded crime (excluding fraud) [note 2]"] = pd.to_numeric( - crime_data["Total recorded crime (excluding fraud) [note 2]"], - errors="coerce" + + # Use your full list of columns + + crime_columns = [ + "Total recorded crime (excluding fraud) [note 2]", + "Violence against the person", "Homicide", "Violence with injury", + "Violence without injury", "Sexual offences", "Robbery", "Theft offences", + "Burglary", "Domestic burglary", "Non-domestic burglary", "Vehicle offences", + "Theft from the person", "Bicycle theft", "Shoplifting", "All other theft offences", + "Criminal damage and arson", "Drug offences", "Possession of weapon offences", + "Public order offences", "Miscellaneous crimes against society", + "Death or serious injury - unlawful driving", "Stalking and harassment", + "Residential burglary", "Non-residential burglary", "Other theft offences", + "Possession of weapons offences", "Miscellaneous crimes" + ] + + # Convert columns to numeric, group + average + for col in crime_columns: + if col in crime_data.columns: + crime_data[col] = pd.to_numeric(crime_data[col], errors="coerce") + grouped_df = crime_data.groupby("PFA22CD", as_index=False)[crime_columns].mean() + + # Merge + data = data.merge(grouped_df, on="PFA22CD", how="left") + + # Create one trace initially (e.g. default to your first column) + default_col = crime_columns[0] + fig = go.Figure( + go.Choroplethmapbox( + geojson=pfa_json, + locations=data["PFA22NM"], + featureidkey="properties.PFA22NM", + z=data[default_col], + colorscale="Reds", + zmin=0, + zmax=data[default_col].max(skipna=True) or 0, + marker_line_width=0.5, + marker_line_color="gray", + hovertemplate="Police Force: %{location}<br>" + default_col + ": %{z}" + ) ) - # Now group and average - crime_data = crime_data.groupby("PFA22CD", as_index=False)[ - "Total recorded crime (excluding fraud) [note 2]" - ].mean() + # Build update menu with each column + buttons = [] + for col in crime_columns: + buttons.append( + dict( + label=col, + method="restyle", + args=[ + {"z": [data[col].fillna(0)], # new z array + "hovertemplate": [f"Police Force: %{{location}}<br>{col}: %{{z}}"], + "zmax": [float(data[col].max(skipna=True) or 0)] + } + ], + ) + ) - - data = data.merge(crime_data[['PFA22CD', 'Total recorded crime (excluding fraud) [note 2]']], on="PFA22CD", how="left") + fig.update_layout( + mapbox_style="carto-positron", + mapbox_zoom=5, + mapbox_center={"lat": 54.0, "lon": -2.0}, + margin={"r": 0, "t": 50, "l": 0, "b": 0}, + updatemenus=[ + dict( + buttons=buttons, + direction="down", + showactive=True, + x=0.02, + xanchor="left", + y=0.98, + yanchor="top" + ) + ], + title=f"UK Crime Map: {default_col}" + ) + return fig - +def graph10(): + # Query the crime data + crime_data_query = querys.UK_crime_data() + crime_data = sql_t_UK.query_db(crime_data_query, table_name="combined_crime_uk.db") - # Create Plotly choropleth map - fig = px.choropleth_mapbox( - data, - geojson=pfa_json, - locations="PFA22NM", - featureidkey="properties.PFA22NM", - color="Total recorded crime (excluding fraud) [note 2]", # Change this to the column you want to color by - hover_name="PFA22NM", # Column to display on hover - hover_data=["PFA22NM", "Total recorded crime (excluding fraud) [note 2]"], # Additional data to display on hover - mapbox_style="carto-positron", # Use a less detailed mapbox style - title="Total Recorded Crime", # Title of the map - labels={"Total recorded crime (excluding fraud) [note 2]": "Total Recorded Crime"}, # Label for the color scale - zoom=5, - center={"lat": 54.0, "lon": -2.0}, - opacity=1 + # List of crime columns + crime_columns = [ + "Total recorded crime (excluding fraud) [note 2]", + "Violence against the person", "Homicide", "Violence with injury", + "Violence without injury", "Sexual offences", "Robbery", "Theft offences", + "Burglary", "Domestic burglary", "Non-domestic burglary", "Vehicle offences", + "Theft from the person", "Bicycle theft", "Shoplifting", "All other theft offences", + "Criminal damage and arson", "Drug offences", "Possession of weapon offences", + "Public order offences", "Miscellaneous crimes against society", + "Death or serious injury - unlawful driving", "Stalking and harassment", + "Residential burglary", "Non-residential burglary", "Other theft offences", + "Possession of weapons offences", "Miscellaneous crimes" + ] + + # Convert columns to numeric + for col in crime_columns: + if col in crime_data.columns: + crime_data[col] = pd.to_numeric(crime_data[col], errors="coerce") + + # Ensure the data is sorted by Year + crime_data = crime_data.sort_values(by="Year") + + # Remove non-numeric or missing values in Year + crime_data["Year"] = pd.to_numeric(crime_data["Year"], errors="coerce") + crime_data = crime_data.dropna(subset=["Year"]) + + # Group by year + grouped_df = crime_data.groupby(["Year"], as_index=False)["Total recorded crime (excluding fraud) [note 2]"].sum() + # Create a line chart by year + fig = px.line( + grouped_df, + x="Year", + y="Total recorded crime (excluding fraud) [note 2]", + labels={"Year": "Year", "Total recorded crime (excluding fraud) [note 2]": "Total Crime"}, + title="Total Recorded Crime Over Time by Area" ) + return fig + +def graph11(): + # Query the crime data + crime_data_query = querys.UK_crime_data() + crime_data = sql_t_UK.query_db(crime_data_query, table_name="combined_crime_uk.db") - # # Show plot - return fig + # List of crime columns (excluding the total recorded crime column) + crime_columns = [ + "Violence against the person", "Homicide", "Violence with injury", + "Violence without injury", "Sexual offences", "Robbery", "Theft offences", + "Burglary", "Domestic burglary", "Non-domestic burglary", "Vehicle offences", + "Theft from the person", "Bicycle theft", "Shoplifting", "All other theft offences", + "Criminal damage and arson", "Drug offences", "Possession of weapon offences", + "Public order offences", "Miscellaneous crimes against society", + "Death or serious injury - unlawful driving", "Stalking and harassment", + "Residential burglary", "Non-residential burglary", "Other theft offences", + "Possession of weapons offences", "Miscellaneous crimes" + ] + # Convert columns to numeric + for col in crime_columns: + if col in crime_data.columns: + crime_data[col] = pd.to_numeric(crime_data[col], errors="coerce") + + # Ensure the data is sorted by Year + crime_data = crime_data.sort_values(by="Year") + + # Remove non-numeric or missing values in Year + crime_data["Year"] = pd.to_numeric(crime_data["Year"], errors="coerce") + crime_data = crime_data.dropna(subset=["Year"]) + + # Create frames for the animation + frames = [] + for year in crime_data["Year"].unique(): + year_data = crime_data[crime_data["Year"] == year] + year_data = year_data[crime_columns].sum().reset_index() + year_data.columns = ["Crime Type", "Count"] + + frames.append(go.Frame( + data=[go.Pie(labels=year_data["Crime Type"], values=year_data["Count"], pull=[0]*len(year_data), textinfo="none")], + name=str(year) + )) + + # Create the initial pie chart + initial_year = crime_data["Year"].unique()[0] + initial_data = crime_data[crime_data["Year"] == initial_year] + initial_data = initial_data[crime_columns].sum().reset_index() + initial_data.columns = ["Crime Type", "Count"] + + fig = go.Figure( + data=[go.Pie(labels=initial_data["Crime Type"], values=initial_data["Count"], pull=[0]*len(initial_data), textinfo="none")], + layout=go.Layout( + title=f"Crime Distribution for {initial_year}", + updatemenus=[dict( + type="buttons", + showactive=False, + buttons=[dict(label="Play", + method="animate", + args=[None, {"frame": {"duration": 1000, "redraw": True}, "fromcurrent": True}]), + dict(label="Pause", + method="animate", + args=[[None], {"frame": {"duration": 0, "redraw": False}, "mode": "immediate"}])] + )], + sliders=[{ + "steps": [ + {"args": [[str(year)], {"frame": {"duration": 1000, "redraw": True}, "mode": "immediate"}], + "label": str(year), + "method": "animate"} for year in crime_data["Year"].unique() + ], + "transition": {"duration": 300}, + "x": 0.1, + "xanchor": "left", + "y": 0, + "yanchor": "top" + }] + ), + frames=frames + ) + + return fig + @@ -462,8 +609,10 @@ if __name__ == "__main__": graphs = [ ("Combined Choropleth", combined_choropleth, "UN"), ("Combined Test", combined_graph, "UN"), - ("Average Funding of Schools Per Local Area Code", graph8, "UK"), - ("Total Recorded Crime", graph9, "UK"), + ("Total Recorded Crime 2015-2024", graph9, "UK"), + ("UK Education Expendature", graph8, "UK"), + ("UK Crime Bar Chart", graph10, "UK"), + ("Distribution of Crime Types", graph11, "UK") ] # Add each graph to the dashboard with a progress bar