start removing old score method
This commit is contained in:
@@ -29,7 +29,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th>Candidate ID</th>
|
<th>Candidate ID</th>
|
||||||
<th>Score</th>
|
<th>Score</th>
|
||||||
<th>Normalised Score</th>
|
{% comment %} <th>Normalised Score</th> {% endcomment %}
|
||||||
</tr>
|
</tr>
|
||||||
{% comment %} {% for user, value in user_answers_marks.items %} {% endcomment %}
|
{% comment %} {% for user, value in user_answers_marks.items %} {% endcomment %}
|
||||||
{% for cid in cids %}
|
{% for cid in cids %}
|
||||||
|
|||||||
@@ -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:
|
class GenericViewBase:
|
||||||
def __init__(self, app_name, QuestionObject, CidUserAnswerObject, ExamObject):
|
def __init__(self, app_name, QuestionObject, CidUserAnswerObject, ExamObject):
|
||||||
|
|||||||
Reference in New Issue
Block a user