Created
April 7, 2015 12:33
-
-
Save Shinichi-Nakagawa/a6e94a6117a98aeee191 to your computer and use it in GitHub Desktop.
セイバーメトリクス計算クラス(抜粋)
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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
__author__ = 'Shinichi Nakagawa' | |
class Stats(object): | |
def __init__(self): | |
pass | |
# 省略 | |
@classmethod | |
def whip(cls, bb, h, ip): | |
""" | |
Walks + Hits / IP | |
:param bb: base on ball | |
:param h: hits | |
:param ip: inning pitched | |
:return: (float) whip | |
""" | |
return round((bb + h) / ip, 3) | |
# 省略 | |
@classmethod | |
def rc(cls, h, bb, hbp, cs, gidp, sf, sh, sb, so, ab, ibb, single, _2b, _3b, hr): | |
""" | |
Runs Created of 2002 ver. | |
[note] | |
http://en.wikipedia.org/wiki/Runs_created#2002_version_of_runs_created | |
:param h: hits | |
:param bb: base on ball | |
:param hbp: hit by pitch | |
:param cs: caught stealing | |
:param gidp: ground into duble play | |
:param tb: total bases | |
:param sf: sacrifice fly | |
:param sh: sacrifice hit | |
:param sb: stolen base | |
:param so: strike out | |
:param ab: at bat | |
:param ibb: intentional base on balls | |
:param single: single hits | |
:param _2b: double | |
:param _3b: triple | |
:param hr: home run | |
:return: (float) run created | |
""" | |
# (出塁能力A * 進塁能力B) / 出塁機会C | |
custom_tb = round(1.125 * single) + round(1.69 * _2b) + round(3.02 * _3b) + round(3.73 * hr) | |
a = h + bb + hbp - cs - gidp | |
b = custom_tb + round(0.29 * (bb + hbp - ibb)) + round(0.492 * (sf + sh + sb)) - round(0.04 * so) | |
c = ab + bb + hbp + sf + sh | |
a_b = round(a + 2.4 * c) * (b + 3 * c) | |
_9c = 9 * c | |
_09c = round(0.9 * c) | |
rc = round(a_b / _9c - _09c, 1) | |
return rc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment