Begining of analyse of results

This commit is contained in:
Thomas FORGIONE 2015-09-14 16:35:16 +02:00
parent 29029ce33a
commit 73bfabd2e7
2 changed files with 147 additions and 0 deletions

6
analysis/analyse.js Normal file
View File

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

141
analysis/loadTables.js Normal file
View File

@ -0,0 +1,141 @@
var pg = require('pg');
var async = require('async');
var users, client, release, scenes, coinCombinations, experiments, callback, url;
function start() {
client = new pg.Client(url);
client.connect(
function() {
client.query(
'SELECT * FROM Users',
function(err, result) {
users = result.rows;
main();
}
);
}
);
}
function main() {
async.series([
// Init
function(done) {
async.parallel([
function(callback) {
client.query(
'SELECT * FROM Scene;',
[],
function(err, result) {
scenes = result.rows;
callback();
}
);
},
function(callback) {
client.query(
'SELECT * FROM CoinCombination;',
function(err, result) {
coinCombinations = result.rows;
callback();
}
);
},
function(callback) {
client.query(
'SELECT * FROM Experiment;',
function(err, result) {
experiments = result.rows;
callback();
}
);
},
], function() {
done();
});
},
function(done) {
async.map(
users,
function(user, callback) {
client.query(
'SELECT * FROM Experiment WHERE user_id = $1',
[user.id],
function(err, result) {
user.experiments = result.rows;
callback();
}
);
},
function(err, result) {
done();
}
);
},
function(done) {
async.map(
experiments,
function(exp, callback) {
client.query(
'SELECT user_id, coin_combination_id FROM Experiment WHERE id = $1',
[exp.id],
function(err, result) {
exp.coinCombination = coinCombinations[result.rows[0].coin_combination_id - 1];
exp.user = users[result.rows[0].user_id - 1];
callback();
}
);
},
done
);
},
// Finish
function(done) {
client.end();
console.log("Finished");
done();
},
function(done) {
module.exports.users = users;
module.exports.experiments = experiments;
module.exports.coinCombinations = coinCombinations;
callback(module.exports);
done();
}
]);
}
module.exports = function(_url, _callback) {
callback = _callback;
url = _url;
start();
return module.exports;
};