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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
| import os
import re
from collections import defaultdict
def search_files(directory, pattern):
matches = []
for root, dirs, files in os.walk(directory):
for file in files:
file_path = os.path.join(root, file)
try:
with open(file_path, "r", encoding="utf-8", errors="ignore") as f:
matches.extend(re.findall(pattern, f.read()))
except UnicodeDecodeError:
print(f"Error decoding file: {file_path}")
return matches
def rate(directory, pattern):
results = defaultdict(dict)
matches = search_files(directory, pattern)
for match in matches:
pId, C, W, L, rate = match
results[pId].update({"C": C, "W": W, "L": L, "rate": round(float(rate), 4)})
return results
def jackpot_buy(directory, pattern):
results = defaultdict(int)
matches = search_files(directory, pattern)
for match in matches:
pId, number = match
results[pId] += int(number)
return results
def jackpot_win(directory, pattern):
results = defaultdict(int)
matches = search_files(directory, pattern)
for match in matches:
pId, win = match
results[pId] += int(win)
return results
def jackpot_win_type(directory, pattern, output_file):
matches = search_files(directory, pattern)
with open(output_file, 'w', encoding='utf-8') as f_out:
for match in matches:
cardType, winType, number = match
result = f"cardType: {cardType} winType: {winType} number: {number}\n"
f_out.write(result)
def merge_data(rates, jackpot_buy, jackpot_win):
merged_data = defaultdict(dict)
for pId, data in rates.items():
merged_data[pId].update(data)
for pId, buy in jackpot_buy.items():
merged_data[pId]['buy'] = buy
for pId, win in jackpot_win.items():
merged_data[pId]['win'] = win
return merged_data
def write_to_file(data, output_file):
with open(output_file, 'w', encoding='utf-8') as f:
for pId, values in data.items():
line = f"pId: {pId} {' '.join(f'{key}: {value}' for key, value in values.items())}\n"
f.write(line)
rate_search = r"PlayerExit pId:(\d+) C:(\d+) W:(\d+) L:(\d+) rate:([\d.]+)"
jackpot_buy_search = r"BugJp:(\d+) number:(\d+)"
jackpot_win_search = r"pId:(\d+) jpWin:(\d+)"
jackpot_win_type_search = r"JackpotWinType cardType:(\d+) winType:(\d+) number:(\d+)"
# jackpot
jackpot_win_type("./logs/bonustexas_a_1/", jackpot_win_type_search, "./all/1-jackpot_win_type.txt")
jackpot_win_type("./logs/bonustexas_a_2/", jackpot_win_type_search, "./all/2-jackpot_win_type.txt")
jackpot_win_type("./logs/bonustexas_a_3/", jackpot_win_type_search, "./all/3-jackpot_win_type.txt")
jackpot_win_type("./logs/bonustexas_a_4/", jackpot_win_type_search, "./all/4-jackpot_win_type.txt")
directory_1 = './logs/bonustexas_a_1/' # 当前目录路径
output_file_1 = './all/1-all.txt' # 输出文件名
directory_2 = './logs/bonustexas_a_2/' # 当前目录路径
output_file_2 = './all/2-all.txt' # 输出文件名
directory_3 = './logs/bonustexas_a_3/' # 当前目录路径
output_file_3 = './all/3-all.txt' # 输出文件名
directory_4 = './logs/bonustexas_a_4/' # 当前目录路径
output_file_4 = './all/4-all.txt' # 输出文件名
rates_data_1 = rate(directory_1, rate_search)
jackpot_buy_data_1 = jackpot_buy(directory_1, jackpot_buy_search)
jackpot_win_data_1 = jackpot_win(directory_1, jackpot_win_search)
merged_data = merge_data(rates_data_1, jackpot_buy_data_1, jackpot_win_data_1)
write_to_file(merged_data, output_file_1)
rates_data_2 = rate(directory_2, rate_search)
jackpot_buy_data_2 = jackpot_buy(directory_2, jackpot_buy_search)
jackpot_win_data_2 = jackpot_win(directory_2, jackpot_win_search)
merged_data = merge_data(rates_data_2, jackpot_buy_data_2, jackpot_win_data_2)
write_to_file(merged_data, output_file_2)
rates_data_3 = rate(directory_3, rate_search)
jackpot_buy_data_3 = jackpot_buy(directory_3, jackpot_buy_search)
jackpot_win_data_3 = jackpot_win(directory_3, jackpot_win_search)
merged_data = merge_data(rates_data_3, jackpot_buy_data_3, jackpot_win_data_3)
write_to_file(merged_data, output_file_3)
rates_data_4 = rate(directory_4, rate_search)
jackpot_buy_data_4 = jackpot_buy(directory_4, jackpot_buy_search)
jackpot_win_data_4 = jackpot_win(directory_4, jackpot_win_search)
merged_data = merge_data(rates_data_4, jackpot_buy_data_4, jackpot_win_data_4)
write_to_file(merged_data, output_file_4)
|