-
Notifications
You must be signed in to change notification settings - Fork 0
/
scrapParam.py
148 lines (121 loc) · 4.56 KB
/
scrapParam.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
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
## scrapParam.py ###############################################################
## an object wrapper for all of the params that scrap needs ####################
## in order to run #############################################################
################################################################################
from outputs import *
class scrapParams(object):
def __init__(self, leagueId, levelId, playoffTeamsOnly=False, teamNames=[], playerNames=[], runMode="Linear", targetStatName="CPQI", independentStatName="GDA", sortOrder='desc'):
self.leagueId = leagueId
self.levelId = levelId
self.playoffTeamsOnly = playoffTeamsOnly
self.teamNames = teamNames
self.playerNames = playerNames
self.runMode = runMode
self.targetStatName = targetStatName
self.independentStatName = independentStatName
self.sortOrder = sortOrder
def info(self):
print "scrapParams object:"
print "leagueId = %s" % (self.getLeagueId())
print "levelId = %s" % (self.getLevelId())
print "playoffTeamsOnly = %r" % (self.getPlayoffTeamsOnly())
print "teamNames = ", self.getTeamNames()
print "playerNames = ", self.getPlayerNames()
print "runMode = %s" % (self.getRunMode())
print "targetStatName = %s" % (self.getTargetStatName())
print "sortOrder = %s" % (self.getSortOrder())
def getLeagueId(self):
return self.leagueId
def setLeagueId(self, newLeagueId):
self.leagueId = newLeagueId
def getLevelId(self):
return self.levelId
def setLevelId(self, newLevelId):
self.levelId = newLevelId
def getTargetStatName(self):
return self.targetStatName
def setTargetStatName(self, newTargetStatName):
self.targetStatName = newTargetStatName
def getIndependentStatName(self):
return self.independentStatName
def setIndependentStatName(self, newIndependentStatName):
self.independentStatName = newIndependentStatName
def getSortOrder(self):
return self.sortOrder
def setSortOrder(self, newSortOrder):
self.sortOrder = newSortOrder
def getPlayoffTeamsOnly(self):
return self.playoffTeamsOnly
def getTeamNames(self):
return self.teamNames
def setTeamNames(self, newTeamNames):
self.teamNames = newTeamNames
def getPlayerNames(self):
return self.playerNames
def setTeamNames(self, newPlayerNames):
self.playerNames = newPlayerNames
def getRunMode(self):
return self.runMode
def getOutputType(self):
try:
with open('./data/%s/%s/seasons.csv' % (self.leagueId, self.levelId), 'rb') as foo:
outputType = "generic"
except IOError:
outputType = "detailed"
return outputType
def watMuLevels():
return ['beginner', 'intermediate', 'advanced', 'allstar']
def proLeagues():
return ['wha', 'nhl']
def filterSeasonsByParams(seasons, parameters):
output = []
if(parameters.getLeagueId() == "watMu"):
if(parameters.getLevelId() in watMuLevels()):
for season in seasons:
if(season.getLeagueId() == "watMu"):
if(season.getLevelId() == parameters.getLevelId()):
output += [season]
## if the level is correct, and the league is right
## (remember watMu seasons will be mixed with nhl & wha)
## append it to our output
if(len(output) > 0):
return output
else:
for season in seasons:
if(season.getLeagueId() == "watMu"):
if(season.getSeasonId() == parameters.getLevelId()):
output += [season]
if(len(output) > 0):
return output
elif(parameters.getLeagueId() in proLeagues()):
## nhl, wha, what have you
seasonIdList = []
try:
with open('./data/%s/%s/seasons.csv' % (parameters.getLeagueId(), parameters.getLevelId()), 'rb') as foo:
seasonIdList += [f.rstrip() for f in foo]
for season in seasons:
if(season.getLeagueId() == parameters.getLeagueId()):
if(season.getSeasonId() in seasonIdList):
output += [season]
if(len(output) > 0):
return output
except IOError:
## couldnt find a seasons manifest for what was supplied, so next we
## check to see if the levelId supplied can be matched to a seasonId
## in the index list
levelIdIsSeason = False
with open('./data/%s/seasonIndex.csv' % (parameters.getLeagueId()), 'rb') as foo:
if(parameters.getLevelId() in [f.rstrip() for f in foo]):
levelIdIsSeason = True
if(levelIdIsSeason):
for season in seasons:
if(season.getLeagueId() == parameters.getLeagueId()):
if(season.getSeasonId() == parameters.getLevelId()):
output += [season]
if(len(output) > 0):
return output
else:
print "Unable to make parameter set work with seasons, params:"
params.info()
elif(parameters.getLeagueId() == "all"):
return seasons