Skip to content

Commit 3c7bd65

Browse files
author
janzert
committed
Script to extract 90% worse and better probability range from LOS
1 parent d101283 commit 3c7bd65

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

planet_wars/backend/los_data.py

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/python
2+
3+
import sys
4+
5+
def parse_los(lines):
6+
header = lines[0]
7+
width = len(header.split()[0]) + 1
8+
name_width = len(header) - len(header.lstrip()) - 1
9+
divisor = 10 ** (float(width) - 1)
10+
los_data = []
11+
for line in lines[1:]:
12+
name = line[0:name_width]
13+
field_str = line[name_width:]
14+
fields = []
15+
for i in range(0, len(field_str) - width, width):
16+
f = field_str[i:i+width]
17+
try:
18+
fields.append(int(f) / divisor)
19+
except ValueError:
20+
if f.strip() == "":
21+
fields.append(None)
22+
else:
23+
raise
24+
los_data.append((name, fields))
25+
return (los_data, name_width, width)
26+
27+
def main(los_filename, leaderboard=None):
28+
los_file = open(los_filename, 'r')
29+
los_lines = los_file.readlines()
30+
los_file.close()
31+
los_data, name_width, width = parse_los(los_lines)
32+
rank = 0
33+
print "Rank Name%*s 10%% 90%%" % (name_width - 17, " ")
34+
for user, probabilities in los_data:
35+
rank += 1
36+
user_id, name, sub_id = user.split(',')
37+
sub_id = int(sub_id)
38+
self = probabilities.index(None)
39+
num_before = len(probabilities[:self])
40+
upper_limit = num_before + 1
41+
for pr_rank, per in enumerate(probabilities[:self]):
42+
if per >= 0.10:
43+
break
44+
upper_limit = num_before - pr_rank
45+
lower_limit = 1
46+
for dist, per in enumerate(probabilities[self+1:]):
47+
if per < 0.90:
48+
lower_limit = dist + 2
49+
print "%4d %-*s %4d %4d" % (rank, name_width-13, name,
50+
upper_limit, lower_limit)
51+
52+
if __name__ == "__main__":
53+
if len(sys.argv) < 2:
54+
print "usage: %s <los file> [leaderboard id]" % (sys.argv[0],)
55+
sys.exit()
56+
leaderboard = None
57+
if len(sys.argv) > 2:
58+
leaderboard = int(sys.argv[2])
59+
main(sys.argv[1], leaderboard)
60+

0 commit comments

Comments
 (0)