This file contains hidden or 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
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 |
This file contains hidden or 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
## 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) |
This file contains hidden or 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, |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
NewerOlder