-
Notifications
You must be signed in to change notification settings - Fork 5
/
Team.py
79 lines (65 loc) · 2.35 KB
/
Team.py
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
import pandas as pd
from Player import Player
import numpy as np
import matplotlib.pyplot as plt
#from teamstats import loadTeamStats
#from teamstats100 import loadTeamStats100
from utility.TeamData import TeamData
year = '2018/' #can change to folder csv is in
#example lakers:1610612747
class Team:
def __init__(self, teamName):
self.teamName = teamName
self.df = pd.read_csv(year+teamName+'.csv')
self.playerIDS = self.df.PLAYER_ID
self.roster = {} #player objects
self.teamTotalShots = 0 #total number of shots taken by the team
self.shotDistPerPlayer = [] #player shot distribution
self.clock = []
self.shotQ = []
self.fga = 0
self.data = TeamData()
self.teamStats = None
self.loadTeamStats()
self.teamStats100 = None
self.loadTeamStats100()
# self.shotdist = np.random.choice(self.playerIDS, p= self.shotDistPerPlayer)
self.loadRoster()
self.teamTotalShotAttempts()
self.shotDist()
def loadRoster(self):
for i in self.playerIDS:
player = {i: Player(i)}
self.roster.update(player)
def teamTotalShotAttempts(self):
count =0
for i in self.roster:
count += self.roster[i].totalShots
self.teamTotalShots = count
def shotDist(self):
li = []
for i in self.roster:
li.append(self.roster[i].totalShots/self.teamTotalShots)
self.shotDistPerPlayer = li
#take a shot
#the player ID will be returned
#you need to then reach into the player shooting chart
def pickShooter(self):
return np.random.choice(self.playerIDS, p= self.shotDistPerPlayer)
def loadTeamStats(self):
self.teamStats = self.data.loadTeamStats(self.df['TeamID'][0])
#usage:
#teamName.teamStats['FGA']
def loadTeamStats100(self):
self.teamStats100 = self.data.loadTeamStats100(self.df['TeamID'][0])
def scat(self):
tot = []
for i in range(25):
tot.append(0)
for i in range(10000):
t = self.getShotClock()
print(t)
tot[t] +=1
x = list(range(25))
plt.scatter(x,tot)
plt.show()