177 lines
6.6 KiB
Python
177 lines
6.6 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")
|
|
contenu = afficher_section_texte(lines, "#### Vulnérabilité combinée IHH-ISG", "###")
|
|
st.markdown(contenu)
|
|
|
|
# 2. Afficher ISG des pays impliqués
|
|
if "##### ISG des pays impliqués" in details_content:
|
|
st.markdown("#### ISG des pays impliqués")
|
|
contenu = afficher_section_avec_tableau(lines, "##### ISG des pays impliqués")
|
|
st.markdown(contenu)
|
|
|
|
# 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
|
|
contenu = afficher_section_avec_tableau(lines, "#### Indice de Herfindahl-Hirschmann")
|
|
st.markdown(contenu)
|
|
|
|
# IHH par entreprise
|
|
if "##### IHH par entreprise (acteurs)" in details_content:
|
|
st.markdown("##### IHH par entreprise (acteurs)")
|
|
contenu = afficher_section_texte(lines, "##### IHH par entreprise (acteurs)", "##### IHH par pays")
|
|
st.markdown(contenu)
|
|
|
|
# IHH par pays
|
|
if "##### IHH par pays" in details_content:
|
|
st.markdown("##### IHH par pays")
|
|
contenu = afficher_section_texte(lines, "##### IHH par pays", "##### En résumé")
|
|
st.markdown(contenu)
|
|
|
|
# En résumé
|
|
if "##### En résumé" in details_content:
|
|
st.markdown("##### En résumé")
|
|
contenu = afficher_section_texte(lines, "##### En résumé", "####")
|
|
st.markdown(contenu)
|
|
|
|
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:
|
|
contenu = '\n'.join(table_lines)
|
|
return contenu
|
|
|
|
def afficher_section_texte(lines, section_start, section_end_marker=None):
|
|
"""Affiche le texte d'une section sans les tableaux"""
|
|
in_section = False
|
|
contenu_md = []
|
|
|
|
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('|'):
|
|
contenu_md.append(line + '\n')
|
|
|
|
contenu = '\n'.join(contenu_md)
|
|
return contenu
|
|
|
|
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")
|
|
contenu = afficher_section_texte(lines, "#### Vulnérabilité combinée ICS-IVC", "####")
|
|
st.markdown(contenu)
|
|
|
|
# 1. Afficher la section ICS complète
|
|
if "#### ICS" in details_content:
|
|
st.markdown("#### ICS")
|
|
|
|
# Afficher le premier tableau ICS (avec toutes les colonnes)
|
|
contenu = afficher_section_avec_tableau(lines, "#### ICS", "##### Valeurs d'ICS par composant")
|
|
st.markdown(contenu)
|
|
|
|
# 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")
|
|
contenu = 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:
|
|
contenu = contenu + line
|
|
break
|
|
|
|
st.markdown(contenu)
|
|
|
|
# 2. Afficher la section IVC complète
|
|
if "#### IVC" in details_content:
|
|
st.markdown("#### IVC")
|
|
|
|
# Afficher tous les détails de la section IVC
|
|
contenu = afficher_section_texte(lines, "#### IVC", "#### Vulnérabilité combinée ICS-IVC")
|
|
st.markdown(contenu)
|