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
+30 -8
View File
@@ -7,19 +7,20 @@
{% if unmarked %} {% if unmarked %}
The following questions need marking The following questions need marking
{% for exam_index in unmarked %} {% for exam_index in unmarked %}
<a href="{% url 'anatomy:mark' exam.pk exam_index %}">{{ exam_index|add:1 }}</a> <a href="{% url 'anatomy:mark' exam.pk exam_index %}">{{ exam_index|add:1 }}</a>
{% endfor %} {% endfor %}
{% endif %} {% endif %}
{% for user, value in user_answers_marks.items %} {% for user, value in user_answers_marks.items %}
<h3>Candidate: <a href="{% url 'cid_scores' user %}">{{ user_names|get_item:user }}</a></h3> <h3>Candidate: <a href="{% url 'cid_scores' user %}">{{ user_names|get_item:user }}</a></h3>
<!-- Answers: {{ user_answers_and_marks|get_item:user }}--> <!-- Answers: {{ user_answers_and_marks|get_item:user }}-->
Answers: {% for ans, score in user_answers_and_marks|get_item:user %} Answers: {% for ans, score in user_answers_and_marks|get_item:user %}
{{ans}} ({{score}}), {{ans}} ({{score}}),
{% endfor %} {% endfor %}
<br /> Total mark: {{ user_scores|get_item:user }} <br /> Total mark: {{ user_scores|get_item:user }}
{% endfor %} {% endfor %}
</div> </div>
<div id="stats-block"> <div id="stats-block">
<h2>Stats</h2> <h2>Stats</h2>
@@ -41,4 +42,25 @@
{% endfor %} {% endfor %}
</table> </table>
</div> </div>
{% endblock %} <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_answers = defaultdict(list)
user_names = {} user_names = {}
by_question = defaultdict(list)
unmarked = set() unmarked = set()
# Loop through all candidates # Loop through all candidates
@@ -590,6 +591,7 @@ def exam_scores_cid(request, pk):
# skip if no answer # skip if no answer
user_answers_marks[cid].append(0) user_answers_marks[cid].append(0)
user_answers[cid].append("") user_answers[cid].append("")
by_question[q].append("")
continue continue
ans = s.answer ans = s.answer
@@ -601,6 +603,8 @@ def exam_scores_cid(request, pk):
user_answers_marks[cid].append(answer_score) user_answers_marks[cid].append(answer_score)
user_answers_and_marks[cid].append((ans, answer_score)) user_answers_and_marks[cid].append((ans, answer_score))
by_question[q].append(ans)
user_scores = {} user_scores = {}
for user in user_answers_marks: for user in user_answers_marks:
user_scores[user] = sum([i for i in user_answers_marks[user] if i != "unmarked"]) 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, request,
"anatomy/exam_scores.html", "anatomy/exam_scores.html",
{ {
"cids": cids,
"exam": exam, "exam": exam,
"unmarked": unmarked, "unmarked": unmarked,
"questions": questions, "questions": questions,
"by_question": by_question,
"user_answers": dict(user_answers), "user_answers": dict(user_answers),
"user_answers_marks": dict(user_answers_marks), "user_answers_marks": dict(user_answers_marks),
"user_scores": user_scores, "user_scores": user_scores,
@@ -712,55 +718,60 @@ def cid_selector(request):
"anatomy/cid_selector.html", "anatomy/cid_selector.html",
) )
@login_required #@login_required
def exam_scores(request, pk): #def exam_scores(request, pk):
exam = get_object_or_404(Exam, pk=pk) #exam = get_object_or_404(Exam, pk=pk)
questions = exam.exam_questions.all() #questions = exam.exam_questions.all()
users = (CidUserAnswer.objects.filter( #users = (CidUserAnswer.objects.filter(
question__in=questions).values_list("user").distinct()) #question__in=questions).values_list("user").distinct())
user_answers_and_marks = defaultdict(list) #user_answers_and_marks = defaultdict(list)
user_answers_marks = defaultdict(list) #user_answers_marks = defaultdict(list)
user_answers = defaultdict(list) #user_answers = defaultdict(list)
user_names = {} #user_names = {}
for u in users: #by_question = defaultdict(list)
# 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 #for u in users:
answer_score = user_answer.get_answer_score() ## Convoluted (probably...)
user_answers[u].append(ans) #user_names[u] = User.objects.filter(pk=u[0]).first().get_username()
user_answers_marks[u].append(answer_score) #for q in questions:
user_answers_and_marks[u].append((ans, answer_score)) #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 = {} #ans = user_answer.answer
for user in user_answers_marks: #answer_score = user_answer.get_answer_score()
user_scores[user] = sum(user_answers_marks[user]) #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( #user_scores = {}
request, #for user in user_answers_marks:
"anatomy/exam_scores.html", #user_scores[user] = sum(user_answers_marks[user])
{
"exam": exam, #total = len(questions)
"questions": questions,
"user_answers": dict(user_answers), #return render(
"user_answers_marks": dict(user_answers_marks), #request,
"user_scores": user_scores, #"anatomy/exam_scores.html",
"user_names": user_names, #{
"user_answers_and_marks": user_answers_and_marks, #"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): #def cid_scores(request, pk):
# #exam = get_object_or_404(Exam, pk=pk) # #exam = get_object_or_404(Exam, pk=pk)