from typing import Dict, Tuple, Union import networkx as nx def preparer_graphe(G: nx.Graph) -> Tuple[nx.Graph, Dict[Union[str, int], int]]: """Nettoie et prépare le graphe pour l'analyse. Args: G (nx.Graph): Le graphe d'origine à nettoyer. Returns: tuple: Un tuple contenant le graphe nettoyé et les niveaux temporels associés aux nœuds du graphe. Le graphe nettoyé a eu ses nœuds qui ne respectaient pas les critères d'admissibilité enlevés. """ niveaux_temp = { node: int(str(attrs.get("niveau")).strip('"')) for node, attrs in G.nodes(data=True) if attrs.get("niveau") and str(attrs.get("niveau")).strip('"').isdigit() } G.remove_nodes_from([n for n in G.nodes() if n not in niveaux_temp]) G.remove_nodes_from( [n for n in G.nodes() if niveaux_temp.get(n) == 10 and 'Reserves' in n]) return G, niveaux_temp