forked from SI507-206-W18/lec24
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel.py
38 lines (31 loc) · 919 Bytes
/
model.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
#model.py
import csv
BB_FILE_NAME = 'umbball.csv'
bb_seasons = []
def init_bball(csv_file_name=BB_FILE_NAME):
pass
def get_bball_seasons(sortby='year', sortorder='desc'):
if sortby == 'year':
sortcol = 1
elif sortby == 'wins':
sortcol = 3
elif sortby == 'pct':
sortcol = 5
else:
sortcol = 0
rev = (sortorder == 'desc')
sorted_list = sorted(bb_seasons, key=lambda row: row[sortcol], reverse=rev)
return sorted_list
def init_bball(csv_file_name=BB_FILE_NAME):
global bb_seasons
with open(csv_file_name) as f:
reader = csv.reader(f)
next(reader) # throw away headers
next(reader) # throw away headers
global bb_seasons
bb_seasons = [] # reset, start clean
for r in reader:
r[3] = int(r[3])
r[4] = int(r[4])
r[5] = float(r[5])
bb_seasons.append(r)