Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Software by Alexandre Campos
- # camposalexandreh@gmail.com
- # 12/30/2018
- # Software made for WDC purpose. It compares when a competitor got a 4BLD result > 12 min to when s/he got a 5BLD < 12 min.
- # Place this program.py alongside with the tsv export of WCA db
- # https://www.worldcubeassociation.org/results/misc/export.html
- # and execute it with
- # python program.py
- import csv
- from datetime import date
- def get_competition_date(competition_id):
- with open('WCA_export_Competitions.tsv','rb') as tsvin:
- tsvin = csv.reader(tsvin, delimiter='\t')
- for line in tsvin:
- if competition_id == line[0]:
- year = int(line[5])
- month = int(line[6])
- day = int(line[7])
- return date(year, month, 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 time_format(time):
- m = int(time/60)
- time -= m*60
- s = int(time)
- time -= s
- d = int(time*100)
- return "%s:%s.%s"%(str(m).zfill(2), str(s).zfill(2), str(d).zfill(2))
- def get_results(ev):
- results = []
- id_list = []
- competition_id = []
- competition_date = []
- with open('WCA_export_Results.tsv','rb') as tsvin:
- tsvin = csv.reader(tsvin, delimiter='\t')
- prev_competition = None
- date = None
- for line in tsvin:
- event = line[1]
- if event == ev:
- best = line[4]
- if best == -1: # competitor got at least one right
- continue
- person_id = line[7]
- i = -1
- try:
- i = id_list.index(person_id)
- except:
- id_list.append(person_id)
- results.append([])
- competition_id.append([])
- competition_date.append([])
- competition = line[0]
- # this saves time since looking for competition date is expensive
- if competition != prev_competition:
- date = get_competition_date(competition)
- prev_competition = competition
- for x in line[10:13]:
- if x not in ["0", "-1", "-2"]:
- results[i].append(float(x)/100)
- competition_date[i].append(date)
- competition_id[i].append(competition)
- return (id_list, results, competition_id, competition_date)
- def main():
- LIMIT = 1000000
- id_list_4, results_4, competition_id_4, bld_date_4 = get_results("444bf")
- id_list_5, results_5, competition_id_5, bld_date_5 = get_results("555bf")
- days = []
- id_list = []
- result4 = []
- comp4 = []
- date4 = []
- result5 = []
- comp5 = []
- date5 = []
- prev_comp_4 = None
- prev_comp_5 = None
- prev_id = None
- for i in range(len(id_list_4)):
- j = None
- try:
- j = id_list_5.index(id_list_4[i])
- except:
- continue
- for k in range(len(results_4[i])):
- if results_4[i][k] < 12*60:
- continue
- for l in range(len(results_5[j])):
- if results_5[j][l] > 12*60:
- continue
- delta = bld_date_5[j][l] - bld_date_4[i][k]
- d = delta.days
- this_comp_4 = competition_id_4[i][k]
- this_comp_5 = competition_id_5[j][l]
- this_id = id_list_5[j]
- # people who got multiple results at same comps
- if this_comp_4 == prev_comp_4 and this_comp_5 == prev_comp_5 and this_id == prev_id:
- continue
- days.append(d)
- id_list.append(this_id)
- result4.append(time_format(results_4[i][k]))
- comp4.append(this_comp_4)
- date4.append(bld_date_4[i][k])
- result5.append(time_format(results_5[j][l]))
- comp5.append(this_comp_5)
- date5.append(bld_date_5[j][l])
- prev_comp_4 = this_comp_4
- prev_comp_5 = this_comp_5
- prev_id = this_id
- list_of_lists = [id_list, result4, comp4, date4, result5, comp5, date5]
- labels = ["Days", "ID", "Result4", "Comp of 4", "Date of 4", "Result5", "Comp of 5", "Date of 5"]
- show_results(labels, days, list_of_lists, LIMIT)
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement