Corrected database

This commit is contained in:
Thomas FORGIONE 2015-08-25 09:25:45 +02:00
parent 82f7a7268a
commit 5f3b2e1862
10 changed files with 29 additions and 50 deletions

View File

@ -453,15 +453,30 @@ DBReq.Info.prototype.loadSwitchedLockOption = function() {
DBReq.Info.prototype.loadRedCoins = function() { DBReq.Info.prototype.loadRedCoins = function() {
var self = this; var self = this;
this.client.query( this.client.query(
"SELECT coin_id FROM coin WHERE exp_id = $1", "SELECT coin_1, \n" +
" coin_2, \n" +
" coin_3, \n" +
" coin_4, \n" +
" coin_5, \n" +
" coin_6, \n" +
" coin_7, \n" +
" coin_8 \n" +
"FROM CoinCombination, Experiment \n" +
"WHERE CoinCombination.id = Experiment.coin_combination_id AND \n" +
" Experiment.id = $1;",
[self.id], [self.id],
function(err, result) { function(err, result) {
if (err !== null) { if (err !== null) {
Log.dberror(err + ' in loadRedCoins'); Log.dberror(err + ' in loadRedCoins');
} else { } else {
for (var i in result.rows) { self.redCoins.push(result.rows[0].coin_1);
self.redCoins.push(result.rows[i].coin_id); self.redCoins.push(result.rows[0].coin_2);
} self.redCoins.push(result.rows[0].coin_3);
self.redCoins.push(result.rows[0].coin_4);
self.redCoins.push(result.rows[0].coin_5);
self.redCoins.push(result.rows[0].coin_6);
self.redCoins.push(result.rows[0].coin_7);
self.redCoins.push(result.rows[0].coin_8);
} }
self.ready.redCoins = true; self.ready.redCoins = true;
self.tryMerge(); self.tryMerge();

View File

@ -2,4 +2,7 @@ extends ../../../views/base.jade
block content block content
h1 Thank you for everything ! h1 Thank you for everything !
audio(autoplay)
source(src="/static/data/music/thankyou.ogg")
source(src="/static/data/music/thankyou.mp3")

View File

@ -48,6 +48,8 @@ saveCoins = function() {
}; };
function main() { function main() {
// Some config
L3D.DB.disable();
// Main container that holds everything // Main container that holds everything
container = document.getElementById('container'); container = document.getElementById('container');
@ -63,9 +65,6 @@ function main() {
// Set the good size of cameras // Set the good size of cameras
onWindowResize(); onWindowResize();
// Some config
L3D.DB.disable();
Coin.update(); Coin.update();
startCanvas.render(L3D.StartCanvas.Black); startCanvas.render(L3D.StartCanvas.Black);

View File

@ -43,6 +43,11 @@ function initThreeElements() {
function init(data) { function init(data) {
console.log(data);
// Some config
L3D.DB.disable();
// Initialize stats counter // Initialize stats counter
stats = new Stats(); stats = new Stats();
stats.setMode(0); stats.setMode(0);

View File

@ -261,9 +261,6 @@ L3D.generateCoins = function(totalCoins, coin_ids) {
indices.push(totalCoins[i].id); indices.push(totalCoins[i].id);
} }
if (coin_ids === undefined || (coin_ids instanceof Array && coin_ids.length === 0))
L3D.DB.Private.sendData('/posts/coin-id', {indices : indices});
return coins; return coins;
}; };

View File

@ -1,32 +0,0 @@
var pg = require('pg');
var secret = require('../../private');
var Log = require('../../lib/NodeLog.js');
function insertCoinId(client, release, exp_id, coin_ids) {
if (coin_ids.length > 0) {
client.query(
'INSERT INTO Coin(exp_id, coin_id) VALUES ($1, $2);',
[exp_id,coin_ids.shift()],
function(err, result) {
if (err !== null)
Log.dberror(err + ' coin-id');
if (coin_ids.length === 0)
release();
else
insertCoinId(client, release, exp_id, coin_ids);
}
);
}
}
module.exports.index = function(req, res) {
pg.connect(secret.url, function(err, client, release) {
insertCoinId(client, release, req.session.exp_id, req.body.indices);
});
res.setHeader('Content-Type', 'text/html');
res.send("");
};

View File

@ -1,3 +0,0 @@
module.exports = {
'/posts/coin-id': 'index'
};

View File

@ -76,11 +76,6 @@ CREATE TABLE Experiment(
recommendation_style VARCHAR(30) recommendation_style VARCHAR(30)
); );
CREATE TABLE Coin(
exp_id SERIAL REFERENCES Experiment (id),
coin_id INTEGER
);
-- Init scene table -- Init scene table
INSERT INTO Scene(name, coin_number) VALUES ('peachcastle' , 41); INSERT INTO Scene(name, coin_number) VALUES ('peachcastle' , 41);
INSERT INTO Scene(name, coin_number) VALUES ('bobomb' , 44); INSERT INTO Scene(name, coin_number) VALUES ('bobomb' , 44);

Binary file not shown.

Binary file not shown.