| import json |
| import networkx as nx |
| import os |
| import sys |
| sys.path.append(os.path.join(os.path.dirname(__file__), "../")) |
| from app.services.agn_service.build_graph import build_graph |
| from app.services.agn_service.visualize_graph import visualize_graph |
|
|
| |
| index_file_path = "graphs/index.json" |
|
|
| |
| def load_json_file(file_path): |
| try: |
| with open(file_path, "r") as file: |
| return json.load(file) |
| except json.JSONDecodeError as e: |
| print(f"Error parsing JSON file: {e}") |
| return None |
| except FileNotFoundError: |
| print(f"File not found: {file_path}") |
| return None |
|
|
| |
| data = load_json_file(index_file_path) |
|
|
| |
| if data is None: |
| print("Failed to load JSON data.") |
| else: |
| |
| try: |
| G = build_graph(data) |
| print("Graph built successfully.") |
| except Exception as e: |
| print(f"Error building graph: {e}") |
| |
|
|
| output_image = "test_graph_visualization.png" |
|
|
| |
| if G: |
| visualize_graph(G, output_file=output_image) |
| print(f"Graph visualization generated and saved as {output_image}") |
| else: |
| print("Failed to build graph.") |