fix physics scores

This commit is contained in:
Ross
2020-12-16 21:40:27 +00:00
parent 90f69c2c14
commit 2e91dff46f
5 changed files with 153 additions and 53 deletions
+18 -30
View File
@@ -154,18 +154,16 @@ def exam_scores_cid(request, pk):
user_answers[cid].append("")
continue
ans = s.answer
answer_score = s.get_answer_score()
if answer_score == "unmarked":
index = exam.get_question_index(q)
unmarked.add(index)
ans = s.get_answers()
answer_scores = s.get_answer_scores()
user_answers[cid].append(ans)
user_answers_marks[cid].append(answer_score)
user_answers_and_marks[cid].append((ans, answer_score))
user_answers_marks[cid].append(answer_scores)
user_answers_and_marks[cid].append((ans, answer_scores))
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[user] = sum([sum(i) for i in user_answers_marks[user]])
user_scores_list = list(user_scores.values())
@@ -223,35 +221,25 @@ def exam_scores_cid_user(request, pk, sk):
for q in questions:
# Get user answer
user_answer = q.cid_user_answers.filter(cid=cid).first()
if not user_answer:
# skip if no answer
answers_marks.append(0)
answers.append("")
answer_score = 0
ans = "Not answered"
else:
ans = user_answer.answer
answer_score = user_answer.get_answer_score()
ans = user_answer.get_answers()
correct_answer = q.GetPrimaryAnswer()
answer_scores = user_answer.get_answer_scores()
correct_answers = q.get_answers()
if not exam.publish_results:
correct_answer = "*****"
answer_score = 0
correct_answers = ("*****", "*****", "*****", "*****", "*****")
answer_scores = (0, 0, 0, 0, 0)
answers.append(ans)
answers_marks.append(answer_score)
answers_and_marks.append((ans, answer_score, correct_answer))
answers_marks.append(answer_scores)
if "unmarked" in answers_marks:
answered = [i for i in answers_marks if type(i) == int]
total_score = sum(answered)
unmarked_number = len(answers_marks) - len(answered)
total_score = "{} ({} unmarked)".format(total_score, unmarked_number)
else:
total_score = sum(answers_marks)
merged_ans = zip(q.get_questions(), ans, answer_scores, correct_answers)
answers_and_marks.append((q, merged_ans))
max_score = len(questions) * 2
total_score = sum(sum(i) for i in answers_marks)
max_score = len(questions) * 5
return render(
request,