fix(batch_ia): gestion robuste du cas edge hafnium dans generate_operations_section
Ajout d'un try/except pour gérer l'erreur lorsque l'hafnium est relié à des composants ET au procédé EUV (connexe), ce qui génère une exception lors du traitement de la section assemblage. Impact: - Module IA'nalyse: génération de rapports plus robuste - Module Plan d'action: génération de rapports plus robuste - Pas d'impact sur les autres modules de l'application 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
6c1465bd6b
commit
bd8b51b315
@ -210,71 +210,74 @@ def generate_operations_section(data, results, config):
|
||||
for product_id, product in data["products"].items():
|
||||
# # print(f"DEBUG: Produit {product_id} ({product['label']}), assembly = {product['assembly']}")
|
||||
if product["assembly"]:
|
||||
template.append(f"### {product['label']} et Assemblage\n")
|
||||
try: # gestion de l'hafnium qui est relié à des composants et au procédé EUV (connexe) ce qui génère une erreur
|
||||
template.append(f"### {product['label']} et Assemblage\n")
|
||||
|
||||
# Récupérer la présentation synthétique
|
||||
# product_slug = product['label'].lower().replace(' ', '-')
|
||||
sous_repertoire = f"{product['label']}"
|
||||
if product["level"] == 0:
|
||||
type = "Assemblage"
|
||||
else:
|
||||
type = "Connexe"
|
||||
sous_repertoire = trouver_dossier_composant(sous_repertoire, type, "Fiche assemblage ")
|
||||
product_slug = sous_repertoire.split(' ', 2)[2]
|
||||
presentation_file = find_corpus_file("présentation-synthétique", f"{type}/Fiche assemblage {product_slug}")
|
||||
if presentation_file:
|
||||
template.append(read_corpus_file(presentation_file, remove_first_title=True))
|
||||
template.append("")
|
||||
# Récupérer la présentation synthétique
|
||||
# product_slug = product['label'].lower().replace(' ', '-')
|
||||
sous_repertoire = f"{product['label']}"
|
||||
if product["level"] == 0:
|
||||
type = "Assemblage"
|
||||
else:
|
||||
type = "Connexe"
|
||||
sous_repertoire = trouver_dossier_composant(sous_repertoire, type, "Fiche assemblage ")
|
||||
product_slug = sous_repertoire.split(' ', 2)[2]
|
||||
presentation_file = find_corpus_file("présentation-synthétique", f"{type}/Fiche assemblage {product_slug}")
|
||||
if presentation_file:
|
||||
template.append(read_corpus_file(presentation_file, remove_first_title=True))
|
||||
template.append("")
|
||||
|
||||
# Récupérer les principaux assembleurs
|
||||
assembleurs_file = find_corpus_file("principaux-assembleurs", f"{type}/Fiche assemblage {product_slug}")
|
||||
if assembleurs_file:
|
||||
template.append(read_corpus_file(assembleurs_file, shift_titles=2))
|
||||
template.append("")
|
||||
# Récupérer les principaux assembleurs
|
||||
assembleurs_file = find_corpus_file("principaux-assembleurs", f"{type}/Fiche assemblage {product_slug}")
|
||||
if assembleurs_file:
|
||||
template.append(read_corpus_file(assembleurs_file, shift_titles=2))
|
||||
template.append("")
|
||||
|
||||
# ISG des pays impliqués
|
||||
assembly_id = product["assembly"]
|
||||
operation = data["operations"][assembly_id]
|
||||
# ISG des pays impliqués
|
||||
assembly_id = product["assembly"]
|
||||
operation = data["operations"][assembly_id]
|
||||
|
||||
template.append("##### ISG des pays impliqués\n")
|
||||
template.append("| Pays | Part de marché | ISG | Criticité |")
|
||||
template.append("| :-- | :-- | :-- | :-- |")
|
||||
template.append("##### ISG des pays impliqués\n")
|
||||
template.append("| Pays | Part de marché | ISG | Criticité |")
|
||||
template.append("| :-- | :-- | :-- | :-- |")
|
||||
|
||||
isg_weighted_sum = 0
|
||||
total_share = 0
|
||||
isg_weighted_sum = 0
|
||||
total_share = 0
|
||||
|
||||
for country_id, share in operation["countries"].items():
|
||||
country = data["countries"][country_id]
|
||||
geo_country = country.get("geo_country")
|
||||
for country_id, share in operation["countries"].items():
|
||||
country = data["countries"][country_id]
|
||||
geo_country = country.get("geo_country")
|
||||
|
||||
if geo_country and geo_country in data["geo_countries"]:
|
||||
isg_value = data["geo_countries"][geo_country]["isg"]
|
||||
color, suffix = determine_threshold_color(isg_value, "ISG", config.get('thresholds'))
|
||||
template.append(f"| {country['label']} | {share}% | {isg_value} | {color} ({suffix}) |")
|
||||
if geo_country and geo_country in data["geo_countries"]:
|
||||
isg_value = data["geo_countries"][geo_country]["isg"]
|
||||
color, suffix = determine_threshold_color(isg_value, "ISG", config.get('thresholds'))
|
||||
template.append(f"| {country['label']} | {share}% | {isg_value} | {color} ({suffix}) |")
|
||||
|
||||
isg_weighted_sum += isg_value * share
|
||||
total_share += share
|
||||
isg_weighted_sum += isg_value * share
|
||||
total_share += share
|
||||
|
||||
# Calculer ISG combiné
|
||||
if total_share > 0:
|
||||
isg_combined = isg_weighted_sum / total_share
|
||||
color, suffix = determine_threshold_color(isg_combined, "ISG", config.get('thresholds'))
|
||||
template.append(f"\n**ISG combiné: {isg_combined:.0f} - {color} ({suffix})**")
|
||||
# Calculer ISG combiné
|
||||
if total_share > 0:
|
||||
isg_combined = isg_weighted_sum / total_share
|
||||
color, suffix = determine_threshold_color(isg_combined, "ISG", config.get('thresholds'))
|
||||
template.append(f"\n**ISG combiné: {isg_combined:.0f} - {color} ({suffix})**")
|
||||
|
||||
# IHH
|
||||
ihh_file = find_corpus_file("matrice-des-risques-liés-à-l-assemblage/indice-de-herfindahl-hirschmann", f"{type}/Fiche assemblage {product_slug}")
|
||||
if ihh_file:
|
||||
template.append(read_corpus_file(ihh_file, shift_titles=1))
|
||||
template.append("\n")
|
||||
# IHH
|
||||
ihh_file = find_corpus_file("matrice-des-risques-liés-à-l-assemblage/indice-de-herfindahl-hirschmann", f"{type}/Fiche assemblage {product_slug}")
|
||||
if ihh_file:
|
||||
template.append(read_corpus_file(ihh_file, shift_titles=1))
|
||||
template.append("\n")
|
||||
|
||||
# Vulnérabilité combinée
|
||||
if assembly_id in results["ihh_isg_combined"]:
|
||||
combined = results["ihh_isg_combined"][assembly_id]
|
||||
template.append("#### Vulnérabilité combinée IHH-ISG\n")
|
||||
template.append(f"* IHH: {combined['ihh_value']} - {combined['ihh_color']} ({combined['ihh_suffix']})")
|
||||
template.append(f"* ISG combiné: {combined['isg_combined']:.0f} - {combined['isg_color']} ({combined['isg_suffix']})")
|
||||
template.append(f"* Poids combiné: {combined['combined_weight']}")
|
||||
template.append(f"* Niveau de vulnérabilité: **{combined['vulnerability']}**\n")
|
||||
# Vulnérabilité combinée
|
||||
if assembly_id in results["ihh_isg_combined"]:
|
||||
combined = results["ihh_isg_combined"][assembly_id]
|
||||
template.append("#### Vulnérabilité combinée IHH-ISG\n")
|
||||
template.append(f"* IHH: {combined['ihh_value']} - {combined['ihh_color']} ({combined['ihh_suffix']})")
|
||||
template.append(f"* ISG combiné: {combined['isg_combined']:.0f} - {combined['isg_color']} ({combined['isg_suffix']})")
|
||||
template.append(f"* Poids combiné: {combined['combined_weight']}")
|
||||
template.append(f"* Niveau de vulnérabilité: **{combined['vulnerability']}**\n")
|
||||
except:
|
||||
pass
|
||||
|
||||
# 2. Traiter les composants (fabrication)
|
||||
for component_id, component in data["components"].items():
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user