From 775aa71c37b583d8875facbfe14fd23782db7afd Mon Sep 17 00:00:00 2001 From: zzjc1234 <2359047351@qq.com> Date: Tue, 10 Sep 2024 17:41:46 +0800 Subject: [PATCH] update --- convert.py | 27 ++++++----- expected_regex.json | 26 +++++++++- ret.md | 116 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 155 insertions(+), 14 deletions(-) create mode 100644 ret.md diff --git a/convert.py b/convert.py index f7831b9..a0641aa 100644 --- a/convert.py +++ b/convert.py @@ -1,7 +1,7 @@ import json import re -# 读取 JSON 文件内容 +# 读取 joj3_result.json 文件内容 with open("joj3_result.json", "r", encoding="utf-8") as file: json_data = file.read() @@ -11,18 +11,19 @@ data = json.loads(json_data) # 定义正则表达式以提取 diff 代码块 diff_pattern = re.compile(r"```diff\n(.*?)\n```", re.DOTALL) -# 提取所有 diff 代码块 -diff_blocks = [] - -for item in data: - if "results" in item: - for result in item["results"]: +# 遍历 "run" 的 results +for run in data: + if run["name"] == "run": + results = run["results"] + for result_index, result in enumerate(results): comment = result.get("comment", "") matches = diff_pattern.findall(comment) - diff_blocks.extend(matches) -# 处理 \n 符号并打印 diff 代码块 -for i, diff in enumerate(diff_blocks): - # 将 \n 替换为实际换行符 - formatted_diff = diff.replace("\\n", "\n") - print(f"Diff block {i+1}:\n{formatted_diff}\n") + if matches: + print(f"Result {result_index + 1} diff blocks:") + for i, diff in enumerate(matches): + # 将 \n 替换为实际换行符 + formatted_diff = diff.replace("\\n", "\n") + print(f"```diff\n{formatted_diff}\n```\n") + else: + print(f"Result {result_index + 1}: the same\n") diff --git a/expected_regex.json b/expected_regex.json index b94a35a..5000024 100644 --- a/expected_regex.json +++ b/expected_regex.json @@ -1 +1,25 @@ -[{"name":"compile","results":[{"score":0,"comment":""}]},{"name":"run","results":[{"score":100,"comment":"executor status: run time: \\d+ ns, memory: \\d+ bytes"},{"score":100,"comment":"executor status: run time: \\d+ ns, memory: \\d+ bytes"}],"force_quit":false}] +[ + { + "name": "compile", + "results": [ + { + "score": 0, + "comment": "" + } + ] + }, + { + "name": "run", + "results": [ + { + "score": 100, + "comment": "executor status: run time: \\d+ ns, memory: \\d+ bytes" + }, + { + "score": 100, + "comment": "executor status: run time: \\d+ ns, memory: \\d+ bytes" + } + ], + "force_quit": false + } +] diff --git a/ret.md b/ret.md new file mode 100644 index 0000000..c687330 --- /dev/null +++ b/ret.md @@ -0,0 +1,116 @@ +Result 1 diff blocks: +```diff + +- +- +``` + +Result 2 diff blocks: +```diff +- 1024 2048 + +``` + +Result 3 diff blocks: +```diff +- asdfljsdfklasdfjklasdfjjkl +- 1024 2048 +- asdfjksdfjkl + +``` + +Result 4 diff blocks: +```diff +- +- +- ++ 1024 +``` + +Result 5 diff blocks: +```diff +- 1024 2048 +- ++ 1024 +``` + +Result 6 diff blocks: +```diff +- asdfljsdfklasdfjklasdfjjkl +- 1024 2048 +- asdfjksdfjkl +- ++ 1024 +``` + +Result 7 diff blocks: +```diff +- 1024 2048 +- asdfjksdfjkl +- asdfljsdfklasdfjklasdfjjkl +- ++ 1024 +``` + +Result 8 diff blocks: +```diff +- 1024 2048 +- asdfjksdfjkl +- asdfljsdfklasdfjklasdfjjkl +- ++ 1024 +``` + +Result 9 diff blocks: +```diff +- +- +- ++ jklasdfklasdfjklf +``` + +Result 10 diff blocks: +```diff +- 1024 2048 +- ++ jklasdfklasdfjklf +``` + +Result 11 diff blocks: +```diff +- jklasdfklasdfjklf asdfhklasdfjl cvsdlfkdjsfklv +- 1024 2048 +- asdfjkl asdfkljdaslasdfjkl asdfjkl +- 1024 2048 +- psdfklj +- ++ jklasdfklasdfjklf +``` + +Result 12 diff blocks: +```diff +- asdfljsdfklasdfjklasdfjjkl +- 1024 2048 +- asdfjksdfjkl +- ++ jklasdfklasdfjklf +``` + +Result 13 diff blocks: +```diff +- 1024 2048 +- asdfjksdfjkl +- asdfljsdfklasdfjklasdfjjkl +- ++ jklasdfklasdfjklf +``` + +Result 14 diff blocks: +```diff +- 1024 2048 +- asdfjksdfjkl +- asdfljsdfklasdfjklasdfjjkl +- ++ jklasdfklasdfjklf +``` +