Added hovered events

This commit is contained in:
Thomas FORGIONE 2015-05-21 15:35:40 +02:00
parent 2a5ae4d985
commit 8e592c87b5
6 changed files with 95 additions and 9 deletions

View File

@ -168,6 +168,27 @@ var addPreviousNextFromId = function(client, req, res, callback, id) {
); );
} }
var addHoveredFromId = function(client, req, res, callback, id) {
client.query(
"SELECT start, time, arrow_id FROM hovered WHERE id = $1",
[id],
function(err, result) {
res.locals.path = res.locals.path || [];
for (var i in result.rows) {
res.locals.path.push(
{
type: "hovered",
time: result.rows[i].time,
start: result.rows[i].start,
id: result.rows[i].arrow_id
}
);
}
callback();
}
);
}
var getAllUsers = function(req, res, callback) { var getAllUsers = function(req, res, callback) {
pg.connect(pgc.url, function(err, client, release) { pg.connect(pgc.url, function(err, client, release) {
client.query( client.query(
@ -238,6 +259,7 @@ module.exports.replay_info = function(req, res) {
addArrowsFromId(client, req, res, function() { addArrowsFromId(client, req, res, function() {
addResetsFromId(client, req, res, function() { addResetsFromId(client, req, res, function() {
addPreviousNextFromId(client, req, res, function() { addPreviousNextFromId(client, req, res, function() {
addHoveredFromId(client, req, res, function() {
res.locals.path.sort(function(elt1, elt2) { res.locals.path.sort(function(elt1, elt2) {
// Dates as string can be compared // Dates as string can be compared
if (elt1.time < elt2.time) if (elt1.time < elt2.time)
@ -252,6 +274,7 @@ module.exports.replay_info = function(req, res) {
}, id); }, id);
}, id); }, id);
}, id); }, id);
}, id);
release(); release();
}); });
} }

27
posts/hovered/index.js Normal file
View File

@ -0,0 +1,27 @@
var pg = require('pg');
var secret = require('../../private');
module.exports.index = function(req, res) {
var user_id = req.session.user_id;
pg.connect(secret.url, function(err, client, release) {
client.query(
"INSERT INTO hovered(user_id, time, start, arrow_id)" +
"VALUES($1, to_timestamp($2), $3, $4);" ,
[
user_id,
req.body.time,
req.body.start ? true : false,
req.body.arrow_id
],
function(err, result) {
release();
}
);
});
res.setHeader('Content-Type', 'text/html');
res.send("user_id = " + user_id);
}

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

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

View File

@ -4,6 +4,7 @@ DROP TABLE IF EXISTS coinclicked CASCADE;
DROP TABLE IF EXISTS keyboardevent CASCADE; DROP TABLE IF EXISTS keyboardevent CASCADE;
DROP TABLE IF EXISTS resetclicked CASCADE; DROP TABLE IF EXISTS resetclicked CASCADE;
DROP TABLE IF EXISTS previousnextclicked CASCADE; DROP TABLE IF EXISTS previousnextclicked CASCADE;
DROP TABLE IF EXISTS hovered CASCADE;
DROP TYPE IF EXISTS VECTOR3 CASCADE; DROP TYPE IF EXISTS VECTOR3 CASCADE;
DROP TYPE IF EXISTS CAMERA CASCADE; DROP TYPE IF EXISTS CAMERA CASCADE;
@ -63,3 +64,11 @@ CREATE TABLE previousnextclicked(
time TIMESTAMP DEFAULT NOW(), time TIMESTAMP DEFAULT NOW(),
camera CAMERA camera CAMERA
); );
CREATE TABLE hovered(
id SERIAL PRIMARY KEY,
user_id SERIAL REFERENCES users (id),
start BOOLEAN NOT NULL,
time TIMESTAMP DEFAULT NOW(),
arrow_id INT
);

View File

@ -77,3 +77,14 @@ BD.Event.PreviousNextClicked.prototype.send = function() {
BD.Private.sendData(url, data); BD.Private.sendData(url, data);
} }
BD.Event.Hovered = function() {};
BD.Event.Hovered.prototype.send = function() {
var url = "/hovered";
var data = {
start: this.start,
arrow_id: this.arrow_id
};
BD.Private.sendData(url, data);
}

View File

@ -66,12 +66,25 @@ CameraSelecter.prototype.update = function(event) {
if (hovered !== undefined && !(hovered instanceof Coin)) { if (hovered !== undefined && !(hovered instanceof Coin)) {
if (hovered !== previousCamera) { if (hovered !== previousCamera) {
// log it
var event = new BD.Event.Hovered();
event.start = true;
event.arrow_id = cameras.cameras.indexOf(this.currentPointedCamera);
event.send();
this.prev.x = this.mouse.x; this.prev.x = this.mouse.x;
this.prev.y = this.mouse.y; this.prev.y = this.mouse.y;
} }
this.prev.camera = hovered; this.prev.camera = hovered;
this.prev.go = true; this.prev.go = true;
} else { } else {
if (this.prev.go) {
// Log if previous was not null
var event = new BD.Event.Hovered();
event.start = false;
event.arrow_id = null;
event.send();
}
this.prev.go = false; this.prev.go = false;
} }
} }