Skip to content

Commit

Permalink
Merge pull request #15 from philosofool/issue#14
Browse files Browse the repository at this point in the history
Fix issue #14
  • Loading branch information
philosofool authored Jun 9, 2020
2 parents 6337e41 + 9226612 commit ecf01c3
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 33 deletions.
35 changes: 19 additions & 16 deletions BaseClasses/player/Hitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,23 +279,26 @@ def adjToPA(self,PA):
To approximate zero, pass a small float (.01) as PA.
"""
try:
self.formerPA = self.PA
ratio = PA/self.PA
self.PA = self.PA * ratio
self.AB = self.AB * ratio
self.BB = self.BB * ratio
self.H1B = self.H1B * ratio
self.H2B = self.H2B * ratio
self.H3B = self.H3B * ratio
self.HR = self.HR * ratio
self.R = self.R * ratio
self.RBI = self.RBI * ratio
self.SB = self.SB * ratio
self.CS = self.CS * ratio
self.SO = self.SO * ratio
self.hits = self.calcHits()
if PA == 0:
pass
else:
self.formerPA = self.PA
ratio = PA/self.PA
self.PA = self.PA * ratio
self.AB = self.AB * ratio
self.BB = self.BB * ratio
self.H1B = self.H1B * ratio
self.H2B = self.H2B * ratio
self.H3B = self.H3B * ratio
self.HR = self.HR * ratio
self.R = self.R * ratio
self.RBI = self.RBI * ratio
self.SB = self.SB * ratio
self.CS = self.CS * ratio
self.SO = self.SO * ratio
self.hits = self.calcHits()
except ZeroDivisionError:
pass
print("Hitter {} has 0 PA. Cannot adjust plate appearances.".format(self))

def asNumberPA(self,pa):
"""
Expand Down
48 changes: 31 additions & 17 deletions BaseClasses/player/Pitcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,24 +90,38 @@ def xWHIP(self):
return (self.lgWHIP - self.WHIP())*self.IP

def adjToIP(self,IP):
self.formerIP = self.IP
"""
Normalizes all the players counting stats to a new number of IP.
Parameters
----------
IP : numeric
The number of IP the player is adjusted to.
In order to prevent data loss, zero is not allowed and passing zero will have no effect.
To approximate zero, pass a small float (.01) as PA.
If the player's IP are already Zero, this has no effect
"""

try:
ratio = IP/self.IP
except:
print(self.name+" Has 0 IP. in Pitcher.adjToIP"
)
ratio = 0
self.W = self.W * ratio
self.L = self.L * ratio
self.GS = self.GS * ratio
self.G = self.G * ratio
self.SV = self.SV * ratio
self.IP = self.IP * ratio
self.H = self.H * ratio
self.ER = self.ER * ratio
self.HR = self.HR * ratio
self.SO = self.SO * ratio
self.BB = self.BB * ratio
if IP == 0:
pass
else:
self.formerIP = self.IP
ratio = IP/self.IP
self.W = self.W * ratio
self.L = self.L * ratio
self.GS = self.GS * ratio
self.G = self.G * ratio
self.SV = self.SV * ratio
self.IP = self.IP * ratio
self.H = self.H * ratio
self.ER = self.ER * ratio
self.HR = self.HR * ratio
self.SO = self.SO * ratio
self.BB = self.BB * ratio
except ZeroDivisionError:
print("Pitcher {} has 0 IP. Cannot adjust stats to innings pitched.".format(self))

def asNumberIP(self,ip):
guy = deepcopy(self)
Expand Down

0 comments on commit ecf01c3

Please sign in to comment.