Browse Source

cleaned around

release
edoardoo 10 years ago
parent
commit
129fa23fa8
11 changed files with 11 additions and 12007 deletions
  1. +2
    -14
      public/index.html
  2. +0
    -4519
      public/scripts/html2canvas.js
  3. +0
    -98
      public/scripts/leaderBoard.js
  4. +3
    -5
      public/scripts/renderer.js
  5. +0
    -7006
      public/scripts/socket.io.js
  6. +0
    -17
      public/scripts/socketSetup.js
  7. BIN
      public/sounds/bell.mp3
  8. +0
    -39
      public/style/style.css
  9. +3
    -126
      public/style/style.less
  10. +0
    -72
      public/style/style.scss
  11. +3
    -111
      server.js

+ 2
- 14
public/index.html View File

@ -1,11 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<title>icfp 2015 visualizer</title>
<!-- <link rel="stylesheet" type="text/css" href="style/style.css"> -->
<title>Icfp 2015 visualizer</title>
<link rel="stylesheet/less" type="text/css" href="style/style.less" />
<script type="text/javascript" src="scripts/less.min.js"></script>
<script type="text/javascript" src="scripts/socket.io.js"></script>
</head>
<body>
@ -19,22 +17,12 @@
<button id="playSlide" data-intervalid="-1"onclick="slidePlay()">PLAY/PAUSE</button>
<button onclick="slideForward()">></button>
</div>
<div id="leaderBoard" class="">
<button onclick="toggleLeaderBoard()">LeaderBoard</button>
<section id="listBoard">Loading...</section>
</div>
<div class="bottomRight"><input placeholder="Paste Json, visible only locally." type="text" id="sendHCJson"><button onclick="sendJson()">Send</button></div>
<section id="honeyComb">
</section>
<section id="renderedHoneyComb"></section>
<script type="text/javascript" src="scripts/socketSetup.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.
</audio>
</body>
</html>

+ 0
- 4519
public/scripts/html2canvas.js
File diff suppressed because it is too large
View File


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

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

+ 3
- 5
public/scripts/renderer.js View File

@ -19,7 +19,6 @@ function loadImageGroup(urls, onCompleteFunc) {
}
function prePopulate(honeyCells){
var honeyCells = JSON.parse(honeyCells);
console.dir(honeyCells);
var urls = [
'images/neutral.png',
'images/active.png',
@ -28,10 +27,11 @@ function prePopulate(honeyCells){
];
document.getElementById("honeyComb").innerHTML="";
loadImageGroup(urls, function(urlToImageMap) {
//all are loaded. draw to canvas here
document.getElementById("honeyComb").innerHTML="";
if( honeyCells.constructor === Array){
for (var i = 0; i < honeyCells.length; i++) {
populateHoneycomb( honeyCells[i], i );
@ -170,9 +170,7 @@ function slidePlay(){
}
function sendJson(){
// console.log("sending mama some json.")
var query = document.getElementById("sendHCJson").value;
socket.emit("jsonToParse", query);
// 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};

+ 0
- 7006
public/scripts/socket.io.js
File diff suppressed because it is too large
View File


+ 0
- 17
public/scripts/socketSetup.js View File

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

BIN
public/sounds/bell.mp3 View File


+ 0
- 39
public/style/style.css View File

@ -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 */

+ 3
- 126
public/style/style.less View File

@ -1,9 +1,4 @@
@activeColor: #FFDDA0;
@touchColor: #F7D7D7;
@unitColor: #C2F19D;
@sizeWidth: 100px;
@border: 1px;
@sizeHeight: @sizeWidth/sqrt(3);
@color: #efefef;
@ -19,9 +14,7 @@ body{
font-weight: 300;
}
audio{
display: none;
}
.transition{
-webkit-transition: all .5s ease-in-out; /* Android 2.1+, Chrome 1-25, iOS 3.2-6.1, Safari 3.2-6 */
transition: all .5s ease-in-out;
@ -66,66 +59,13 @@ audio{
position: absolute;
display: none;
height: 100%;
&.visible, &:first-child{
&.visible{
display: block;
}
}
}
#leaderBoard:extend(.transition) {
position: fixed;
top: 0px;
right: 0;
width: 500px;
height: 100%;
overflow: hidden;
background-color: rgba(255,255,255,1);
right: -400px;
color: #333;
opacity: .2;
z-index: 999;
h1, h2, p{
padding-left: 10px;
}
&:hover{
opacity: 1;
}
button{
height: 100%;
background-color: rgba(0,0,0,0.5);
color: white;
border-color: transparent;
float: left;
width: 100px;
opacity: .4;
}
#listBoard{
float: left;
overflow: auto;
height: 100%;
width: 400px;
table, tr{
width: 100%;
td{
width: 100%/3;
text-align: center;
}
}
tr:nth-child(even){
background-color: #dedede;
}
}
&.open:extend(.transition){
right: 0;
opacity: 1;
}
}
.honeycombIndex{
position: fixed;
top: 0;
@ -145,68 +85,5 @@ audio{
.canvasRendered{
background-color: #333;
}
.hex {
float: left;
margin-left: @border;
margin-bottom: -@sizeWidth/4;
.top {
width: 0;
border-bottom: @sizeHeight/2 solid @color;
border-left: @sizeWidth/2 solid transparent;
border-right: @sizeWidth/2 solid transparent;
}
.middle {
width: @sizeWidth;
height: @sizeHeight;
background: @color;
}
.bottom {
width: 0;
border-top: @sizeHeight/2 solid @color;
border-left: @sizeWidth/2 solid transparent;
border-right: @sizeWidth/2 solid transparent;
}
&.active{
.top:extend(.hex .top){
border-bottom-color: @activeColor;
}
.middle:extend(.hex .middle){
background: @activeColor;
}
.bottom:extend(.hex .bottom){
border-top-color: @activeColor;
}
}
&.touched{
.top:extend(.hex .top){
border-bottom-color: @touchColor;
}
.middle:extend(.hex .middle){
background: @touchColor;
}
.bottom:extend(.hex .bottom){
border-top-color: @touchColor;
}
}
&.unitMember{
.middle:extend(.hex .middle){
background-color: @unitColor;
// background-image:
}
}
&-row{
clear: left;
&.even {
margin-left: (@sizeWidth/2);
}
}
}

+ 0
- 72
public/style/style.scss View File

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

+ 3
- 111
server.js View File

@ -1,122 +1,14 @@
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();
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);
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 });
}

Loading…
Cancel
Save