Cleaning commit

This commit is contained in:
Thomas FORGIONE 2015-09-28 09:36:49 +02:00
parent f9b5e4a14b
commit 322fe99ea9
4 changed files with 102 additions and 19 deletions

View File

@ -1,6 +1,42 @@
var pgc = require('../private.js'); function main() {
var db = require('./loadTables.js')(pgc.url, function() {
console.log(db.users); var db = JSON.parse(require('fs').readFileSync('./data.json', 'utf8'));
}); console.log('There were ' + db.users.length + ' users for ' + db.experiments.length + ' experiments');
var meanTimeNoReco = 0;
var meanTimeArrow = 0;
var meanTimeViewport = 0;
for (var i = 0; i < db.experiments.length; i++) {
var exp = db.experiments[i];
var events = exp.elements.events;
if (events.length === 0 || exp.user.worker_id === null) {
continue;
}
console.log(exp.user.worker_id + ' : ' + exp.user.rating + ' -> ' + timeToString(timeDifference(events[0].time, events[events.length-1].time)));
}
}
function timeDifference(time1, time2) {
return new Date(time2).getTime() - new Date(time1).getTime();
}
function timeToString(_time) {
var time = _time / 1000;
return Math.floor(time / 3600) + 'h' + Math.floor((time % 3600) / 60) + 'm' + Math.floor(time % 60);
}
main();

9
analysis/generateData.js Normal file
View File

@ -0,0 +1,9 @@
var pgc = require('../private.js');
var url = pgc.url;
require('./loadTables.js')(url, function(db) {
console.log(JSON.stringify(db));
});

View File

@ -1,14 +1,21 @@
var pg = require('pg'); var pg = require('pg');
var async = require('async'); var async = require('async');
var DBReq = require('../controllers/prototype/dbrequests.js');
var users, client, release, scenes, coinCombinations, experiments, callback, url; var users, client, release, scenes, coinCombinations, experiments, callback, url, db = {};
function write(str) {
process.stderr.write('\033[31m' + str + '\033[0m');
}
function start() { function start() {
client = new pg.Client(url); client = new pg.Client(url);
write("Connecting to the database...");
client.connect( client.connect(
function() { function() {
write(" done !\n");
client.query( client.query(
'SELECT * FROM Users', 'SELECT * FROM Users',
function(err, result) { function(err, result) {
@ -27,6 +34,8 @@ function main() {
// Init // Init
function(done) { function(done) {
write("Getting scenes and coin combinations...");
async.parallel([ async.parallel([
function(callback) { function(callback) {
client.query( client.query(
@ -64,13 +73,16 @@ function main() {
}, },
], function() { ], function() {
write(" done !\n");
done(); done();
}); });
}, },
function(done) { function(done) {
async.map(
write("Getting experiments for each user...");
async.each(
users, users,
function(user, callback) { function(user, callback) {
client.query( client.query(
@ -83,6 +95,7 @@ function main() {
); );
}, },
function(err, result) { function(err, result) {
write(' done !\n');
done(); done();
} }
); );
@ -90,7 +103,9 @@ function main() {
function(done) { function(done) {
async.map( write('Getting experiments...');
async.each(
experiments, experiments,
function(exp, callback) { function(exp, callback) {
client.query( client.query(
@ -103,7 +118,31 @@ function main() {
} }
); );
}, },
done function() {
write(' done !\n');
done();
}
);
},
function(done) {
write('Getting interactions from experiments (might be long)');
async.each( // Don't know why each doesn't work
experiments,
function(exp, callback) {
DBReq.getInfo(exp.id, function(result) {
exp.elements = result;
write('.');
callback();
});
},
function () {
write(' done !\n');
done();
}
); );
}, },
@ -112,17 +151,15 @@ function main() {
function(done) { function(done) {
client.end(); client.end();
console.log("Finished");
done(); done();
}, },
function(done) { function(done) {
module.exports.users = users; db.users = users;
module.exports.experiments = experiments; db.experiments = experiments;
module.exports.coinCombinations = coinCombinations; db.coinCombinations = coinCombinations;
callback(); callback(db);
done(); done();
} }

View File

@ -73,9 +73,9 @@ DBReq.Info = function(id, finishAction) {
// Connect to db // Connect to db
var self = this; var self = this;
pg.connect(pgc.url, function(err, client, release) { self.client = new pg.Client(pgc.url);
self.client = client;
self.release = release; self.client.connect(function() {
self.execute(); self.execute();
}); });
}; };
@ -108,8 +108,9 @@ DBReq.Info.prototype.tryMerge = function() {
} }
// Release db connection // Release db connection
this.release(); // this.release();
this.release = null; // this.release = null;
this.client.end();
this.client = null; this.client = null;
this.merge(); this.merge();