Improved database

This commit is contained in:
Thomas FORGIONE 2015-06-22 09:41:59 +02:00
parent 1662a9dd99
commit 55de96688b
9 changed files with 141 additions and 27 deletions

View File

@ -11,11 +11,11 @@ BD.Private.sendData = function(url, data) {
xhr.open("POST", url, true); xhr.open("POST", url, true);
xhr.setRequestHeader("Content-type", "application/json;charset=UTF-8"); xhr.setRequestHeader("Content-type", "application/json;charset=UTF-8");
// xhr.onreadystatechange = function() { xhr.onreadystatechange = function() {
// if(xhr.readyState == 4 && xhr.status == 200) { if(xhr.readyState == 4 && xhr.status == 200) {
// console.log("Done : " + xhr.responseText); console.log("Done : " + xhr.responseText);
// } }
// } }
xhr.send(JSON.stringify(data)); xhr.send(JSON.stringify(data));
} }
@ -102,3 +102,15 @@ BD.Event.Hovered.prototype.send = function() {
BD.Private.sendData(url, data); BD.Private.sendData(url, data);
} }
BD.Event.Fps = function() {};
BD.Event.Fps.prototype.send = function() {
var url = "/fps";
var data = {
fps: this.fps
}
BD.Private.sendData(url, data);
}

View File

@ -6,7 +6,7 @@ else
CLOSURE=./compiler.sh CLOSURE=./compiler.sh
endif endif
all: List ListTest Socket Three Stats ThreeTools Bouncing Multisphere StreamingSimulator PrototypeTools PrototypeReplay PrototypeInteractive Tutorial Sponza all: List ListTest Socket Three Stats ThreeTools Bouncing Multisphere StreamingSimulator PrototypeTools PrototypeReplay PrototypeInteractive Tutorial
Socket: Socket:
cp socket.io/socket.io.min.js ../static/js cp socket.io/socket.io.min.js ../static/js

44
js/MousePointer.js Normal file
View File

@ -0,0 +1,44 @@
var MousePointer = function(camera) {
this.domElement = document.createElement('canvas');
this.domElement.style.position = 'absolute';
this.domElement.style.cssFloat = 'top-left';
this.ctx = this.domElement.getContext('2d');
this.size = 10;
this.drawn = false;
camera.mousePointer = this;
}
MousePointer.prototype.render = function() {
if (!this.drawn) {
this.drawn = true;
var i = container_size.width() / 2;
var imin = i - this.size;
var imax = i + this.size;
var j = container_size.height() / 2;
var jmin = j - this.size;
var jmax = j + this.size;
this.ctx.stokeStyle = "black";
this.ctx.beginPath();
this.ctx.moveTo(imin, j);
this.ctx.lineTo(imax, j);
this.ctx.moveTo(i, jmin);
this.ctx.lineTo(i, jmax);
this.ctx.closePath();
this.ctx.stroke();
}
}
MousePointer.prototype.clear = function() {
if (this.drawn) {
this.drawn = false;
this.domElement.width = this.domElement.width;
}
}

View File

@ -164,13 +164,27 @@ PointerCamera.prototype.normalMotion = function(time) {
if (this.motion.decreaseTheta) {this.theta -= this.sensitivity * time / 20; this.changed = true; } if (this.motion.decreaseTheta) {this.theta -= this.sensitivity * time / 20; this.changed = true; }
if ( this.pointerLocked || this.dragging) { if ( this.pointerLocked || this.dragging) {
this.theta += this.mouseMove.x; this.theta += this.mouseMove.x * time / 20;
this.phi -= this.mouseMove.y; this.phi -= this.mouseMove.y * time / 20;
this.mouseMove.x = 0; this.mouseMove.x = 0;
this.mouseMove.y = 0; this.mouseMove.y = 0;
this.changed = true; this.changed = true;
if (this.shouldLogCameraAngles) {
this.shouldLogCameraAngles = false;
var self = this;
setTimeout(function() {
self.shouldLogCameraAngles = true;
}, 500);
var event = new BD.KeyboardEvent();
event.camera = this;
}
} }
// Clamp phi and theta // Clamp phi and theta
@ -386,8 +400,8 @@ PointerCamera.prototype.onMouseMovePointer = function(e) {
this.mouseMove.x = e.movementX || e.mozMovementX || e.webkitMovementX || 0; this.mouseMove.x = e.movementX || e.mozMovementX || e.webkitMovementX || 0;
this.mouseMove.y = e.movementY || e.mozMovementY || e.webkitMovementY || 0; this.mouseMove.y = e.movementY || e.mozMovementY || e.webkitMovementY || 0;
this.mouseMove.x /= -200; this.mouseMove.x *= -(this.sensitivity/5);
this.mouseMove.y /= 200; this.mouseMove.y *= (this.sensitivity/5);
this.mouseMoved = true; this.mouseMoved = true;
} }

21
js/prototype/main.js vendored
View File

@ -19,6 +19,8 @@ var container_size = {
height: function() { return 768; } height: function() { return 768; }
} }
var stats;
// Let's be sure we avoid using global variables // Let's be sure we avoid using global variables
var onWindowResize = (function() { var onWindowResize = (function() {
@ -33,7 +35,7 @@ var objects = [];
var cameras, cameraSelecter; var cameras, cameraSelecter;
var spheres = new Array(mesh_number); var spheres = new Array(mesh_number);
var visible = 0; var visible = 0;
var stats; // stats;
var previewer; var previewer;
var camera1; var camera1;
var loader; var loader;
@ -43,8 +45,25 @@ var previousTime;
init(); init();
if (initMainScene !== initPeach && initMainScene !== initSponza)
logfps();
animate(); animate();
function logfps() {
// Log fps
if (stats !== undefined) {
var event = new BD.Event.Fps();
event.fps = stats.getFps();
event.send();
}
setTimeout(logfps, 1000);
}
function init() { function init() {
// Initialize scene // Initialize scene
scene = new THREE.Scene(); scene = new THREE.Scene();

10
js/three/stats.min.js vendored
View File

@ -1,6 +1,4 @@
// stats.js - http://github.com/mrdoob/stats.js 'use strict';var Stats=function(){function f(a,e,b){a=document.createElement(a);a.id=e;a.style.cssText=b;return a}function l(a,e,b){var d=f("div",a,"padding:0 0 3px 3px;text-align:left;background:"+b),c=f("div",a+"Text","font-family:Helvetica,Arial,sans-serif;font-size:9px;font-weight:bold;line-height:15px;color:"+e);c.innerHTML=a.toUpperCase();d.appendChild(c);a=f("div",a+"Graph","width:74px;height:30px;background:"+e);d.appendChild(a);for(e=0;74>e;e++)a.appendChild(f("span","","width:1px;height:30px;float:left;opacity:0.9;background:"+
var Stats=function(){var l=Date.now(),m=l,g=0,n=Infinity,o=0,h=0,p=Infinity,q=0,r=0,s=0,f=document.createElement("div");f.id="stats";f.addEventListener("mousedown",function(b){b.preventDefault();t(++s%2)},!1);f.style.cssText="width:80px;opacity:0.9;cursor:pointer";var a=document.createElement("div");a.id="fps";a.style.cssText="padding:0 0 3px 3px;text-align:left;background-color:#002";f.appendChild(a);var i=document.createElement("div");i.id="fpsText";i.style.cssText="color:#0ff;font-family:Helvetica,Arial,sans-serif;font-size:9px;font-weight:bold;line-height:15px"; b));return d}function m(a){for(var b=d.children,c=0;c<b.length;c++)b[c].style.display=c===a?"block":"none";n=a}function p(a,b){a.appendChild(a.firstChild).style.height=Math.min(30,30-30*b)+"px"}var q=self.performance&&self.performance.now?self.performance.now.bind(performance):Date.now,k=q(),r=k,t=0,n=0,d=f("div","stats","width:80px;opacity:0.9;cursor:pointer");d.addEventListener("mousedown",function(a){a.preventDefault();m(++n%d.children.length)},!1);var c=0,u=Infinity,v=0,b=l("fps","#0ff","#002"),
i.innerHTML="FPS";a.appendChild(i);var c=document.createElement("div");c.id="fpsGraph";c.style.cssText="position:relative;width:74px;height:30px;background-color:#0ff";for(a.appendChild(c);74>c.children.length;){var j=document.createElement("span");j.style.cssText="width:1px;height:30px;float:left;background-color:#113";c.appendChild(j)}var d=document.createElement("div");d.id="ms";d.style.cssText="padding:0 0 3px 3px;text-align:left;background-color:#020;display:none";f.appendChild(d);var k=document.createElement("div"); A=b.children[0],B=b.children[1];d.appendChild(b);var g=0,w=Infinity,x=0,b=l("ms","#0f0","#020"),C=b.children[0],D=b.children[1];d.appendChild(b);if(self.performance&&self.performance.memory){var h=0,y=Infinity,z=0,b=l("mb","#f08","#201"),E=b.children[0],F=b.children[1];d.appendChild(b)}m(n);return{REVISION:14,domElement:d,setMode:m,getFps:function(){return c},begin:function(){k=q()},end:function(){var a=q();g=a-k;w=Math.min(w,g);x=Math.max(x,g);C.textContent=(g|0)+" MS ("+(w|0)+"-"+(x|0)+")";p(D,
k.id="msText";k.style.cssText="color:#0f0;font-family:Helvetica,Arial,sans-serif;font-size:9px;font-weight:bold;line-height:15px";k.innerHTML="MS";d.appendChild(k);var e=document.createElement("div");e.id="msGraph";e.style.cssText="position:relative;width:74px;height:30px;background-color:#0f0";for(d.appendChild(e);74>e.children.length;)j=document.createElement("span"),j.style.cssText="width:1px;height:30px;float:left;background-color:#131",e.appendChild(j);var t=function(b){s=b;switch(s){case 0:a.style.display= g/200);t++;if(a>r+1E3&&(c=Math.round(1E3*t/(a-r)),u=Math.min(u,c),v=Math.max(v,c),A.textContent=c+" FPS ("+u+"-"+v+")",p(B,c/100),r=a,t=0,void 0!==h)){var b=performance.memory.usedJSHeapSize,d=performance.memory.jsHeapSizeLimit;h=Math.round(9.54E-7*b);y=Math.min(y,h);z=Math.max(z,h);E.textContent=h+" MB ("+y+"-"+z+")";p(F,b/d)}return a},update:function(){k=this.end()}}};"object"===typeof module&&(module.exports=Stats);
"block";d.style.display="none";break;case 1:a.style.display="none",d.style.display="block"}};return{REVISION:12,domElement:f,setMode:t,begin:function(){l=Date.now()},end:function(){var b=Date.now();g=b-l;n=Math.min(n,g);o=Math.max(o,g);k.textContent=g+" MS ("+n+"-"+o+")";var a=Math.min(30,30-30*(g/200));e.appendChild(e.firstChild).style.height=a+"px";r++;b>m+1E3&&(h=Math.round(1E3*r/(b-m)),p=Math.min(p,h),q=Math.max(q,h),i.textContent=h+" FPS ("+p+"-"+q+")",a=Math.min(30,30-30*(h/100)),c.appendChild(c.firstChild).style.height=
a+"px",m=b,r=0);return b},update:function(){l=this.end()}}};"object"===typeof module&&(module.exports=Stats);

18
posts/fps/index.js Normal file
View File

@ -0,0 +1,18 @@
var pg = require('pg');
var secret = require('../../private');
module.exports.index = function(req, res) {
pg.connect(secret.url, function(err, client, release) {
client.query(
"INSERT INTO fpscounter(exp_id, fps) VALUES($1,$2);",
[req.session.exp_id, req.body.fps],
function(err, result) {
release();
}
);
});
res.setHeader('Content-Type', 'text/html');
res.send("");
}

3
posts/fps/urls.js Normal file
View File

@ -0,0 +1,3 @@
module.exports = {
'/fps': 'index'
}

View File

@ -95,3 +95,9 @@ CREATE TABLE hovered(
time TIMESTAMP DEFAULT NOW(), time TIMESTAMP DEFAULT NOW(),
arrow_id INTEGER arrow_id INTEGER
); );
CREATE TABLE fpscounter(
id SERIAL PRIMARY KEY,
exp_id SERIAL REFERENCES experiment (id),
fps REAL
);