Update app.py
Browse files
app.py
CHANGED
|
@@ -52,31 +52,29 @@ if df_full is None:
|
|
| 52 |
st.error("Impossible de continuer car les données n'ont pas pu être chargées.")
|
| 53 |
st.stop()
|
| 54 |
|
| 55 |
-
# ---
|
| 56 |
-
|
| 57 |
-
with st.expander("🕵️♂️ Cliquez ici pour voir les noms de colonnes détectés dans le fichier Excel"):
|
| 58 |
-
st.write("Le programme s'attend à trouver des colonnes comme 'busca', 'titre', 'matrice', 'danger', etc.")
|
| 59 |
-
st.write("Voici les noms de colonnes réellement trouvés (après nettoyage) :")
|
| 60 |
st.write(df_full.columns.tolist())
|
| 61 |
|
| 62 |
-
# --- ÉTAPE 3: DÉFINIR LES NOMS DE COLONNES
|
| 63 |
-
#
|
| 64 |
COL_BUSCA = 'busca'
|
| 65 |
COL_TITRE = 'titre'
|
| 66 |
-
COL_MATRICE = 'matrice'
|
| 67 |
-
COL_DANGER = 'danger'
|
| 68 |
COL_SECTION = 'section'
|
| 69 |
COL_TEXTE = 'texte'
|
| 70 |
COL_LIEN1 = 'lien'
|
| 71 |
COL_LIEN2 = 'lien2'
|
| 72 |
|
| 73 |
# --- Vérification de la présence des colonnes essentielles ---
|
|
|
|
| 74 |
essential_cols = [COL_BUSCA, COL_TITRE, COL_TEXTE, COL_MATRICE, COL_DANGER]
|
| 75 |
missing_cols = [col for col in essential_cols if col not in df_full.columns]
|
| 76 |
|
| 77 |
if missing_cols:
|
| 78 |
-
st.error(f"ERREUR : Les colonnes essentielles suivantes sont manquantes
|
| 79 |
-
st.warning("
|
| 80 |
st.stop()
|
| 81 |
|
| 82 |
|
|
@@ -87,32 +85,22 @@ df_full = df_full.sort_values(by=COL_BUSCA, ascending=False)
|
|
| 87 |
with st.sidebar:
|
| 88 |
st.header("🛠️ Filtres")
|
| 89 |
|
| 90 |
-
# Bouton pour vider le cache et recharger
|
| 91 |
if st.button("🔄 Rafraîchir les données"):
|
| 92 |
st.cache_data.clear()
|
| 93 |
st.experimental_rerun()
|
| 94 |
|
| 95 |
-
# Filtres
|
| 96 |
with st.expander("📌 Plage de numéros de BuSCA", expanded=True):
|
| 97 |
min_val = int(df_full[COL_BUSCA].min())
|
| 98 |
max_val = int(df_full[COL_BUSCA].max())
|
| 99 |
busca_range = st.slider("Numéros de BuSCA", min_val, max_val, (max_val - 20, max_val))
|
| 100 |
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
with st.expander("🌍 Matrices"):
|
| 105 |
-
unique_matrices = sorted(df_full[COL_MATRICE].dropna().unique())
|
| 106 |
-
matrices = st.multiselect("Sélectionner les matrices", options=unique_matrices)
|
| 107 |
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
with st.expander("⚠️ Dangers"):
|
| 112 |
-
unique_dangers = sorted(df_full[COL_DANGER].dropna().unique())
|
| 113 |
-
dangers = st.multiselect("Sélectionner les dangers", options=unique_dangers)
|
| 114 |
-
|
| 115 |
-
# ... autres filtres que vous pouvez ajouter sur le même modèle
|
| 116 |
|
| 117 |
apply_filter = st.button("Appliquer les filtres", use_container_width=True)
|
| 118 |
|
|
@@ -123,20 +111,25 @@ if apply_filter:
|
|
| 123 |
(df_display[COL_BUSCA] >= busca_range[0]) &
|
| 124 |
(df_display[COL_BUSCA] <= busca_range[1])
|
| 125 |
]
|
| 126 |
-
if matrices
|
| 127 |
df_display = df_display[df_display[COL_MATRICE].isin(matrices)]
|
| 128 |
-
if dangers
|
| 129 |
df_display = df_display[df_display[COL_DANGER].isin(dangers)]
|
| 130 |
|
| 131 |
# Affichage des résultats
|
| 132 |
st.markdown(f"### 📑 Affichage de {len(df_display)} résultats")
|
| 133 |
for index, row in df_display.iterrows():
|
| 134 |
-
|
| 135 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
st.markdown("---")
|
| 137 |
st.markdown(str(row.get(COL_TEXTE, 'Texte manquant')))
|
| 138 |
|
| 139 |
-
# Liens
|
| 140 |
if pd.notna(row.get(COL_LIEN1)):
|
| 141 |
st.markdown(f"🔗 [Lien 1]({row[COL_LIEN1]})")
|
| 142 |
if pd.notna(row.get(COL_LIEN2)):
|
|
|
|
| 52 |
st.error("Impossible de continuer car les données n'ont pas pu être chargées.")
|
| 53 |
st.stop()
|
| 54 |
|
| 55 |
+
# --- (Optionnel) Affichage des colonnes pour le débogage ---
|
| 56 |
+
with st.expander("🕵️♂️ Cliquez ici pour voir les noms de colonnes détectés"):
|
|
|
|
|
|
|
|
|
|
| 57 |
st.write(df_full.columns.tolist())
|
| 58 |
|
| 59 |
+
# --- ÉTAPE 3: DÉFINIR LES NOMS DE COLONNES CORRECTS ---
|
| 60 |
+
# MODIFICATIONS APPORTÉES ICI POUR CORRESPONDRE AU FICHIER ACTUEL
|
| 61 |
COL_BUSCA = 'busca'
|
| 62 |
COL_TITRE = 'titre'
|
| 63 |
+
COL_MATRICE = 'matrices' # <- CORRECTION: 'matrice' devient 'matrices'
|
| 64 |
+
COL_DANGER = 'dangers' # <- CORRECTION: 'danger' devient 'dangers'
|
| 65 |
COL_SECTION = 'section'
|
| 66 |
COL_TEXTE = 'texte'
|
| 67 |
COL_LIEN1 = 'lien'
|
| 68 |
COL_LIEN2 = 'lien2'
|
| 69 |
|
| 70 |
# --- Vérification de la présence des colonnes essentielles ---
|
| 71 |
+
# On utilise maintenant les variables corrigées pour la vérification
|
| 72 |
essential_cols = [COL_BUSCA, COL_TITRE, COL_TEXTE, COL_MATRICE, COL_DANGER]
|
| 73 |
missing_cols = [col for col in essential_cols if col not in df_full.columns]
|
| 74 |
|
| 75 |
if missing_cols:
|
| 76 |
+
st.error(f"ERREUR : Les colonnes essentielles suivantes sont manquantes : {', '.join(missing_cols)}")
|
| 77 |
+
st.warning("Veuillez ajuster les variables 'COL_...' dans le code.")
|
| 78 |
st.stop()
|
| 79 |
|
| 80 |
|
|
|
|
| 85 |
with st.sidebar:
|
| 86 |
st.header("🛠️ Filtres")
|
| 87 |
|
|
|
|
| 88 |
if st.button("🔄 Rafraîchir les données"):
|
| 89 |
st.cache_data.clear()
|
| 90 |
st.experimental_rerun()
|
| 91 |
|
|
|
|
| 92 |
with st.expander("📌 Plage de numéros de BuSCA", expanded=True):
|
| 93 |
min_val = int(df_full[COL_BUSCA].min())
|
| 94 |
max_val = int(df_full[COL_BUSCA].max())
|
| 95 |
busca_range = st.slider("Numéros de BuSCA", min_val, max_val, (max_val - 20, max_val))
|
| 96 |
|
| 97 |
+
with st.expander("🌍 Matrices"):
|
| 98 |
+
unique_matrices = sorted(df_full[COL_MATRICE].dropna().unique())
|
| 99 |
+
matrices = st.multiselect("Sélectionner les matrices", options=unique_matrices)
|
|
|
|
|
|
|
|
|
|
| 100 |
|
| 101 |
+
with st.expander("⚠️ Dangers"):
|
| 102 |
+
unique_dangers = sorted(df_full[COL_DANGER].dropna().unique())
|
| 103 |
+
dangers = st.multiselect("Sélectionner les dangers", options=unique_dangers)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
|
| 105 |
apply_filter = st.button("Appliquer les filtres", use_container_width=True)
|
| 106 |
|
|
|
|
| 111 |
(df_display[COL_BUSCA] >= busca_range[0]) &
|
| 112 |
(df_display[COL_BUSCA] <= busca_range[1])
|
| 113 |
]
|
| 114 |
+
if matrices:
|
| 115 |
df_display = df_display[df_display[COL_MATRICE].isin(matrices)]
|
| 116 |
+
if dangers:
|
| 117 |
df_display = df_display[df_display[COL_DANGER].isin(dangers)]
|
| 118 |
|
| 119 |
# Affichage des résultats
|
| 120 |
st.markdown(f"### 📑 Affichage de {len(df_display)} résultats")
|
| 121 |
for index, row in df_display.iterrows():
|
| 122 |
+
titre = row.get(COL_TITRE, 'Titre manquant')
|
| 123 |
+
busca_num = row.get(COL_BUSCA, 'N/A')
|
| 124 |
+
|
| 125 |
+
with st.expander(f"📄 **{titre}** (BuSCA n°{busca_num})"):
|
| 126 |
+
danger_val = row.get(COL_DANGER, 'N/A')
|
| 127 |
+
matrice_val = row.get(COL_MATRICE, 'N/A')
|
| 128 |
+
|
| 129 |
+
st.markdown(f"**Danger :** `{danger_val}` | **Matrice :** `{matrice_val}`")
|
| 130 |
st.markdown("---")
|
| 131 |
st.markdown(str(row.get(COL_TEXTE, 'Texte manquant')))
|
| 132 |
|
|
|
|
| 133 |
if pd.notna(row.get(COL_LIEN1)):
|
| 134 |
st.markdown(f"🔗 [Lien 1]({row[COL_LIEN1]})")
|
| 135 |
if pd.notna(row.get(COL_LIEN2)):
|