This commit is contained in:
Ross
2022-06-26 22:45:52 +01:00
parent 455be37922
commit e2c8f751f2
13 changed files with 108 additions and 705 deletions
-203
View File
@@ -399,126 +399,6 @@ def exam_scores_refresh(request, pk):
)
# @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()
#
# 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
#
# 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())
#
# 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
#
# 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,
# "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,
# "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)
@@ -589,89 +469,6 @@ def exam_scores_cid_user(request, pk, cid, passcode):
)
# @login_required
# def exam_scores(request, pk):
# exam = get_object_or_404(Exam, pk=pk)
# questions = exam.exam_questions.all()
# 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 = {}
# by_question = defaultdict(list)
# 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
# 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))
# by_question[q].append(ans)
# 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)
#
# # TODO:Need some kind of test for cid
# cid = pk
#
# #questions = exam.exam_questions.all()
# answers = CidUserAnswer.objects.filter(
# cid=cid)
#
#
# if not answers:
# raise Http404("cid not found")
#
# exam_ids = answers.values_list("exam").distinct()
#
# exams = Exam.objects.filter(id__in=exam_ids)
#
#
# return render(
# request,
# "anatomy/cid_scores.html",
# {
# "exams": exams,
# "cid": cid,
# },
# )
class AnatomyQuestionCreateBase(RevisionMixin, LoginRequiredMixin, CreateView):
model = AnatomyQuestion