campos20

Most DNF Ratio on WCA, excluding BLDs and FM

Jan 20th, 2019
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.17 KB | None | 0 0
  1.  
  2. # program made for the WCA Statistics
  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 24 min on my PC
  8.  
  9. import csv
  10. from datetime import date
  11.  
  12. def show_results(labels, results_list, list_of_lists, limit = float("inf"), direction = "asc"):
  13.     """'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."""
  14.  
  15.     pos = 1
  16.  
  17.     prev = None
  18.    
  19.     out = "Pos"
  20.     for x in labels:
  21.         out += "\t"+x
  22.     print out
  23.    
  24.     temp = []
  25.     if direction == "asc":
  26.         temp = sorted(zip(results_list, range(len(results_list))))
  27.     elif direction == "des":
  28.         temp = sorted(zip(results_list, range(len(results_list))))[::-1]
  29.  
  30.     for a, b in temp:
  31.         out = ""
  32.         if a != prev:
  33.             if pos > limit:
  34.                 break
  35.             out+="%s)\t"%pos
  36.         else:
  37.             out += "---\t"
  38.         out += str(a)+"\t"
  39.         for x in list_of_lists:
  40.             out += str(x[b])+"\t"
  41.         print out.strip()
  42.         prev = a
  43.         pos += 1
  44.  
  45. def main():
  46.  
  47.     with open("WCA_export_Results.tsv") as tsvfile:
  48.  
  49.         tsvreader = csv.reader(tsvfile, delimiter="\t")
  50.        
  51.         ids = []
  52.         names = []
  53.         countries = []
  54.         results_count = []
  55.         attempts_count = []
  56.         dnf_count = []
  57.         dns_count = []
  58.         no_results = []
  59.         exclude = ["333bf", "444bf", "555bf", "333fm", "333mbf", "333mbo"]
  60.        
  61.         header = True
  62.  
  63.         for line in tsvreader:
  64.        
  65.             if header:
  66.                 header = False
  67.                 continue
  68.            
  69.             event = line[1]
  70.             if event in exclude:
  71.                 continue
  72.            
  73.             this_id = line[7]
  74.            
  75.             i = -1
  76.             try:
  77.                 i = ids.index(this_id)
  78.             except:
  79.                 name = line[6]
  80.                 country = line[8]
  81.  
  82.                 ids.append(this_id)
  83.                 names.append(name)
  84.                 countries.append(country)
  85.                
  86.                 results_count.append(0)
  87.                 dnf_count.append(0)
  88.                 dns_count.append(0)
  89.                 no_results.append(0)
  90.                 attempts_count.append(0)
  91.            
  92.             for x in line[10:15]:
  93.            
  94.                 if x == "-1":
  95.                     dnf_count[i] += 1
  96.                     attempts_count[i] += 1
  97.                 elif x == "-2":
  98.                     dns_count[i] += 1
  99.                 elif x == "0":
  100.                     no_results[i] += 1
  101.                 else:
  102.                     results_count[i] += 1
  103.                     attempts_count[i] += 1
  104.                    
  105.         ratio = []
  106.         out_names = []
  107.         out_countries = []
  108.         out_results = []
  109.         out_dnf = []
  110.         out_attempt = []
  111.        
  112.         hold = 100
  113.        
  114.         for i in range(len(ids)):
  115.             attempts = attempts_count[i]
  116.             if attempts < hold:
  117.                 continue
  118.             result = results_count[i]
  119.             if result == 0:
  120.                 continue
  121.            
  122.             name = names[i]
  123.             country = countries[i]
  124.             dnf = dnf_count[i]
  125.            
  126.             out_names.append(name)
  127.             out_countries.append(country)
  128.             out_results.append(result)
  129.             out_dnf.append(dnf)
  130.             out_attempt.append(attempts)
  131.             ratio.append(1.0*dnf/attempts)
  132.        
  133.         labels = ["DNF Ratio", "Name", "Country", "DNF", "Attempts"]
  134.         list_of_lists = [out_names, out_countries, out_dnf, out_attempt]
  135.        
  136.         assert len(labels) == len(list_of_lists)+1
  137.        
  138.         limit = 100
  139.         show_results(labels, ratio, list_of_lists, limit, "des")
  140.            
  141. main()
Advertisement
Add Comment
Please, Sign In to add comment