From 84d02e947a8e63b397d7525ab873b51afeab678e Mon Sep 17 00:00:00 2001 From: Ross Date: Wed, 30 Mar 2022 21:36:27 +0100 Subject: [PATCH] . --- rapids/views.py | 231 ------------------------------------------------ 1 file changed, 231 deletions(-) diff --git a/rapids/views.py b/rapids/views.py index 11c6a31d..24636edf 100755 --- a/rapids/views.py +++ b/rapids/views.py @@ -585,123 +585,6 @@ def mark_review(request, exam_pk, sk): return mark(request, exam_pk, sk, unmarked_exam_answers_only=False, review=True) -@login_required -def exam_scores_cid2(request, pk): - exam = get_object_or_404(Exam, pk=pk) - - if not exam.exam_mode: - raise Http404("Packet not in exam mode") - - user_answers_and_marks = defaultdict(list) - user_answers_marks = defaultdict(list) - user_answers = defaultdict(list) - user_names = {} - - score_by_question = defaultdict(dict) - ans_by_question = defaultdict(dict) - unmarked = set() - - questions = exam.exam_questions.all() - - cid_user_answers = CidUserAnswer.objects.filter(question__in=questions, exam__id=pk) - - cids = set() - - # Loop through all candidates - for cid_user_answer in cid_user_answers: - # Convoluted (probably...) - cid = cid_user_answer.cid - cids.add(cid) - s = cid_user_answer - user_names[cid] = cid - - q = cid_user_answer.question - - # if not s: - # # skip if no answer - # user_answers_marks[cid].append(0) - # user_answers[cid].append("") - # by_question[q].append(("", 0)) - # continue - if s.normal: - ans = "Normal" - else: - 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)) - - score_by_question[q][cid] = answer_score - ans_by_question[q][cid] = ans - - user_scores = {} - user_scores_normalised = {} - for user in user_answers_marks: - user_scores[user] = sum( - [i for i in user_answers_marks[user] if i != "unmarked"] - ) - user_scores_normalised[user] = normaliseScore( - sum([i for i in user_answers_marks[user] if i != "unmarked"]) - ) - - 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) * 2 - - return render( - request, - "rapids/exam_scores_new.html", - { - "cids": sorted(cids), - "exam": exam, - "unmarked": unmarked, - "questions": questions, - "score_by_question": score_by_question, - "ans_by_question": ans_by_question, - "user_answers": dict(user_answers), - "user_answers_marks": dict(user_answers_marks), - "user_scores": user_scores, - "user_scores_normalised": user_scores_normalised, - "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, - }, - ) - - # @user_passes_test(user_is_admin, login_url="/accounts/login") @login_required def mark(request, exam_pk, sk, unmarked_exam_answers_only=True, review=False): @@ -855,120 +738,6 @@ def mark(request, exam_pk, sk, unmarked_exam_answers_only=True, review=False): ) -@login_required -def exam_scores_cid(request, pk): - 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().prefetch_related("answers") - - 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) - user_answers[cid].append("") - by_question[q].append(("", 0)) - continue - elif s.normal: - ans = "Normal" - else: - 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 = {} - user_scores_normalised = {} - for user in user_answers_marks: - user_scores[user] = sum( - [i for i in user_answers_marks[user] if i != "unmarked"] - ) - user_scores_normalised[user] = normaliseScore( - sum([i for i in user_answers_marks[user] if i != "unmarked"]) - ) - - 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) * 2 - - return render( - request, - "rapids/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_normalised": user_scores_normalised, - "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, cid, passcode): exam = get_object_or_404(Exam, pk=pk)