-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>mlb-research</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.python.pydev.PyDevBuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.python.pydev.pythonNature</nature> | ||
</natures> | ||
</projectDescription> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
<?eclipse-pydev version="1.0"?> | ||
|
||
<pydev_project> | ||
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property> | ||
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.7</pydev_property> | ||
<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH"> | ||
<path>/mlb-research/src/main/python</path> | ||
</pydev_pathproperty> | ||
</pydev_project> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
''' | ||
Created on Jul 2, 2013 | ||
RMI is an alternative measure to the traditional Runs Batted In (RBI) statistic. | ||
It measures potential runner movement and assigns a percentage success. | ||
For example, if a batter comes up with a runner on 1st and 3rd, there is a potential | ||
to move runners a total of 4 bases. In the event the batter advances the runner on | ||
1st to 2nd and the runner on 3rd to home, they will be credited with .500 RMI since | ||
the runners moved 2 out of a potential 4 bases. | ||
@author: kruser | ||
''' | ||
from pymongo import MongoClient; | ||
from datetime import datetime; | ||
import pprint; | ||
|
||
''' | ||
@param players: hashtable of players stats, key is their playerId | ||
@param atbat: an atbat object | ||
''' | ||
def adjustRmi(players, atbat): | ||
pprint.pprint(atbat); | ||
''' | ||
if players[atbat.batter]: | ||
players[atbat.batter] += 1; | ||
else: | ||
players[atbat.batter] = 1; | ||
''' | ||
|
||
# Setup the database connection | ||
client = MongoClient(); | ||
db = client.mlbatbat; | ||
atBatsCollection = db.atbats; | ||
|
||
# Define the time range for our query | ||
start = datetime(2013, 1, 1); | ||
end = datetime(2014, 1, 1); | ||
|
||
players = {}; | ||
atbatsWithRunners = atBatsCollection.find({"runner.start":{"$in":["1B","2B","3B"]}, "start_tfs_zulu":{"$gte":start, "$lt":end}}); | ||
for atbat in atbatsWithRunners: | ||
adjustRmi(players, atbat); | ||
|
||
print players; |