244 lines
8.2 KiB
Python
244 lines
8.2 KiB
Python
import streamlit as st
|
|
|
|
def afficher_bloc_ihh_isg(titre, ihh, isg, details_content="", ui = True) -> str|None:
|
|
contenu_bloc = ""
|
|
if ui:
|
|
st.markdown(f"### {titre}")
|
|
else:
|
|
contenu_bloc = f"### {titre}\n"
|
|
|
|
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:
|
|
contenu_md = "#### Vulnérabilité combinée IHH-ISG\n"
|
|
contenu_md += afficher_section_texte(lines, "#### Vulnérabilité combinée IHH-ISG", "###")
|
|
contenu_md += "\n"
|
|
if ui:
|
|
conteneur, = st.columns([1], gap="small", border=True)
|
|
with conteneur:
|
|
st.markdown(contenu_md)
|
|
else:
|
|
contenu_bloc += contenu_md
|
|
|
|
# 2. Afficher ISG des pays impliqués
|
|
if "##### ISG des pays impliqués" in details_content:
|
|
# Afficher le résumé ISG combiné
|
|
for line in lines:
|
|
if "**ISG combiné:" in line:
|
|
st.markdown(line)
|
|
break
|
|
|
|
contenu_md = "#### ISG des pays impliqués\n"
|
|
contenu_md += afficher_section_avec_tableau(lines, "##### ISG des pays impliqués")
|
|
contenu_md += "\n"
|
|
if ui:
|
|
st.markdown(contenu_md)
|
|
else:
|
|
contenu_bloc += contenu_md
|
|
|
|
# 3. Afficher la section IHH complète
|
|
if "#### Indice de Herfindahl-Hirschmann" in details_content:
|
|
contenu_md = "#### Indice de Herfindahl-Hirschmann\n"
|
|
|
|
# Tableau de résumé IHH
|
|
contenu_md += afficher_section_avec_tableau(lines, "#### Indice de Herfindahl-Hirschmann")
|
|
contenu_md += "\n"
|
|
if ui:
|
|
st.markdown(contenu_md)
|
|
else:
|
|
contenu_bloc += contenu_md
|
|
|
|
# IHH par entreprise
|
|
if "##### IHH par entreprise (acteurs)" in details_content:
|
|
contenu_md = "##### IHH par entreprise (acteurs)\n"
|
|
contenu_md += afficher_section_texte(lines, "##### IHH par entreprise (acteurs)", "##### IHH par pays")
|
|
st.markdown(contenu_md)
|
|
|
|
# IHH par pays
|
|
if "##### IHH par pays" in details_content:
|
|
contenu_md = "##### IHH par pays\n"
|
|
contenu_md += afficher_section_texte(lines, "##### IHH par pays", "##### En résumé")
|
|
contenu_md += "\n"
|
|
if ui:
|
|
st.markdown(contenu_md)
|
|
else:
|
|
contenu_bloc += contenu_md
|
|
|
|
# En résumé
|
|
if "##### En résumé" in details_content:
|
|
contenu_md = "##### En résumé\n"
|
|
contenu_md += afficher_section_texte(lines, "##### En résumé", "####")
|
|
contenu_md += "\n"
|
|
if ui:
|
|
st.markdown(contenu_md)
|
|
else:
|
|
contenu_bloc += contenu_md
|
|
|
|
if not ui:
|
|
return contenu_bloc
|
|
else:
|
|
return None
|
|
|
|
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, ui = True) -> str|None:
|
|
contenu_bloc = ""
|
|
if ui:
|
|
st.markdown(f"### {titre}")
|
|
else:
|
|
contenu_bloc = f"### {titre}\n"
|
|
|
|
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
|
|
contenu_md = ' '.join(description_lines)
|
|
else:
|
|
contenu_md = "Description non disponible"
|
|
else:
|
|
contenu_md = "Description non disponible"
|
|
|
|
if ui:
|
|
conteneur, = st.columns([1], gap="small", border=True)
|
|
with conteneur:
|
|
st.markdown(contenu_md)
|
|
return None
|
|
else:
|
|
contenu_bloc += contenu_md
|
|
return contenu_bloc
|
|
|
|
def afficher_caracteristiques_minerai(minerai, mineraux_data, details_content="", ui = True) -> str|None:
|
|
contenu_bloc = ""
|
|
if ui:
|
|
st.markdown("### Caractéristiques générales")
|
|
else:
|
|
contenu_bloc = "### Caractéristiques générales\n"
|
|
|
|
if not details_content:
|
|
if ui:
|
|
st.markdown("Données non disponibles")
|
|
else:
|
|
contenu_bloc += "Données non disponibles\n"
|
|
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:
|
|
contenu_md = "#### Vulnérabilité combinée ICS-IVC\n"
|
|
contenu_md += afficher_section_texte(lines, "#### Vulnérabilité combinée ICS-IVC", "####")
|
|
contenu_md += "\n"
|
|
if ui:
|
|
conteneur, = st.columns([1], gap="small", border=True)
|
|
with conteneur:
|
|
st.markdown(contenu_md)
|
|
else:
|
|
contenu_bloc += contenu_md
|
|
|
|
# 1. Afficher la section ICS complète
|
|
if "#### ICS" in details_content:
|
|
contenu_md = "#### ICS\n"
|
|
|
|
# Afficher le premier tableau ICS (avec toutes les colonnes)
|
|
contenu_md += afficher_section_avec_tableau(lines, "#### ICS", "##### Valeurs d'ICS par composant concerné")
|
|
contenu_md += "\n"
|
|
if ui:
|
|
st.markdown(contenu_md)
|
|
else:
|
|
contenu_bloc += contenu_md
|
|
|
|
# Afficher la sous-section "Valeurs d'ICS par composant"
|
|
if "##### Valeurs d'ICS par composant concerné" in details_content:
|
|
contenu_md = "##### Valeurs d'ICS par composant concerné\n"
|
|
|
|
# Afficher le résumé ICS moyen
|
|
for line in lines:
|
|
if "**ICS moyen" in line:
|
|
contenu_md += line
|
|
break
|
|
|
|
contenu_md += "\n"
|
|
contenu_md += afficher_section_avec_tableau(lines, "##### Valeurs d'ICS par composant concerné", "**ICS moyen")
|
|
contenu_md += "\n"
|
|
|
|
if ui:
|
|
st.markdown(contenu_md)
|
|
else:
|
|
contenu_bloc += contenu_md
|
|
|
|
# 2. Afficher la section IVC complète
|
|
if "#### IVC" in details_content:
|
|
contenu_md = "#### IVC\n"
|
|
|
|
# Afficher tous les détails de la section IVC
|
|
contenu_md += afficher_section_texte(lines, "#### IVC", "#### Vulnérabilité combinée ICS-IVC")
|
|
contenu_md += "\n"
|
|
if ui:
|
|
st.markdown(contenu_md)
|
|
return None
|
|
else:
|
|
contenu_bloc += contenu_md
|
|
return contenu_bloc
|