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');
var db = require('./loadTables.js')(pgc.url, function() {
function main() {
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 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() {
client = new pg.Client(url);
write("Connecting to the database...");
client.connect(
function() {
write(" done !\n");
client.query(
'SELECT * FROM Users',
function(err, result) {
@ -27,6 +34,8 @@ function main() {
// Init
function(done) {
write("Getting scenes and coin combinations...");
async.parallel([
function(callback) {
client.query(
@ -64,13 +73,16 @@ function main() {
},
], function() {
write(" done !\n");
done();
});
},
function(done) {
async.map(
write("Getting experiments for each user...");
async.each(
users,
function(user, callback) {
client.query(
@ -83,6 +95,7 @@ function main() {
);
},
function(err, result) {
write(' done !\n');
done();
}
);
@ -90,7 +103,9 @@ function main() {
function(done) {
async.map(
write('Getting experiments...');
async.each(
experiments,
function(exp, callback) {
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) {
client.end();
console.log("Finished");
done();
},
function(done) {
module.exports.users = users;
module.exports.experiments = experiments;
module.exports.coinCombinations = coinCombinations;
callback();
db.users = users;
db.experiments = experiments;
db.coinCombinations = coinCombinations;
callback(db);
done();
}

View File

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