Created
November 4, 2014 13:15
-
-
Save Shinichi-Nakagawa/fb651c46b590f6881a5a to your computer and use it in GitHub Desktop.
service/stats.py
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 ip(cls, ip_outs): | |
""" | |
Inning Pitched | |
:param ip_outs: inning pitched outs | |
:return: (float) ip | |
""" | |
return round(ip_outs / 3, 1) | |
""" | |
※省略 | |
""" | |
@classmethod | |
def babip(cls, h, hr, ab, so, sf): | |
""" | |
Batting average on balls in play(BABIP) | |
:param h: hits | |
:param hr: home run | |
:param ab: at bat | |
:param so: strike out | |
:param sf: sacrifice fly | |
:return: (float) babip | |
""" | |
return round((h - hr) / (ab - so - hr + sf), 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 | |
@classmethod | |
def rc27(cls, rc, ab, h, sh, sf, cs, gidp): | |
""" | |
Runs created 27 | |
:param rc: run created | |
:param ab: at bat | |
:param h: hits | |
:param sh: sacrifice hit | |
:param sf: sacrifice fly | |
:param cs: caught stealing | |
:param gidp: ground into duble play | |
:return: (float) run created 27 | |
""" | |
to = ab - h + sh + sf + cs + gidp | |
rc27 = round(27 * rc / to, 1) | |
return rc27 | |
@classmethod | |
def adam_dunn_batter(cls, hr, bb, so, pa): | |
""" | |
Adam dunn %(batter) | |
:param hr: home run | |
:param bb: base on ball | |
:param so: strike out | |
:param pa: plate appearance | |
:return: (float) adam dunn | |
""" | |
return round(((hr + bb + so) / pa) * 100, 1) | |
@classmethod | |
def adam_dunn_pitcher(cls, hr, bb, hbp, so, bfp): | |
""" | |
Adam dunn %(pitcher) | |
:param hr: home run | |
:param bb: base on ball | |
:param hbp: hit by pitch | |
:param so: strike out | |
:param bfp: batters faced | |
:return: (float) adam dunn | |
""" | |
return round(((hr + bb + hbp + so) / bfp) * 100, 1) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment