Skip to content

Commit 8fab40c

Browse files
authored
Create tackle_pred.py
1 parent 40b0aa2 commit 8fab40c

1 file changed

Lines changed: 46 additions & 0 deletions

File tree

tackle_pred.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env python3
2+
import os
3+
import json
4+
from pathlib import Path
5+
6+
7+
def find_patch_files_in_final_folders(root_path):
8+
result = {}
9+
root = Path(root_path)
10+
final_folders = [folder for folder in root.iterdir() if folder.is_dir() and folder.name.endswith('-final')]
11+
print(f"找到 {len(final_folders)} 个 -final 文件夹:")
12+
for folder in final_folders:
13+
print(f"处理文件夹: {folder.name}")
14+
patch_files = list(folder.glob('*.patch'))
15+
if patch_files:
16+
patch_file = patch_files[0]
17+
try:
18+
with open(patch_file, 'r', encoding='utf-8') as f:
19+
patch_content = f.read()
20+
original_id = folder.name.replace('-sample-final', '')
21+
result[original_id] = {
22+
"model_name_or_path": "default__openai--GLM-4.7__t-0.70__p-1.00__c-0.00___swe_bench_verified_test",
23+
"instance_id": original_id,
24+
"model_patch": patch_content
25+
}
26+
print(f"✓ 成功读取 {patch_file.name}")
27+
except Exception as e:
28+
print(f"✗ 读取文件失败 {patch_file}: {e}")
29+
else:
30+
print(f"未找到 .patch 文件")
31+
return result
32+
33+
def main():
34+
root_directory = "" # Please Enter The absolute path obtained in Phase 2
35+
patches_data_final = find_patch_files_in_final_folders(root_directory)
36+
if patches_data:
37+
output_file = os.path.join(root_directory, "answer_final.json")
38+
with open(output_file, 'w', encoding='utf-8') as f:
39+
json.dump(patches_data, f, indent=4, ensure_ascii=False)
40+
print(f"\n✓ 成功生成 {output_file}")
41+
print(f"共处理了 {len(patches_data)} 个patch文件")
42+
else:
43+
print("未找到任何patch文件")
44+
45+
if __name__ == "__main__":
46+
main()

0 commit comments

Comments
 (0)