Preloading of the experiments
This commit is contained in:
@@ -15,6 +15,6 @@ block content
|
||||
script.
|
||||
document.getElementById('next').onclick = function() {
|
||||
document.getElementById('next').disabled = true;
|
||||
window.location = '/prototype/game';
|
||||
window.location = '/prototype/play';
|
||||
}
|
||||
|
||||
|
||||
63
controllers/prototype/dbrequests.js
vendored
63
controllers/prototype/dbrequests.js
vendored
@@ -920,6 +920,65 @@ DBReq.ExpIdChecker.prototype.finish = function() {
|
||||
this.finishAction(this.finalResult);
|
||||
};
|
||||
|
||||
DBReq.LastExpGetter = function(userId, finishAction) {
|
||||
|
||||
var self = this;
|
||||
this.userId = userId;
|
||||
this.finishAction = finishAction;
|
||||
this.finalResult = {};
|
||||
|
||||
pg.connect(pgc.url, function(err, client, release) {
|
||||
self.client = client;
|
||||
self.release = release;
|
||||
self.execute();
|
||||
});
|
||||
};
|
||||
|
||||
DBReq.LastExpGetter.prototype.execute = function() {
|
||||
var self = this;
|
||||
this.client.query(
|
||||
'SELECT scene_id AS "sceneId", \n' +
|
||||
' coin_1, \n' +
|
||||
' coin_2, \n' +
|
||||
' coin_3, \n' +
|
||||
' coin_4, \n' +
|
||||
' coin_5, \n' +
|
||||
' coin_6, \n' +
|
||||
' coin_7, \n' +
|
||||
' coin_8, \n' +
|
||||
' Experiment.recommendation_style AS "recommendationStyle" \n' +
|
||||
'FROM Experiment, CoinCombination \n' +
|
||||
'WHERE Experiment.coin_combination_id = CoinCombination.id \n' +
|
||||
' AND Experiment.user_id = $1 \n' +
|
||||
'ORDER BY Experiment.id DESC \n' +
|
||||
'LIMIT 1;',
|
||||
[self.userId],
|
||||
function (err, result) {
|
||||
self.finalResult.sceneId = result.rows[0].sceneId;
|
||||
self.finalResult.recommendationStyle = result.rows[0].recommendationStyle;
|
||||
self.finalResult.coins = [
|
||||
result.rows[0].coin_1,
|
||||
result.rows[0].coin_2,
|
||||
result.rows[0].coin_3,
|
||||
result.rows[0].coin_4,
|
||||
result.rows[0].coin_5,
|
||||
result.rows[0].coin_6,
|
||||
result.rows[0].coin_7,
|
||||
result.rows[0].coin_8
|
||||
];
|
||||
self.finish();
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
DBReq.LastExpGetter.prototype.finish = function() {
|
||||
this.release();
|
||||
this.client = null;
|
||||
this.release = null;
|
||||
|
||||
this.finishAction(this.finalResult.sceneId, this.finalResult.recommendationStyle, this.finalResult.coins);
|
||||
}
|
||||
|
||||
/**
|
||||
* Class that gets the info from all experiment
|
||||
* @param finishAction {function} callback that has as a parameter which is an
|
||||
@@ -1133,4 +1192,8 @@ DBReq.getAllExps = function(callback) {
|
||||
new DBReq.ExpGetter(callback);
|
||||
};
|
||||
|
||||
DBReq.getLastExp = function(id, callback) {
|
||||
new DBReq.LastExpGetter(id, callback);
|
||||
};
|
||||
|
||||
module.exports = DBReq;
|
||||
|
||||
59
controllers/prototype/index.js
vendored
59
controllers/prototype/index.js
vendored
@@ -34,35 +34,62 @@ module.exports.game = function(req, res) {
|
||||
req.session.userId,
|
||||
function(expId, coinCombinationId, sceneId, recommendationStyle, coins) {
|
||||
|
||||
if (expId === undefined) {
|
||||
// if (expId === undefined) {
|
||||
|
||||
res.redirect('/feedback');
|
||||
return;
|
||||
// req.session.finished = true;
|
||||
// req.session.save();
|
||||
// return;
|
||||
|
||||
}
|
||||
// }
|
||||
|
||||
req.session.expId = expId;
|
||||
req.session.save();
|
||||
// req.session.expId = expId;
|
||||
// req.session.save();
|
||||
|
||||
res.locals.scene = sceneToFunction(sceneId);
|
||||
res.locals.recommendationStyle = recommendationStyle;
|
||||
res.locals.coins = coins;
|
||||
// res.locals.scene = sceneToFunction(sceneId);
|
||||
// res.locals.recommendationStyle = recommendationStyle;
|
||||
// res.locals.coins = coins;
|
||||
|
||||
res.setHeader('Content-Type','text/html');
|
||||
res.render('prototype_recommendation.jade', res.locals, function(err, result) {
|
||||
res.send(result);
|
||||
});
|
||||
// res.setHeader('Content-Type','text/html');
|
||||
// res.send("Ok");
|
||||
});
|
||||
|
||||
} else {
|
||||
|
||||
res.redirect('/');
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.play = function(req, res) {
|
||||
|
||||
req.session.counter = req.session.counter === undefined ? 0 : req.session.counter + 1;
|
||||
req.session.save();
|
||||
|
||||
if (req.session.counter > 2) {
|
||||
|
||||
res.redirect('/feedback');
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
db.getLastExp(req.session.userId, function(sceneId, recoStyle, coins) {
|
||||
|
||||
res.locals.scene = sceneToFunction(sceneId);
|
||||
res.locals.recommendationStyle= recoStyle;
|
||||
res.locals.coins = coins;
|
||||
|
||||
// Prepare next experiment
|
||||
module.exports.game(req, null);
|
||||
|
||||
res.setHeader('Content-Type', 'text/html');
|
||||
res.render('prototype_recommendation.jade', res.locals, function(err, result) {
|
||||
res.send(result);
|
||||
});
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
module.exports.sponza = function(req, res) {
|
||||
res.setHeader('Content-Type', 'text/html');
|
||||
|
||||
@@ -127,6 +154,10 @@ module.exports.tutorial = function(req, res) {
|
||||
|
||||
// 1 is the ID of peach scene
|
||||
db.createTutorial(req.session.userId, function(id, coins) {
|
||||
|
||||
// Generate next experiment
|
||||
module.exports.game(req, null);
|
||||
|
||||
req.session.tutorialDone = true;
|
||||
req.session.expId = id;
|
||||
res.locals.coins = coins;
|
||||
|
||||
3
controllers/prototype/urls.js
vendored
3
controllers/prototype/urls.js
vendored
@@ -10,5 +10,6 @@ module.exports = {
|
||||
'/prototype/coin-viewer/:scene': 'viewer',
|
||||
'/prototype/coin-checker/:scene': 'checker',
|
||||
'/user-study': 'userstudy',
|
||||
'/prototype/next': 'next'
|
||||
'/prototype/next': 'next',
|
||||
'/prototype/play': 'play'
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user