File size: 3,014 Bytes
5bfc765 | 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 | """
Complete path fix for all 48 scripts
"""
import os
from pathlib import Path
scripts_dir = Path("c:/numerai48models/scripts")
all_scripts = list(scripts_dir.rglob("*.py"))
fixed = 0
for script in all_scripts:
try:
with open(script, 'r', encoding='utf-8', errors='ignore') as f:
content = f.read()
# Determine tournament from path
if 'main' in str(script):
tournament = 'main'
elif 'signals' in str(script):
tournament = 'signals'
elif 'crypto' in str(script):
tournament = 'crypto'
else:
continue
# Find and replace the configuration section
if '# CONFIGURATION' in content and 'BASE_DIR' in content:
# Replace entire config section with working version
lines = content.split('\n')
new_lines = []
in_config = False
skip_until_print = False
for i, line in enumerate(lines):
if '# CONFIGURATION' in line:
in_config = True
new_lines.append(line)
new_lines.append('# ' + '=' * 44)
new_lines.append('TESTING_MODE = os.getenv("TESTING_MODE", "true").lower() == "true"')
new_lines.append('if TESTING_MODE:')
new_lines.append(f' BASE_DIR = Path("c:/numerai48models")')
new_lines.append(f' MODEL_DIR = BASE_DIR / "models" / "{tournament}"')
new_lines.append(f' DATA_DIR = BASE_DIR / "data" / "{tournament}"')
new_lines.append(f' OUTPUT_DIR = BASE_DIR / "submissions" / "{tournament}"')
new_lines.append('else:')
new_lines.append(' BASE_DIR = Path("/app")')
new_lines.append(f' MODEL_DIR = BASE_DIR / "models" / "{tournament}"')
new_lines.append(f' DATA_DIR = BASE_DIR / "data" / "{tournament}"')
new_lines.append(f' OUTPUT_DIR = BASE_DIR / "submissions" / "{tournament}"')
new_lines.append('')
new_lines.append('for dir_path in [DATA_DIR, OUTPUT_DIR]:')
new_lines.append(' dir_path.mkdir(exist_ok=True, parents=True)')
skip_until_print = True
elif skip_until_print and 'print(f"[FOLDER] Model directory' in line:
skip_until_print = False
new_lines.append(line)
elif not skip_until_print:
new_lines.append(line)
content = '\n'.join(new_lines)
with open(script, 'w', encoding='utf-8', errors='ignore') as f:
f.write(content)
print(f"[OK] {script.relative_to(scripts_dir)}")
fixed += 1
except Exception as e:
print(f"[ERR] {script.name}: {e}")
print(f"\nFixed {fixed} scripts!")
|