summaryrefslogtreecommitdiff
path: root/db/analyse.py
diff options
context:
space:
mode:
authorEila Väyrynen <evayryne@local>2023-12-03 13:28:36 +0200
committerEila Väyrynen <evayryne@local>2023-12-03 13:28:36 +0200
commit83eefd51d79dc2c0fa778303042c581b4691e82e (patch)
treebb957d130855e7ba798f90604468c3665a81528d /db/analyse.py
parente0ca9caf5a49981ad999b1c0c3fec69d7c4871e4 (diff)
Rearrenge rest of db actions.
Diffstat (limited to 'db/analyse.py')
-rw-r--r--db/analyse.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/db/analyse.py b/db/analyse.py
new file mode 100644
index 0000000..a4076f5
--- /dev/null
+++ b/db/analyse.py
@@ -0,0 +1,22 @@
+from sqlalchemy.sql import text
+
+class DBAnalyse:
+ def __init__(self, db):
+ self.db = db
+
+ def comparable(self, quiz_id,user1,user2):
+ sql = "SELECT q.question, q.neg_answer, q.pos_answer, \
+ a1.answer, a2.answer, \
+ 100 - ABS( a1.answer - a2.answer ) / 10 \
+ FROM questionaires quiz \
+ JOIN questions q ON q.id = ANY(quiz.questionset) \
+ JOIN answers a1 ON a1.user_id = (:user1) \
+ JOIN answers a2 ON a2.user_id = (:user2) \
+ WHERE a1.question_id = q.id \
+ AND a2.question_id = q.id \
+ AND quiz.id = (:quiz_id);"
+ return self.db.session.execute( text(sql), {
+ "quiz_id":quiz_id,
+ "user1":user1,
+ "user2":user2
+ } ).fetchall()