diff --git a/dashboard_code/dashboard.py b/dashboard_code/dashboard.py index 9c9550d9546b1ceb3d160c0aade5d876e2d16bda..0635112efece43156a9327441b583bc245bdb506 100644 --- a/dashboard_code/dashboard.py +++ b/dashboard_code/dashboard.py @@ -8,7 +8,10 @@ class Dashboard: self.home_graphs = [] # Store the graphs that should also appear on the home page def add_graph(self, group_name, category_name, fig, title): - graph_html = pio.to_html(fig, full_html=False) + # Make the figure responsive + fig.update_layout(autosize=True) + graph_html = pio.to_html(fig, full_html=False, config={"responsive": True}) + # Always add to group pages if group_name not in self.graph_groups: self.graph_groups[group_name] = {} @@ -16,9 +19,9 @@ class Dashboard: self.graph_groups[group_name][category_name] = [] self.graph_groups[group_name][category_name].append((title, graph_html)) + graph_home_html = pio.to_html(fig, full_html=False, config={"responsive": True}) # Add to home page if it’s one of these choropleths - if title in ["Combined Choropleth", "Total Recorded Crime 2015-2024"]: - graph_home_html = pio.to_html(fig, full_html=False) + if title == "Map of World Crime": self.home_graphs.append((title, graph_home_html)) def generate_html(self, output_path="dashboard_code/graphs_display.html"): @@ -48,6 +51,18 @@ class Dashboard: border-radius: 5px; box-shadow: 0 2px 5px rgba(0,0,0,0.1); margin-bottom: 30px; + width: 100%; + height: 80%; + }} + .home-graph-container {{ + background: #fff; + color: #000; + padding: 20px; + border-radius: 5px; + box-shadow: 0 2px 5px rgba(0,0,0,0.1); + margin-bottom: 30px; + width: 100%; + height: 100%; /* Adjust the height as needed */ }} .nav-tabs .nav-link {{ color: #f8f9fa; @@ -69,7 +84,7 @@ class Dashboard: }} iframe {{ width: 100%; - height: 1000px; + height: 100%; }} .plotly-graph {{ font-size: 16px; @@ -102,6 +117,17 @@ class Dashboard: <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"> </script> + <script> + window.addEventListener('load', function() {{ + window.dispatchEvent(new Event('resize')); + }}); + var triggerTabList = [].slice.call(document.querySelectorAll('#myTab button')) + triggerTabList.forEach(function (triggerEl) {{ + triggerEl.addEventListener('shown.bs.tab', function (event) {{ + window.dispatchEvent(new Event('resize')); + }}) + }}) + </script> </body> </html> """ @@ -123,17 +149,18 @@ class Dashboard: </li> """ - # Home tab content: two choropleths side by side in a single row + # Home tab content: Map of World Crime taking up the entire page home_html = '<div class="row">' for title, graph_html in self.home_graphs: - home_html += f""" - <div class="col-md-6"> - <div class="graph-container"> - <h4>{title}</h4> - {graph_html} + if title == "Map of World Crime": + home_html += f""" + <div class="col-12"> + <div class="home-graph-container"> + <h4>{title}</h4> + {graph_html} + </div> </div> - </div> - """ + """ home_html += "</div>" # Optionally include text below diff --git a/data_storage/UK/Crime/combined_crime_uk.db b/data_storage/UK/Crime/combined_crime_uk.db index f4fe0dad3334ee04f9e956e19a143bc5ce6ce414..6d5281bcb78561d54a3afbe97a335d0c6113f994 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 499fed3e92df38ecfe3cbfdf61642bea9272e467..80d80ecd725de464ce3dc13aecba0bc10c8cc6fd 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 486415ac74ef4f42328e8be9446395825d7b6805..3ca9ffb9827a993e335212e4c46fec8054f6af52 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 8f5bfba6751eb8c7a94d4a1e56bd372399097a49..bd9886f4548e33952604cc949065eb0baa25bca2 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 a4d7acd575ae724d5e3828d79f07a6d02828543a..7902b615ab82831138e1e11b58d6fe6ef48ddbb6 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 0c7526a43921a57533e6d3db76729e28e6ce03d7..eb66727d5b73ab33de6c26f642f538849cbd1105 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 8fdfadc31590fdaf0163ef0d1e28ee348eded41e..91ca59622cbe8affa42ed7665dbe3f019c3bc95a 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 8b996d251e935af8e521f7845cae052f285b8cbf..6bc77c5989eed9389e1a38f184d31e056c070ee4 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 46bd9147db3a8dce8c8549b3b305c4438a3ebe86..e1fdf2a5d444bf288190a16734e20c8d962004d0 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 c91f104d49cadac005382cfb633fa57e7f873ed4..3dfed68612c7b69d0a16848dd6cc05f45853eca9 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 2539c9c8b0cbf69b636dd817183ac9c1e36fee37..5845143ff9df15dc86b0f4f8a13a0cce7ef78306 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 308694d2c982ddc726c77e60bc23f6c4d7010f36..1a309804c247479d2af9ed0c6e3473da8939edd1 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 a4d38f1a4f33f6dcc6d2d570bf8621d859f4a3ca..c8c9c2f4c86958a9793855dfb3c6f653ca814ff8 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 39d740c95d30c6d9d88eb256f58e9e1aec9089aa..a3e6509402d980e04beb98e8e0a315db9255ba6f 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 73f2007b73816be40adf8329dd699572732e7414..94cd8d7adb721c656521aa9665950bc9f200c9e5 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 6b5300aa7ce23ef4ed0eb8ceaae166d9e301946a..99be58afe51df9fa9059060ef1a99c8fd47d1295 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 ab0438d99f99d727c0a96bdb886d0e43933de663..897510ecc9a7d3b93f093d2a25d6baa02b319a39 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 8362488a56db588197253dba96ef8a793bba5e47..9819bf449794f3b22c8b12bf5e6dc0b97db0a381 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 89352128af67f75f8d35e901461751f9545fff1b..481c4fd859a60192426ed2e6e24d7ca81090cbab 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 536539a01540176fa101955fa75ed1a66328dee4..ecb65f303282ad00b8058dc9d876c1869c746dbb 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 3cd965d0078c2d084196514b4c1b2bad96d274dc..bd4d44913d1a687b865160b2787adbdc74243124 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 12b1f7e9555a16f3a9df01b0282a2fe1b2d936b0..806b5bb9be253709ab9203e1039f8ca670efa88d 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/Crime/UN_Crime_Continents.db b/data_storage/UN/Crime/UN_Crime_Continents.db index 5c65a9542fd1de60b8ca859f9fd3fd584cd5d6fd..f3226cfa940a8a1605fc02a38ea959682194f0a0 100644 Binary files a/data_storage/UN/Crime/UN_Crime_Continents.db and b/data_storage/UN/Crime/UN_Crime_Continents.db differ diff --git a/data_storage/UN/Economy/GDP_per_capita_continents.db b/data_storage/UN/Economy/GDP_per_capita_continents.db index 9a19dcc96c53abf75d214d6bc873e814217f25c4..08881b9a8caea3f2288960e97a6e43a1d98b122f 100644 Binary files a/data_storage/UN/Economy/GDP_per_capita_continents.db and b/data_storage/UN/Economy/GDP_per_capita_continents.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 3fb2e7c2a2cde9596a991c6ba4f84d9fa9f9b3be..eee002abbb6161bd7c94b98a1b19a973a21713a0 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 379e2be685362170a3cf37fa532e0f84ec1dd2d8..56b8395196a8ff5319ecb6c01e2d0f9239fdba61 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 6bbe1a7ceaa6afd011a9ccc4b728e3a761134446..273991b2dc98d3d6b7d41b355ee5714870222c0f 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 8d5bc504d54f2acd7d165c8713e09bba0a1eb697..8e082aa8c72f225db0cbcffc4103e6fffd5ea71e 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 5288480a79911942ddd75c594690e00b5aaf8884..5218fe46614a47a8d2efefbc33b3ea0e9e6a6047 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 aa82fa2d50121eebb0eb2adf81d67a0aa81999b6..5e780aa845112654dff1b5e918f8ec3920636de2 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 62b18ca2b71782155d9ab4ac03216174690e3d04..96a88475ff8b967110913e030819e6a151f684e6 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 e2ebd6b85c0052ce91c5f06ae7d1534d498cdcfc..e299fb3b1fad099436dc66e1bcfb86e6fd3c8efd 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 662e11de1bcba4202179dad040ec8411c8e77d82..9bee12caa159af8b600485421172b9750f314d53 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 91f27d6ff01fc372ce590123a1381fbce12a639e..3aa5ad63739219878eb0f302fb8bebac30d1ea07 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 6321e4b08359d963cd6134f7d56442bb12bff922..41c3a9db24fff1fa8112b551fdb98af297226c4c 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 7cb1132d5793b24df45b0bba39f091b86971e702..2a48a2bd0f9425c34b9ca0c42beea55ef142e83c 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 668c296034d6c3cfd2afca580b8bb7a12d01b34f..4a4b30e8a4ddcf792f22d63e26364b7bb589432e 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 c62d6f5d527c3ae368d0046d45acd4e0f363832a..4b0066443cd6e55c613753c0262c3bac83f390e2 100644 Binary files a/graphs/graphs_display.html and b/graphs/graphs_display.html differ diff --git a/main.py b/main.py index 196136d41c272f1c6738fd6058157cfba1f6be08..05ace6118811722fa71854bd434208ca9d1b4aec 100644 --- a/main.py +++ b/main.py @@ -27,7 +27,7 @@ table_list = sql_t_UN.list_db(verbose=True) ## UK DATA ### sql_t_UK = SQL_tool(data_storage_location="data_storage/UK") # Initialises all the data bases for sqlite -table_list_UK = sql_t_UK.list_db(verbose=False) +table_list_UK = sql_t_UK.list_db(verbose=True) @@ -92,9 +92,7 @@ def un_crime_line_chart(): return fig - - -def gdp_per_continent(): +def gdp_per_continent(threshold=4): # Query the GDP data gdp_per_cap_query = querys.gdp_per_cap() df = sql_t_UN.query_db( @@ -108,48 +106,83 @@ def gdp_per_continent(): # Filter the data to include only GDP per capita gdp_per_capita_df = df[df["Row_Descriptor"] == "GDP per capita (US dollars)"] - # Calculate the total GDP per capita for each year - total_gdp_per_capita_per_year = gdp_per_capita_df.groupby("Year")["Value"].sum().reset_index() - total_gdp_per_capita_per_year.rename(columns={"Value": "Total_GDP_Per_Capita"}, inplace=True) + # Calculate total GDP per capita for each year + totals = gdp_per_capita_df.groupby("Year")["Value"].sum().reset_index() + totals.rename(columns={"Value": "Total_GDP_Per_Capita"}, inplace=True) - # Merge the total GDP per capita back into the original DataFrame - gdp_per_capita_df = gdp_per_capita_df.merge(total_gdp_per_capita_per_year, on="Year") + # Merge totals back + gdp_per_capita_df = gdp_per_capita_df.merge(totals, on="Year") - # Calculate the percentage of the total GDP per capita for each region for each year - gdp_per_capita_df["Percentage"] = (gdp_per_capita_df["Value"] / gdp_per_capita_df["Total_GDP_Per_Capita"]) * 100 + # Calculate the percentage of the total GDP per capita for each region each year + gdp_per_capita_df["Percentage"] = ( + gdp_per_capita_df["Value"] / gdp_per_capita_df["Total_GDP_Per_Capita"] + ) * 100 # Create frames for the animation frames = [] for year in gdp_per_capita_df["Year"].unique(): - year_data = gdp_per_capita_df[gdp_per_capita_df["Year"] == year] + year_data = gdp_per_capita_df[gdp_per_capita_df["Year"] == year].copy() + + # Split into main vs. Other + main_df = year_data[year_data["Percentage"] >= threshold].copy() + other_df = year_data[year_data["Percentage"] < threshold].copy() + + if not other_df.empty: + other_sum = other_df["Percentage"].sum() + main_df = pd.concat([ + main_df, + pd.DataFrame({"Region_Country_Area": ["Other"], "Percentage": [other_sum]}) + ], ignore_index=True) + frames.append(go.Frame( - data=[go.Pie(labels=year_data["Region_Country_Area"], values=year_data["Percentage"])], + data=[go.Pie( + labels=main_df["Region_Country_Area"], + values=main_df["Percentage"] + )], name=str(year) )) # Create the initial pie chart initial_year = gdp_per_capita_df["Year"].min() - initial_data = gdp_per_capita_df[gdp_per_capita_df["Year"] == initial_year] + initial_data = gdp_per_capita_df[gdp_per_capita_df["Year"] == initial_year].copy() + + # Split into main vs. Other for initial data + main_init = initial_data[initial_data["Percentage"] >= threshold].copy() + other_init = initial_data[initial_data["Percentage"] < threshold].copy() + + if not other_init.empty: + other_init_sum = other_init["Percentage"].sum() + main_init = pd.concat([ + main_init, + pd.DataFrame({"Region_Country_Area": ["Other"], "Percentage": [other_init_sum]}) + ], ignore_index=True) fig = go.Figure( - data=[go.Pie(labels=initial_data["Region_Country_Area"], values=initial_data["Percentage"])], + data=[go.Pie( + labels=main_init["Region_Country_Area"], + values=main_init["Percentage"] + )], layout=go.Layout( - title=f"GDP per Capita as a Percentage of the Total for {initial_year}", + title=f"GDP per Capita (Percentage) - {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"}])] + 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 gdp_per_capita_df["Year"].unique() + {"args": [[str(y)], {"frame": {"duration": 1000, "redraw": True}, "mode": "immediate"}], + "label": str(y), + "method": "animate"} for y in sorted(gdp_per_capita_df["Year"].unique()) ], "transition": {"duration": 300}, "x": 0.1, @@ -339,11 +372,10 @@ def combined_choropleth(): geo=dict(showframe=False, showcoastlines=False), margin=dict(l=0, r=0, t=50, b=0), updatemenus=[dict( - x=0.1, # position of the dropdown horizontally - y=1.15, # position of the dropdown vertically - xanchor="left", + x=0.85, # position of the dropdown horizontally + y=1.3, # position of the dropdown vertically + xanchor="right", yanchor="top", - active=crime_types.index("Intentional homicide rates per 100,000"), buttons=buttons )] ) @@ -453,6 +485,8 @@ 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") + + # List of crime columns crime_columns = [ @@ -511,61 +545,91 @@ def graph11(): "Residential burglary", "Non-residential burglary", "Other theft offences", "Possession of weapons offences", "Miscellaneous crimes" ] + + threshold = 4 # Threshold for percentage to include in the main pie chart + # 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 + # Sort and clean 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 + # Create frames 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"] + total_count = year_data["Count"].sum() + year_data["Percentage"] = (year_data["Count"] / total_count) * 100 + + main_df = year_data[year_data["Percentage"] >= threshold].copy() + other_df = year_data[year_data["Percentage"] < threshold].copy() + + if not other_df.empty: + other_value = other_df["Count"].sum() + main_df = pd.concat([ + main_df, + pd.DataFrame({"Crime Type": ["Other"], "Count": [other_value]}) + ], ignore_index=True) + frames.append(go.Frame( - data=[go.Pie(labels=year_data["Crime Type"], values=year_data["Count"], pull=[0]*len(year_data), textinfo="none")], + data=[go.Pie(labels=main_df["Crime Type"], values=main_df["Count"], textinfo="percent")], name=str(year) )) + + # Initial data + first_year = crime_data["Year"].unique()[0] + init_data = crime_data[crime_data["Year"] == first_year] + init_data = init_data[crime_columns].sum().reset_index() + init_data.columns = ["Crime Type", "Count"] - # 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"] + total_count_init = init_data["Count"].sum() + init_data["Percentage"] = (init_data["Count"] / total_count_init) * 100 + main_init = init_data[init_data["Percentage"] >= threshold].copy() + other_init = init_data[init_data["Percentage"] < threshold].copy() + + if not other_init.empty: + other_val_init = other_init["Count"].sum() + main_init = pd.concat([ + main_init, + pd.DataFrame({"Crime Type": ["Other"], "Count": [other_val_init]}) + ], ignore_index=True) + + # Create figure fig = go.Figure( - data=[go.Pie(labels=initial_data["Crime Type"], values=initial_data["Count"], pull=[0]*len(initial_data), textinfo="none")], + data=[go.Pie(labels=main_init["Crime Type"], values=main_init["Count"], textinfo="percent")], layout=go.Layout( - title=f"Crime Distribution for {initial_year}", + title=f"Crime Distribution for {first_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"}])] + 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() + {"args": [[str(y)], {"frame": {"duration": 1000, "redraw": True}, "mode": "immediate"}], + "label": str(y), + "method": "animate"} for y in crime_data["Year"].unique() ], "transition": {"duration": 300}, - "x": 0.1, - "xanchor": "left", - "y": 0, + "x": 0.85, + "xanchor": "right", + "y": 1.15, "yanchor": "top" }] ), @@ -574,6 +638,8 @@ def graph11(): return fig + + def graph8(): # Query the education expenditure data education_expenditure_query = querys.uk_education_expenditure() @@ -596,6 +662,9 @@ def graph8(): # 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() + grouped_df = grouped_df[grouped_df["education_function"] != "Total"] + + # Create a stacked bar chart by year fig = px.bar( grouped_df, @@ -639,7 +708,7 @@ def graph8(): if __name__ == "__main__": graphs = [ - ("Combined Choropleth", combined_choropleth, "UN", "Crime"), + ("Map of World Crime", combined_choropleth, "UN", "Crime"), ("Total Recorded Crime 2002-2022", un_crime_line_chart, "UN", "Crime"), ("GDP per Capita (USD) by Continent", gdp_per_continent, "UN", "Socioeconomic"), ("Crime and Economy", large_grouped_bar_chart, "UN", "Crime"),