start score table

This commit is contained in:
Ross
2020-12-18 17:48:08 +00:00
parent e4ac3bef19
commit 947959d4da
2 changed files with 82 additions and 49 deletions
@@ -20,6 +20,7 @@
{% endfor %}
<br /> Total mark: {{ user_scores|get_item:user }}
{% endfor %}
</div>
<div id="stats-block">
<h2>Stats</h2>
@@ -41,4 +42,25 @@
{% endfor %}
</table>
</div>
<div>
<h3>Answers as a table</h3>
<table>
<tr>
<th>Candidate</th>
{% for cid in cids %}
<th>{{cid}}</th>
{% endfor %}
</tr>
{% for question in questions %}
<tr>
<td>Question {{forloop.counter}}</td>
{% for ans in by_question|get_item:question %}
<td>{{ans}}</td>
{% endfor %}
</tr>
{% endfor %}
</table>
</div>
{% endblock %}
+52 -41
View File
@@ -577,6 +577,7 @@ def exam_scores_cid(request, pk):
user_answers = defaultdict(list)
user_names = {}
by_question = defaultdict(list)
unmarked = set()
# Loop through all candidates
@@ -590,6 +591,7 @@ def exam_scores_cid(request, pk):
# skip if no answer
user_answers_marks[cid].append(0)
user_answers[cid].append("")
by_question[q].append("")
continue
ans = s.answer
@@ -601,6 +603,8 @@ def exam_scores_cid(request, pk):
user_answers_marks[cid].append(answer_score)
user_answers_and_marks[cid].append((ans, answer_score))
by_question[q].append(ans)
user_scores = {}
for user in user_answers_marks:
user_scores[user] = sum([i for i in user_answers_marks[user] if i != "unmarked"])
@@ -630,9 +634,11 @@ def exam_scores_cid(request, pk):
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,
@@ -712,55 +718,60 @@ def cid_selector(request):
"anatomy/cid_selector.html",
)
@login_required
def exam_scores(request, pk):
exam = get_object_or_404(Exam, pk=pk)
#@login_required
#def exam_scores(request, pk):
#exam = get_object_or_404(Exam, pk=pk)
questions = exam.exam_questions.all()
#questions = exam.exam_questions.all()
users = (CidUserAnswer.objects.filter(
question__in=questions).values_list("user").distinct())
#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 = {}
#user_answers_and_marks = defaultdict(list)
#user_answers_marks = defaultdict(list)
#user_answers = defaultdict(list)
#user_names = {}
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
#by_question = defaultdict(list)
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))
#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
user_scores = {}
for user in user_answers_marks:
user_scores[user] = sum(user_answers_marks[user])
#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))
total = len(questions)
#by_question[q].append(ans)
return render(
request,
"anatomy/exam_scores.html",
{
"exam": exam,
"questions": questions,
"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,
},
)
#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)