-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
237 lines (200 loc) · 7.7 KB
/
index.html
File metadata and controls
237 lines (200 loc) · 7.7 KB
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
235
236
237
<html>
<head>
<title>Antti's top cut calculator</title>
<meta property="og:title" content="Antti's top cut calculator" />
<meta property="og:type" content="website:tool" />
<meta property="og:locale" content="en_GB" />
<meta property="og:url" content="https://github.com/antsy/TopCutCalc" />
<meta property="og:description"
content="Calculate how many players will make it to the top through swiss rounds." />
<meta property="og:image"
content="https://upload.wikimedia.org/wikipedia/commons/a/a7/Korvatunturi_kes%C3%A4ll%C3%A4.jpg" />
<meta property="og:image:type" content="image/jpeg" />
<meta property="og:image:width" content="524" />
<meta property="og:image:height" content="254" />
</head>
<style>
@import url('https://fonts.googleapis.com/css2?family=Oswald&family=Raleway:wght@300&family=Roboto+Mono&display=swap');
:root {
--scale: 1vmin;
}
h1, h2, #resultHead {
font-family: 'Oswald', sans-serif;
font-size: calc(var(--scale) * 6);
margin-top: calc(var(--scale) * 2);
margin-bottom: calc(var(--scale) * 2);
}
#resultHead {
font-size: calc(var(--scale) * 2.4);
}
p, input, label, #resultTable {
font-family: 'Raleway', sans-serif;
font-size: calc(var(--scale) * 2.4);
}
#TopCutCalc {
display: grid;
grid-template-columns: 1fr 80% 1fr;
}
#inputs {
grid-column: 2 / -2;
display: grid;
grid-template-columns: 2fr 100px 3fr;
grid-gap: calc(var(--scale) * 1.6);
}
#inputs>h1 {
grid-row-start: 1;
grid-column-end: span 3;
}
#inputs>label {
grid-column: 1;
}
#inputs>input {
color: rgb(11, 87, 250, 1);
grid-column: 2;
text-align: center;
font-family: 'Roboto Mono', monospace;
border-radius: 1vmin;
-webkit-transition: all 0.30s ease-in-out;
-moz-transition: all 0.30s ease-in-out;
-ms-transition: all 0.30s ease-in-out;
-o-transition: all 0.30s ease-in-out;
outline: none;
padding: 3px 0px 3px 3px;
margin: 5px 1px 3px 0px;
border: 1px solid #DDDDDD;
}
#inputs>input:focus {
box-shadow: 0 0 5px rgb(11, 87, 250, 0.5);
padding: 3px 0px 3px 3px;
margin: 5px 1px 3px 0px;
border: 1px solid rgb(11, 87, 250, 0.8);;
}
#inputs .note {
font-size: calc(var(--scale) * 1.8);
grid-column-end: span 2;
}
#outputs {
grid-column: 2 / -2;
display: grid;
}
#outputs table {
width: auto;
}
#resultHead {
display: grid;
grid-template-columns: 2fr 3fr 3fr;
}
#resultTable {
display: grid;
grid-template-columns: 2fr 3fr 3fr;
}
#inDanger {
font-weight: bold;
font-family: 'Oswald', sans-serif;
}
.record {
font-family: 'Roboto Mono', monospace;
letter-spacing: -0.2rem;
text-overflow: ellipsis;
white-space: nowrap;
}
.note {
font-style: italic;
}
</style>
<script src="topcutcalc.js"></script>
<body>
<div id="TopCutCalc">
<div id="inputs">
<h1>Antti's top cut calculator</h1>
<label for="playerCount">Total number of players</label>
<input id="playerCount" name="playerCount" type="number" value="64" />
<label for="swissRounds">Number of swiss rounds</label>
<input id="swissRounds" name="swissRounds" type="number" value="6" />
<label for="topCut">How many make it to the top</label>
<input id="topCut" name="topCut" type="number" value="" />
<p class="note">The results will update automatically as input values change.</p>
</div>
<div id="outputs">
<h2>Result records estimate</h2>
<p id="explanation"></p>
<div id="resultHead">
<div>Record</div>
<div>Number of players with record</div>
<div>Percentage of all players</div>
</div>
<div id="resultTable"></div>
<p id="inDanger"></p>
</div>
</div>
<script>
const getCurrentValues = () => {
const inputs = document.getElementById('inputs');
const playerCount = +(inputs.querySelector('#playerCount').value);
const swissRounds = +(inputs.querySelector('#swissRounds').value);
const topCut = +(inputs.querySelector('#topCut').value);
return {
playerCount: playerCount,
swissRounds: swissRounds,
topCut: topCut,
}
}
const updateOutputs = (e) => {
const output = document.getElementById('outputs');
const explanation = output.querySelector('#explanation');
const resultTable = output.querySelector('#resultTable');
const inDanger = output.querySelector('#inDanger');
const { playerCount, swissRounds, topCut } = getCurrentValues();
if (topCut < playerCount && topCut > 0) {
explanation.innerHTML = `In a ${playerCount} player ${swissRounds} rounds tournament, the Top${topCut} will consist of records:`;
} else {
explanation.innerHTML = `In a ${playerCount} player ${swissRounds} rounds tournament, the final record distribution will look something like this:`;
}
const resultData = calculate(playerCount, swissRounds, topCut);
const results = getTable(resultData, swissRounds);
resultTable.innerHTML = "";
for (let result of results) {
const cell1 = document.createElement('div');
cell1.classList = "record"
cell1.appendChild(document.createTextNode(`${result.record}`));
const cell2 = document.createElement('div');
cell2.appendChild(document.createTextNode(`${result.howMany.toFixed(2)}`));
const cell3 = document.createElement('div');
cell3.appendChild(document.createTextNode(percentFrom(result.howMany, playerCount)));
resultTable.appendChild(cell1)
resultTable.appendChild(cell2)
resultTable.appendChild(cell3)
}
let cutOff = topCut;
for (let result of results) {
if (result.howMany <= cutOff) {
cutOff -= result.howMany;
}
}
if (topCut < playerCount && topCut > 0) {
const lastRecord = results[results.length - 1];
if (cutOff != 0) {
const plural = cutOff === 1 ? `only a single player` : `${cutOff} players`
const percentage = percentFrom(cutOff, lastRecord.howMany);
inDanger.innerHTML = `Out of ${lastRecord.howMany} players with record "${lastRecord.record}", ${plural} (${percentage}) will make it to the top${topCut}.`;
} else {
inDanger.innerHTML = `Looks like no player with record lower than ${lastRecord.record} can make it to the Top${topCut}`
}
} else {
inDanger.innerHTML = "";
}
}
const percentFrom = (value1, value2) => {
return `${(value1 / value2 * 100).toFixed(1)} %`;
}
(function () {
const inputs = document.getElementsByTagName('INPUT');
for (let input of inputs) {
input.addEventListener('change', updateOutputs, false);
}
// Do initial update with default values
updateOutputs();
})();
</script>
</body>
</html>