|
|
function toggleLeaderBoard(){
|
|
var leaderBoard = document.getElementById("leaderBoard");
|
|
if( hasClass(leaderBoard, "open")){
|
|
removeClass(leaderBoard, "open");
|
|
}else{
|
|
leaderBoard.className += " open";
|
|
}
|
|
updateLeaderBoard()
|
|
}
|
|
function populateBoard(){
|
|
var listBoard = document.getElementById("listBoard");
|
|
var results = "";
|
|
var rankings = data.data.rankings;
|
|
var date = new Date();
|
|
var seconds = date.getSeconds();
|
|
var minutes = date.getMinutes();
|
|
var hour = date.getHours();
|
|
var leaderBoardServerJson = {};
|
|
leaderBoardServerJson.timeStamp = date.getTime();
|
|
|
|
for (var i = rankings.length - 1; i >= 0; i--) {
|
|
if( rankings[i].teamId == 235 ){
|
|
|
|
results += "<p>Updated "+hour+"h "+minutes+"m "+seconds+"s</p>";
|
|
results += "<h1>Cazziammolla Placement: "+rankings[i].rank+"</h1>";
|
|
results += "<h2>with a score of: "+rankings[i].score+"</h2>";
|
|
|
|
leaderBoardServerJson.placement = rankings[i].rank;
|
|
leaderBoardServerJson.score = rankings[i].score;
|
|
|
|
if (rankings[i].rank != points && points != 0){
|
|
ringTheBell();
|
|
}
|
|
points = rankings[i].rank;
|
|
|
|
}
|
|
};
|
|
leaderBoardServerJson.settings = [];
|
|
var settings = data.data.settings;
|
|
for (var i = 0; i < settings.length; i++) {
|
|
for (var j = settings[i].rankings.length - 1; j >= 0; j--) {
|
|
if(settings[i].rankings[j].teamId == 235){
|
|
results += "<tr><td>"+i+"</td><td>"+settings[i].rankings[j].rank+"</td><td>"+settings[i].rankings[j].score+"</td></tr>"
|
|
leaderBoardServerJson.settings[i] = { rank: settings[i].rankings[j].rank, score: settings[i].rankings[j].score};
|
|
}
|
|
};
|
|
};
|
|
var results = "<table><thead><th>Setting</th><th>Placement</th><th>Score</th></thead>"+results+"</table>";
|
|
listBoard.innerHTML = results;
|
|
try{
|
|
socket.emit('leaderBoard', JSON.stringify( leaderBoardServerJson));
|
|
|
|
}catch(e){
|
|
console.log("error");
|
|
}
|
|
|
|
|
|
}
|
|
function updateLeaderBoard(){
|
|
loadRankingJs('https://davar.icfpcontest.org/rankings.js?cachebuster='+ new Date().getTime());
|
|
|
|
var intervalID = setInterval( function(){
|
|
loadRankingJs('https://davar.icfpcontest.org/rankings.js?cachebuster='+ new Date().getTime());
|
|
}, 30000);
|
|
}
|
|
function loadRankingJs(scriptName) {
|
|
var rankingScript = document.getElementById("rankingScript");
|
|
if ( rankingScript ){
|
|
removeId("rankingScript");
|
|
}
|
|
var docHeadObj = document.getElementsByTagName("head")[0];
|
|
var dynamicScript = document.createElement("script");
|
|
dynamicScript.type = "text/javascript";
|
|
dynamicScript.id = "rankingScript";
|
|
dynamicScript.src = scriptName;
|
|
dynamicScript.onload = function(){ populateBoard();};
|
|
docHeadObj.appendChild(dynamicScript);
|
|
|
|
return dynamicScript;
|
|
}
|
|
|
|
function ringTheBell(){
|
|
document.getElementById("bell").play();
|
|
}
|
|
document.onkeydown = checkKey;
|
|
|
|
|
|
function checkKey(e) {
|
|
|
|
e = e || window.event;
|
|
|
|
if (e.keyCode == '37') {
|
|
slideBack();
|
|
}else if(e.keyCode == '39') {
|
|
slideForward();
|
|
}
|
|
}
|