-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgetstats.py
executable file
·26 lines (22 loc) · 910 Bytes
/
getstats.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/usr/bin/python3
import re
fileName = 'probs.txt'
def getProbability(homeOrVisitor, inning, outs, runners, scoreDiff):
return getProbabilityOfString('"%s",%d,%d,%d,%d' % (homeOrVisitor, inning, outs, runners, scoreDiff))
def getProbabilityOfString(stringToLookFor):
probsRe = re.compile(r'^%s,(\d+),(\d+)' % (stringToLookFor))
probsFile = open(fileName, 'r')
for line in probsFile.readlines():
if (line.startswith(stringToLookFor)):
probsMatch = probsRe.match(line)
if (probsMatch):
totalGames = int(probsMatch.group(1))
winGames = int(probsMatch.group(2))
probsFile.close()
return float(winGames)/float(totalGames)
else:
print("ERROR - inconsistent re!")
probsFile.close()
return -1
if (__name__ == '__main__'):
print(getProbability('V', 1, 0, 1, 0))