Created
October 8, 2013 18:25
-
-
Save AdolfVonKleist/6889212 to your computer and use it in GitHub Desktop.
Play around with WCT scores.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Play around with WCT scores using the .csv files from the ASP website. | |
Download the latest rankings in .csv format: | |
http://www.aspworldtour.com/rankings/asp-world-championship-tour-ranking | |
Run the parse-asp.py script with the .csv file: | |
$ ./parse-asp.py --csv wct.csv | |
Get the scores and rankings: | |
$ ./parse-asp.py --csv wct.csv -a | |
Consulate the stars, what would happen if Taj Burrow won the next two events? | |
$ ./parse-asp.py --csv wct2.csv -a -n "Taj Burrow,1" -n "Taj Burrow,1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import csv, operator | |
def ranks_to_points( ranks ): | |
new_ranks = [] | |
for tok in ranks[5:14]: | |
if tok=="'-'": | |
continue | |
elif tok=="'INJ'": | |
tok = 25 | |
else: | |
tok = int(tok.strip("'")) | |
new_ranks.append(tok) | |
return new_ranks | |
def load_asp_csv( csv_file ): | |
rankings = {} | |
with open(csv_file, 'r') as csvfile: | |
reader = csv.reader(csvfile) | |
headers = reader.next() | |
for row in reader: | |
rankings[row[3].strip("'")] = ranks_to_points( row ) | |
return rankings | |
def rerank( rankings, actual_best=False, additional=[] ): | |
points = { 1:10000, 2:8000, 3:6500, 5:5200, 9:4000, 13:1750, 25:500 } | |
if actual_best: | |
for item in additional: | |
n, s = item.split(",") | |
rankings[n].append(int(s)) | |
for surfer in rankings: | |
rankings[surfer].sort() | |
if len(rankings[surfer])==9: | |
rankings[surfer].pop(-1) | |
if len(rankings[surfer])>=10: | |
rankings[surfer].pop(-1) | |
rankings[surfer].pop(-1) | |
rankings[surfer] = [ points[r] for r in rankings[surfer] ] | |
re_sorted = sorted(rankings.items(), key=lambda x: sum(x[1]) ) | |
for item in re_sorted: | |
print "{0: <18}\t{1: <7}\t{2}".format(item[0], sum(item[1]), item[1]) | |
return | |
if __name__=="__main__": | |
import sys, argparse | |
example = "{0} --actual_best".format(sys.argv[0]) | |
parser = argparse.ArgumentParser( description=example ) | |
parser.add_argument( "--actual_best", "-a", help="Drop the two worst scores and recalculate the rankings.", default=False, action="store_true" ) | |
parser.add_argument( "--csv", "-c", help="The .csv file from the ASP website.", required=True ) | |
parser.add_argument( "--new", "-n", help="Add a score for a surfer.", action="append", default=[] ) | |
args = parser.parse_args( ) | |
rankings = load_asp_csv( args.csv ) | |
rerank( rankings, args.actual_best, args.new ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment