campos20

Latest Sub 10 WCA

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