-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplayer.py
More file actions
269 lines (244 loc) · 8.71 KB
/
Copy pathplayer.py
File metadata and controls
269 lines (244 loc) · 8.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
import util
class Roster:
def __init__(self, r):
self.roster = r
class Player:
def __init__(
self,
is_nba,
cp,
finishingBonus,
midBonus,
threePtBonus,
bwBonus,
rebBonus,
matchType,
):
self.ID = cp["ID"]
self.FirstName = cp["FirstName"]
self.LastName = cp["LastName"]
self.TeamID = cp["TeamID"]
self.TeamAbbr = cp["TeamAbbr"]
if is_nba == False:
self.IsRedshirt = cp["IsRedshirt"]
self.IsRedshirting = cp["IsRedshirting"]
self.Stars = cp["Stars"]
else:
self.IsGLeague = cp["IsGLeague"]
self.IsTwoWay = cp["IsTwoWay"]
self.IsInternational = cp["IsInternational"]
self.IsNBA = cp["IsNBA"]
self.Position = cp["Position"]
self.PositionOne = cp["PositionOne"]
self.PositionTwo = cp["PositionTwo"]
self.PositionThree = cp["PositionThree"]
self.Age = cp["Age"]
self.Height = util.Get_Inches(cp["Height"])
self.Shooting2 = cp["Shooting2"] + midBonus
self.Shooting3 = cp["Shooting3"] + threePtBonus
self.FreeThrow = cp["FreeThrow"]
self.Finishing = cp["Finishing"] + finishingBonus
self.Ballwork = cp["Ballwork"] + bwBonus
self.Rebounding = cp["Rebounding"] + rebBonus
self.InteriorDefense = cp["InteriorDefense"]
self.PerimeterDefense = cp["PerimeterDefense"]
self.Stealing = (cp["InteriorDefense"] + cp["PerimeterDefense"]) / 2
self.Stamina = cp["Stamina"]
self.Minutes = cp["Minutes"]
if self.Minutes > self.Stamina:
self.Minutes = self.Stamina
self.InsideProportion = cp["InsideProportion"]
self.MidRangeProportion = cp["MidRangeProportion"]
self.ThreePointProportion = cp["ThreePointProportion"]
self.Overall = cp["Overall"]
self.Stats = PlayerStats(cp, matchType)
self.Shooting = 0
self.AdjShooting = 0
self.AdjFinishing = 0
self.AdjBallwork = 0
self.AdjRebounding = 0
self.AdjInteriorDefense = 0
self.AdjPerimeterDefense = 0
self.AdjStealing = 0
self.ReboundingPer = 0
self.InteriorDefensePer = 0
self.PerimeterDefensePer = 0
self.DefensePer = 0
self.AssistPer = 0
self.Usage = 0
self.InsideUsage = 0
self.MidUsage = 0
self.ThreePointUsage = 0
self.DefRateTO = 0
self.Discipline = cp["Discipline"]
self.FouledOut = False
self.IsInjured = cp["IsInjured"]
self.InjuryRating = cp["InjuryRating"]
self.InjuryName = cp["InjuryName"]
self.InjuryType = cp["InjuryType"]
self.WeeksOfRecovery = cp["WeeksOfRecovery"]
self.AdjInjury = 0
self.AdjDiscipline = 0
def increment_shot_proportion(self, ins, mid, three):
if self.Minutes > 0:
self.InsideProportion += ins
self.MidRangeProportion += mid
self.ThreePointProportion += three
def get_advanced_stats(
self,
totalrebounding,
totalDefense,
totalAssist,
InsideProportion,
MidProportion,
ThreePtProportion,
turnoverBonus,
):
self.Shooting = (self.Shooting2 + self.Shooting3) / 2
self.AdjShooting = self.Shooting * self.Minutes
self.AdjFinishing = self.Finishing * self.Minutes
self.AdjBallwork = self.Ballwork * self.Minutes
self.AdjRebounding = self.Rebounding * self.Minutes
self.AdjInteriorDefense = self.InteriorDefense * self.Minutes
self.AdjPerimeterDefense = self.PerimeterDefense * self.Minutes
self.AdjStealing = self.Stealing * self.Minutes
self.ReboundingPer = self.AdjRebounding / totalrebounding
# self.InteriorDefensePer = self.AdjInteriorDefense / totalDefense
# self.PerimeterDefensePer = self.AdjPerimeterDefense / totalDefense
self.DefensePer = (
((self.InteriorDefense + self.PerimeterDefense) / 2) * self.Minutes
) / totalDefense
self.AssistPer = self.AdjBallwork / totalAssist
self.InsideUsage = 0
self.MidUsage = 0
self.ThreePointUsage = 0
if self.FouledOut == False or self.IsInjured == False:
self.Usage = self.Minutes / 20
if self.Usage > 0:
self.InsideUsage = self.InsideProportion / (
240 * (InsideProportion / 100) * 2.4
)
self.MidUsage = self.MidRangeProportion / (
240 * (MidProportion / 100) * 2.4
)
self.ThreePointUsage = self.ThreePointProportion / (
240 * (ThreePtProportion / 100) * 2.4
)
self.DefRateTO = (
(self.PerimeterDefense + self.InteriorDefense + turnoverBonus) / 2
) * self.Minutes
self.AdjInjury = (20 - self.InjuryRating) * self.Minutes
self.AdjDiscipline = (20 - self.Discipline) * self.Minutes
def WithdrawFromGame(self, percent):
shots = {
"Ins": self.InsideProportion,
"Mid": self.MidRangeProportion,
"Three": self.ThreePointProportion,
}
self.Minutes = 0
self.Usage = 0
self.InsideProportion = 0
self.MidRangeProportion = 0
self.ThreePointProportion = 0
self.InsideUsage = 0
self.MidUsage = 0
self.ThreePointUsage = 0
self.Stats.AdjustMinutesBasedOnWidthdraw(percent)
return shots
def RecordInjury(self, name, severity, recovery, total_poss, max_poss):
self.IsInjured = True
self.InjuryName = name
self.InjuryType = severity
self.WeeksOfRecovery = recovery
percentageOfGame = total_poss / max_poss
self.Stats.AddInjury(name, severity, recovery)
return self.WithdrawFromGame(percentageOfGame)
def AddFoul(self, is_nba, total_poss, max_poss):
self.Stats.AddFoul()
if (self.Stats.Fouls == 6 and is_nba) or (
self.Stats.Fouls == 5 and is_nba == False
):
print(f"{self.FirstName} {self.LastName} has fouled out.")
self.FouledOut = True
percentageOfGame = total_poss / max_poss
self.Stats.FoulOut()
return self.WithdrawFromGame(percentageOfGame)
class PlayerStats:
def __init__(self, cp, matchType):
self.PlayerID = cp["ID"]
self.Minutes = cp["Minutes"]
self.Year = cp["Year"]
self.MatchType = matchType
self.Possessions = 0
self.FGM = 0
self.FGA = 0
self.FGPercent = 0
self.ThreePointsMade = 0
self.ThreePointAttempts = 0
self.ThreePointPercent = 0
self.FTM = 0
self.FTA = 0
self.FTPercent = 0
self.Points = 0
self.TotalRebounds = 0
self.OffRebounds = 0
self.DefRebounds = 0
self.Assists = 0
self.Steals = 0
self.Blocks = 0
self.Turnovers = 0
self.Fouls = 0
self.FouledOut = False
self.IsInjured = False
self.InjuryName = ""
self.InjuryType = ""
self.WeeksOfRecovery = 0
def AdjustMinutesBasedOnWidthdraw(self, percent):
self.Minutes = round(self.Minutes * percent)
def AddPossession(self):
self.Possessions += 1
def AddInjury(self, ij_name, ij_type, w_o_r):
self.IsInjured = True
self.InjuryName = ij_name
self.InjuryType = ij_type
self.WeeksOfRecovery = w_o_r
def AddFieldGoal(self, made_shot, pts=0):
self.Possessions += 1
self.FGA += 1
if made_shot:
self.FGM += 1
self.Points += pts
self.FGPercent = self.FGM / self.FGA
if pts == 3:
self.AddThreePoint(made_shot)
def AddThreePoint(self, made_shot):
self.ThreePointAttempts += 1
if made_shot:
self.ThreePointsMade += 1
self.ThreePointPercent = self.ThreePointsMade / self.ThreePointAttempts
def AddFTAttempt(self):
self.FTA += 1
self.FTPercent = self.FTM / self.FTA
def AddFTMade(self):
self.FTA += 1
self.FTM += 1
self.FTPercent = self.FTM / self.FTA
self.Points += 1
def AddAssist(self):
self.Assists += 1
def AddSteal(self):
self.Steals += 1
def AddBlock(self):
self.Blocks += 1
def AddRebound(self, is_offense):
self.TotalRebounds += 1
if is_offense == True:
self.OffRebounds += 1
else:
self.DefRebounds += 1
def AddTurnover(self):
self.Turnovers += 1
def AddFoul(self):
self.Fouls += 1
def FoulOut(self):
self.FouledOut = True