From 2982b9804bdf5f33b0f8ddb63e8cb3570fcd21d0 Mon Sep 17 00:00:00 2001 From: Thomas FORGIONE Date: Fri, 2 Oct 2015 11:07:40 +0200 Subject: [PATCH] Added check to see if there were any incorrect experiments in the database --- sql/check.pgsql | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 sql/check.pgsql diff --git a/sql/check.pgsql b/sql/check.pgsql new file mode 100644 index 0000000..34e5706 --- /dev/null +++ b/sql/check.pgsql @@ -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;