Skip to content

Commit

Permalink
setting up a script to pull RMI
Browse files Browse the repository at this point in the history
  • Loading branch information
kruser committed Jul 3, 2013
1 parent 8de2b13 commit 98b3dc4
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .project
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>
10 changes: 10 additions & 0 deletions .pydevproject
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>
46 changes: 46 additions & 0 deletions src/main/python/RunnersMovedIndicator.py
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;

0 comments on commit 98b3dc4

Please sign in to comment.