From 6f641d63107f82071beb19899504e0cbbacf19d5 Mon Sep 17 00:00:00 2001 From: Aria F <51890782+ariafyy@users.noreply.github.com> Date: Wed, 11 Oct 2023 10:45:58 +0800 Subject: [PATCH] #refactor: refactor Utils class for log parsing --- examples/werewolf_game/evals/utils.py | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/examples/werewolf_game/evals/utils.py b/examples/werewolf_game/evals/utils.py index ac2eecdf6..d788496a3 100644 --- a/examples/werewolf_game/evals/utils.py +++ b/examples/werewolf_game/evals/utils.py @@ -1,6 +1,6 @@ ''' Filename: MetaGPT/examples/werewolf_game/evals/utils.py -Created Date: Oct 10, 2023 +Created Date: Oct 11, 2023 Author: [Aria](https://github.com/ariafyy) ''' from metagpt.const import WORKSPACE_ROOT, PROJECT_ROOT @@ -10,10 +10,8 @@ import re class Utils: """Utils: utils of logs""" - def __init__(self): - pass - - def polish_log(self, in_logfile, out_txtfile): + @staticmethod + def polish_log(in_logfile, out_txtfile): """polish logs for evaluation""" pattern_text = r"(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}) \| (\w+) +\| ([\w\.]+:\w+:\d+) - (.*\S)" pattern_player = r"(Player(\d{1}): \w+)" @@ -49,13 +47,7 @@ class Utils: out.write(line.strip()) json_start = False - elif line.startswith("(User):"): - out.write(line) - - elif line.startswith("********** STEP:"): - out.write(line) - - elif re.search(pattern_player, line): + elif line.startswith("(User):") or line.startswith("********** STEP:") or re.search(pattern_player,line): out.write(line) else: