Cette mise a jour complete ameliore significativement la qualite et la maintenabilite du projet. 1. Extension de la couverture de tests Couverture globale passee de 8% a 16% (+100%) - Ajout de 25 nouveaux tests (total: 67 tests, 100% passent) - Nouveaux fichiers de tests: * tests/unit/test_gitea.py (17 tests) * tests/unit/test_fiches_tickets.py (8 tests) Etat de la couverture par module: - utils/gitea.py: 100% - utils/widgets.py: 100% - utils/logger.py: 94% - app/fiches/utils/tickets/core.py: 77% - utils/graph_utils.py: 59% 2. Documentation d'architecture complete Creation de 3 nouveaux documents (30 Ko total): - docs/ARCHITECTURE.md (15 Ko) * Architecture complete du projet * Flux de donnees detailles * Indices de vulnerabilite (IHH, ISG, ICS, IVC) * Structure du graphe NetworkX - docs/MODULES.md (15 Ko) * Guide des 11 modules principaux * Exemples de code (15+ snippets) * Bonnes pratiques * Guide de depannage - docs/README.md (4 Ko) * Index de toute la documentation Contenu documente: - 5 modules applicatifs - 6 modules utilitaires - 4 indices de vulnerabilite avec formules et seuils - Conventions de code 3. Reorganisation de la documentation Structure finale optimisee: - Racine: README.md (mis a jour) + Instructions.md - docs/: 11 documents organises par categorie Fichiers deplaces vers docs/: - README_connexion.md -> docs/CONNEXION.md - GUIDE_LOGS.md -> docs/ - GUIDE_RUFF.md -> docs/ - RAPPORT_RUFF.md -> docs/ - RAPPORT_CORRECTIONS_AUTO.md -> docs/ - REFACTORING_REPORT.md -> docs/ - VERIFICATION_LOGS.md -> docs/ - TODO_IA_BATCH.md -> docs/ 4. Ajout de docstrings 52 fonctions documentees en style Google (100%) Documentation en francais avec Args, Returns, Raises 5. Corrections automatiques Ruff Application de 347 corrections automatiques: - Formatage du code (line-length: 120) - Organisation des imports - Simplifications syntaxiques - Suppressions de code mort - Ameliorations de performance 6. Configuration qualite du code Nouveaux fichiers: - pyproject.toml: configuration Ruff complete - .vscode/settings.json: integration Ruff avec formatOnSave - GUIDE_RUFF.md: documentation du linter - GUIDE_LOGS.md: documentation du logging - .gitignore: ajout htmlcov/ pour rapports de couverture Etat final du projet: - Linter: Ruff configure (15 regles actives) - Tests: 67 tests (100% passent) - Couverture de code: 16% - Docstrings: 52/52 (100%) - Documentation: 11 fichiers organises Impact: - Tests plus robustes et maintenables - Documentation technique complete - Meilleure organisation des fichiers - Workflow optimise avec Ruff - Code pret pour integration continue References: - Architecture: docs/ARCHITECTURE.md - Guide modules: docs/MODULES.md - Tests: tests/unit/ - Configuration: pyproject.toml Co-Authored-By: Claude <noreply@anthropic.com>
111 lines
4.7 KiB
Python
111 lines
4.7 KiB
Python
# === Ajout de produit personnalisé ===
|
|
import networkx as nx
|
|
import streamlit as st
|
|
|
|
from utils.persistance import get_champ_statut, maj_champ_statut, supprime_champ_statut
|
|
from utils.translations import _
|
|
|
|
|
|
def ajouter_produit(G: nx.DiGraph) -> nx.DiGraph:
|
|
"""Affiche l'interface d'ajout d'un nouveau produit personnalise au graphe."""
|
|
st.markdown(f"## {str(_('pages.personnalisation.add_new_product'))}")
|
|
|
|
# Restauration des produits personnalisés sauvegardés
|
|
if "pages.personnalisation.create_product.fait" not in st.session_state and get_champ_statut("pages.personnalisation.create_product.fait") == "oui":
|
|
index = 0
|
|
while True:
|
|
new_prod = get_champ_statut(f"pages.personnalisation.create_product.{index}.nom")
|
|
if new_prod == "":
|
|
break
|
|
|
|
G.add_node(new_prod, niveau="0", personnalisation="oui", label=new_prod)
|
|
|
|
sel_new_op = get_champ_statut(f"pages.personnalisation.create_product.{index}.edge")
|
|
if sel_new_op:
|
|
G.add_edge(new_prod, sel_new_op)
|
|
|
|
i = 0
|
|
while True:
|
|
comp = get_champ_statut(f"pages.personnalisation.create_product.{index}.composants.{i}")
|
|
if comp == "":
|
|
break
|
|
G.add_edge(new_prod, comp)
|
|
i += 1
|
|
|
|
index += 1
|
|
|
|
niveau1 = sorted([n for n, d in G.nodes(data=True) if d.get("niveau") == "1"])
|
|
ops_dispo = sorted([n for n, d in G.nodes(data=True) if d.get("niveau") == "assemblage"])
|
|
|
|
if "pages.personnalisation.add.new_product_name" not in st.session_state:
|
|
st.session_state["pages.personnalisation.add.new_product_name"] = get_champ_statut("pages.personnalisation.add.new_product_name")
|
|
|
|
new_prod = st.text_input(
|
|
str(_("pages.personnalisation.new_product_name")),
|
|
key="pages.personnalisation.add.new_product_name"
|
|
)
|
|
|
|
if new_prod:
|
|
if new_prod in G.nodes:
|
|
st.warning(str(_("pages.personnalisation.product_exists")))
|
|
return G
|
|
|
|
if "pages.personnalisation.add.assembly_operation" not in st.session_state:
|
|
st.session_state["pages.personnalisation.add.assembly_operation"] = get_champ_statut("pages.personnalisation.add.assembly_operation")
|
|
|
|
if "pages.personnalisation.add.components_to_link" not in st.session_state:
|
|
composants = []
|
|
i = 0
|
|
while True:
|
|
val = get_champ_statut(f"pages.personnalisation.add.components_to_link.{i}")
|
|
if val == "":
|
|
break
|
|
composants.append(val)
|
|
i += 1
|
|
st.session_state["pages.personnalisation.add.components_to_link"] = composants
|
|
|
|
ops_dispo = sorted([
|
|
n for n, d in G.nodes(data=True)
|
|
if d.get("niveau") == "10"
|
|
and any(G.has_edge(p, n) and G.nodes[p].get("niveau") == "0" for p in G.predecessors(n))
|
|
])
|
|
sel_new_op = st.selectbox(str(_("pages.personnalisation.assembly_operation")), ops_dispo,
|
|
key="pages.personnalisation.add.assembly_operation")
|
|
|
|
sel_comps = st.multiselect(
|
|
str(_("pages.personnalisation.components_to_link")),
|
|
options=niveau1,
|
|
key="pages.personnalisation.add.components_to_link"
|
|
)
|
|
|
|
if st.button(str(_("pages.personnalisation.create_product"))):
|
|
G.add_node(new_prod, niveau="0", personnalisation="oui", label=new_prod)
|
|
|
|
# Trouver le prochain index disponible
|
|
index = 0
|
|
while get_champ_statut(f"pages.personnalisation.create_product.{index}.nom") != "":
|
|
index += 1
|
|
|
|
maj_champ_statut(f"pages.personnalisation.create_product.{index}.nom", new_prod)
|
|
|
|
if sel_new_op != str(_("pages.personnalisation.none")):
|
|
G.add_edge(new_prod, sel_new_op)
|
|
maj_champ_statut(f"pages.personnalisation.create_product.{index}.edge", sel_new_op)
|
|
|
|
for j, comp in enumerate(sel_comps):
|
|
G.add_edge(new_prod, comp)
|
|
maj_champ_statut(f"pages.personnalisation.create_product.{index}.composants.{j}", comp)
|
|
|
|
maj_champ_statut("pages.personnalisation.create_product.fait", "oui")
|
|
|
|
# Nettoyage de session et des champs persistants
|
|
del st.session_state["pages.personnalisation.add.new_product_name"]
|
|
del st.session_state["pages.personnalisation.add.assembly_operation"]
|
|
del st.session_state["pages.personnalisation.add.components_to_link"]
|
|
supprime_champ_statut("pages.personnalisation.add")
|
|
|
|
st.success(f"{new_prod} {str(_('pages.personnalisation.added'))}")
|
|
st.rerun()
|
|
|
|
return G
|