Advertisement
campos20

Untitled

Jun 19th, 2018
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.99 KB | None | 0 0
  1. # this program and the extract of the wca export must be in the same folder
  2. # to run, just type "python program.py"
  3.  
  4. import csv
  5.  
  6. country_list = []
  7. event_list = []
  8. avg_list = []
  9.  
  10. def avg(l):
  11.     out = 0.0
  12.     if len(l)==0: return 0.0
  13.     for x in l:
  14.         out += x
  15.     return 1.0*out/len(l)
  16.  
  17. count = 0
  18. discard = 1 # at least 2 competitions per country
  19.  
  20. with open('WCA_export_Competitions.tsv','rb') as tsvin:
  21.     tsvin = csv.reader(tsvin, delimiter='\t')
  22.            
  23.     for line in tsvin:
  24.  
  25.         count += 1
  26.         if count == 1: continue # :'(
  27.    
  28.         country = line[3]
  29.        
  30.         year = line[5]
  31.        
  32.         if country not in country_list:
  33.             country_list.append(country)
  34.             event_list.append([])
  35.        
  36.         i = country_list.index(country)
  37.        
  38.         events = line[10].split()
  39.         event_list[i].append(len(events))
  40.        
  41.     for x in event_list:
  42.         avg_list.append(avg(x))
  43.    
  44.     count = 1
  45.     for (x, y, z) in sorted(zip(avg_list, country_list, event_list))[::-1]:
  46.         if (len(z)>discard):
  47.             print "%3s"%count+")", ("%.2f"%x).zfill(5), y
  48.             count += 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement