File size: 2,421 Bytes
97842c4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1067020
 
 
 
 
 
97842c4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env python3
"""
Script to recursively find JSON files and replace 'np.float64' with 'np.float32'
"""

import os
import json
from pathlib import Path

def process_json_files(root_directory):
    """
    Recursively scan directories for JSON files and replace np.float64 with np.float32
    
    Args:
        root_directory (str): The root directory to start scanning from
    """
    root_path = Path(root_directory)
    
    if not root_path.exists():
        print(f"Error: Directory '{root_directory}' does not exist")
        return
    
    json_files_found = 0
    json_files_modified = 0
    
    # Recursively find all JSON files
    for json_file in root_path.rglob("*.json"):
        json_files_found += 1
        print(f"Processing: {json_file}")
        
        try:
            # Read the file as text
            with open(json_file, 'r', encoding='utf-8') as f:
                content = f.read()
            
            # Check if replacement is needed
            string_to_replace = "_threshold': (" 
            if string_to_replace in content:
                # "_threshold': ("
                modified_content = content.replace(string_to_replace, "_threshold': " )
                # modified_content = content.replace("np.float64", "")
                # modified_content = modified_content.replace("), 'man", ", 'man")
                
                # Write back to the same file
                with open(json_file, 'w', encoding='utf-8') as f:
                    f.write(modified_content)
                
                json_files_modified += 1
                print(f"  ✓ Modified: {json_file}")
            else:
                print(f"  - No changes needed: {json_file}")
                
        except Exception as e:
            print(f"  ✗ Error processing {json_file}: {e}")
    
    print(f"\nSummary:")
    print(f"JSON files found: {json_files_found}")
    print(f"JSON files modified: {json_files_modified}")

def main():
    """Main function"""
    # Get the current directory or specify your target directory
    current_dir = "."
    
    # You can change this to your specific directory path
    # current_dir = "/path/to/your/directory"
    
    print(f"Scanning directory: {os.path.abspath(current_dir)}")
    print("Looking for JSON files to process...")
    print("-" * 50)
    
    process_json_files(current_dir)

if __name__ == "__main__":
    main()