-
Notifications
You must be signed in to change notification settings - Fork 0
/
season.py
83 lines (63 loc) · 2.33 KB
/
season.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
80
81
82
83
## season.py ###################################################################
## general object representing seasons of a ####################################
## league ######################################################################
################################################################################
from team import *
class Season(Team):
def __init__(self, leagueId, levelId, seasonId, teamIdList):
self.Teams = []
## list containing objects of type team<insert league here>
self.seasonId = seasonId
self.leagueId = leagueId
self.levelId = levelId
def getLeagueId(self):
return self.leagueId
def getLevelId(self):
return self.levelId
def getSeasonId(self):
return self.seasonId
def getTotalNumberOfTeams(self):
## total teams in the league playing this season
return len(self.Teams)
def getSeasonTeams(self):
## get a list of the team objects for this season
return self.Teams
## we often want to retrieve a team object from a season based
## on a variety of information about it#
def getTeamByPosition(self, position):
## get the team object that finished at the given spot in the
## standings, ie first overall would be position 1, second
## overall would be position 2 and so on
## this needs to raise an exception on failing to find what we
## looking for
for team in self.Teams:
if((position -1) == self.Teams.index(team)):
return team
print "Unable to find team, position %i out of range" % position
def getTeamByTeamName(self, teamName):
## get the team object by its name in text,
## ie 'Toronto Maple Leafs'
## again, where those exceptions at
for team in self.Teams:
if(team.getTeamName() == teamName):
return team
print "Unable to find team, no team with name %s found" % teamName
def getTeamStatAverage(self, statName):
output = 0.00
for team in self.Teams:
output += statName(team)
output /= float(len(self.Teams))
return output
def getTeamStatList(self, statName):
output = []
for team in self.Teams:
output.append(statName(team))
return output
def getTeamsAboveOneGoalCutoff(self):
output = 0
for team in self.Teams:
if(team.getCPQI() > 0.987):
## 0.987 instead of 1.0 , since we want to ignore the possible
## effect of one bad game (ie 1/82 lower than 1)
output += 1
return output