From 947959d4dae45366980c1a8750571b37ec41b855 Mon Sep 17 00:00:00 2001 From: Ross Date: Fri, 18 Dec 2020 17:48:08 +0000 Subject: [PATCH] start score table --- anatomy/templates/anatomy/exam_scores.html | 38 +++++++-- anatomy/views.py | 93 ++++++++++++---------- 2 files changed, 82 insertions(+), 49 deletions(-) diff --git a/anatomy/templates/anatomy/exam_scores.html b/anatomy/templates/anatomy/exam_scores.html index 7faa4133..83466eef 100644 --- a/anatomy/templates/anatomy/exam_scores.html +++ b/anatomy/templates/anatomy/exam_scores.html @@ -7,19 +7,20 @@ {% if unmarked %} The following questions need marking {% for exam_index in unmarked %} - {{ exam_index|add:1 }} + {{ exam_index|add:1 }} {% endfor %} {% endif %} {% for user, value in user_answers_marks.items %} -

Candidate: {{ user_names|get_item:user }}

- - Answers: {% for ans, score in user_answers_and_marks|get_item:user %} - {{ans}} ({{score}}), - {% endfor %} -
Total mark: {{ user_scores|get_item:user }} +

Candidate: {{ user_names|get_item:user }}

+ + Answers: {% for ans, score in user_answers_and_marks|get_item:user %} + {{ans}} ({{score}}), + {% endfor %} +
Total mark: {{ user_scores|get_item:user }} {% endfor %} +

Stats

@@ -41,4 +42,25 @@ {% endfor %}
-{% endblock %} +
+

Answers as a table

+ + + + {% for cid in cids %} + + {% endfor %} + + + {% for question in questions %} + + + {% for ans in by_question|get_item:question %} + + {% endfor %} + + {% endfor %} +
Candidate{{cid}}
Question {{forloop.counter}}{{ans}}
+ +
+{% endblock %} \ No newline at end of file diff --git a/anatomy/views.py b/anatomy/views.py index 19adfae7..ac32272b 100644 --- a/anatomy/views.py +++ b/anatomy/views.py @@ -577,6 +577,7 @@ def exam_scores_cid(request, pk): user_answers = defaultdict(list) user_names = {} + by_question = defaultdict(list) unmarked = set() # Loop through all candidates @@ -590,6 +591,7 @@ def exam_scores_cid(request, pk): # skip if no answer user_answers_marks[cid].append(0) user_answers[cid].append("") + by_question[q].append("") continue ans = s.answer @@ -601,6 +603,8 @@ def exam_scores_cid(request, pk): user_answers_marks[cid].append(answer_score) user_answers_and_marks[cid].append((ans, answer_score)) + by_question[q].append(ans) + user_scores = {} for user in user_answers_marks: user_scores[user] = sum([i for i in user_answers_marks[user] if i != "unmarked"]) @@ -630,9 +634,11 @@ def exam_scores_cid(request, pk): request, "anatomy/exam_scores.html", { + "cids": cids, "exam": exam, "unmarked": unmarked, "questions": questions, + "by_question": by_question, "user_answers": dict(user_answers), "user_answers_marks": dict(user_answers_marks), "user_scores": user_scores, @@ -712,55 +718,60 @@ def cid_selector(request): "anatomy/cid_selector.html", ) -@login_required -def exam_scores(request, pk): - exam = get_object_or_404(Exam, pk=pk) +#@login_required +#def exam_scores(request, pk): + #exam = get_object_or_404(Exam, pk=pk) - questions = exam.exam_questions.all() + #questions = exam.exam_questions.all() - users = (CidUserAnswer.objects.filter( - question__in=questions).values_list("user").distinct()) + #users = (CidUserAnswer.objects.filter( + #question__in=questions).values_list("user").distinct()) - user_answers_and_marks = defaultdict(list) - user_answers_marks = defaultdict(list) - user_answers = defaultdict(list) - user_names = {} + #user_answers_and_marks = defaultdict(list) + #user_answers_marks = defaultdict(list) + #user_answers = defaultdict(list) + #user_names = {} - for u in users: - # Convoluted (probably...) - user_names[u] = User.objects.filter(pk=u[0]).first().get_username() - for q in questions: - user_answer = q.user_answers.filter(user__in=u).first() - if not user_answer: - user_answers_marks[u].append(0) - user_answers[u].append("") - continue + #by_question = defaultdict(list) - ans = user_answer.answer - answer_score = user_answer.get_answer_score() - user_answers[u].append(ans) - user_answers_marks[u].append(answer_score) - user_answers_and_marks[u].append((ans, answer_score)) + #for u in users: + ## Convoluted (probably...) + #user_names[u] = User.objects.filter(pk=u[0]).first().get_username() + #for q in questions: + #user_answer = q.user_answers.filter(user__in=u).first() + #if not user_answer: + #user_answers_marks[u].append(0) + #user_answers[u].append("") + #continue - user_scores = {} - for user in user_answers_marks: - user_scores[user] = sum(user_answers_marks[user]) + #ans = user_answer.answer + #answer_score = user_answer.get_answer_score() + #user_answers[u].append(ans) + #user_answers_marks[u].append(answer_score) + #user_answers_and_marks[u].append((ans, answer_score)) - total = len(questions) + #by_question[q].append(ans) - return render( - request, - "anatomy/exam_scores.html", - { - "exam": exam, - "questions": questions, - "user_answers": dict(user_answers), - "user_answers_marks": dict(user_answers_marks), - "user_scores": user_scores, - "user_names": user_names, - "user_answers_and_marks": user_answers_and_marks, - }, - ) + #user_scores = {} + #for user in user_answers_marks: + #user_scores[user] = sum(user_answers_marks[user]) + + #total = len(questions) + + #return render( + #request, + #"anatomy/exam_scores.html", + #{ + #"exam": exam, + #"questions": questions, + #"by_question": by_question, + #"user_answers": dict(user_answers), + #"user_answers_marks": dict(user_answers_marks), + #"user_scores": user_scores, + #"user_names": user_names, + #"user_answers_and_marks": user_answers_and_marks, + #}, + #) #def cid_scores(request, pk): # #exam = get_object_or_404(Exam, pk=pk)