-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathleaderboard.html
More file actions
executable file
·64 lines (60 loc) · 2.12 KB
/
leaderboard.html
File metadata and controls
executable file
·64 lines (60 loc) · 2.12 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
---
layout: page
title: Leaderboard
dummies:
- nick: Apprentice
task: [email, install_software, computational_thinking, data_types, python, git, 1st_website]
- nick: Journeyman
task: [email, install_software, computational_thinking, data_types, python, git, constraint_programming, javascript_fun, 1st_website, unix_koans, unix_command_line]
- nick: Master
task: [email, install_software, computational_thinking, data_types, python, git, constraint_programming, javascript_fun, 1st_website, unix_koans, unix_command_line, pygame, touch_typing, power_searching_google, audacity, gimp]
students:
- nick: Dummy
task: [email]
- nick: Novice
task: [email, install_software, computational_thinking, scratch_blockly_maze]
- nick: Tth3jtr
name: Rok Štular
task: [email]
- nick: Matej
name: Matej Vrečar
task: [email, scratch_blockly_maze]
---
<h1>{{ page.title }}</h1>
<p>The list of leaders by points awarded.
Complete <a href="tasks.html">tasks</a> to earn more points.</p>
<div id="leaderboard">
</div>
<script>
var students = {
{% for s in page.students %}'{{ s.nick }}':['{{ s.task | join: "','" }}'],{% endfor %}
};
var tasks = [];
var leaderboard = $('#leaderboard');
leaderboard.html('Refreshing scores...');
$.get('/tasks.html', function(data) {
// parse each task worth
$(data).find('ul li a[href^="tasks/"]').each(function() {
var a = $(this);
try {
var name = a.attr('href').substring(6, a.attr('href').length - 5);
var points = parseInt(a.prev('img').attr('alt').replace('[','').replace(']', ''));
tasks[name] = points;
} catch (err) {
// some inline links, like [vim]
}
});
leaderboard.html('<ol></ol>');
var scores = [];
for (s in students) {
var total = 0;
for (var task=0; task<students[s].length; ++task)
total += tasks[students[s][task]];
scores.push([s, total]);
}
scores.sort(function (a,b) { return b[1] - a[1]; });
for (var i=0; i<scores.length; ++i) {
$('#leaderboard ol').append('<li>' + scores[i][0] + ' (' + scores[i][1] + ')</li>');
}
});
</script>