-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevaluator.py
119 lines (105 loc) · 3.17 KB
/
evaluator.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
# TODO: given a schedule, evaluates its score
# calDict: (or print calDict to see what it is)
#'mm/dd/yy' -> set([(away1, home1), (away2, home2), ...])
#still need to deal with distance
import sys
from timeUtil import *
from distanceReader import *
import time
import timeUtil
import collections
import math
total = 0
teams = set()
teamScores = dict()
teamDistance = dict()
# to be determined
btbOnTotal = -10
btbOnTeam = -10
weightBtb = 0.3
weightFairness = 0.4
weightDistance = 0.3
distanceReader = CsvReader("distances.csv")
distance = distanceReader.distanceDict
def allTeams(calDict):
for date in calDict:
s = calDict[date]
for game in s:
for team in game:
teams.add(team)
def initialTeamSocores(calDict):
for eachTeam in teams:
teamScores[eachTeam] = 0
teamDistance[eachTeam] = (0,None)
# return True if team not relevant in games
def inGame(team, games):
for game in games:
if team in game:
return True
return None
def backToback(calDict,team):
totalPanelty = 0
totalDistance = 0
counter = 0
for date in calDict:
nextDate = nextDay(date)
games = calDict[date]
if inGame(team,games):
if (nextDate in calDict) and inGame(team,calDict[nextDate]):
counter += 1
totalPanelty += btbOnTeam
return (totalPanelty,counter)
def getStdDev(teamScores):
total = 0
for team in teamScores:
total += teamScores[team]
mean = total * 1.0 /len(teams)
variance = 0
for team in teamScores:
variance += (teamScores[team] - mean)**2
variance = variance * 1.0 / len(teams)
return math.sqrt(variance)
def totalDistance(calDict,teams):
total = 0
for date in calDict:
games = calDict[date]
for game in games:
homeTeam = game[1]
awayTeam = game[0]
hDistance = teamDistance[homeTeam][0]
aDistance = teamDistance[awayTeam][0]
if (teamDistance[awayTeam][1] == None):
teamDistance[awayTeam] = (distance[awayTeam,homeTeam] + aDistance, homeTeam)
else:
previous = teamDistance[awayTeam][1]
teamDistance[awayTeam] = (distance[awayTeam,previous] + aDistance, homeTeam)
if (teamDistance[homeTeam][1] == None):
teamDistance[homeTeam] = (hDistance, None)
else:
previous = teamDistance[awayTeam][1]
teamDistance[homeTeam] = (distance[homeTeam,previous] + hDistance, homeTeam)
for each in teamDistance:
total += teamDistance[each][0]
return total
def evaluate(calDict):
allTeams(calDict)
initialTeamSocores(calDict)
btbNum = 0
distanceSum = totalDistance(calDict, teams)
for team in teamScores:
teamScoreDelta, btbNumDelta = backToback(calDict,team)
teamScores[team] += teamScoreDelta
btbNum += btbNumDelta
btbStdev = getStdDev(teamScores)
teamD = dict()
for each in teamDistance:
teamD[each] = teamDistance[each][0]
distanceStdev = getStdDev(teamD)
totalScore = -0.05 * btbStdev + (-0.3) * (btbNum**2) + distanceStdev * (- 0.01) /10000 + - 0.5 * (distanceSum/10000)
retObject = {}
retObject["score"] = totalScore
retObject["btbNum"] = btbNum
retObject["btbStdev"] = btbStdev
retObject["distanceSum"] = distanceSum
retObject["distanceStdev"] = distanceStdev
return retObject