From 73bfabd2e7c4227511c6fc5318639ce6c529cb6e Mon Sep 17 00:00:00 2001 From: Thomas FORGIONE Date: Mon, 14 Sep 2015 16:35:16 +0200 Subject: [PATCH] Begining of analyse of results --- analysis/analyse.js | 6 ++ analysis/loadTables.js | 141 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 147 insertions(+) create mode 100644 analysis/analyse.js create mode 100644 analysis/loadTables.js diff --git a/analysis/analyse.js b/analysis/analyse.js new file mode 100644 index 0000000..dcdbda8 --- /dev/null +++ b/analysis/analyse.js @@ -0,0 +1,6 @@ +var pgc = require('../private.js'); +var db = require('./loadTables.js')(pgc.url, function() { + + console.log(db.users); + +}); diff --git a/analysis/loadTables.js b/analysis/loadTables.js new file mode 100644 index 0000000..7b296e8 --- /dev/null +++ b/analysis/loadTables.js @@ -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; +}; + +