import pandas as pd import networkx as nx def analyze_trace(source_node): df = pd.read_csv("data/network_topology.csv") # Build directed graph from the CSV G = nx.from_pandas_edgelist(df, source='Source', target='Target', create_using=nx.DiGraph()) # Get all nodes nodes = list(G.nodes()) # Default: no path found path = ["Unknown"] # Attempt to find path to CoreNetwork target_node = "CoreNetwork" if source_node in G and target_node in G: try: path = nx.shortest_path(G, source=source_node, target=target_node) except nx.NetworkXNoPath: path = ["No path to CoreNetwork"] return path, nodes