Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # acampos@worldcubeassociation.org
- # program made after a request from Vasco Vasconcelos
- # 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 9 min on my computer
- import csv
- from datetime import date
- def competition_date(competition_id):
- with open('WCA_export_Competitions.tsv','rb') as tsvin:
- tsvin = csv.reader(tsvin, delimiter='\t')
- for line in tsvin:
- if line[0] == competition_id:
- end_day = int(line[9])
- end_month = int(line[8])
- year = int(line[5])
- return date(year, end_month, end_day)
- return None
- 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 latest_sub10():
- LIMIT = 50
- id_list = []
- name_list = []
- country_list = []
- first_competition_name = []
- sub10_competition_name = []
- first_competition_date = []
- sub10_competition_date = []
- day_diff = []
- with open('WCA_export_Results.tsv','rb') as tsvin:
- tsvin = csv.reader(tsvin, delimiter='\t')
- prev = None
- this_date = None
- for line in tsvin:
- event = line[1]
- if event != "333":
- continue
- competition_id = line[0]
- if prev != competition_id:
- this_date = competition_date(competition_id)
- prev = competition_id
- this_id = line[7]
- i = -1 # also works if we include a new competitor, since -1 is the lastest on python
- try:
- i = id_list.index(this_id)
- except:
- name = line[6]
- country = line[8]
- id_list.append(this_id)
- name_list.append(name)
- country_list.append(country)
- first_competition_name.append(competition_id)
- day_diff.append(-1)
- first_competition_date.append(this_date)
- sub10_competition_name.append(None)
- sub10_competition_date.append(None)
- best = line[4]
- if best in ["-2", "-1"]:
- continue
- else:
- best = int(best)
- if best < 1000 and (sub10_competition_name[i] == None or (sub10_competition_date[i]-this_date).days>0):
- sub10_competition_name[i] = line[0]
- sub10_competition_date[i] = this_date
- if (first_competition_date[i]-this_date).days>0:
- first_competition_date[i] = this_date
- first_competition_name[i] = competition_id
- for i in range(len(id_list)):
- if sub10_competition_name[i] != None:
- delta = sub10_competition_date[i] - first_competition_date[i]
- day_diff[i] = delta.days
- list_of_lists = [name_list, country_list, first_competition_name, sub10_competition_name]
- labels = ["Days", "Name", "Country", "1st comp", "1st sub10 comp"]
- show_results(labels, day_diff, list_of_lists, LIMIT, "des")
- latest_sub10()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement