Advertisement
campos20

Latest Sub 10 WCA

Jan 18th, 2019
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.54 KB | None | 0 0
  1. # acampos@worldcubeassociation.org
  2. # program made after a request from Vasco Vasconcelos
  3. # place this program alongside with the tsv (unziped) export from
  4. # https://www.worldcubeassociation.org/results/misc/WCA_export.tsv.zip
  5. # and run it with
  6. # python program.py
  7. # it takes about 9 min on my computer
  8.  
  9. import csv
  10. from datetime import date
  11.  
  12. def competition_date(competition_id):
  13.     with open('WCA_export_Competitions.tsv','rb') as tsvin:
  14.         tsvin = csv.reader(tsvin, delimiter='\t')
  15.        
  16.         for line in tsvin:
  17.             if line[0] == competition_id:
  18.                 end_day = int(line[9])
  19.                 end_month = int(line[8])
  20.                 year = int(line[5])
  21.                
  22.                 return date(year, end_month, end_day)
  23.        
  24.         return None
  25.  
  26. def show_results(labels, results_list, list_of_lists, limit = float("inf"), direction = "asc"):
  27.     """Labels is intuitive. Results_list is the main order list and list_of_lists are other lists that are gonna be ordered as well (eg.: country, name, etc). You can set limit if you wish. Direction = 'asc' if you wanna the lower results first; direction = 'des' if you wanna bigger results first."""
  28.  
  29.     pos = 1
  30.  
  31.     prev = None
  32.    
  33.     out = "Pos"
  34.     for x in labels:
  35.         out += "\t"+x
  36.     print out
  37.    
  38.     temp = []
  39.     if direction == "asc":
  40.         temp = sorted(zip(results_list, range(len(results_list))))
  41.     elif direction == "des":
  42.         temp = sorted(zip(results_list, range(len(results_list))))[::-1]
  43.  
  44.     for a, b in temp:
  45.         out = ""
  46.         if a != prev:
  47.             if pos > limit:
  48.                 break
  49.             out+="%s)\t"%pos
  50.         else:
  51.             out += "---\t"
  52.         out += str(a)+"\t"
  53.         for x in list_of_lists:
  54.             out += str(x[b])+"\t"
  55.         print out.strip()
  56.         prev = a
  57.         pos += 1
  58.  
  59. def latest_sub10():
  60.  
  61.     LIMIT = 50
  62.     id_list = []
  63.     name_list = []
  64.     country_list = []
  65.     first_competition_name = []
  66.     sub10_competition_name = []
  67.     first_competition_date = []
  68.     sub10_competition_date = []
  69.     day_diff = []
  70.    
  71.     with open('WCA_export_Results.tsv','rb') as tsvin:
  72.         tsvin = csv.reader(tsvin, delimiter='\t')
  73.        
  74.         prev = None
  75.         this_date = None
  76.         for line in tsvin:
  77.  
  78.             event = line[1]
  79.            
  80.             if event != "333":
  81.                 continue
  82.            
  83.             competition_id = line[0]
  84.             if prev != competition_id:
  85.                 this_date = competition_date(competition_id)
  86.             prev = competition_id
  87.            
  88.             this_id = line[7]
  89.  
  90.             i = -1 # also works if we include a new competitor, since -1 is the lastest on python
  91.             try:
  92.                 i = id_list.index(this_id)
  93.             except:
  94.                 name = line[6]
  95.                 country = line[8]
  96.  
  97.                 id_list.append(this_id)
  98.                 name_list.append(name)
  99.                 country_list.append(country)
  100.                 first_competition_name.append(competition_id)
  101.                 day_diff.append(-1)
  102.                
  103.                 first_competition_date.append(this_date)
  104.                
  105.                 sub10_competition_name.append(None)
  106.                 sub10_competition_date.append(None)
  107.            
  108.             best = line[4]
  109.            
  110.             if best in ["-2", "-1"]:
  111.                 continue
  112.             else:
  113.                 best = int(best)
  114.                 if best < 1000 and (sub10_competition_name[i] == None or (sub10_competition_date[i]-this_date).days>0):
  115.                     sub10_competition_name[i] = line[0]
  116.                     sub10_competition_date[i] = this_date
  117.            
  118.             if (first_competition_date[i]-this_date).days>0:
  119.                 first_competition_date[i] = this_date
  120.                 first_competition_name[i] = competition_id
  121.    
  122.     for i in range(len(id_list)):
  123.         if sub10_competition_name[i] != None:
  124.             delta = sub10_competition_date[i] - first_competition_date[i]
  125.             day_diff[i] = delta.days
  126.        
  127.     list_of_lists = [name_list, country_list, first_competition_name, sub10_competition_name]
  128.     labels = ["Days", "Name", "Country", "1st comp", "1st sub10 comp"]
  129.     show_results(labels, day_diff, list_of_lists, LIMIT, "des")
  130.                
  131. latest_sub10()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement