Stefan
Legend
Triple triple crown
. Oh, the really good old days where it was so easy...
\n')
print(time.time() - start_time)
[/noparse][/code]
Code:
Number of events:
3 Stefan Pochmann
2 Feliks Zemdegs
2 Mátyás Kuti
2 Dan Cohen
1 Grzegorz Prusak
1 Yu Nakajima (中島悠)
1 Rowe Hessler
1 Yuki Hayashi (林祐樹)
1 Kevin Hays
1 Jaap Scherphuis
1 Frank Morris
1 Simon Westlund
1 Anssi Vanhala
1 Lars Vandenbergh
1 Erik Akkersdijk
1 Ryan Patricio
1 Bálint Bodor
1 Michał Halczuk
Code:
[noparse]# Requested at: http://www.speedsolving.com/forum/showthread.php?26121-Odd-WCA-stats-Stats-request-Thread&p=923537&viewfull=1#post923537
# Note: This might not be exact, because of overlapping competitions and me being too lazy to think about whether/how it can be done fully exact.
source = 'WCA_export197_20131113.tsv.zip'
import zipfile, csv, re, time
start_time = time.time()
champ, singleHolder, averageHolder = {}, {}, {}
triple_crowns, tc_ctr, name = {}, {}, {}
with zipfile.ZipFile(source) as zf:
with zf.open('WCA_export_Results.tsv') as pf:
for row in csv.DictReader(pf, delimiter='\t'):
person, event = row['personId'], row['eventId']
if re.match(r'WC\d{4}$', row['competitionId']) and row['roundId'] in ('f', 'c') and row['pos'] == '1' and int(row['best']) > 0:
champ[event] = person
if row['regionalSingleRecord'] == 'WR':
singleHolder[event] = person
if row['regionalAverageRecord'] == 'WR':
averageHolder[event] = person
if champ.get(event) == singleHolder.get(event) == averageHolder.get(event) == person:
tcs = triple_crowns.setdefault(event, [])
name[person] = row['personName']
if person not in tcs:
tcs.append(person)
tc_ctr[person] = tc_ctr.get(person, 0) + 1
with open('triple_crown.txt', 'w') as f:
f.write('[code]Events and their triple crowners:\n')
for event, tcs in sorted(triple_crowns.items()):
f.write('{:6} {}\n'.format(event, ', '.join(name[p] for p in tcs)))
f.write('\nNumber of events:\n')
for person, ctr in sorted(tc_ctr.items(), key=lambda pc: -pc[1]):
f.write('{} {}\n'.format(ctr, name[person]))
f.write('
print(time.time() - start_time)
[/noparse][/code]
