diff options
| author | Emma Koistila <ekoistil@local> | 2023-12-03 14:11:21 +0200 | 
|---|---|---|
| committer | Emma Koistila <ekoistil@local> | 2023-12-03 14:11:21 +0200 | 
| commit | b538d8236cd9cf92c36df47ddf244096896f5068 (patch) | |
| tree | c94f2becffb7b213b7288405b4a6b3fa7b70b4e7 /db | |
| parent | 83eefd51d79dc2c0fa778303042c581b4691e82e (diff) | |
Moving comparison calculations to SQL query.
Diffstat (limited to 'db')
| -rw-r--r-- | db/analyse.py | 20 | 
1 files changed, 19 insertions, 1 deletions
| diff --git a/db/analyse.py b/db/analyse.py index a4076f5..612f637 100644 --- a/db/analyse.py +++ b/db/analyse.py @@ -4,7 +4,7 @@ class DBAnalyse:      def __init__(self, db):          self.db = db -    def comparable(self, quiz_id,user1,user2): +    def pagedata(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 \ @@ -20,3 +20,21 @@ class DBAnalyse:                  "user1":user1,                  "user2":user2              } ).fetchall() +             +    def compare(self, quiz_id,user1,user2): +        sql = "SELECT \ +                AVG (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 +            } ).scalar() +         +         |