Commit 550cab021b5e8af13d107af860865288f492eaa8

Authored by Miguel Barao
1 parent 2327acae
Exists in master and in 1 other branch dev

- /results now shows only the best result from each student.

database.py
... ... @@ -15,9 +15,18 @@ class Database(object):
15 15 # return list of students and their results for a given test
16 16 def test_grades(self, test_id):
17 17 with sqlite3.connect(self.db) as c:
18   - cmd = 'SELECT student_id,name,grade FROM students INNER JOIN tests ON students.number=tests.student_id WHERE test_id==? ORDER BY grade DESC;'
19   - results = c.execute(cmd, [test_id])
20   - return results.fetchall()
  18 + # with all tests done by each student:
  19 + # cmd = 'SELECT student_id,name,grade FROM students INNER JOIN tests ON students.number=tests.student_id WHERE test_id==? ORDER BY grade DESC;'
  20 +
  21 + # only the best result for each student
  22 + cmd = '''
  23 + SELECT student_id, name, MAX(grade)
  24 + FROM students INNER JOIN tests
  25 + ON students.number=tests.student_id
  26 + WHERE test_id==?
  27 + GROUP BY student_id
  28 + ORDER BY grade DESC;'''
  29 + return c.execute(cmd, [test_id]).fetchall()
21 30  
22 31 # get list of students in the database
23 32 def get_students(self):
... ...
serve.py
... ... @@ -23,8 +23,7 @@ class Root(object):
23 23 self.database = database.Database(testconf['database'])
24 24 self.auth = AuthController(database=testconf['database'])
25 25 self.templates = TemplateLookup(directories=['templates'], input_encoding='utf-8')
26   - self.tags = {'online': set(), 'finished': set()}
27   - # self.loggedin = set() # students currently logged in
  26 + self.tags = {'online': set(), 'finished': set()} # should be in application, not server
28 27  
29 28 # --- DEFAULT ------------------------------------------------------------
30 29 # any path, e.g. /xpto/aargh is redirected to the test
... ...
templates/students.html
... ... @@ -63,9 +63,7 @@
63 63 <div class="input-group">
64 64 <input type="password" class="form-control" placeholder="${r[2][:8]}" name="${r[0]}">
65 65 <span class="input-group-btn">
66   - <!-- <button class="btn btn-danger" type="submit">reset</button> -->
67 66 <button form="${r[0]}" type="submit" value="submit" class="btn btn-danger">reset</button>
68   -
69 67 </span>
70 68 </div><!-- /input-group -->
71 69 </form>
... ...