Instantly share code, notes, and snippets.

# Jeff SackmannJeffSackmann

• Sort options
Created Sep 3, 2012
reseeder takes a list of players (perhaps an existing draw) and generates a (new) draw according to non-strict seeding rules.
View reseeder.py
 import random from operator import itemgetter def insertSeedOrNonseed(ndraw, seeds, nonseeds, sj, nj): if sj < len(seeds): ndraw.append(seeds[sj]) sj += 1 else: ndraw.append(nonseeds[nj]) nj += 1
Created Sep 1, 2012
Given probability of winning a best-of-three-set match and the assumption that sets are independent, output the probability of winning a best-of-five-set match
View fiveSetProb.py
 ## given probability of winning a best-of-three-set match and the assumption that sets are independent, ## output the probability of winning a best-of-five-set match ##One way to find the probability of winning an n-set match is to start with the probability of winning ##a single set. If we have an estimated probability of winning a best-of-three, e.g. from betting odds, ##we need to work backwards to get the probability of winning a single set. ## ##If x is p(set win), the probability of winning a three-setter is: ## x^2 + 2(x^2)(1-x) ## x^2 is the p(winning in straight sets)
Created Feb 7, 2011
Find win expectancy and volatility given inning, out, base, run situation.
View wpaCalc.py
 ## Find win expectancy and volatility given inning, out, base, run situation. ## no. of runs that score with HR in diff. base situations baseHr = {1: 1, 2: 2, 3: 2, 4: 3, 5: 2, 6: 3, 7: 3,
Created Jan 16, 2011
run simulations of a single-elimination tournament
View aussie_draw_2011.csv
Nadal 1 12390 Daniel 564 Sweeting Q 486 Gimeno-Traver 844 Tomic W 239 Chardy 960 Falla 540 Lopez F 31 1310 Isner 20 1850 Serra 711
Created Jan 14, 2011
Generate a full season's worth of pitching Marcel projections from past years' stats
View generatePitchingMarcels.py
 ## Generate a full season's worth of pitching Marcel projections from past years' stats from createTuple import createTuple ## gist: 778481 from writeMatrixCSV import writeMatrixCSV ## gist: 778484 def makePitTable(r): for stat in ['AB', 'H', 'D', 'T', 'HR', 'SO', 'BB', 'SF', 'HP', 'CI', 'IPouts', 'R']: if stat in r: pass else: r[stat] = 0 ab = 0.9*r['IPouts'] + r['H']
Created Jan 14, 2011
Generate a full season's worth of batting Marcel projections from past years' stats
View generateBattingMarcels.py
 ## Generate a full season's worth of batting Marcel projections from past years' stats from createTuple import createTuple ## gist: 778481 from writeMatrixCSV import writeMatrixCSV ## gist: 778484 def makeBatTable(r): for stat in ['AB', 'H', 'D', 'T', 'HR', 'SO', 'BB', 'SF', 'HP', 'CI']: if stat in r: pass else: r[stat] = 0 if r['AB'] == 0:
Created Jan 13, 2011
turn a 2-d python matrix (list of lists) into a .csv file
View writeMatrixCSV.py
 ## turn a 2-d python matrix (list of lists) into a .csv file ## see also gist: 778481 to reverse the process def writeMatrixCSV(mx, fname): ## mx is a 2-d python matrix ## fname is the desired output filename f = open(fname, 'w') for r in mx: tx = ''
Created Jan 13, 2011
turn a .csv file into a 2-dimensional python matrix (an array of arrays)
View createTuple.py
 # turn a .csv file into a 2-dimensional python matrix (a list of lists) # this will not make you happy if cells have commas in them, however escaped they may be # reverse the process (go from matrix to .csv) with gist: 778484 def fixText(text): row = [] z = text.find(',') if z == 0: row.append('')
Created Jan 13, 2011
calculates probability of winning a tennis match from any given score dependent on the skill levels of the two players
View tennisMatchProbability.py
 ## calculates probability of winning a tennis match from any given score dependent on the skill levels ## of the two players ## requires functions in other gists: ## gameProb: https://gist.github.com/768862 ## setGeneral: https://gist.github.com/776986 ## tiebreakProb: https://gist.github.com/776875 def fact(x): if x in [0, 1]: return 1
Created Jan 12, 2011
calculate the probability of the current server winning a 6-game, tiebreak set, given prob. of server winning any given service point (s) or return point (u), and the current game score (v, w)
View tennisSetProbability.py
 ## calculate the probability of the current server winning ## a 6-game, tiebreak set, given prob. of server winning any ## given service point (s) or return point (u), and the current ## game score (v, w) ## some results: ## http://summerofjeff.wordpress.com/2010/12/02/single-set-win-expectancy-tables/ def fact(x): if x in [0, 1]: return 1
You can’t perform that action at this time.