import pandas as pd import streamlit as st import plotly.express as px from query.requetes import ( query_zone_catg_prop, query_mon_wise_prop, query_practice_mon_wise, query_zone_per_species, ) def dashboard( list_category, list_months, list_regions, list_department, list_species, list_practices, ): df_zone_catg_prop = query_zone_catg_prop(list_category) df_mon_wise_prop = query_mon_wise_prop(list_species, list_months) df_practice_mon_wise = query_practice_mon_wise(list_practices, list_months) df_zone_per_species = query_zone_per_species( list_species, list_regions, list_department ) MONTHS = [ "janvier", "fevrier", "mars", "avril", "mai", "juin", "juillet", "août", "septembre", "octobre", "novembre", "decembre", ] MONTH_MAPPING = {k: v + 1 for v, k in enumerate(MONTHS)} # Add a numeric_months column based on MONTH_MAPPING df_practice_mon_wise["numeric_months"] = df_practice_mon_wise["months"].map( MONTH_MAPPING ) df_mon_wise_prop["numeric_months"] = df_mon_wise_prop["months"].map(MONTH_MAPPING) # Sort by numeric_months and reset index before dropping it df_practice_mon_wise = df_practice_mon_wise.sort_values( ["numeric_months", "species_id"] ).reset_index(drop=True) df_practice_mon_wise.drop("numeric_months", axis=1, inplace=True) df_mon_wise_prop = df_mon_wise_prop.sort_values( ["numeric_months", "proportion"] ).reset_index(drop=True) df_mon_wise_prop.drop("numeric_months", axis=1, inplace=True) st.markdown( """

Visualization of Biodiv-Sport Database

""", unsafe_allow_html=True, ) # Charts fig_pie = px.pie(df_zone_catg_prop, values="proportion", names="zone_category") fig_pie.update_layout( paper_bgcolor="#002b36", plot_bgcolor="#586e75", font_color="#fafafa", title={"text": "Proportions of Zone Categories", "x": 0.0, "y": 1}, ) fig_bar = px.bar(df_zone_per_species, x="name", y="number_of_zones") fig_bar.update_layout( paper_bgcolor="#002b36", plot_bgcolor="#586e75", font_color="#fafafa", title={"text": "Total Number of Zones Per Species", "x": 0.0, "y": 1}, ) fig_line = px.line(df_mon_wise_prop, x="months", y="proportion", color="species_id") fig_line.update_layout( paper_bgcolor="#002b36", plot_bgcolor="#586e75", font_color="#fafafa", title={ "text": "Monthly Proportion Distribution Across Year", "x": 0.0, "y": 1, }, ) fig_heatmap = px.density_heatmap( df_practice_mon_wise, x="months", y="practices", z="nombre_zone", color_continuous_scale="OrRd", nbinsx=12, # Set the number of bins in the x direction (months) nbinsy=10, ) fig_heatmap.update_layout( xaxis={ "tickmode": "array", "tickvals": list(MONTH_MAPPING.keys()), }, paper_bgcolor="#002b36", plot_bgcolor="#586e75", font_color="#fafafa", title={ "text": "Number of Zones According to Activity Practiced and By Month", "x": 0.0, "y": 1.0, }, ) st.plotly_chart(fig_pie) st.plotly_chart(fig_bar) st.plotly_chart(fig_line) st.plotly_chart(fig_heatmap)