Browse Source

now save on server

visualizer2
edoardoo 9 years ago
parent
commit
c65ba53518
13 changed files with 142 additions and 115 deletions
  1. BIN
      mongodb/journal/j._0
  2. BIN
      mongodb/journal/lsn
  3. BIN
      mongodb/local.0
  4. BIN
      mongodb/local.ns
  5. +1
    -0
      mongodb/mongod.lock
  6. BIN
      mongodb/visualizer.0
  7. BIN
      mongodb/visualizer.ns
  8. +1
    -0
      package.json
  9. +3
    -1
      public/index.html
  10. +86
    -0
      public/scripts/leaderBoard.js
  11. +10
    -106
      public/scripts/renderer.js
  12. +12
    -0
      public/scripts/tools.js
  13. +29
    -8
      server.js

BIN
mongodb/journal/j._0 View File


BIN
mongodb/journal/lsn View File


BIN
mongodb/local.0 View File


BIN
mongodb/local.ns View File


+ 1
- 0
mongodb/mongod.lock View File

@ -0,0 +1 @@
39273

BIN
mongodb/visualizer.0 View File


BIN
mongodb/visualizer.ns View File


+ 1
- 0
package.json View File

@ -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": {},


+ 3
- 1
public/index.html View File

@ -29,7 +29,9 @@
</section>
<section id="renderedHoneyComb"></section>
<script type="text/javascript" src="scripts/socketSetup.js"></script>
<script type="text/javascript" src="scripts/functions.js"></script>
<script type="text/javascript" src="scripts/tools.js"></script>
<script type="text/javascript" src="scripts/renderer.js"></script>
<script type="text/javascript" src="scripts/leaderBoard.js"></script>
<audio id="bell" controls>
<source src="sounds/bell.mp3" type="audio/mpeg">
Your browser does not support the audio element.


+ 86
- 0
public/scripts/leaderBoard.js View File

@ -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 += "<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>";
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 += "<tr><td>"+i+"</td><td>"+j+"</td></tr>"
}
};
};
var results = "<table><thead><th>Setting</th><th>Placement</th></thead>"+results+"</table>";
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();
}
}

public/scripts/functions.js → public/scripts/renderer.js View File


+ 12
- 0
public/scripts/tools.js View File

@ -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);
}

+ 29
- 8
server.js View File

@ -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 });
}

Loading…
Cancel
Save