import json
import yaml
import os

STATS_DIR = "stats"  # Define the stats directory

def convert_json_to_yaml():
    """Recursively process all JSON files in STATS_DIR and convert them to YAML."""
    for root, _, files in os.walk(STATS_DIR):
        for file in files:
            if file.endswith(".json"):
                json_path = os.path.join(root, file)
                yaml_path = os.path.join(root, file.replace(".json", ".yaml"))
                
                # Read JSON file
                with open(json_path, 'r') as json_file:
                    data = json.load(json_file)
                
                # Write YAML file
                with open(yaml_path, 'w', encoding='utf-8') as yaml_file:
                    yaml.dump(data, yaml_file, default_flow_style=False, sort_keys=False, allow_unicode=False, width=120, explicit_start=True, explicit_end=True, default_style="", line_break="unix", indent=2)
                
                print(f"Converted: {json_path} --> {yaml_path}")

def main():
    convert_json_to_yaml()

if __name__ == "__main__":
    main()
