import os
import json

def aggregate_results(results_dir="tool_gen/generated"):
    for entry in sorted(os.listdir(results_dir)):
        iteration_path = os.path.join(results_dir, entry)
        if os.path.isdir(iteration_path) and entry.startswith("iteration_"):
            results_file = os.path.join(iteration_path, "results.json")
            with open(results_file, "r") as f:
                try:
                    data = json.load(f)
                    print(f"Iteration {entry}:")
                    for experiment in data:
                        print(f"{experiment['p2p_success']+experiment['f2p_success']} ")
                except Exception as e:
                    print(f"Failed to load {results_file}: {e}")

if __name__ == "__main__":
    aggregate_results()