-
Notifications
You must be signed in to change notification settings - Fork 15
/
index-main.php
296 lines (283 loc) · 9.96 KB
/
index-main.php
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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="0">
<?php
include 'definitions.php';
if( !array_key_exists('competition',$_GET) ) {
echo 'No competition to present.'.PHP_EOL;
exit(-1);
}
$competition = $_GET['competition'];
if( preg_match('/\\.\\.?|.*[\\/:].*/',$competition) ) {
echo "Bad competition name.".PHP_EOL;
exit(-1);
}
if( array_key_exists('root',$_GET) ) {
$path_html = '';
$root_html = $_GET['root'].'/';
} else {
$path_html = $competition.'/';
$root_html = '';
}
echo ' <link rel="stylesheet" type="text/css" href="'.$root_html.'master.css">'.PHP_EOL;
echo ' <script src="'.$root_html.'definitions.js"></script>'.PHP_EOL;
include $competition.'/info.php';
$mcats = make_categories($categories,$closed);
$refresh = array_key_exists( 'refresh', $_GET );
$finalize = array_key_exists( 'finalize', $_GET );
$team_ranking = array_key_exists( 'team-ranking', $_GET );
?>
<title><?php echo $title; ?></title>
</head>
<body>
<h1><?php echo $title; ?>
<span class="headerFollower">
<?php echo $note.PHP_EOL; ?>
<span id=configToggler class=button></span>
<span id=scoreToggler class=button></span>
<span id=columnToggler class=button></span>
</span>
</h1>
<script>
var configToggler = StyleToggler(
document.getElementById("configToggler"), ".config", [
{ text: "Show configs", assign: { display: "none" } },
{ text: "Hide configs", assign: { display: "" } },
],
<?php echo $showconfig ? '1' : '0'; ?>
);
var scoreToggler = StyleToggler(
document.getElementById("scoreToggler"), ".score:not(.important)", [
{ text: "Show scores", assign: { display: "none" } },
{ text: "Hide scores", assign: { display: "" } },
],
<?php echo $showscore ? '1' : '0'; ?>
);
var columnToggler = StyleToggler(
document.getElementById("columnToggler"), "span.category", [
{ text: "One column", assign: { display: "inline" } },
{ text: "Many column", assign: { display: "block" } },
]
);
<?php
if( $team_ranking ) {
// team scoring
echo 'var teamCategoryScores = [';
foreach($teams as $team) { echo '[],'; }
echo '];'.PHP_EOL;
echo 'var teamScores = [';
foreach($teams as $team) { echo '[0,0],'; }
echo '];'.PHP_EOL;
echo 'const solver_id2team_id = {'.PHP_EOL;
$team_id = 0;
foreach( $teams as $team => $solvers ) {
foreach( $mcats as $mcat => $cats ) {
foreach( $cats as $cat => $info ) {
foreach( $solvers as $solver ) {
if( array_key_exists($solver,$info['participants']) ) {
echo ' "'.$info['participants'][$solver].'": "'.$team_id.'",'.PHP_EOL;
}
if( array_key_exists($solver,$info['certified']['participants']) ) {
echo ' "'.$info['certified']['participants'][$solver].'": "'.$team_id.'",'.PHP_EOL;
}
}
}
}
$team_id++;
}
echo '};'.PHP_EOL;
echo 'const score_exponent = 2;// Ln norm. 2 means Euclidean
function updateScores(catname,participants) {
// first clear scores for the teams of this category
for( let solver_id in participants ) {
teamCategoryScores[solver_id2team_id[solver_id]][catname] = [0,0];
}
// then add up scores of the team, in case it participates in certified category. We don\'t support two tools from one team in the same category!
for( let solver_id in participants ) {
let x = { it: teamCategoryScores[solver_id2team_id[solver_id]][catname] };
x.it[0] += Math.pow(participants[solver_id].normalized,score_exponent);
x.it[1] += participants[solver_id].news;
}
// updating the team scores
for( let i in teamScores ) {
let score_sum = Object.values(teamCategoryScores[i]).reduce(
(x,y) => { return [ x[0] + y[0], x[1] + y[1] ]; }, [0,0]
);
teamScores[i] = [ Math.pow(score_sum[0],1/score_exponent).toFixed(4), score_sum[1] ];
}
// sorting the team ranking. For smooth display, do not apply sorting directly on the dom objects.
for( var k = 0; k < 2; k++ ) {
let ranking = Object.keys(teamScores).sort(
(i,j) => { return teamScores[j][k] - teamScores[i][k]; }
);
// refreshing the display. For smooth display, do not move elements if they don\'t have to.
let div = document.getElementById( "team_ranking" + k );
var cur = div.firstElementChild;
for( var i = 0; i < ranking.length; i++ ) {
let span = document.getElementById("team"+ranking[i]+"_"+k);
let score = teamScores[ranking[i]][k];
let elt = span.querySelector(".score");
if( elt.innerHTML != score.toString() ) {// don\'t touch unless necessary
elt.innerHTML = score;
}
if( span == cur ) {
cur = cur.nextSibling;
} else {
div.insertBefore(span,cur);
}
}
}
}
</script>
';
// creating team rankings
echo ' <h3>Competition-Wide Ranking</h3>'.PHP_EOL;
echo ' <div id="team_ranking0">'.PHP_EOL;
$team_id = 0;
foreach( $teams as $team => $solvers ) {
echo ' <span id="team'.$team_id.'_0" class="team">'.$team.'<span class="score"></span></span>'.PHP_EOL;
$team_id++;
}
echo ' </div>'.PHP_EOL;
echo ' <h3>Advancing-the-State-of-the-Art Ranking</h3>'.PHP_EOL;
echo ' <div id="team_ranking1">'.PHP_EOL;
$team_id = 0;
foreach( $teams as $team => $solvers ) {
echo ' <span id="team'.$team_id.'_1" class="team">'.$team.'<span class="score"></span></span>'.PHP_EOL;
$team_id++;
}
echo ' </div>'.PHP_EOL;
} else {
echo 'function updateScores(catname,participants) {}'.PHP_EOL;
echo '</script>'.PHP_EOL;
}
if( !$closed ) {
echo 'Registration is open! Please register following the README of <a href="https://github.com/TermCOMP/starexec-master">this repository</a>';
}
$mcatid = 0;
$catid = 0;
foreach( $mcats as $mcatname => $cats ) {
if (empty($cats)) continue;
$total_done = 0;
$total_togo = 0;
$total_cpu = 0;
$total_time = 0;
echo '<h2>'.$mcatname.' <span id=stat'.$mcatid.' class=stats></span></h2>'.PHP_EOL;
$table = [];
$tools = [];
// creating progress summary
echo ' <script>'.PHP_EOL.
' function summer(a,b){'.PHP_EOL.
' return {done: a.done + b.done, cpu: a.cpu + b.cpu, time: a.time + b.time, togo: a.togo + b.togo};'.PHP_EOL.
' }'.PHP_EOL.
' var progress'.$mcatid.' = [];'.PHP_EOL.
' function updateProgress'.$mcatid.'() {'.PHP_EOL.
' var sum = progress'.$mcatid.'.reduce(summer);'.PHP_EOL.
' document.getElementById("stat'.$mcatid.'").innerHTML ='.PHP_EOL.
' "Progress: " + Math.floor(1000 * sum.done / (sum.done + sum.togo))/10 +'.PHP_EOL.
' "%, CPU Time: " + seconds2str(sum.cpu) + ", Node Time: "+ seconds2str(sum.time);'.PHP_EOL.
' }'.PHP_EOL.
'</script>'.PHP_EOL;
$catindex = 0;
foreach( $cats as $catname => $cat ) {
$type = $cat['type'];
$id = $cat['id'];
$spaceid = array_key_exists('spaceid',$cat) ? $cat['spaceid'] : null;
if( $id == null ) {// This means the job is not yet started or linked to starexec-master.
echo ' <div class=category>';
if( $spaceid != null ) {
echo '<a href="'.spaceid2url($spaceid).'">'.$catname.'</a>'.PHP_EOL;
} else {
echo $catname.PHP_EOL;
}
echo ' <div class=ranking>'.PHP_EOL;
foreach( $cat['certified']['participants'] as $partname => $configid ) {
echo ' <div class="CERTIFIED participant">'.PHP_EOL.
' '.$partname.'<a class=starexecid href="'. configid2url($configid) .'">'. $configid .'</a></div>'.PHP_EOL;
}
foreach( $cat['participants'] as $partname => $configid ) {
echo ' <div class="participant">'. $partname.
'<a class=starexecid href="'. configid2url($configid) .'">'. $configid .'</a></div>'.PHP_EOL;
}
echo ' </div>'.PHP_EOL.
' </div>';
continue;
}
// creating job html
$jobids = explode('_',$id);
$jobid = $jobids[0];
$overlay = array_key_exists( 1, $jobids ) ? $jobids[1] : false;
$job_file = jobname2local($catname);
$graph_file = jobname2graph($catname);
// penalty file if exists
$penalty_file = $competition.'/'.jobname2penaltyfile($catname);
$jobargs = [
'id' => $id,
'name' => $catname,
'mcatname' => $mcatname,
'type' => $type,
'competition' => $competition,
'competitionname' => $shortname,
'db' => $db,
'dir' => $cat['dir'],
'refresh' => $refresh,
];
if( isset($previous) ) {
if( array_key_exists('previous',$cat) ) {
if( $cat['previous'] != null ) {
$jobargs['previous-category'] = $cat['previous'];
$jobargs['previous-competition'] = $previous;
}
} else {
$jobargs['previous-competition'] = $previous;
}
}
if( isset($cat['note']) ) {
$jobargs['note'] = $cat['note'];
}
if( file_exists($penalty_file) ) {
error_log($penalty_file);
$jobargs['penalty'] = $penalty_file;
}
$query = http_build_query( $jobargs, '', ' ' );
$tmp = tempnam('','');
system( 'php-cgi -f "job.php" '. $query .' > "'. $tmp . '"');
rename($tmp,$competition.'/'.$job_file);
chmod($competition.'/'.$job_file, 0644);
$tmp = tempnam('','');
system( 'php-cgi -f "graph.php" '. $query .' > "'. $tmp . '"');
rename($tmp,$competition.'/'.$graph_file);
echo ' <span id="'.$id.'" class=category></span>'.PHP_EOL.
' <script>'.PHP_EOL.
' function load'.$id.'() {'.PHP_EOL.
' var elm = document.getElementById("'.$id.'");'.PHP_EOL.
' loadURL("'.$path_html.$graph_file.'", function(xhttp) {'.PHP_EOL.
' elm.innerHTML = xhttp.responseText;'.PHP_EOL.
' scoreToggler.apply(elm);'.PHP_EOL.
' configToggler.apply(elm);'.PHP_EOL.
' });'.PHP_EOL.
' loadURL("'.$path_html.jobname2sumfile($catname).'", function(xhttp) {'.PHP_EOL.
' var data = JSON.parse(xhttp.responseText);'.PHP_EOL.
' progress'.$mcatid.'['.$catindex.'] = data["layers"].reduce(summer);'.PHP_EOL.
' updateProgress'.$mcatid.'();'.PHP_EOL;
chmod($competition.'/'.$graph_file, 0644);
if( $mcatname != 'Demonstrations' ) {
echo ' updateScores("'.$catname.'",data["participants"]);'.PHP_EOL;
}
echo ' });'.PHP_EOL.
' }'.PHP_EOL.
' load'.$id.'();'.PHP_EOL.
' setInterval(load'.$id.', 10000);'.PHP_EOL.
' </script>'.PHP_EOL;
$catindex++;
$catid++;
}
$mcatid++;
}
?>
</body>
</html>