Skip to content

Commit

Permalink
Merge pull request #29 from dataforgoodfr/22-onglet-data-améliorations
Browse files Browse the repository at this point in the history
Améliorations onglet data : volumes en m3, harmonisation graphiques (labels, polices, etc), wording et explications méthodologiques (périmètre données)
  • Loading branch information
tgazagnes authored Jul 6, 2024
2 parents 92c056e + e919f14 commit dfaa73c
Show file tree
Hide file tree
Showing 8 changed files with 1,230 additions and 1,114 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ ipython_config.py
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock
poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
Expand Down
1,643 changes: 931 additions & 712 deletions dashboards/app/pages/data.py

Large diffs are not rendered by default.

100 changes: 61 additions & 39 deletions dashboards/app/pages/hotspots.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,25 +432,30 @@ def calculate_and_display_metrics(data, indicator_col1, indicator_col2, indicato
def couleur_milieu(type):
return couleur.get(type, "white") # Returns 'white' if the type is not found


def update_lieu_options(selected_milieu):
if selected_milieu and selected_milieu != "Sélectionnez un milieu...":
filtered_data = data_zds[data_zds['TYPE_MILIEU'] == selected_milieu]
return ["Sélectionnez un lieu..."] + list(filtered_data['TYPE_LIEU2'].dropna().unique())
filtered_data = data_zds[data_zds["TYPE_MILIEU"] == selected_milieu]
return ["Sélectionnez un lieu..."] + list(
filtered_data["TYPE_LIEU2"].dropna().unique()
)
return ["Sélectionnez un lieu..."]


@st.cache_data
def process_data(data_zds):
# Filtering data to ensure surface area is not zero
data_zds = data_zds[data_zds['SURFACE'] > 0]
data_zds = data_zds[data_zds["SURFACE"] > 0]
# Calculating density and filtering out anomalous values
data_zds['DENSITE'] = data_zds['VOLUME_TOTAL'] / data_zds['SURFACE']
data_zds = data_zds[data_zds['DENSITE'] < 20]
data_zds["DENSITE"] = data_zds["VOLUME_TOTAL"] / data_zds["SURFACE"]
data_zds = data_zds[data_zds["DENSITE"] < 20]
# Rounding values for better display
data_zds['DENSITE'] = data_zds['DENSITE'].round(4)
data_zds['SURFACE_ROND'] = data_zds['SURFACE'].round(2)
data_zds["DENSITE"] = data_zds["DENSITE"].round(4)
data_zds["SURFACE_ROND"] = data_zds["SURFACE"].round(2)
return data_zds

#Zoom from admin level

# Zoom from admin level
if NIVEAU_ADMIN == "Commune":
zoom_admin = 12
elif NIVEAU_ADMIN == "EPCI":
Expand All @@ -469,14 +474,16 @@ def plot_density_map(data_zds: pd.DataFrame, filtered_data: pd.DataFrame) -> fol

else:
# Use processed data
processed_data = process_data(filtered_data if not filtered_data.empty else data_zds)
processed_data = process_data(
filtered_data if not filtered_data.empty else data_zds
)

m = folium.Map(
location=[
processed_data['LIEU_COORD_GPS_Y'].mean(),
processed_data['LIEU_COORD_GPS_X'].mean()
processed_data["LIEU_COORD_GPS_Y"].mean(),
processed_data["LIEU_COORD_GPS_X"].mean(),
],
zoom_start=zoom_admin
zoom_start=zoom_admin,
)

# Loop over each row in the DataFrame to place markers
Expand All @@ -491,26 +498,25 @@ def plot_density_map(data_zds: pd.DataFrame, filtered_data: pd.DataFrame) -> fol
</div>
"""
lgd_txt = '<span style="color: {col};">{txt}</span>'
color = couleur_milieu(row['TYPE_MILIEU'])
color = couleur_milieu(row["TYPE_MILIEU"])
folium.CircleMarker(
fg = folium.FeatureGroup(name= lgd_txt.format( txt= ['TYPE_MILIEU'], col= color)),
location=[row['LIEU_COORD_GPS_Y'], row['LIEU_COORD_GPS_X']],
radius=np.log(row['DENSITE'] + 1)*15,
fg=folium.FeatureGroup(
name=lgd_txt.format(txt=["TYPE_MILIEU"], col=color)
),
location=[row["LIEU_COORD_GPS_Y"], row["LIEU_COORD_GPS_X"]],
radius=np.log(row["DENSITE"] + 1) * 15,
popup=folium.Popup(popup_html, max_width=300),
color=color,
fill=True,

).add_to(m)

folium_static(m)

return m


# Function for 'milieu' density table
def density_table_milieu(
data_zds: pd.DataFrame,
filtered_data: pd.DataFrame
):
def density_table_milieu(data_zds: pd.DataFrame, filtered_data: pd.DataFrame):

if data_zds.empty:
st.write("Aucune donnée disponible pour la région sélectionnée.")
Expand Down Expand Up @@ -554,10 +560,7 @@ def density_table_milieu(
)


def density_table_lieu(
data_zds: pd.DataFrame,
filtered_data: pd.DataFrame
):
def density_table_lieu(data_zds: pd.DataFrame, filtered_data: pd.DataFrame):

if data_zds.empty:
st.write("Aucune donnée disponible pour la région sélectionnée.")
Expand Down Expand Up @@ -766,55 +769,74 @@ def create_contributors_table(data_zds: pd.DataFrame, multi_filter_dict: dict) -
# Add a default "Select a milieu..." option
selected_milieu = st.selectbox(
"Sélectionnez un milieu:",
["Sélectionnez un milieu..."] + list(pd.unique(data_zds_correct['TYPE_MILIEU']))
["Sélectionnez un milieu..."]
+ list(pd.unique(data_zds_correct["TYPE_MILIEU"])),
)
with right_column:
# Update lieu options based on selected milieu
lieu_options = update_lieu_options(selected_milieu)
selected_lieu = st.selectbox("Sélectionnez un lieu:", lieu_options)


# Place the map centrally by using a wider column for the map and narrower ones on the sides
col1, map_col, col3 = st.columns([4, 10, 1]) # Adjust column ratios as needed

with map_col:
st.markdown("### Carte des Densités")
if selected_milieu != "Sélectionnez un milieu..." and selected_lieu != "Sélectionnez un lieu...":
filtered_data = data_zds_correct[(data_zds_correct['TYPE_MILIEU'] == selected_milieu) & (data_zds_correct['TYPE_LIEU2'] == selected_lieu)]
if (
selected_milieu != "Sélectionnez un milieu..."
and selected_lieu != "Sélectionnez un lieu..."
):
filtered_data = data_zds_correct[
(data_zds_correct["TYPE_MILIEU"] == selected_milieu)
& (data_zds_correct["TYPE_LIEU2"] == selected_lieu)
]
plot_density_map(data_zds_correct, filtered_data)
else:
plot_density_map(data_zds_correct, data_zds_correct) # Show all data by default

plot_density_map(
data_zds_correct, data_zds_correct
) # Show all data by default

col1, col2, col3 = st.columns([3, 3, 2])

with col1:
st.markdown("#### Tableau des Densités par Milieu")
if selected_milieu != "Sélectionnez un milieu..." and selected_lieu != "Sélectionnez un lieu...":
filtered_data = data_zds_correct[(data_zds_correct['TYPE_MILIEU'] == selected_milieu) & (data_zds_correct['TYPE_LIEU2'] == selected_lieu)]
if (
selected_milieu != "Sélectionnez un milieu..."
and selected_lieu != "Sélectionnez un lieu..."
):
filtered_data = data_zds_correct[
(data_zds_correct["TYPE_MILIEU"] == selected_milieu)
& (data_zds_correct["TYPE_LIEU2"] == selected_lieu)
]
density_table_milieu(data_zds_correct, filtered_data)
else:
density_table_milieu(data_zds_correct, data_zds_correct)

with col2:
st.markdown("#### Tableau des Densités par Lieu")
if selected_milieu != "Sélectionnez un milieu..." and selected_lieu != "Sélectionnez un lieu...":
filtered_data = data_zds_correct[(data_zds_correct['TYPE_MILIEU'] == selected_milieu) & (data_zds_correct['TYPE_LIEU2'] == selected_lieu)]
if (
selected_milieu != "Sélectionnez un milieu..."
and selected_lieu != "Sélectionnez un lieu..."
):
filtered_data = data_zds_correct[
(data_zds_correct["TYPE_MILIEU"] == selected_milieu)
& (data_zds_correct["TYPE_LIEU2"] == selected_lieu)
]
density_table_lieu(data_zds_correct, filtered_data)
else:
density_table_lieu(data_zds_correct, data_zds_correct)

with col3:
with st.expander("###### Notice ℹ️", expanded=True):
st.write(
"""
with st.expander("###### Notice ℹ️", expanded=True):
st.write(
"""
**Milieu** désigne de grands types d'environnements comme le Littoral,
les Cours d'eau ou la Montagne.\n
Chaque Milieu est ensuite divisé en
**Lieux** plus spécifiques. Par exemple, sous le Milieu Littoral,
on trouve des Lieux comme les Plages, les Roches, les Digues, ou les Parkings.
"""
)
)

with tab2:
# Use the selected filters
Expand Down
1 change: 1 addition & 0 deletions dashboards/app/pages/ongletdata_colormap_materiaux.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"Textile": "#C384B1", "Papier": "#CAA674", "Metal": "#A0A0A0", "Verre": "#3DCE89", "Autre": "#F3B900", "Plastique": "#48BEF0", "Caoutchouc": "#364E74", "Bois": "#673C11", "Papier/Carton": "#CAA674", "M\u00e9tal": "#A0A0A0", "Verre/C\u00e9ramique": "#3DCE89"}
1 change: 1 addition & 0 deletions dashboards/app/pages/ongletdata_colormap_secteurs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"AGRICULTURE": "#156644", "ALIMENTATION": "#F7D156", "AMEUBLEMENT, D\u00c9CORATION ET \u00c9QUIPEMENT DE LA MAISON": "#F79D65", "AQUACULTURE": "#0067C2", "B\u00c2TIMENT, TRAVAUX ET MAT\u00c9RIAUX DE CONSTRUCTION": "#FF9900", "CHASSE ET ARMEMENT": "#23A76F", "COSM\u00c9TIQUES, HYGI\u00c8NE ET SOINS PERSONNELS": "#BF726B", "D\u00c9TERGENTS ET PRODUITS D'ENTRETIENS": "#506266", "EMBALLAGE INDUSTRIEL ET COLIS": "#754B30", "GRAPHIQUE ET PAPETERIE ET FOURNITURES DE BUREAU": "#EFEFEF", "IND\u00c9TERMIN\u00c9": "#967EA1", "INFORMATIQUE ET HIGHTECH": "#E351F7", "JOUETS ET LOISIR": "#A64D79", "MAT\u00c9RIEL \u00c9LECTRIQUE ET \u00c9LECTROM\u00c9NAGER": "#AE05C3", "M\u00c9TALLURGIE": "#EC4773", "P\u00caCHE": "#003463", "PETROCHIMIE": "#0D0D0D", "PHARMACEUTIQUE/PARAM\u00c9DICAL": "#61BF5E", "PLASTURGIE": "#05A2AD", "TABAC": "#E9003F", "TEXTILE ET HABILLEMENT": "#FA9EE5", "TRAITEMENT DES EAUX": "#4AA6F7", "TRANSPORT / AUTOMOBILE": "#6C2775", "VAISSELLE \u00c0 USAGE UNIQUE": "#732D3A", "AUTRES SECTEURS": "#D9C190"}
1 change: 0 additions & 1 deletion dashboards/app/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ streamlit==1.32.2
openpyxl==3.1.2
streamlit-folium==0.19.1
plotly==5.19.0
streamlit-dynamic-filters==0.1.6
streamlit-authenticator==0.3.2
st-pages==0.4.5
babel==2.11.0
Loading

0 comments on commit dfaa73c

Please sign in to comment.