Corrected bad bug

This commit is contained in:
Thomas FORGIONE 2015-10-01 16:25:02 +02:00
parent 3d007e8877
commit 0c8338895a
4 changed files with 54 additions and 19 deletions

View File

@ -855,6 +855,14 @@ DBReq.ExpCreator.prototype.execute = function() {
DBReq.ExpCreator.prototype.finish = function() { DBReq.ExpCreator.prototype.finish = function() {
var self = this; var self = this;
// self.finishAction(
// self.finalResult.expId,
// self.finalResult.coinCombinationId,
// self.finalResult.sceneId,
// self.finalResult.recommendationStyle,
// self.finalResult.coins
// );
// Commit, and then release // Commit, and then release
this.client.query("COMMIT;", function() { this.client.query("COMMIT;", function() {
@ -1046,10 +1054,12 @@ DBReq.LastExpGetter.prototype.execute = function() {
'FROM Experiment, CoinCombination \n' + 'FROM Experiment, CoinCombination \n' +
'WHERE Experiment.coin_combination_id = CoinCombination.id \n' + 'WHERE Experiment.coin_combination_id = CoinCombination.id \n' +
' AND Experiment.user_id = $1 \n' + ' AND Experiment.user_id = $1 \n' +
' AND NOT Experiment.finished \n' +
'ORDER BY Experiment.id DESC \n' + 'ORDER BY Experiment.id DESC \n' +
'LIMIT 1;', 'LIMIT 1;',
[self.userId], [self.userId],
function (err, result) { function (err, result) {
if (err !== null) { if (err !== null) {
Log.dberror(err + ' in LastExpGetter (DBReq)'); Log.dberror(err + ' in LastExpGetter (DBReq)');
} }
@ -1059,21 +1069,29 @@ DBReq.LastExpGetter.prototype.execute = function() {
}, 1000); }, 1000);
return; return;
} }
self.finalResult.sceneId = result.rows[0].sceneId;
self.finalResult.recommendationStyle = result.rows[0].recommendationStyle; self.client.query(
self.finalResult.coins = [ 'UPDATE Experiment SET finished = true WHERE id = $1',
result.rows[0].coin_1, [result.rows[0].expId],
result.rows[0].coin_2, function() {
result.rows[0].coin_3, self.finalResult.sceneId = result.rows[0].sceneId;
result.rows[0].coin_4, self.finalResult.recommendationStyle = result.rows[0].recommendationStyle;
result.rows[0].coin_5, self.finalResult.coins = [
result.rows[0].coin_6, result.rows[0].coin_1,
result.rows[0].coin_7, result.rows[0].coin_2,
result.rows[0].coin_8 result.rows[0].coin_3,
]; result.rows[0].coin_4,
self.finalResult.coinCombinationId = result.rows[0].coinCombinationId; result.rows[0].coin_5,
self.finalResult.expId = result.rows[0].expId; result.rows[0].coin_6,
self.finish(); result.rows[0].coin_7,
result.rows[0].coin_8
];
self.finalResult.coinCombinationId = result.rows[0].coinCombinationId;
self.finalResult.expId = result.rows[0].expId;
self.finish();
}
);
} }
); );
}; };
@ -1192,8 +1210,8 @@ DBReq.TutorialCreator.prototype.execute = function() {
function(err, result) { function(err, result) {
// Create experiment // Create experiment
self.client.query( self.client.query(
"INSERT INTO Experiment(user_id, coin_combination_id)\n" + "INSERT INTO Experiment(user_id, coin_combination_id, finished)\n" +
"VALUES($1,$2)\n" + "VALUES($1,$2, true)\n" +
"RETURNING id;", "RETURNING id;",
[self.id, result.rows[0].id], [self.id, result.rows[0].id],
function(err, result) { function(err, result) {

View File

@ -81,10 +81,26 @@ module.exports.play = function(req, res) {
db.getLastExp(req.session.userId, function(expId, sceneId, coinId, recoStyle, coins) { db.getLastExp(req.session.userId, function(expId, sceneId, coinId, recoStyle, coins) {
// if (coinId === undefined) {
// console.log("=== ERROR : COIN_ID IS UNDEFINED ===");
// process.exit(-1)
// }
res.locals.scene = sceneToFunction(sceneId); res.locals.scene = sceneToFunction(sceneId);
res.locals.recommendationStyle = recoStyle; res.locals.recommendationStyle = recoStyle;
res.locals.coins = coins; res.locals.coins = coins;
// var elt = req.session.experiments.find(function(elt) {
// return elt.coinCombinationId === coinId;
// });
// if (elt !== undefined) {
// console.log("=== ERROR DETECTED === user " + req.session.userId);
// console.log(req.session.experiments);
// console.log(coinId);
// process.exit(-1)
// }
req.session.experiments.push({ req.session.experiments.push({
sceneId: sceneId, sceneId: sceneId,
recommendationStyle: recoStyle, recommendationStyle: recoStyle,

View File

@ -73,7 +73,8 @@ CREATE TABLE Experiment(
id SERIAL PRIMARY KEY, id SERIAL PRIMARY KEY,
user_id SERIAL REFERENCES Users (id), user_id SERIAL REFERENCES Users (id),
coin_combination_id SERIAL REFERENCES CoinCombination (id), coin_combination_id SERIAL REFERENCES CoinCombination (id),
recommendation_style VARCHAR(30) recommendation_style VARCHAR(30),
finished BOOLEAN DEFAULT(false)
); );
-- Init scene table -- Init scene table

View File

@ -1,5 +1,5 @@
var baseUrl = 'http://localhost:4000/'; var baseUrl = 'http://localhost:4000/';
var baseUrl = 'http://3dinterface.no-ip.org/'; // var baseUrl = 'http://3dinterface.no-ip.org/';
function makeId() function makeId()
{ {