-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfield.html
234 lines (185 loc) · 9.39 KB
/
field.html
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
<!DOCTYPE html>
<html>
<head>
<title>Fantasy League Solver</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://fonts.googleapis.com/css2?family=Lato:wght@400;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.4.1/semantic.min.css"
integrity="sha512-8bHTC73gkZ7rZ7vpqUQThUDhqcNFyYi2xgDgPDHc+GXVGHXq+xPjynxIopALmOPqzo9JZj0k6OqqewdGO3EsrQ=="
crossorigin="anonymous" />
<link href="field.css" rel="stylesheet">
<link
rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<body>
<div class="container">
<div class="logo"></div>
<div class="options ui fluid formation">
<h3>Formation</h3>
<div class="opt-players">
<p>You can either let the algorithm select the 15 players who will get you the maximum number of points, or specify a
formation and the algorithm will select the lowest cost players as subs, ensuring the maximum points are gained from only outfield players.
</p>
</div>
<br />
<select id="team-formation" class="ui dropdown formation-select" name="team-formation"
placeholder="Team Formation">
<option value="all" selected>Select the best overall team (including subs)</option>
<option value="343"> 1 4 3</option>
<option value="352">3 5 2</option>
<option value="442">4 4 2</option>
<option value="451">4 5 1</option>
<option value="433">4 3 3</option>
</select>
</div>
<div class="options ui fluid positive">
<h3>Players whose stat are best for playing in the Team</h3>
<div class="opt-players">
<p>I would like to have these players in my team:</p>
</div>
<br />
<select id="player-initial-positive" class="ui search selection dropdown player-select" name="positive-players" multiple=""
placeholder="Search for a player">
</select>
</div>
<div class="options ui fluid negative">
<h3>Players whose stats are less than other players</h3>
<div class="opt-players">
<p>I don't want these players in my team:</p>
</div>
<br />
<select id="player-initial-negative" class="ui search selection dropdown player-select" name="negative-players" multiple=""
placeholder="Search for a player">
</select>
</div>
<div class="result">
<div class="pitch"></div>
<div class="player-price-summary">
<p>Players in <span class="grey-player-area">Grey</span> are cheap players (less than or equal to £4.5m). At least one goalkeeper is always cheap, and depending on your preferred formation, others can be too.</p>
</div>
<div class="points-summary">
<p>This team generated <span id="total_points"></span> points last season.</p>
</div>
</div>
<footer>
<div class="footer-content">
<h3>KICK It!</h3>
<p> We are one of the best squad builder website in terms of kickking the nepotism.
We compare between players and choose the best Eleven for the squad.
Hope You All Enjoy Our Website!
</p>
<ul class="socials">
<li><a href="https://www.facebook.com/"><i class="fa fa-facebook"></i></a></li>
<li><a href="https://twitter.com/"><i class="fa fa-twitter"></i></a></li>
<li><a href="https://www.youtube.com/"><i class="fa fa-youtube"></i></a></li>
<li><a href="https://www.linkedin.com/signup"><i class="fa fa-linkedin-square"></i></a></li>
</ul>
</div>
<div class="footer-bottom">
<p> <a href="#"></a> </p>
<div class="footer-menu">
<ul class="f-menu">
<li class="a"><a href="#"><i class="fa fa-home"></i></a></li>
<li><a href="#"><i class="fa fa-map-marker"></i></a></li>
<li><a href="#"><i class="fa fa-phone"></i></a></li>
<li><a href="#"><i class="fa fa-envelope"></i></a></li>
</ul>
</div>
</div>
</footer>
<div class="clear"></div>
<br/>
<div class="info" style="margin-top: 20vh;">
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"
integrity="sha512-bLT0Qm9VnAYZDflyKcBaQ2gg0hSYNQrJ8RilYldYQ1FxQYoCLtUjuuRuZo+fjqhx/qtq/1itJ0C2ejDxltZVFg=="
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.4.1/semantic.min.js"
integrity="sha512-dqw6X88iGgZlTsONxZK9ePmJEFrmHwpuMrsUChjAw1mRUhUITE5QU9pkcSox+ynfLhL15Sv2al5A0LVyDCmtUw=="
crossorigin="anonymous"></script>
<script src="solver.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/6.1.1/d3.min.js"
integrity="sha512-5xkNvFVCctXwOszeifE8pzjyDFlHvHDCKIrhwmuSbCtTHqc7IhA6/1tTNYXE8WmYvwP5KFQegCS1QRR4poYgjg=="
crossorigin="anonymous"></script>
<script src="fantasy-solve.js" type="text/javascript"></script>
<script>
var players;
function output_result(result) {
var counts = { 'GKP': 0, 'DEF': 0, 'MID': 0, 'FWD': 0 };
// reset
if(result.feasible) {
d3.select('.pitch').html('');
console.log(result);
Object.keys(result).forEach(function (r) {
if (r in players) {
var player = players[r];
var player_elem = d3.select('.pitch').append('div').attr('class', function () {
counts[player.position] += 1;
return player.position.toLowerCase() + ' ' + player.position.toLowerCase() + counts[player.position];
})
player_elem.append('h4').attr('class', player.cost <= 4.5 ? 'low-cost' : '').text(player.name);
player_elem.append('p').attr('class', 'team').html(player.team + ' £' + player.cost + 'm');
}
});
d3.select('#total_points').text(result.result);
} else {
d3.select('.pitch').html('<p>No optimal team can be found. Try relaxing the constraints.</p>');
}
}
function build_player_lookup(players){
var player_lookup = {};
players.forEach(function(p) {
player_lookup[p.name + '' + p.team + '' + p.position] = p;
});
return player_lookup;
}
d3.json('players.json').then(function (response) {
players = build_player_lookup(response.players);
var result = fantasySolver.solve(players);
output_result(result);
var for_select = [];
Object.keys(players).forEach(function (p_key) {
for_select.push({ 'name': players[p_key].name + ' - ' + players[p_key].team + ' - £' + players[p_key].cost + 'm', 'value': p_key })
});
$('.formation-select').dropdown();
$('.player-select')
.dropdown({
action: 'combo',
values: for_select.sort(function(a, b){return a.name < b.name ? -1 : 1})
});
function recalculate() {
var positive_values = [];
var negative_values = [];
setTimeout(function() {
d3.selectAll('.options.positive a.ui.label.transition.visible').each(function (d) {
positive_values.push(d3.select(this).attr('data-value'));
});
d3.selectAll('.options.negative a.ui.label.transition.visible').each(function (d) {
negative_values.push(d3.select(this).attr('data-value'));
});
var formation = d3.select('#team-formation').node().value;
var result = fantasySolver.runWithInitialPlayers(positive_values, negative_values, formation);
console.log(result);
output_result(result);
}, 250);
d3.selectAll('a.ui.label.transition.visible i.delete.icon').on("click", function(d) {
recalculate();
})
}
d3.select("#player-initial-positive")
.on("change", function () {
recalculate();
});
d3.select("#player-initial-negative")
.on("change", function () {
recalculate();
});
d3.select("#team-formation")
.on("change", function () {
recalculate();
});
});
</script>
</body>
</html>