-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathncaa14.py
More file actions
78 lines (68 loc) · 2.67 KB
/
ncaa14.py
File metadata and controls
78 lines (68 loc) · 2.67 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
from data import Data
from team import Team
from game import Game, Location
import csv
class NCAA14:
def __init__(self, data):
self.data = data
def run(self):
self.get_team_info()
self.get_team_season_info()
def save_bcs_rank(self):
output = open('data/teams_ranked.csv', 'w')
reader = csv.reader(open('data/teams.csv'))
lines = [l for l in reader]
output.write(lines[0][0] + ',' + lines[0][1] + "\n")
with open('data/teams.csv') as csvfile:
next(csvfile)
teams = csv.DictReader(csvfile)
csvwriter = csv.DictWriter(output, teams.fieldnames)
csvwriter.writeheader()
rankings = self.data.sorted_rankings()
for team in teams:
finder = [t for t in rankings if t.url == team['TSNA']]
if len(finder) > 0:
if int(team['TBPR']) == 0:
team['TBPR'] = team['TBRK']
else:
team['TBPR'] = finder[0].previous_bcs_rank
team['TBRK'] = rankings.index(finder[0]) + 1
csvwriter.writerow(team)
def get_win_qualities(self):
with open('data/wqs.csv', 'w') as csvfile:
for team in self.data.fbs_teams():
for game in team.games:
csvfile.write(team.name + ',' + game.opponent.name + ',' + str(game.adjusted_quality()) + "\n")
def get_team_info(self):
with open('data/teams.csv') as csvfile:
next(csvfile)
teams = csv.DictReader(csvfile)
for team in teams:
new_team = Team(team['TDNA'], team['TSNA'])
new_team._id = team['TGID']
new_team.division = 'Div FBS' if team['LGID'] == '0' else 'FCS'
new_team.wins = int(team['TSWI'])
new_team.losses = int(team['TSLO'])
new_team.bcs_rank = int(team['TBRK'])
new_team.previous_bcs_rank = int(team['TBPR'])
new_team.games = []
self.data.teams.append(new_team)
def get_team_season_info(self):
with open('data/games.csv') as csvfile:
next(csvfile)
games = csv.DictReader(csvfile)
for game in games:
home_score = int(game['GHSC'])
away_score = int(game['GASC'])
if home_score == 0 and away_score == 0:
continue # game hasn't played yet
home_team = [team for team in self.data.teams if team._id == game['GHTG']][0]
away_team = [team for team in self.data.teams if team._id == game['GATG']][0]
if home_team.division == 'Div FBS':
home_team.games.append(Game(Location.home, away_team, home_score, away_score))
else:
home_team.games.append([])
if away_team.division == 'Div FBS':
away_team.games.append(Game(Location.away, home_team, away_score, home_score))
else:
away_team.games.append([])