From 2c5982b66953faa689bd02052faca8fa45efef77 Mon Sep 17 00:00:00 2001 From: Ross Date: Sat, 18 Dec 2021 20:30:48 +0000 Subject: [PATCH] start removing old score method --- .../templates/anatomy/exam_scores_new.html | 2 +- generic/views.py | 124 ------------------ 2 files changed, 1 insertion(+), 125 deletions(-) diff --git a/anatomy/templates/anatomy/exam_scores_new.html b/anatomy/templates/anatomy/exam_scores_new.html index fa0924b5..2ad3b17a 100644 --- a/anatomy/templates/anatomy/exam_scores_new.html +++ b/anatomy/templates/anatomy/exam_scores_new.html @@ -29,7 +29,7 @@ Candidate ID Score - Normalised Score + {% comment %} Normalised Score {% endcomment %} {% comment %} {% for user, value in user_answers_marks.items %} {% endcomment %} {% for cid in cids %} diff --git a/generic/views.py b/generic/views.py index 2da566e9..5bd65f24 100644 --- a/generic/views.py +++ b/generic/views.py @@ -993,130 +993,6 @@ class ExamViews(View, LoginRequiredMixin): }, ) - def exam_scores_cid(self, request, pk): - exam = get_object_or_404(self.Exam, pk=pk) - - if request.user not in exam.author.all(): - if not self.check_user_access(request.user, pk): - raise PermissionDenied - - if not exam.exam_mode: - raise Http404("Packet not in exam mode") - - questions = exam.exam_questions.all() - - cids = ( - self.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) - user_answers[cid].append("") - by_question[q].append(("", 0)) - continue - - ans = s.answer - answer_score = s.get_answer_score() - if answer_score == "unmarked": - index = exam.get_question_index(q) - unmarked.add(index) - user_answers[cid].append(ans) - user_answers_marks[cid].append(answer_score) - user_answers_and_marks[cid].append((ans, answer_score)) - - by_question[q].append((ans, answer_score)) - - user_scores = {} - for user in user_answers_marks: - user_scores[user] = sum( - [i for i in user_answers_marks[user] if i != "unmarked"] - ) - - user_scores_list = list(user_scores.values()) - - max_score = len(questions) * 2 - - 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() - - exam.stats_mean = mean - exam.stats_median = median - exam.stats_mode = mode - - exam.stats_candidates = len(user_scores_list) - exam.stats_max_possible = max_score - - exam.stats_min = min(user_scores_list) - exam.stats_max = max(user_scores_list) - - exam.stats_graph = fig_html - exam.save() - - - - return render( - request, - f"{self.app_name}/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, - }, - ) - class GenericViewBase: def __init__(self, app_name, QuestionObject, CidUserAnswerObject, ExamObject):