diff --git a/mongodb/journal/j._0 b/mongodb/journal/j._0 new file mode 100644 index 0000000..336fa42 Binary files /dev/null and b/mongodb/journal/j._0 differ diff --git a/mongodb/journal/lsn b/mongodb/journal/lsn new file mode 100644 index 0000000..f24174a Binary files /dev/null and b/mongodb/journal/lsn differ diff --git a/mongodb/local.0 b/mongodb/local.0 new file mode 100644 index 0000000..3e0abea Binary files /dev/null and b/mongodb/local.0 differ diff --git a/mongodb/local.ns b/mongodb/local.ns new file mode 100644 index 0000000..24f2d78 Binary files /dev/null and b/mongodb/local.ns differ diff --git a/mongodb/mongod.lock b/mongodb/mongod.lock new file mode 100755 index 0000000..a943521 --- /dev/null +++ b/mongodb/mongod.lock @@ -0,0 +1 @@ +39273 diff --git a/mongodb/visualizer.0 b/mongodb/visualizer.0 new file mode 100644 index 0000000..ffad20d Binary files /dev/null and b/mongodb/visualizer.0 differ diff --git a/mongodb/visualizer.ns b/mongodb/visualizer.ns new file mode 100644 index 0000000..ef26edb Binary files /dev/null and b/mongodb/visualizer.ns differ diff --git a/package.json b/package.json index b917a27..374d4a0 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "body-parser": "^1.13.3", "cookie-parser": "^1.3.5", "express": "^4.13.3", + "mongojs": "^1.2.1", "socket.io": "^1.3.6" }, "devDependencies": {}, diff --git a/public/index.html b/public/index.html index a8a1c54..e342ea8 100644 --- a/public/index.html +++ b/public/index.html @@ -29,7 +29,9 @@ - + + + Your browser does not support the audio element. diff --git a/public/scripts/leaderBoard.js b/public/scripts/leaderBoard.js new file mode 100644 index 0000000..aa2d553 --- /dev/null +++ b/public/scripts/leaderBoard.js @@ -0,0 +1,86 @@ + +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(); + + for (var i = rankings.length - 1; i >= 0; i--) { + if( rankings[i].teamId == 235 ){ + + results += "Updated "+hour+"h "+minutes+"m "+seconds+"s"; + results += "Cazziammolla Placement: "+rankings[i].rank+""; + results += "with a score of: "+rankings[i].score+""; + if (rankings[i].rank != points && points != 0){ + ringTheBell(); + } + points = rankings[i].rank; + + } + }; + + 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 += ""+i+""+j+"" + } + }; + }; + var results = "SettingPlacement"+results+""; + listBoard.innerHTML = results; + + +} +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); + console.dir(intervalID); +} +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(); + } +} \ No newline at end of file diff --git a/public/scripts/functions.js b/public/scripts/renderer.js similarity index 66% rename from public/scripts/functions.js rename to public/scripts/renderer.js index 8422ba7..8341298 100644 --- a/public/scripts/functions.js +++ b/public/scripts/renderer.js @@ -131,11 +131,6 @@ function slideBack(){ } updateLabels(document.getElementById("canvas_"+actualId)); -} -function updateLabels( e ){ - document.getElementById("score").innerHTML = e.getAttribute("data-score"); - document.getElementById("index").innerHTML = e.getAttribute("data-index"); - } function slideForward(){ @@ -151,6 +146,13 @@ function slideForward(){ document.getElementById("canvas_"+actualId).className += " visible"; updateLabels(document.getElementById("canvas_"+actualId)); } + +function updateLabels( e ){ + document.getElementById("score").innerHTML = e.getAttribute("data-score"); + document.getElementById("index").innerHTML = e.getAttribute("data-index"); + +} + function slidePlay(){ var play = document.getElementById("playSlide"); @@ -166,109 +168,11 @@ function slidePlay(){ } } -function hasClass(el, cls) { - return el.className && new RegExp("(\\s|^)" + cls + "(\\s|$)").test(el.className); -} -function removeClass(ele,cls) { - if (hasClass(ele,cls)) { - var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)'); - ele.className=ele.className.replace(reg,' '); - } -} -function removeId(id) { - return (elem=document.getElementById(id)).parentNode.removeChild(elem); -} - -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(); - - for (var i = rankings.length - 1; i >= 0; i--) { - if( rankings[i].teamId == 235 ){ - - results += "Updated "+hour+"h "+minutes+"m "+seconds+"s"; - results += "Cazziammolla Placement: "+rankings[i].rank+""; - results += "with a score of: "+rankings[i].score+""; - if (rankings[i].rank != points && points != 0){ - ringTheBell(); - } - points = rankings[i].rank; - - } - }; - - 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 += ""+i+""+j+"" - } - }; - }; - var results = "SettingPlacement"+results+""; - listBoard.innerHTML = results; - - -} -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); - console.dir(intervalID); -} -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 sendJson(){ // console.log("sending mama some json.") - // socket.emit("jsonToParse", document.getElementById("sendHCJson").value); - prePopulate( document.getElementById("sendHCJson").value); -} - -function checkKey(e) { - - e = e || window.event; - - if (e.keyCode == '37') { - slideBack(); - }else if(e.keyCode == '39') { - slideForward(); - } - + var query = document.getElementById("sendHCJson").value; + socket.emit("jsonToParse", query); + prePopulate( query); } // jsonExample = {"height":15,"width":15,"sourceSeeds":[0],"units":[{"members":[{"x":0,"y":0}],"pivot":{"x":0,"y":0}}],"id":1,"filled":[{"x":2,"y":4},{"x":3,"y":4},{"x":4,"y":4},{"x":5,"y":4},{"x":6,"y":4},{"x":11,"y":4},{"x":2,"y":5},{"x":8,"y":5},{"x":11,"y":5},{"x":2,"y":6},{"x":11,"y":6},{"x":2,"y":7},{"x":3,"y":7},{"x":4,"y":7},{"x":8,"y":7},{"x":11,"y":7},{"x":2,"y":8},{"x":9,"y":8},{"x":11,"y":8},{"x":2,"y":9},{"x":8,"y":9},{"x":2,"y":10},{"x":3,"y":10},{"x":4,"y":10},{"x":5,"y":10},{"x":6,"y":10},{"x":9,"y":10},{"x":11,"y":10}],"sourceLength":100}; diff --git a/public/scripts/tools.js b/public/scripts/tools.js new file mode 100644 index 0000000..7a70254 --- /dev/null +++ b/public/scripts/tools.js @@ -0,0 +1,12 @@ +function hasClass(el, cls) { + return el.className && new RegExp("(\\s|^)" + cls + "(\\s|$)").test(el.className); +} +function removeClass(ele,cls) { + if (hasClass(ele,cls)) { + var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)'); + ele.className=ele.className.replace(reg,' '); + } +} +function removeId(id) { + return (elem=document.getElementById(id)).parentNode.removeChild(elem); +} diff --git a/server.js b/server.js index 4fb9ca0..9bd09c0 100644 --- a/server.js +++ b/server.js @@ -1,11 +1,18 @@ -var express = require('express'); -var http = require('http'); -var io = require('socket.io'); -var bodyParser = require('body-parser'); -var cookieParser = require('cookie-parser'); +var express = require('express'), + http = require('http'), + io = require('socket.io'), + bodyParser = require('body-parser'), + cookieParser = require('cookie-parser'), + mongojs = require('mongojs'); var app = express(); app.use(express.static('./public')); + +var mongoUri = "mongodb://localhost:27017/visualizer"; +var db = mongojs( mongoUri ); +var honeyCombs = db.collection('honeyCombs'); +// honeyCombs.insert({dio: "cane", type: "flyingPig"}); + //Specifying the public folder of the server to make the html accesible using the static middleware app.use(cookieParser()); @@ -35,6 +42,7 @@ app.post('/show', urlencodedParser, function (req, res) { 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); @@ -68,10 +76,23 @@ io.sockets.on('connection', function(socket){ } }); socket.on('jsonToParse', function(msg){ - if(msg == "true"){ console.log('Json received.'); - socket.emit("jsonHoneycomb", msg); - } + saveQuery(msg); + // socket.emit("jsonHoneycomb", msg); + }); }); +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 }); +}
Updated "+hour+"h "+minutes+"m "+seconds+"s