-
Notifications
You must be signed in to change notification settings - Fork 0
/
worldCupPredictor.py
executable file
·154 lines (140 loc) · 4.74 KB
/
worldCupPredictor.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from model.team import Team, Stats
from model.group import Group
from model.bracket import Bracket
from predictors.cost import Predictor as CostPredictor
from predictors.history import Predictor as HistoryPredictor
from simulators.match import MatchSimulator
from simulators.group import GroupSimulator
from simulators.knockout import KnockoutSimulator
from scoring import ScoringCriteria
from picker import Picker
DISPLAY_FINAL_STATS = True
def main():
currency = unichr(163).encode('utf-8').strip()
groups = makeGroups()
for g in groups:
print "Group", g.name
for t in g.teams:
print " ", t.name, currency + str(t.cost)
print ""
predictor = HistoryPredictor(CostPredictor())
matchSimulator = MatchSimulator(predictor)
# simulate group
groupSimulator = GroupSimulator(groups, matchSimulator)
groupResults = groupSimulator.simulateAllGroups()
# simulate knockout
round16 = makeRound16(groupResults)
bracket = Bracket(round16)
koSimulator = KnockoutSimulator(bracket, matchSimulator)
koSimulator.simulateAllStages()
print ""
print "Finishing Order:"
print "Winner: ", bracket.champion[0].name
print "Runner Up:", bracket.runnerUp[0].name
print "Third: ", bracket.third[0].name
print ""
# score teams
scoringCriteria = ScoringCriteria(Stats(10, 7, 5, 5, 2, 0, 3, -2, 5, 0))
teams = []
for g in groups:
for t in g.teams:
teamScore = scoringCriteria.teamScore(t)
t.score = teamScore
teamTuple = (t, float(teamScore)/float(t.cost))
teams.append(teamTuple)
teams.sort(key=lambda x: (x[1], -x[0].cost), reverse=True)
# display teams scored by best to worst based on a per-cost basis
print "Team Scores:"
printLine()
pFormat = "| {:>13} | {:>6} | {:>6} | {:>8} |"
print pFormat.format("Team", "Score", "Cost", "S/C")
printLine()
for tup in teams:
print pFormat.format(tup[0].name, tup[0].score, tup[0].cost, "{:.4f}".format(tup[1]))
printLine()
print ""
print "Picks:"
# pick best team from all the groups (picker params taken from scoring criteria)
groupPicks, score, underfundedScore, cost = Picker(250, 0.2, 10).bestPick(groups)
i = 1
for g in groupPicks:
for t in g.picks:
print " {:2}. (Group {:1}) {:13}".format(i, g.group.name, t.name),
if DISPLAY_FINAL_STATS:
print " (score = {:6} cost = {}{:5} s/c = {:>5.2f})".format(str(t.score) + ",", currency, str(t.cost) + ",", float(t.score)/float(t.cost)),
else:
print currency + str(t.cost),
print ""
i += 1
printLine()
if DISPLAY_FINAL_STATS:
print " Total Cost = {}{}".format(currency, cost)
print " Total Score = {:.1f} (incld. underfunded score = {})".format(score + underfundedScore, underfundedScore)
else:
print " Total Cost {:>19}{}".format(currency, cost)
printLine()
def printLine():
print "-------------------------------------------------"
def makeRound16(groupResults):
round16 = [None] * 16
for i in range(0, 8, 2):
round16[i] = groupResults[i].winner
round16[i + 1] = groupResults[i + 1].runner_up
round16[i + 8] = groupResults[i + 1].winner
round16[i + 8 + 1] = groupResults[i].runner_up
return round16
def makeGroups():
return [
Group("A", [
Team("Egypt", 4),
Team("Russia", 16),
Team("Saudi Arabia", 1),
Team("Uruguay", 20),
]),
Group("B", [
Team("Iran", 2),
Team("Morocco", 2),
Team("Portugal", 31),
Team("Spain", 70),
]),
Group("C", [
Team("Australia", 3),
Team("Denmark", 9),
Team("France", 80),
Team("Peru", 5),
]),
Group("D", [
Team("Argentina", 55),
Team("Croatia", 20),
Team("Iceland", 5),
Team("Nigeria", 5),
]),
Group("E", [
Team("Brazil", 99),
Team("Costa Rica", 2),
Team("Switzerland", 9),
Team("Serbia", 5),
]),
Group("F", [
Team("Germany", 99),
Team("South Korea", 2),
Team("Mexico", 9),
Team("Sweden", 7),
]),
Group("G", [
Team("Belgium", 45),
Team("England", 33),
Team("Panama", 1),
Team("Tunisia", 2),
]),
Group("H", [
Team("Columbia", 19),
Team("Japan", 3),
Team("Poland", 11),
Team("Senegal", 5),
]),
]
if __name__ == "__main__":
main()