Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # acampos@worldcubeassociation.org
- # program made for the WCA Statistics
- # place this program alongside with the tsv (unziped) export from
- # https://www.worldcubeassociation.org/results/misc/WCA_export.tsv.zip
- # and run it with
- # python program.py
- # it takes about 24 min on my PC
- import csv
- from datetime import date
- def show_results(labels, results_list, list_of_lists, limit = float("inf"), direction = "asc"):
- """'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."""
- pos = 1
- prev = None
- out = "Pos"
- for x in labels:
- out += "\t"+x
- print out
- temp = []
- if direction == "asc":
- temp = sorted(zip(results_list, range(len(results_list))))
- elif direction == "des":
- temp = sorted(zip(results_list, range(len(results_list))))[::-1]
- for a, b in temp:
- out = ""
- if a != prev:
- if pos > limit:
- break
- out+="%s)\t"%pos
- else:
- out += "---\t"
- out += str(a)+"\t"
- for x in list_of_lists:
- out += str(x[b])+"\t"
- print out.strip()
- prev = a
- pos += 1
- def main():
- with open("WCA_export_Results.tsv") as tsvfile:
- tsvreader = csv.reader(tsvfile, delimiter="\t")
- ids = []
- names = []
- countries = []
- results_count = []
- attempts_count = []
- dnf_count = []
- dns_count = []
- no_results = []
- exclude = ["333bf", "444bf", "555bf", "333fm", "333mbf", "333mbo"]
- header = True
- for line in tsvreader:
- if header:
- header = False
- continue
- event = line[1]
- if event in exclude:
- continue
- this_id = line[7]
- i = -1
- try:
- i = ids.index(this_id)
- except:
- name = line[6]
- country = line[8]
- ids.append(this_id)
- names.append(name)
- countries.append(country)
- results_count.append(0)
- dnf_count.append(0)
- dns_count.append(0)
- no_results.append(0)
- attempts_count.append(0)
- for x in line[10:15]:
- if x == "-1":
- dnf_count[i] += 1
- attempts_count[i] += 1
- elif x == "-2":
- dns_count[i] += 1
- elif x == "0":
- no_results[i] += 1
- else:
- results_count[i] += 1
- attempts_count[i] += 1
- ratio = []
- out_names = []
- out_countries = []
- out_results = []
- out_dnf = []
- out_attempt = []
- hold = 100
- for i in range(len(ids)):
- attempts = attempts_count[i]
- if attempts < hold:
- continue
- result = results_count[i]
- if result == 0:
- continue
- name = names[i]
- country = countries[i]
- dnf = dnf_count[i]
- out_names.append(name)
- out_countries.append(country)
- out_results.append(result)
- out_dnf.append(dnf)
- out_attempt.append(attempts)
- ratio.append(1.0*dnf/attempts)
- labels = ["DNF Ratio", "Name", "Country", "DNF", "Attempts"]
- list_of_lists = [out_names, out_countries, out_dnf, out_attempt]
- assert len(labels) == len(list_of_lists)+1
- limit = 100
- show_results(labels, ratio, list_of_lists, limit, "des")
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement