Code/app/plan_d_action/utils/data/pda_interface.py
2025-06-04 08:35:53 +02:00

168 lines
6.2 KiB
Python

import streamlit as st
def afficher_bloc_ihh_isg(titre, ihh, isg, details_content=""):
st.markdown(f"### {titre}")
if not details_content:
st.markdown("Données non disponibles")
return
lines = details_content.split('\n')
# 1. Afficher vulnérabilité combinée en premier
if "#### Vulnérabilité combinée IHH-ISG" in details_content:
conteneur, = st.columns([1], gap="small", border=True)
with conteneur:
st.markdown("#### Vulnérabilité combinée IHH-ISG")
afficher_section_texte(lines, "#### Vulnérabilité combinée IHH-ISG", "###")
# 2. Afficher ISG des pays impliqués
if "##### ISG des pays impliqués" in details_content:
print(details_content)
st.markdown("#### ISG des pays impliqués")
afficher_section_avec_tableau(lines, "##### ISG des pays impliqués")
# Afficher le résumé ISG combiné
for line in lines:
if "**ISG combiné:" in line:
st.markdown(line)
break
# 3. Afficher la section IHH complète
if "#### Indice de Herfindahl-Hirschmann" in details_content:
st.markdown("#### Indice de Herfindahl-Hirschmann")
# Tableau de résumé IHH
afficher_section_avec_tableau(lines, "#### Indice de Herfindahl-Hirschmann")
# IHH par entreprise
if "##### IHH par entreprise (acteurs)" in details_content:
st.markdown("##### IHH par entreprise (acteurs)")
afficher_section_texte(lines, "##### IHH par entreprise (acteurs)", "##### IHH par pays")
# IHH par pays
if "##### IHH par pays" in details_content:
st.markdown("##### IHH par pays")
afficher_section_texte(lines, "##### IHH par pays", "##### En résumé")
# En résumé
if "##### En résumé" in details_content:
st.markdown("##### En résumé")
afficher_section_texte(lines, "##### En résumé", "####")
def afficher_section_avec_tableau(lines, section_start, section_end=None):
"""Affiche une section contenant un tableau"""
in_section = False
table_lines = []
for line in lines:
if section_start in line:
in_section = True
continue
elif in_section and section_end and section_end in line:
break
elif in_section and line.startswith('#') and section_start not in line:
break
elif in_section:
if line.strip().startswith('|'):
table_lines.append(line)
elif table_lines and not line.strip().startswith('|'):
# Fin du tableau
break
if table_lines:
st.markdown('\n'.join(table_lines))
def afficher_section_texte(lines, section_start, section_end_marker=None):
"""Affiche le texte d'une section sans les tableaux"""
in_section = False
for line in lines:
if section_start in line:
in_section = True
continue
elif in_section and section_end_marker and line.startswith(section_end_marker):
break
elif in_section and line.startswith('#') and section_start not in line:
break
elif in_section and line.strip() and not line.strip().startswith('|'):
st.markdown(line)
def afficher_description(titre, description):
st.markdown(f"## {titre}")
conteneur, = st.columns([1], gap="small", border=True)
with conteneur:
if description:
lines = description.split('\n')
description_lines = []
# Extraire le premier paragraphe descriptif
for line in lines:
line = line.strip()
if not line:
if description_lines: # Si on a déjà du contenu, une ligne vide termine le paragraphe
break
continue
# Arrêter aux titres de sections ou tableaux
if (line.startswith('####') or
line.startswith('|') or
line.startswith('**Unité')):
break
description_lines.append(line)
if description_lines:
# Rejoindre les lignes en un seul paragraphe
full_description = ' '.join(description_lines)
st.markdown(full_description)
else:
st.markdown("Description non disponible")
else:
st.markdown("Description non disponible")
def afficher_caracteristiques_minerai(minerai, mineraux_data, details_content=""):
st.markdown("### Caractéristiques générales")
if not details_content:
st.markdown("Données non disponibles")
return
lines = details_content.split('\n')
# 3. Afficher la vulnérabilité combinée ICS-IVC en dernier
if "#### Vulnérabilité combinée ICS-IVC" in details_content:
conteneur, = st.columns([1], gap="small", border=True)
with conteneur:
st.markdown("#### Vulnérabilité combinée ICS-IVC")
afficher_section_texte(lines, "#### Vulnérabilité combinée ICS-IVC", "####")
# 1. Afficher la section ICS complète
if "#### ICS" in details_content:
st.markdown("#### ICS")
# Afficher le premier tableau ICS (avec toutes les colonnes)
afficher_section_avec_tableau(lines, "#### ICS", "##### Valeurs d'ICS par composant")
# Afficher la sous-section "Valeurs d'ICS par composant"
if "##### Valeurs d'ICS par composant" in details_content:
st.markdown("##### Valeurs d'ICS par composant")
afficher_section_avec_tableau(lines, "##### Valeurs d'ICS par composant", "**ICS moyen")
# Afficher le résumé ICS moyen
for line in lines:
if "**ICS moyen" in line:
st.markdown(line)
break
# 2. Afficher la section IVC complète
if "#### IVC" in details_content:
st.markdown("#### IVC")
# Afficher la valeur IVC principale
for line in lines:
if "**IVC:" in line:
st.markdown(line)
break
# Afficher tous les détails de la section IVC
afficher_section_texte(lines, "#### IVC", "#### Vulnérabilité combinée ICS-IVC")