File size: 1,234 Bytes
504b2e4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import re

# 定义读取日志文件并提取分数的函数
def extract_scores(log_file_path):
    scores = []
    # 使用正则表达式匹配 "Game Over, You got XX score"
    score_pattern = re.compile(r"INFO:root:Game Over, You got (\d+) score")
    
    # 打开并读取日志文件
    with open(log_file_path, 'r') as file:
        for line in file:
            match = score_pattern.search(line)
            if match:
                scores.append(int(match.group(1)))
    
    return scores

# 定义计算统计值的函数
def calculate_statistics(scores):
    if not scores:
        return None, None, None
    return min(scores), max(scores), sum(scores) / len(scores)

# 主函数
def main(log_file_path):
    scores = extract_scores(log_file_path)
    if scores:
        min_score, max_score, avg_score = calculate_statistics(scores)
        print(f"分数:{scores}")
        print(f"最小值: {min_score}")
        print(f"最大值: {max_score}")
        print(f"均值: {avg_score:.2f}")
    else:
        print("未找到任何得分记录") 

if __name__ == "__main__":
    # 运行主函数,替换为你的日志文件路径
    log_file_path = input("Input the log file path: ")
    main(log_file_path)