"""
Master script to generate all figures for the paper
Run this to create all PDF and PNG figures at once
"""

import subprocess
import sys
import os

# Change to LaTeX directory
script_dir = os.path.dirname(os.path.abspath(__file__))
os.chdir(script_dir)

scripts = [
    'generate_slipnet_graph.py',
    'compare_formulas.py',
    'activation_spreading.py',
    'resistance_distance.py',
    'clustering_analysis.py',
    'workspace_evolution.py',
]

print("="*70)
print("Generating all figures for the paper:")
print("  'From Hardcoded Heuristics to Graph-Theoretical Constructs'")
print("="*70)
print()

failed_scripts = []

for i, script in enumerate(scripts, 1):
    print(f"[{i}/{len(scripts)}] Running {script}...")
    try:
        result = subprocess.run([sys.executable, script],
                              capture_output=True,
                              text=True,
                              timeout=60)
        if result.returncode == 0:
            print(f"    ✓ Success")
            if result.stdout:
                print(f"    {result.stdout.strip()}")
        else:
            print(f"    ✗ Failed with return code {result.returncode}")
            if result.stderr:
                print(f"    Error: {result.stderr.strip()}")
            failed_scripts.append(script)
    except subprocess.TimeoutExpired:
        print(f"    ✗ Timeout (>60s)")
        failed_scripts.append(script)
    except Exception as e:
        print(f"    ✗ Exception: {e}")
        failed_scripts.append(script)
    print()

print("="*70)
print("Summary:")
print("="*70)

if not failed_scripts:
    print("✓ All figures generated successfully!")
    print()
    print("Generated files:")
    print("  - figure1_slipnet_graph.pdf/.png")
    print("  - figure2_activation_spreading.pdf/.png")
    print("  - figure3_resistance_distance.pdf/.png")
    print("  - figure4_workspace_evolution.pdf/.png")
    print("  - figure5_betweenness_dynamics.pdf/.png")
    print("  - figure6_clustering_distribution.pdf/.png")
    print("  - formula_comparison.pdf/.png")
    print("  - scalability_comparison.pdf/.png")
    print("  - slippability_temperature.pdf/.png")
    print("  - external_strength_comparison.pdf/.png")
    print()
    print("You can now compile the LaTeX document with these figures.")
    print("To include them in paper.tex, replace the placeholder \\fbox commands")
    print("with \\includegraphics commands:")
    print()
    print("  \\includegraphics[width=0.8\\textwidth]{figure1_slipnet_graph.pdf}")
else:
    print(f"✗ {len(failed_scripts)} script(s) failed:")
    for script in failed_scripts:
        print(f"  - {script}")
    print()
    print("Please check the error messages above and ensure you have")
    print("the required packages installed:")
    print("  pip install matplotlib numpy networkx scipy")

print("="*70)
