forked from lau-gary10/nbaPowerRanking
/
evaluate_gap.py
163 lines (139 loc) · 6.01 KB
/
evaluate_gap.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
'''
Find the gap between each team and put them on a tier
If the true_pct gap between teams are 4.0% or greater, than the lesser team belongs on a lesser
tier.
Explanation of tiers:
Tier A - Title Contender. Teams that are fully capable of winning the championship.
Projection: Conference Finals - League Finals
Tier B - Playoff Contender. Teams that are fully capable of getting into the playoffs.
Possibly Title Contender.
Projection: 2nd Round - League Finals
Tier C and D - Playoff Runner. Teams that can get into the playoffs. Unlikely to contend
for a title.
Projection: 1st Round - Conference Finals
Tier E and F - Playoff Struggler. Teams that will struggle to get into playoffs. Highly
unlikely to contend for a title.
Projection: 10th Conference Place - 2nd Round
Tier G and below - Yawner. Teams that are tanking, or just do not have any
potential to reach the playoffs. Unlikely to pay tickets to see these teams.
Projection: Lottery Pick
#########################################################################
The MIT License (MIT)
Copyright (c) 2014 Gary Lau
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
#########################################################################
'''
import common_lib, sys
NBA_POWER_RANKING_CSV_FILE = sys.argv[1]
PCT_GAP_CUTOFF = .040
# Assigns a label and projection to the letter
def assign_label_and_projection_to_tier(letter):
if 'A' == letter:
label = 'Title Contender'
projection = 'Conference Finals - League Finals'
elif 'B' == letter:
label = 'Playoff Contender'
projection = '2nd Round - League Finals'
elif 'C' == letter:
label = 'Playoff Runner'
projection = '1st Round - Conference Finals'
elif 'D' == letter:
label = 'Playoff Runner'
projection = '1st Round - Conference Finals'
elif 'E' == letter:
label = 'Playoff Struggler'
projection = '10th Place - 2nd Round'
elif 'F' == letter:
label = 'Playoff Struggler'
projection = '10th Place - 2nd Round'
else:
label = 'Yawner'
projection = 'Lottery Pick'
return label, projection
def start_main():
list2 = []
finalList = []
theList = common_lib.get_multiple_col(NBA_POWER_RANKING_CSV_FILE, 0,1,2,3,4)
i = 0
while i < len(theList):
teamName = common_lib.parse_the_popped_element_to_return_str(theList.pop())
roadWin = common_lib.parse_the_popped_element_to_return_str(theList.pop())
homeLoss = common_lib.parse_the_popped_element_to_return_str(theList.pop())
pct = common_lib.parse_the_popped_element_to_return_str(theList.pop())
truePct = common_lib.parse_the_popped_element_to_return_str(theList.pop())
list2.append([teamName, roadWin, homeLoss, pct, truePct])
# Add column 'PCT_GAP', 'TIER', and 'LABEL' onto header
list2.reverse()
header = list2.pop()
header.append('PCT_GAP')
header.append('TIER')
header.append('LABEL')
header.append('PROJECTION')
finalList.append(header)
# Evaluates team's TRUE_PCT to find PCT_GAP, TIER, and LABEL
# Set initial values up for looping
length = len(list2)
tier = 0
letterTier = chr(tier + ord('A')) # Converts the int to corresponding english alphabet
labelProjeTuple = assign_label_and_projection_to_tier(letterTier)
element1 = list2.pop()
element1.append('0')
element1.append(str(letterTier))
element1.append(str(labelProjeTuple[0]))
element1.append(str(labelProjeTuple[1]))
list2.append(element1)
for i in range(length):
# for i in range(0,1):
try:
# Grab two elements from the list
element1 = list2.pop()
element2 = list2.pop()
except IndexError:
finalList.append(element2)
break
else:
# Get PCT_GAP
floatTruePct1 = float(element1[4])
floatTruePct2 = float(element2[4])
pctGap = (floatTruePct1 / floatTruePct2) - 1
# Get TIER
if pctGap > PCT_GAP_CUTOFF:
tier += 1
letterTier = chr(tier + ord('A'))
# Assign LABEL to corresponding TIER
labelProjeTuple = assign_label_and_projection_to_tier(letterTier)
element2.append(str(pctGap))
element2.append(str(letterTier))
element2.append(str(labelProjeTuple[0]))
element2.append(str(labelProjeTuple[1]))
finalList.append(element1)
list2.append(element2)
finalList = common_lib.convert_list_into_str(finalList)
common_lib.write_file(finalList, NBA_POWER_RANKING_CSV_FILE)
# Get run time of the parameter module
def actual_run_time():
def new_func():
start_main()
from timeit import timeit
seconds = timeit(new_func, number=1)
from datetime import timedelta
seconds = timedelta(seconds=float(seconds))
name = common_lib.module_name() + '.py'
print('Actual run time on ' + name + ':', seconds)
def main():
actual_run_time()
main()