-
Notifications
You must be signed in to change notification settings - Fork 0
/
reader.py
171 lines (152 loc) · 5.94 KB
/
reader.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import csv
from player import *
def normalize(name):
return
content = []
with open("./csv/" + name, "r") as f:
content = f.readlines()
f.close()
output = ""
prevLine = ""
for i, line in enumerate(content):
if i % 2 == 0:
prevLine = line.strip()
else:
prevLine += line
output += prevLine
with open("./csv/" + name, "w") as f:
f.write(output)
f.close()
def fetchQBs():
players = []
with open("./csv/qb.csv", 'r') as f:
reader = csv.reader(f, delimiter=",", quotechar='"')
for row in reader:
player = parseBasics(row, QB, 13, 14)
if row[4] != '--':
# Passing
player.attempts = int(
str(row[4]).replace(',', '')) / player.games
player.pass_yd = int(
str(row[6]).replace(',', '')) / player.games
player.interception = int(
str(row[7]).replace(',', '')) / player.games
player.passing_td = int(
str(row[8]).replace(',', '')) / player.games
# Rushing
player.rush_yd = int(
str(row[9]).replace(',', '')) / player.games
player.rush_td = int(
str(row[10]).replace(',', '')) / player.games
player.fumbles = int(
str(row[11]).replace(',', '')) / player.games
players.append(player)
return players
def fetchRBs():
players = []
with open("./csv/rb.csv", 'r') as f:
reader = csv.reader(f, delimiter=",", quotechar='"')
for row in reader:
player = parseBasics(row, RB, 12, 13)
if row[4] != '--':
# Rushing
player.rushes = int(
str(row[4]).replace(',', '')) / player.games
player.rush_yd = int(
str(row[5]).replace(',', '')) / player.games
player.rush_td = int(
str(row[6]).replace(',', '')) / player.games
# Recieving
player.recv = int(str(row[7]).replace(',', '')) / player.games
player.recv_yd = int(
str(row[8]).replace(',', '')) / player.games
player.recv_td = int(
str(row[9]).replace(',', '')) / player.games
player.fumbles = int(
str(row[10]).replace(',', '')) / player.games
players.append(player)
return players
def fetchWRs():
players = []
with open("./csv/wr.csv", 'r') as f:
reader = csv.reader(f, delimiter=",", quotechar='"')
for row in reader:
player = parseBasics(row, WR, 12, 13)
if row[4] != '--':
# Recieving
player.recv = int(str(row[4]).replace(',', '')) / player.games
player.recv_yd = int(
str(row[5]).replace(',', '')) / player.games
player.targets = int(
str(row[6]).replace(',', '')) / player.games
player.recv_td = int(
str(row[7]).replace(',', '')) / player.games
# Rushing
player.rush_yd = int(
str(row[8]).replace(',', '')) / player.games
player.rush_td = int(
str(row[9]).replace(',', '')) / player.games
player.fumbles = int(
str(row[10]).replace(',', '')) / player.games
players.append(player)
return players
def fetchTEs():
players = []
with open("./csv/te.csv", 'r') as f:
reader = csv.reader(f, delimiter=",", quotechar='"')
for row in reader:
player = parseBasics(row, TE, 12, 13)
if row[4] != '--':
# Recieving
player.recv = int(str(row[4]).replace(',', '')) / player.games
player.recv_yd = int(
str(row[5]).replace(',', '')) / player.games
player.targets = int(
str(row[6]).replace(',', '')) / player.games
player.recv_td = int(
str(row[7]).replace(',', '')) / player.games
# Rushing
player.rush_yd = int(
str(row[8]).replace(',', '')) / player.games
player.rush_td = int(
str(row[9]).replace(',', '')) / player.games
player.fumbles = int(
str(row[10]).replace(',', '')) / player.games
players.append(player)
return players
def fetchDSTs():
players = []
with open("./csv/dst.csv", 'r') as f:
reader = csv.reader(f, delimiter=",", quotechar='"')
for row in reader:
player = parseBasics(row, DST, 14, 15)
player.sack = int(row[4]) / player.games
player.def_interception = int(row[5]) / player.games
player.fumb_recovery = int(row[6]) / player.games
player.safety = int(row[7]) / player.games
player.def_touchdowns = int(row[9]) / player.games
player.points_allowed = int(
str(row[10]).replace(',', '')) / player.games
player.pass_yd_allowed = int(
str(row[11]).replace(',', '')) / player.games
player.rush_yd_allowed = int(
str(row[12]).replace(',', '')) / player.games
players.append(player)
return players
def parseBasics(row, pos, ptsPos, salaryPos):
name = row[0].strip()
team = ""
if "," in name:
chunks = name.split(',')
name = chunks[0].strip()
team = chunks[1].strip()
opposition = row[1].strip()
if row[3].strip() == '--':
games = 0
else:
games = int(row[3])
avgpts = float(row[ptsPos].strip())
salary = int(row[salaryPos].strip())
p = Player(pos, name, salary, opposition, avgpts, games)
p.team = team
return p