@ -1,98 +0,0 @@ | |||||
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(); | |||||
} | |||||
} |
@ -1,17 +0,0 @@ | |||||
var socket = io(); | |||||
/*Initializing the connection with the server via websockets */ | |||||
socket.emit('liveMessage', "true"); | |||||
socket.on("jsonHoneycomb",function(message){ | |||||
/* | |||||
When server sends data to the client it will trigger "message" event on the client side , by | |||||
using socket.on("message") , one cna listen for the ,message event and associate a callback to | |||||
be executed . The Callback function gets the dat sent from the server | |||||
*/ | |||||
console.log("Message from the server arrived") | |||||
prePopulate(message); | |||||
socket.emit('ackMessage', "true"); | |||||
}); | |||||
@ -1,39 +0,0 @@ | |||||
html, body { | |||||
margin: 0; | |||||
padding: 0; | |||||
height: 100%; | |||||
width: 100%; } | |||||
body { | |||||
background-color: #333; } | |||||
.hex { | |||||
float: left; | |||||
margin-left: 3px; | |||||
margin-bottom: -26px; } | |||||
.hex .top, .hex.disabled .top { | |||||
width: 0; | |||||
border-bottom: 30.02221px solid #6C6; | |||||
border-left: 52px solid transparent; | |||||
border-right: 52px solid transparent; } | |||||
.hex .middle { | |||||
width: 104px; | |||||
height: 60.04443px; | |||||
background: #6C6; } | |||||
.hex .bottom { | |||||
width: 0; | |||||
border-top: 30.02221px solid #6C6; | |||||
border-left: 52px solid transparent; | |||||
border-right: 52px solid transparent; } | |||||
.hex.disabled .top { | |||||
border-bottom-color: #efefef; } | |||||
.hex.disabled .middle { | |||||
background: #efefef; } | |||||
.hex.disabled .bottom { | |||||
border-top-color: #efefef; } | |||||
.hex-row { | |||||
clear: left; } | |||||
.hex-row.even { | |||||
margin-left: 53px; } | |||||
/*# sourceMappingURL=style.css.map */ |
@ -1,72 +0,0 @@ | |||||
@function sqrt($r) { | |||||
$x0: 1; | |||||
$x1: $x0; | |||||
@for $i from 1 through 10 { | |||||
$x1: $x0 - ($x0 * $x0 - abs($r)) / (2 * $x0); | |||||
$x0: $x1; | |||||
} | |||||
@return $x1; | |||||
} | |||||
$disabledColor: #efefef; | |||||
$sizeWidth: 104px; | |||||
$border: 1px; | |||||
$sizeHeight: $sizeWidth/sqrt(3); | |||||
html, body{ | |||||
margin: 0; | |||||
padding: 0; | |||||
height: 100%; | |||||
width: 100%; | |||||
} | |||||
body{ | |||||
background-color: #333; | |||||
} | |||||
.hex { | |||||
float: left; | |||||
margin-left: 3px; | |||||
margin-bottom: -26px; | |||||
.top { | |||||
width: 0; | |||||
border-bottom: $sizeHeight/2 solid #6C6; | |||||
border-left: $sizeWidth/2 solid transparent; | |||||
border-right: $sizeWidth/2 solid transparent; | |||||
} | |||||
.middle { | |||||
width: $sizeWidth; | |||||
height: $sizeHeight; | |||||
background: #6C6; | |||||
} | |||||
.bottom { | |||||
width: 0; | |||||
border-top: $sizeHeight/2 solid #6C6; | |||||
border-left: $sizeWidth/2 solid transparent; | |||||
border-right: $sizeWidth/2 solid transparent; | |||||
} | |||||
&.disabled{ | |||||
.top{ | |||||
@extend .top; | |||||
border-bottom-color: $disabledColor; | |||||
} | |||||
.middle{ | |||||
background: $disabledColor; | |||||
} | |||||
.bottom{ | |||||
border-top-color: $disabledColor; | |||||
} | |||||
} | |||||
&-row{ | |||||
clear: left; | |||||
&.even { | |||||
margin-left: ($sizeWidth/2)+1; | |||||
} | |||||
} | |||||
} | |||||
@ -1,122 +1,14 @@ | |||||
var express = require('express'), | var express = require('express'), | ||||
http = require('http'), | |||||
io = require('socket.io'), | |||||
bodyParser = require('body-parser'), | |||||
cookieParser = require('cookie-parser'), | |||||
mongojs = require('mongojs'); | |||||
http = require('http'); | |||||
var app = express(); | var app = express(); | ||||
app.use(express.static('./public')); | app.use(express.static('./public')); | ||||
var mongoUri = "mongodb://localhost:27017/visualizer"; | |||||
var db = mongojs( mongoUri ); | |||||
var honeyCombs = db.collection('honeyCombs'); | |||||
var leaderBoards = db.collection('leaderBoards'); | |||||
// leaderBoards.insert({dio: "cane", type: "flyingPig"}); | |||||
//Specifying the public folder of the server to make the html accesible using the static middleware | |||||
app.use(cookieParser()); | |||||
var jsonParser = bodyParser.json() | |||||
// create application/x-www-form-urlencoded parser | |||||
var urlencodedParser = bodyParser.urlencoded({ extended: false }) | |||||
// POST /login gets urlencoded bodies | |||||
function findSocketByCookie(cookie) { | |||||
for(var i in io.sockets.connected) { | |||||
var socket = io.sockets.connected[i]; | |||||
if(socket.handshake.headers.cookie.indexOf(cookie) !== -1){ | |||||
return socket; | |||||
} | |||||
} | |||||
} | |||||
app.post('/show', urlencodedParser, function (req, res) { | |||||
res.sendStatus(200); | |||||
console.log("Sending json to live interfaces..."); | |||||
// console.dir(io.sockets.connected); | |||||
for(var i in io.sockets.connected) { | |||||
var socket = io.sockets.connected[i]; | |||||
socket.emit("jsonHoneycomb", req.body.honeyComb); | |||||
saveQuery(req.body.honeyComb); | |||||
} | |||||
// var socket = findSocketByCookie(req.cookies.myUniqueCookie); | |||||
}); | |||||
var server = http.createServer(app).listen(8080); | var server = http.createServer(app).listen(8080); | ||||
console.log("Listening on port 8080"); | console.log("Listening on port 8080"); | ||||
console.log("Send jsons to /show please."); | |||||
//Server listens on the port 8124 | |||||
var io = io.listen(server); | |||||
/*initializing the websockets communication , server instance has to be sent as the argument */ | |||||
io.sockets.on('connection', function(socket){ | |||||
console.log("New Client Connected."); | |||||
socket.on('disconnect', function () { | |||||
console.log("Client disconnected.") | |||||
}); | |||||
socket.on('ackMessage', function(msg){ | |||||
if(msg == "true"){ | |||||
console.log('Message received.'); | |||||
} | |||||
}); | |||||
socket.on('liveMessage', function(msg){ | |||||
if(msg == "true"){ | |||||
console.log('Live interface connected.'); | |||||
} | |||||
}); | |||||
socket.on('jsonToParse', function(msg){ | |||||
console.log('Json received.'); | |||||
saveQuery(msg); | |||||
// socket.emit("jsonHoneycomb", msg); | |||||
}); | |||||
socket.on('leaderBoard',function(lb){ | |||||
leaderBoards.find().sort({timeStamp:-1}).limit(1, function(err, docs){ | |||||
var parsedLb = JSON.parse(lb); | |||||
if( docs.length ){ | |||||
if(typeof docs[0].timeStamp != "undefined"){ | |||||
if( parsedLb.timeStamp - docs[0].timeStamp > 600000){ | |||||
leaderBoards.insert(parsedLb); | |||||
console.log("Saving stats report."); | |||||
} | |||||
} | |||||
}else{ | |||||
leaderBoards.insert(parsedLb); | |||||
} | |||||
if(err){ | |||||
console.dir(err); | |||||
} | |||||
}); | |||||
// | |||||
}); | |||||
console.log("Visit http://localhost:8080 please."); | |||||
}); | |||||
function saveQuery(query){ | |||||
var d = new Date(); | |||||
d = | |||||
("00" + (d.getMonth() + 1)).slice(-2) + "/" + | |||||
("00" + d.getDate()).slice(-2) + "/" + | |||||
d.getFullYear() + " " + | |||||
("00" + d.getHours()).slice(-2) + ":" + | |||||
("00" + d.getMinutes()).slice(-2) + ":" + | |||||
("00" + d.getSeconds()).slice(-2) | |||||
; | |||||
console.log("Saving query in db..."); | |||||
honeyCombs.insert({ honeyComb: query, dateStamp: d }); | |||||
} |