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
+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,
},
)