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
## calculate the probability of server winning a single game, | |
## given p(winning single point) and current point score | |
## some results and commentary here: | |
## http://summerofjeff.wordpress.com/2010/12/03/single-game-win-expectancy-tables/ | |
def fact(x): | |
if x in [0, 1]: return 1 | |
r = 1 | |
for a in range(1, (x+1)): r = r*a |
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
## calculate the probability that the current server wins a best-of-p tiebreak. | |
## some results shown here: | |
## http://summerofjeff.wordpress.com/2010/12/04/7-point-tiebreak-win-expectancy-tables/ | |
def fact(x): | |
if x in [0, 1]: return 1 | |
r = 1 | |
for a in range(1, (x+1)): r = r*a | |
return r |
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
## 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 |
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
## 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 |
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
# 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('') |
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
## 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 = '' |
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
## 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: |
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
## 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'] |
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
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 |
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
## 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, |
OlderNewer