This commit is contained in:
Ross
2021-02-17 14:23:33 +00:00
parent c1f082abe1
commit 67ad358f2b
7 changed files with 75 additions and 52 deletions
@@ -0,0 +1,17 @@
# Generated by Django 3.1.3 on 2021-02-17 14:23
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('longs', '0023_auto_20210216_1315'),
]
operations = [
migrations.AlterModelOptions(
name='ciduseranswer',
options={'ordering': ['cid']},
),
]
+5 -5
View File
@@ -406,15 +406,15 @@ class CidUserAnswer(models.Model):
class ScoreOptions(models.TextChoices):
UNMARKED = "", _("Unmarked")
FOUR = "4", _("4")
FOUR = 4, _("4")
FOUR_HALF = "4.5", _("4.5")
FIVE = "5", _("5")
FIVE = 5, _("5")
FIVE_HALF = "5.5", _("5.5")
SIX = "6", _("6")
SIX = 6, _("6")
SIX_HALF = "6.5", _("6.5")
SEVEN = "7", _("7")
SEVEN = 7, _("7")
SEVEN_HALF = "7.5", _("7.5")
EIGHT = "8", _("8")
EIGHT = 8, _("8")
score = models.CharField(
max_length=3, choices=ScoreOptions.choices, default=ScoreOptions.UNMARKED, blank=True
+1 -1
View File
@@ -49,7 +49,7 @@
<tr>
<td>Question {{forloop.counter}}</td>
{% for ans, score in by_question|get_item:question %}
<td class="user-answer-score-{{score}}" title="answer score: {{score}}">{{ans}}</td>
<td class="user-answer-score-{{score}}" title="answer score: {{score}}">{{score}}</td>
{% endfor %}
</tr>
{% endfor %}
+2 -2
View File
@@ -5,8 +5,8 @@
<h2>Exam: {{ exam.name }}</h2>
<h3>Candidate: {{ cid }}</h3>
Answers:
<ul>{% for ans, score, correct_answer in answers_and_marks %}
<li class="user-answer-li">Question {{forloop.counter}} - Correct answer: <span class="correct-answer">{{ correct_answer }}</span></li>
<ul>{% for score in answers_marks %}
<li class="user-answer-li">Question {{forloop.counter}}</li>
<span class="user-answer-score user-answer-score-{{score}}"><pre>{{ans}}</pre> ({{score}})</span>
{% endfor %}
</ul>
+22 -29
View File
@@ -787,27 +787,27 @@ def exam_scores_cid(request, pk):
s = q.cid_user_answers.filter(cid=cid).first()
if not s:
# skip if no answer
user_answers_marks[cid].append(0)
user_answers[cid].append("")
by_question[q].append(("", 0))
# skip if no answer, (score 4)
user_answers_marks[cid].append(4)
#user_answers[cid].append("")
by_question[q].append(("", 4))
continue
else:
ans = s.answer
ans = ""
answer_score = s.get_answer_score()
if answer_score == "unmarked":
if answer_score == "":
index = exam.get_question_index(q)
unmarked.add(index)
user_answers[cid].append(ans)
#user_answers[cid].append(ans)
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, 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"]
[float(i) for i in user_answers_marks[user] if i != ""]
)
user_scores_list = list(user_scores.values())
@@ -847,12 +847,12 @@ def exam_scores_cid(request, pk):
"unmarked": unmarked,
"questions": questions,
"by_question": by_question,
"user_answers": dict(user_answers),
#"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,
#"user_answers_and_marks": user_answers_and_marks,
"max_score": max_score,
"mean": mean,
"median": median,
@@ -870,9 +870,9 @@ def exam_scores_cid_user(request, pk, sk):
questions = exam.exam_questions.all()
answers_and_marks = []
#answers_and_marks = []
answers_marks = []
answers = []
#answers = []
for q in questions:
# Get user answer
@@ -881,28 +881,21 @@ def exam_scores_cid_user(request, pk, sk):
if not user_answer or user_answer is None:
# skip if no answer
answers_marks.append(0)
#answers_marks.append("")
#answers.append("")
answer_score = 0
ans = "Not answered"
answer_score = 4
#ans = "Not answered"
else:
if user_answer.normal:
ans = "Normal"
else:
ans = user_answer.answer
answer_score = user_answer.get_answer_score()
correct_answer = q.GetPrimaryAnswer()
if not exam.publish_results:
correct_answer = "*****"
answer_score = 0
answers.append(ans)
#answers.append(ans)
answers_marks.append(answer_score)
answers_and_marks.append((ans, answer_score, correct_answer))
#answers_and_marks.append((ans, answer_score, correct_answer))
if "unmarked" in answers_marks:
answered = [i for i in answers_marks if type(i) == int]
if "" in answers_marks:
answered = [int(i) for i in answers_marks if i != ""]
total_score = sum(answered)
unmarked_number = len(answers_marks) - len(answered)
total_score = "{} ({} unmarked)".format(total_score, unmarked_number)
@@ -918,11 +911,11 @@ def exam_scores_cid_user(request, pk, sk):
"exam": exam,
"cid": cid,
"questions": questions,
"answers": answers,
#"answers": answers,
"answers_marks": answers_marks,
"total_score": total_score,
"max_score": max_score,
"answers_and_marks": answers_and_marks,
#"answers_and_marks": answers_and_marks,
},
)