Skip to main content

Baseball Statistics Simulator

Project description

bbcmd

PyPI version shields.io PyPI pyversions PyPI license

Command Line Baseball Data Tools. This project includes 2 command line tools for generating a variety of stats and scraping data from the web.

Contents

Installation

Use pip via PyPi

pip install bbcmd

Or use git

git clone git://github.com/luciancooper/bbcmd.git bbcmd
cd bbcmd
python setup.py install
Install Notes

This project depends on cmdprogress for command line progress bars

Commands

After installation, the bbsim and bbscrape commands should be in your systems path, via the Scripts directory of your Python installation

Scraper

The bbscrape command is a tool that scrapes data from the following websites:

Simulator Setup

Step 1. Download Data

Download the necessary play by play data source files that the simulator depends on to run simulations. These files are stored on github in the bbsrc repository. The data in these files is derived from the play by play data provided by retrosheet.org. Retrosheet is an amazing organization that has painstakingly compiled the play by play data for every MLB game dating back to 1921. Find out more about the Retrosheet project here.

bbsim setup --env years path
  • years - required: the specified MLB seasons you wish to download play by play data for, can be a single year (2016), range of years (2014-2016) or comma separated combination of the two (2012-2014,2016 or 2012-2014,2015-2017, etc.)
  • path - optional: the local path in which you wish to keep store your play by play data files. You will want to remember this location, as you will have to come back later if you want to delete these files. If not specified, the current working directory will be used

Step 2. Create Data Pointer

bbsim setup --xml years path
  • years - required: the specified MLB seasons you wish bbdata.xml to point to. Can be a single year (2016), range of years (2014-2016) or comma separated combination of the two (2012-2014,2016 or 2012-2014,2015-2017, etc.)
  • path - optional: the local path in which you wish to create the pointer file in. This is the directory you will be running your simulations in later, so again, remember this location. If not specified, the current working directory will be used. If you want to keep it simple, specify the same path as in the previous command

Step 3. Run a test

If the current path does not contain your bbdata.xml file, navigate to that path. Run the following command, which will simulate the games for all the seasons specified by bbdata.xml, without recording any of the data.

bbsim test game

Simulator Usage

The following simulations are currently supported by this project

Gamescores

The gamescore command generates data grouped by mlb game. Columns include:

ascore,hscore,aout,hout

bbsim gamescore [-v] [-y YEARS]

Generate Aggregated Stats

The batting, fielding, pitching, and rbi commands generate aggregated stats. By default, the simulator will group the outputted data by season. The following optional flags will change how the data is grouped.

  • -l : by league (AL and NL).
  • -t : by team
  • -g : by game
  • -p : by player (8 character playerid)
  • -ph : by player hand (batting hand or pitching hand)
  • -phm : by player hand matchups

batting command

The batting command generates offensive stats. Columns include:

O,E,S,D,T,HR,BB,IBB,HBP,K,I,SH,SF,GDP,R,RBI,SB,CS,PO

The batting command has an additional optional flag: -np or --nopitcher. If this is included, the simulator will ignore pitchers when aggregating results.

bbsim batting [-l | -t | -g | -p | -ph | -phm] [-v] [-np] [-y YEARS]

fielding command

The fielding command generates defensive aggregated stats. Columns include:

UR,TUR,P,A,E,PB

bbsim fielding [-l | -t | -g | -p] [-v] [-y YEARS]

pitching command

The pitching command generates aggregated pitching stats. Columns include:

W,L,SV,IP,BF,R,ER,S,D,T,HR,BB,HBP,IBB,K,BK,WP,PO,GDP

bbsim pitching [-l | -t | -g | -p | -ph | -phm] [-v] [-y YEARS]

rbi command

The rbi command generates details about each event in which an RBI was credited

RBI,O,E,S,D,T,HR,BB,IBB,HBP,K,I,SF,SH,GDP

bbsim rbi [-l | -t | -g | -p | -ph | -phm] [-v] [-y YEARS]

Generate Appearance Stats

appearance command

bbsim appearance [normal | lahman | position | simple] [-v] [-y YEARS]
  • -v - optional:
  • -y YEARS

Generate Advanced Stats

Currently two sub commands supported:

  • woba: simulates the seasonal linear weights used for calculating weighted
bbsim advcalc (woba | war) [-v] [-y YEARS]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bbcmd-1.2.tar.gz (43.3 kB view details)

Uploaded Source

Built Distribution

bbcmd-1.2-py3-none-any.whl (58.8 kB view details)

Uploaded Python 3

File details

Details for the file bbcmd-1.2.tar.gz.

File metadata

  • Download URL: bbcmd-1.2.tar.gz
  • Upload date:
  • Size: 43.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.14.2 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.1

File hashes

Hashes for bbcmd-1.2.tar.gz
Algorithm Hash digest
SHA256 f80da7ec78e663ec74d2ba1a3bdc4f93e4108c4502ae76116937f6e390e3efc5
MD5 12e451a9eeb06d1a46a1b1e7913951a1
BLAKE2b-256 18751a3d40f52f45b8126bccdd67e2f7e62cf4f1848d65bbe239bb5e18fda99e

See more details on using hashes here.

File details

Details for the file bbcmd-1.2-py3-none-any.whl.

File metadata

  • Download URL: bbcmd-1.2-py3-none-any.whl
  • Upload date:
  • Size: 58.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.14.2 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.1

File hashes

Hashes for bbcmd-1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 11ddccaa7c429bfa392b00be0d72101b03b207fa0dac49cdc0bb5850efb32c29
MD5 31c333316616108d118d2a15d51f994d
BLAKE2b-256 266f294cdebf268af288d3e88d343599cd41c76aee28a1745af6ea374c3082ba

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page