-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_bias.py
190 lines (182 loc) · 5.79 KB
/
get_bias.py
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
import sys
import re
import string
import re
base_bias = 0
if len(sys.argv) == 4:
pass
elif len(sys.argv) == 5:
base_bias = string.atoi(sys.argv[4])
else:
print 'Parameter error!'
sys.exit(1)
compmap = {}
fin = open(sys.argv[3], 'r')
read_head = False
while True:
reads = fin.readline()
if reads.startswith('<TABLE') or reads.startswith('<TBODY'):
continue
elif reads.startswith('</TBODY'):
break
elif reads.startswith('<TR'):
if not read_head:
read_head = True
else:
match = re.match('<TR><TD>(.*)</TD><TD>(.*)</TD><TD>(.*)</TD><TD>(.*)</TD><TD>(.*)</TD><TD>(.*)</TD><TD>(.*)%</TD><TD>(.*)</TD><TD>(.*)%</TD><TD>(.*)</TD><TD>(.*)</TD></TR>', reads)
name = match.group(2)
intelo = string.atoi(match.group(3))
compmap[name] = intelo
fin.close()
sum_rating = 0
count_rating = 0
records = []
fin = open(sys.argv[1], 'r')
read_head = False
while True:
reads = fin.readline()
if reads.startswith('<TABLE') or reads.startswith('<TBODY'):
continue
elif reads.startswith('</TBODY'):
break
elif reads.startswith('<TR'):
if not read_head:
read_head = True
else:
match = re.match('<TR><TD>(.*)</TD><TD>(.*)</TD><TD>(.*)</TD><TD>(.*)</TD><TD>(.*)</TD><TD>(.*)</TD><TD>(.*)%</TD><TD>(.*)</TD><TD>(.*)%</TD><TD>(.*)</TD><TD>(.*)</TD></TR>', reads)
rank = match.group(1)
name = match.group(2)
elo = match.group(3)
intelo = string.atoi(elo)
plus = match.group(4)
minus = match.group(5)
games = match.group(6)
score = match.group(7)
oppo = match.group(8)
draws = match.group(9)
author = match.group(10)
place = match.group(11)
if compmap.has_key(name):
bias = compmap[name] - intelo
sum_rating += bias
count_rating += 1
records.append((rank, name, elo, plus, minus, games, score, oppo, draws, author, place))
fin.close()
records_0 = []
fin = open(sys.argv[2], 'r')
read_head = False
while True:
reads = fin.readline()
if reads.startswith('<TABLE') or reads.startswith('<TBODY'):
continue
elif reads.startswith('</TBODY'):
break
elif reads.startswith('<TR'):
if not read_head:
read_head = True
else:
match = re.match('<TR><TD>(.*)</TD><TD>(.*)</TD><TD>(.*)</TD><TD>(.*)</TD><TD>(.*)</TD><TD>(.*)</TD><TD>(.*)%</TD><TD>(.*)</TD><TD>(.*)%</TD><TD>(.*)</TD><TD>(.*)</TD></TR>', reads)
rank = match.group(1)
name = match.group(2)
elo = match.group(3)
plus = match.group(4)
minus = match.group(5)
games = match.group(6)
score = match.group(7)
oppo = match.group(8)
draws = match.group(9)
author = match.group(10)
place = match.group(11)
records_0.append((rank, name, elo, plus, minus, games, score, oppo, draws, author, place))
fin.close()
bias = int(round(sum_rating * 1.0 / count_rating)) + base_bias
fout = open(sys.argv[1], 'w')
fout.write('<TABLE border=1>\n')
fout.write('<TBODY>\n')
fout.write('<TR><TH>Rank</TH><TH>Name</TH><TH>Elo</TH><TH>+</TH><TH>-</TH><TH>games</TH><TH>score</TH><TH>oppo.</TH><TH>draws</TH><TH>Author</TH><TH>Place</TH></TR>\n')
for each in records:
fout.write('<TR>')
fout.write('<TD>')
fout.write(each[0])
fout.write('</TD>')
fout.write('<TD>')
fout.write(each[1])
fout.write('</TD>')
rating = string.atoi(each[2]) + bias
fout.write('<TD>')
fout.write(str(rating))
fout.write('</TD>')
fout.write('<TD>')
fout.write(each[3])
fout.write('</TD>')
fout.write('<TD>')
fout.write(each[4])
fout.write('</TD>')
fout.write('<TD>')
fout.write(each[5])
fout.write('</TD>')
fout.write('<TD>')
fout.write(each[6])
fout.write('%</TD>')
oppo = string.atoi(each[7]) + bias
fout.write('<TD>')
fout.write(str(oppo))
fout.write('</TD>')
fout.write('<TD>')
fout.write(each[8])
fout.write('%</TD>')
fout.write('<TD>')
fout.write(each[9])
fout.write('</TD>')
fout.write('<TD>')
fout.write(each[10])
fout.write('</TD>')
fout.write('</TR>\n')
fout.write('</TBODY>\n')
fout.write('</TABLE>\n')
fout.close()
fout = open(sys.argv[2], 'w')
fout.write('<TABLE border=1>\n')
fout.write('<TBODY>\n')
fout.write('<TR><TH>Rank</TH><TH>Name</TH><TH>Elo</TH><TH>+</TH><TH>-</TH><TH>games</TH><TH>score</TH><TH>oppo.</TH><TH>draws</TH><TH>Author</TH><TH>Place</TH></TR>\n')
for each in records_0:
fout.write('<TR>')
fout.write('<TD>')
fout.write(each[0])
fout.write('</TD>')
fout.write('<TD>')
fout.write(each[1])
fout.write('</TD>')
rating = string.atoi(each[2]) + bias
fout.write('<TD>')
fout.write(str(rating))
fout.write('</TD>')
fout.write('<TD>')
fout.write(each[3])
fout.write('</TD>')
fout.write('<TD>')
fout.write(each[4])
fout.write('</TD>')
fout.write('<TD>')
fout.write(each[5])
fout.write('</TD>')
fout.write('<TD>')
fout.write(each[6])
fout.write('%</TD>')
oppo = string.atoi(each[7]) + bias
fout.write('<TD>')
fout.write(str(oppo))
fout.write('</TD>')
fout.write('<TD>')
fout.write(each[8])
fout.write('%</TD>')
fout.write('<TD>')
fout.write(each[9])
fout.write('</TD>')
fout.write('<TD>')
fout.write(each[10])
fout.write('</TD>')
fout.write('</TR>\n')
fout.write('</TBODY>\n')
fout.write('</TABLE>\n')
fout.close()