From 220a3a5fd8a4e638810ebcffc0b24e0d68d9b17f Mon Sep 17 00:00:00 2001 From: Ross Date: Sun, 19 Dec 2021 22:06:57 +0000 Subject: [PATCH] . --- generic/models.py | 2 +- physics/tables.py | 3 +- .../templates/physics/exam_scores_new.html | 4 +- physics/views.py | 118 +----------------- sbas/views.py | 2 +- 5 files changed, 8 insertions(+), 121 deletions(-) diff --git a/generic/models.py b/generic/models.py index bce76c02..a54fdd03 100644 --- a/generic/models.py +++ b/generic/models.py @@ -148,7 +148,7 @@ class ExamBase(models.Model): return authors def check_cid_user(self, cid, passcode, request=None): - if request is not None and request.user.is_superuser(): + if request is not None and request.user.is_superuser: return True if self.valid_users.exists(): diff --git a/physics/tables.py b/physics/tables.py index d42acdfc..408ec3de 100644 --- a/physics/tables.py +++ b/physics/tables.py @@ -51,7 +51,8 @@ class QuestionTable(tables.Table): # "c_answer", # "d_answer", # "e_answer", - "best_answer", + # "best_answer", + "feedback", "created_date", "category", "author", diff --git a/physics/templates/physics/exam_scores_new.html b/physics/templates/physics/exam_scores_new.html index 4584043f..17c77290 100644 --- a/physics/templates/physics/exam_scores_new.html +++ b/physics/templates/physics/exam_scores_new.html @@ -37,8 +37,8 @@ Candidate {% for cid in cids %} - {% comment %} {{cid}} {% endcomment %} - {{cid}} + {{cid}} + {% comment %} {{cid}} {% endcomment %} {% endfor %} diff --git a/physics/views.py b/physics/views.py index 9ac8222a..1862f67c 100644 --- a/physics/views.py +++ b/physics/views.py @@ -88,124 +88,10 @@ def active_exams(request): return render(request, "physics/available_exam_list.html", {"exams": active_exams}) -@login_required -def exam_scores_cid(request, pk): +def exam_scores_cid_user(request, pk, cid, passcode): exam = get_object_or_404(Exam, pk=pk) - if not exam.exam_mode: - raise Http404("Packet not in exam mode") - - questions = exam.exam_questions.all() - - cids = ( - CidUserAnswer.objects.filter(question__in=questions, exam__id=pk) - .order_by("cid") - .values_list("cid", flat=True) - .distinct() - ) - - user_answers_and_marks = defaultdict(list) - user_answers_marks = defaultdict(list) - user_answers = defaultdict(list) - user_names = {} - - by_question = defaultdict(list) - unmarked = set() - - # Loop through all candidates - for cid in cids: - # Convoluted (probably...) - user_names[cid] = cid - for q in questions: - # Get user answer - s = q.cid_user_answers.filter(cid=cid, exam__id=pk).first() - if not s: - # skip if no answer - user_answers_marks[cid].append((0, 0, 0, 0, 0)) - user_answers[cid].append(("", "", "", "", "")) - by_question[q].append( - ( - ("", 0), - ("", 0), - ("", 0), - ("", 0), - ("", 0), - ) - ) - continue - - ans = s.get_answers() - answer_scores = s.get_answer_score() - - user_answers[cid].append(ans) - user_answers_marks[cid].append(answer_scores) - user_answers_and_marks[cid].append((ans, answer_scores)) - - zipped_ans_scores = zip(ans, answer_scores) - - by_question[q].append(zipped_ans_scores) - - user_scores = {} - for user in user_answers_marks: - user_scores[user] = sum([sum(i) for i in user_answers_marks[user]]) - - user_scores_list = list(user_scores.values()) - - if len(user_scores_list) < 1: - mean = 0 - median = 0 - mode = 0 - fig_html = "" - else: - mean = statistics.mean(user_scores_list) - median = statistics.median(user_scores_list) - try: - mode = statistics.mode(user_scores_list) - except statistics.StatisticsError: - mode = "No unique mode" - - df = user_scores_list - fig = px.histogram( - df, - x=0, - title="{}: distribution of scores".format(exam), - labels={"0": "Score"}, - height=400, - width=600, - ) - fig_html = fig.to_html() - - max_score = len(questions) - - return render( - request, - "physics/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, - "user_scores_list": user_scores_list, - "user_names": user_names, - "user_answers_and_marks": user_answers_and_marks, - "max_score": max_score, - "mean": mean, - "median": median, - "mode": mode, - "plot": fig_html, - }, - ) - - -def exam_scores_cid_user(request, pk, sk, passcode): - exam = get_object_or_404(Exam, pk=pk) - - cid = sk - if not exam.check_cid_user(cid, passcode): + if not exam.check_cid_user(cid, passcode, request): raise Http404("Error accessing exam") questions = exam.exam_questions.all() diff --git a/sbas/views.py b/sbas/views.py index 61df8f89..be3f74c8 100644 --- a/sbas/views.py +++ b/sbas/views.py @@ -105,7 +105,7 @@ def exam_scores_cid_user(request, pk, cid, passcode): answer_score = 0 ans = "" else: - answer_score = user_answer.get_score() + answer_score = user_answer.get_answer_score() ans = user_answer.get_answer() correct_answer = q.get_correct_answer()