-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
22 onglet data ameliorations #29
The head ref may contain hidden characters: "22-onglet-data-am\u00E9liorations"
Changes from all commits
fb186a5
2ad8ba5
47049af
1c9d037
b941905
c19f74b
55e4894
5c17732
042e133
f224645
e1c7a80
dc7a302
34b0996
9f1b0e4
0835d03
9225aea
3f24729
5334ee7
4c048eb
f7dc00c
fb43f53
a9ff5f1
858bb7a
0c42b3b
9ddfbed
ba83666
8cc6880
e919f14
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -432,25 +432,30 @@ def calculate_and_display_metrics(data, indicator_col1, indicator_col2, indicato | |
def couleur_milieu(type): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prévoir du type hinting There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. à voir avec l'onglet hotspots |
||
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": | ||
|
@@ -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 | ||
|
@@ -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.") | ||
|
@@ -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.") | ||
|
@@ -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 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note pour plus tard : Si l'on a d'autres export de colormap ou autre, autant tout centraliser dans un 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"} |
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"} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pas d'impact sur les autres onglets? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nope on l'avait testé sur data et remplacé ensuite. aucun autre onglet ne l'utilise |
||
streamlit-authenticator==0.3.2 | ||
st-pages==0.4.5 | ||
babel==2.11.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pourquoi l'onglet hotspot est modifié, si l'on modifie data ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C'est precommit qui a fait passer du reformatage (black je pense vu les modifs), je pense qu'ils ne l'ont pas utilisé dans les derniers commit du staging. Je les laisserai écraser les modifs avec leur dernière version pré-commitée :). Aucune modif volontaire de ma part