Advertisement
campos20

Most DNF Ratio on WCA, excluding BLDs and FM

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