Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # this program and the extract of the wca export must be in the same folder
- # to run, just type "python program.py"
- # avg number of comps per country since 2010
- # sum the number of competitions from 2010 and 2018 and divide by 9 seems booring,
- # so we are taking the average of the number of comps/year since 2010.
- import csv
- country_list = []
- comp_year = []
- avg_list = []
- base_year = 2010
- count = 0
- discard = 1 # ignore countries with 1 competition
- def avg(l):
- out = 0.0
- if len(l)==0: return 0.0
- for x in l:
- out += x
- return 1.0*out/len(l)
- with open('WCA_export_Competitions.tsv','rb') as tsvin:
- tsvin = csv.reader(tsvin, delimiter='\t')
- for line in tsvin:
- count += 1
- if count == 1: continue # discard the header. I'm too lazy to search for a better way to do this.
- country = line[3]
- year = int(line[5])
- if year < base_year: continue
- if country not in country_list:
- country_list.append(country)
- comp_year.append([])
- i = country_list.index(country)
- while len(comp_year[i]) < year-base_year+1:
- comp_year[i].append(0)
- comp_year[i][year-base_year] += 1 # 2010 is 0, 2011 is 1, etc. we add 1 for each comp
- for x in comp_year:
- avg_list.append(avg(x))
- prev = 0 # tied stats
- count = 1
- for (x, y, z) in sorted(zip(avg_list, country_list, comp_year))[::-1]:
- if sum(z) <= discard: continue
- print "%3s"%(str(count).zfill(2)+")" if x!=prev else ""), ("%.2f"%x).zfill(5), y, z
- count += 1
- prev = x
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement