-
Notifications
You must be signed in to change notification settings - Fork 1
/
besttop3.py
73 lines (56 loc) · 2.05 KB
/
besttop3.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
#!/usr/bin/python
import sys
from db import WCA_Database
# Print table
def table(rank):
sys.stdout=open("besttop3.txt","w")
print('[spoiler=Best top 3]')
print('[table]')
print('[tr][td][td]Sum of averages[/td][td]round[/td][td]Competition[/td][/tr]')
# If more than 100 people have an average, just take top 100
for k in range(0, len(rank)):
i = k+1
for l in range(0,k):
if rank[k][0] == rank[k-l][0]:
i = k-l+1
print('[tr][td]', i, '[/td][td]', rank[k][0],'[/td][td]', rank[k][2], '[/td][td]', rank[k][1], '[/td][/tr]')
if k > 100:
break
print('[/table]')
print('[/spoiler]')
sys.stdout.close()
cur = WCA_Database.query("SELECT best, average, pos, competitionId, eventId, roundTypeId FROM Results WHERE (pos = 1 or pos = 2 or pos = 3) AND eventId = '333' GROUP BY competitionId, roundTypeId, average")
rows = cur.fetchall()
# Adding the results of top3 of this round and sorting by lowest sum
res = []
for i in range(0,len(rows)):
sum = 0
if rows[i]['pos'] == 1 and rows[i]['average'] != 0:
for k in range(i,i+3):
sum = sum + rows[k]['average']
res.append((sum, rows[i]['competitionId'], rows[i]['roundTypeId']))
else:
continue
sorted_x = sorted(res, key=lambda x:x[0])
# Counting the best averages for each round-type
fircoun = 0
seccoun = 0
thicoun = 0
fincoun = 0
dafuq = 0
for i in range(0, 250):
if sorted_x[i][2] == '1' or sorted_x[i][2] == 'a' or sorted_x[i][2] == '0' or sorted_x[i][2] == 'd':
fircoun = fircoun + 1
elif sorted_x[i][2] == '2' or sorted_x[i][2] == 'b':
seccoun = seccoun + 1
elif sorted_x[i][2] == '3' or sorted_x[i][2] == 'c':
thicoun = thicoun + 1
elif sorted_x[i][2] == '4' or sorted_x[i][2] == 'f':
fincoun = fincoun + 1
else:
dafuq = dafuq + 1
give = [fircoun, seccoun, thicoun, fincoun]
# Print final results + generate results table
for i in range(0,len(give)):
print('Best averages in round', i+1, ':', give[i])
table(sorted_x)