This commit is contained in:
Zyy554
2025-12-16 00:10:16 +08:00
parent ef93f0cc6a
commit 3ca49b8b81
46 changed files with 7508 additions and 566 deletions

View File

@@ -4,6 +4,7 @@ import subprocess
import sys
from concurrent.futures import ProcessPoolExecutor, as_completed
from pathlib import Path
import os
import pandas as pd
@@ -30,14 +31,27 @@ def load_factory_codes(year: int) -> list[str]:
def run_single(factory_code: str, python_exe: str, script_path: Path) -> tuple[str, int, str]:
cmd = [python_exe, str(script_path), "--factory", factory_code]
result = subprocess.run(cmd, capture_output=True, text=True)
# 设置环境变量确保子进程使用UTF-8编码
env = os.environ.copy()
env['PYTHONIOENCODING'] = 'utf-8'
# 明确指定编码为UTF-8并设置错误处理策略
result = subprocess.run(
cmd,
capture_output=True,
text=True,
encoding='utf-8',
errors='replace', # 将无法解码的字符替换为占位符
env=env
)
output = (result.stdout or "") + (result.stderr or "")
return factory_code, result.returncode, output
def main():
parser = argparse.ArgumentParser(description="Parallel GA calibration for all factories.")
parser.add_argument("--max-workers", type=int, default=6, help="并行进程数上限(默认 6")
parser.add_argument("--max-workers", type=int, default=3, help="并行进程数上限(默认 6")
args = parser.parse_args()
year = json.load(open("year.json", "r", encoding="utf-8"))["year"]