Added check to see if there were any incorrect experiments in the

database
This commit is contained in:
Thomas FORGIONE 2015-10-02 11:07:40 +02:00
parent 27dad08861
commit 2982b9804b
1 changed files with 34 additions and 0 deletions

34
sql/check.pgsql Normal file
View File

@ -0,0 +1,34 @@
-- Checks that each user has never twice either the same scene or the same recommendation style
SELECT count(*) = 0
FROM
Experiment as E1,
Experiment as E2,
CoinCombination as C1,
CoinCombination as C2
WHERE
E1.user_id = E2.user_id
AND E1.id != E2.id
AND E1.coin_combination_id = C1.id
AND E2.coin_combination_id = C2.id
AND (E1.recommendation_style = E2.recommendation_style OR C1.scene_id = C2.scene_id);
-- Checks that a CoinCombination is never used more than 3 times (except for the tutorial)
SELECT count(*) = 0
FROM (
SELECT count(CoinCombination.id)
FROM Experiment, CoinCombination
WHERE Experiment.coin_combination_id = CoinCombination.id AND scene_id != 1
GROUP BY Experiment.coin_combination_id
HAVING count(CoinCombination.id) > 3
) AS T;
-- Checks that the CoinCombination for a tutorial is only used once
SELECT count(*) = 0
FROM (
SELECT count(CoinCombination.id)
FROM Experiment, CoinCombination
WHERE Experiment.coin_combination_id = CoinCombination.id AND scene_id = 1
GROUP BY Experiment.coin_combination_id
HAVING count(CoinCombination.id) != 1
) AS T;