dbrequests is now better : logs error and gets more info

This commit is contained in:
Thomas FORGIONE 2015-07-09 16:02:01 +02:00
parent cd10d76d89
commit 3297ddec09
1 changed files with 154 additions and 73 deletions

View File

@ -1,5 +1,6 @@
var pg = require('pg'); var pg = require('pg');
var pgc = require('../../private.js'); var pgc = require('../../private.js');
var Log = require('../../lib/NodeLog.js');
var Info = function(id, finishAction) { var Info = function(id, finishAction) {
this.id = id; this.id = id;
@ -10,7 +11,9 @@ var Info = function(id, finishAction) {
arrows: false, arrows: false,
resets : false, resets : false,
previousNext: false, previousNext: false,
hovered: false hovered: false,
pointerLocked: false,
switchedLockOption: false
}; };
this.results = {}; this.results = {};
@ -32,6 +35,8 @@ Info.prototype.execute = function() {
this.loadResets(); this.loadResets();
this.loadPreviousNext(); this.loadPreviousNext();
this.loadHovered(); this.loadHovered();
this.loadSwitchedLockOption();
this.loadPointerLocked();
}; };
Info.prototype.tryMerge = function() { Info.prototype.tryMerge = function() {
@ -91,24 +96,28 @@ Info.prototype.loadCameras = function() {
"FROM keyboardevent WHERE exp_id = $1 ORDER BY time;", "FROM keyboardevent WHERE exp_id = $1 ORDER BY time;",
[self.id], [self.id],
function(err, result) { function(err, result) {
self.results.cameras = []; if (err !== null) {
for (var i in result.rows) { Log.dberror(err + ' in loadCameras');
self.results.cameras.push( } else {
{ self.results.cameras = [];
type: 'camera', for (var i in result.rows) {
position : { self.results.cameras.push(
x: result.rows[i].px, {
y: result.rows[i].py, type: 'camera',
z: result.rows[i].pz position : {
}, x: result.rows[i].px,
target : { y: result.rows[i].py,
x: result.rows[i].tx, z: result.rows[i].pz
y: result.rows[i].ty, },
z: result.rows[i].tz target : {
}, x: result.rows[i].tx,
time: result.rows[i].time y: result.rows[i].ty,
} z: result.rows[i].tz
); },
time: result.rows[i].time
}
);
}
} }
self.ready.cameras = true; self.ready.cameras = true;
self.tryMerge(); self.tryMerge();
@ -122,15 +131,19 @@ Info.prototype.loadCoins = function() {
"SELECT coin_id, time FROM coinclicked WHERE exp_id = $1 ORDER BY time;", "SELECT coin_id, time FROM coinclicked WHERE exp_id = $1 ORDER BY time;",
[self.id], [self.id],
function(err,result) { function(err,result) {
self.results.coins = []; if (err !== null) {
for (var i in result.rows) { Log.dberror(err + ' in loadCoins');
self.results.coins.push( } else {
{ self.results.coins = [];
type: 'coin', for (var i in result.rows) {
time: result.rows[i].time, self.results.coins.push(
id: result.rows[i].coin_id {
} type: 'coin',
); time: result.rows[i].time,
id: result.rows[i].coin_id
}
);
}
} }
self.ready.coins = true; self.ready.coins = true;
self.tryMerge(); self.tryMerge();
@ -144,15 +157,19 @@ Info.prototype.loadArrows = function() {
"SELECT arrow_id, time FROM arrowclicked WHERE exp_id = $1 ORDER BY time;", "SELECT arrow_id, time FROM arrowclicked WHERE exp_id = $1 ORDER BY time;",
[self.id], [self.id],
function(err, result) { function(err, result) {
self.results.arrows = []; if (err !== null) {
for (var i in result.rows) { Log.dberror(err + ' in loadArrows');
self.results.arrows.push( } else {
{ self.results.arrows = [];
type: 'arrow', for (var i in result.rows) {
time: result.rows[i].time, self.results.arrows.push(
id: result.rows[i].arrow_id {
} type: 'arrow',
); time: result.rows[i].time,
id: result.rows[i].arrow_id
}
);
}
} }
self.ready.arrows = true; self.ready.arrows = true;
self.tryMerge(); self.tryMerge();
@ -166,14 +183,18 @@ Info.prototype.loadResets = function() {
"SELECT time FROM resetclicked WHERE exp_id = $1 ORDER BY time;", "SELECT time FROM resetclicked WHERE exp_id = $1 ORDER BY time;",
[self.id], [self.id],
function(err, result) { function(err, result) {
self.results.resets = []; if (err !== null) {
for (var i in result.rows) { Log.dberror(err + ' in loadResets');
self.results.resets.push( } else {
{ self.results.resets = [];
type: 'reset', for (var i in result.rows) {
time: result.rows[i].time self.results.resets.push(
} {
); type: 'reset',
time: result.rows[i].time
}
);
}
} }
self.ready.resets = true; self.ready.resets = true;
self.tryMerge(); self.tryMerge();
@ -194,25 +215,29 @@ Info.prototype.loadPreviousNext = function () {
"FROM previousnextclicked WHERE exp_id = $1 ORDER BY time;", "FROM previousnextclicked WHERE exp_id = $1 ORDER BY time;",
[self.id], [self.id],
function(err, result) { function(err, result) {
self.results.previousNext = []; if (err !== null) {
for (var i in result.rows) { Log.dberror(err + ' in loadPreviousNext');
self.results.previousNext.push( } else {
{ self.results.previousNext = [];
type: 'previousnext', for (var i in result.rows) {
time: result.rows[i].time, self.results.previousNext.push(
previous: result.rows[i].previousnext == 'p', {
position : { type: 'previousnext',
x: result.rows[i].px, time: result.rows[i].time,
y: result.rows[i].py, previous: result.rows[i].previousnext == 'p',
z: result.rows[i].pz position : {
}, x: result.rows[i].px,
target : { y: result.rows[i].py,
x: result.rows[i].tx, z: result.rows[i].pz
y: result.rows[i].ty, },
z: result.rows[i].tz target : {
x: result.rows[i].tx,
y: result.rows[i].ty,
z: result.rows[i].tz
}
} }
} );
); }
} }
self.ready.previousNext = true; self.ready.previousNext = true;
self.tryMerge(); self.tryMerge();
@ -226,16 +251,20 @@ Info.prototype.loadHovered = function() {
"SELECT start, time, arrow_id FROM hovered WHERE exp_id = $1 ORDER BY time;", "SELECT start, time, arrow_id FROM hovered WHERE exp_id = $1 ORDER BY time;",
[self.id], [self.id],
function(err, result) { function(err, result) {
self.results.hovered = []; if (err !== null) {
for (var i in result.rows) { Log.dberror(err + ' in loadHovered');
self.results.hovered.push( } else {
{ self.results.hovered = [];
type: "hovered", for (var i in result.rows) {
time: result.rows[i].time, self.results.hovered.push(
start: result.rows[i].start, {
id: result.rows[i].arrow_id type: "hovered",
} time: result.rows[i].time,
); start: result.rows[i].start,
id: result.rows[i].arrow_id
}
);
}
} }
self.ready.hovered = true; self.ready.hovered = true;
self.tryMerge(); self.tryMerge();
@ -243,6 +272,58 @@ Info.prototype.loadHovered = function() {
); );
}; };
Info.prototype.loadPointerLocked = function() {
var self = this;
this.client.query(
"SELECT time, locked FROM pointerlocked WHERE exp_id = $1 ORDER BY time;",
[self.id],
function(err, result) {
if (err !== null) {
Log.dberror(err + ' in loadPointerLocked');
} else {
self.results.pointerlocked = [];
for (var i in result.rows) {
self.results.pointerlocked.push(
{
type: "pointerlocked",
locked: result.rows[i].locked,
time: result.rows[i].time
}
);
}
}
self.ready.pointerLocked = true;
self.tryMerge();
}
);
}
Info.prototype.loadSwitchedLockOption = function() {
var self = this;
this.client.query(
"SELECT time, locked FROM switchedlockoption WHERE exp_id = $1 ORDER BY time;",
[self.id],
function(err, result) {
if (err !== null) {
Log.dberror(err + ' in loadSwitchedLockOption');
} else {
self.results.switchedlockoption = [];
for (var i in result.rows) {
self.results.switchedlockoption.push(
{
type: "switchedlockoption",
locked: result.rows[i].locked,
time: result.rows[i].time
}
);
}
}
self.ready.switchedLockOption = true;
self.tryMerge();
}
);
}
var UserCreator = function(finishAction) { var UserCreator = function(finishAction) {
this.finishAction = finishAction; this.finishAction = finishAction;