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
+11 -1
View File
@@ -95,7 +95,7 @@ button a {
color: inherit;
}
#admin-link, #logout-link, #profile-link {
#admin-link, #logout-link, #profile-link, #physics-link, #anatomy-link {
float: right;
padding-left: 10px;
}
@@ -327,6 +327,7 @@ img.uploading:hover {
#full-question-list-physics .abcde li {
padding: 0px;
clear: right;
vertical-align: text-top;
}
#full-question-list-physics li {
@@ -335,7 +336,16 @@ img.uploading:hover {
#full-question-list-physics {
width: 800px;
user-select: none;
-moz-user-select: none;
-webkit-user-select: none;
}
.answer-1 {
color: green;
}
.answer-0 {
color: red;
}
+41 -1
View File
@@ -92,6 +92,13 @@ class Question(models.Model):
if self.e:
self.e = self.e.strip()
def get_answers(self):
return (self.a_answer, self.b_answer, self.c_answer, self.d_answer, self.e_answer)
def get_questions(self):
return (self.a, self.b, self.c, self.d, self.e)
class Exam(models.Model):
name = models.CharField(max_length=200)
exam_questions = SortedManyToManyField(
@@ -142,4 +149,37 @@ class CidUserAnswer(models.Model):
updated = models.DateTimeField(auto_now=True)
def __str__(self):
return "{}/{}/{}".format(self.cid, self.exam, self.question.pk)
return "{}/{}/{}".format(self.cid, self.exam, self.question.pk)
def get_answers(self):
return (self.a, self.b, self.c, self.d, self.e)
def get_answer_scores(self):
q = self.question
if self.a == q.a_answer:
score_a = 1
else:
score_a = 0
if self.b == q.b_answer:
score_b = 1
else:
score_b = 0
if self.c == q.c_answer:
score_c = 1
else:
score_c = 0
if self.d == q.d_answer:
score_d = 1
else:
score_d = 0
if self.e == q.e_answer:
score_e = 1
else:
score_e = 0
return (score_a, score_b, score_c, score_d, score_e)
@@ -0,0 +1,23 @@
{% extends 'physics/base.html' %}
{% block content %}
<div class="physics">
<h2>Exam: {{ exam.name }}</h2>
<h3>Candidate: {{ cid }}</h3>
Answers:
<ul>
{% for question, ans in answers_and_marks %}
<li class="user-answer-li">Question {{forloop.counter}} - {{ question.stem }}</li>
<ol type="a">
{% for q, a, score, correct_answer in ans %}
<li>{{q}}: {{a}} <br />Correct answer: {{correct_answer}} <span class="answer-{{score}}">(Score: {{score}})</span></li>
{% endfor %}
</ol>
{% endfor %}
</ul>
<br /> Total mark: {{ total_score }} / {{max_score}}
<div>
<a href="{% url 'physics:cid_scores' cid %}">Other exams</a>
</div>
</div>
{% endblock %}
+60 -21
View File
@@ -21,32 +21,32 @@
<ol type="a" class="abcde">
<li>
<span class="question-text">{{ question.a }}:</span> <label class="truefalse-switch"> <input
type="checkbox" class="question" id="{{question.pk}}-a-checkbox" data-q="{{question.pk}}" data-a="a">
<div class="slider round"></div>
type="checkbox" class="question a" id="{{question.pk}}-a-checkbox" data-q="{{question.pk}}" data-a="a">
<div class="slider round a"></div>
</label>
</li>
<li>
<span class="question-text">{{ question.b }}:</span> <label class="truefalse-switch"> <input
type="checkbox" class="question" id="{{question.pk}}-b-checkbox" data-q="{{question.pk}}" data-a="b">
<div class="slider round"></div>
type="checkbox" class="question b" id="{{question.pk}}-b-checkbox" data-q="{{question.pk}}" data-a="b">
<div class="slider round b"></div>
</label>
</li>
<li>
<span class="question-text">{{ question.c }}:</span> <label class="truefalse-switch"> <input
type="checkbox" class="question" id="{{question.pk}}-c-checkbox" data-q="{{question.pk}}" data-a="c">
<div class="slider round"></div>
type="checkbox" class="question c" id="{{question.pk}}-c-checkbox" data-q="{{question.pk}}" data-a="c">
<div class="slider round c"></div>
</label>
</li>
<li>
<span class="question-text">{{ question.d }}:</span> <label class="truefalse-switch"> <input
type="checkbox" class="question" id="{{question.pk}}-d-checkbox" data-q="{{question.pk}}" data-a="d">
<div class="slider round"></div>
type="checkbox" class="question d" id="{{question.pk}}-d-checkbox" data-q="{{question.pk}}" data-a="d">
<div class="slider round d"></div>
</label>
</li>
<li>
<span class="question-text">{{ question.e }}:</span> <label class="truefalse-switch"> <input
type="checkbox" class="question" id="{{question.pk}}-e-checkbox" data-q="{{question.pk}}" data-a="e">
<div class="slider round"></div>
type="checkbox" class="question e" id="{{question.pk}}-e-checkbox" data-q="{{question.pk}}" data-a="e">
<div class="slider round e"></div>
</label>
</li>
</ol>
@@ -108,14 +108,13 @@ function postAnswers(ans) {
$.post("{% url 'physics:exam_answers_submit' %}", JSON.stringify(ans)).done((data) => {
console.log(data);
if (data.success) {
if (data.question_count == window.number_of_questions) {
let ret = confirm(
`${data.question_count} answers sucessfully submitted. Click OK to finish the exam.`
window.answers_submitted = true;
`Answers sucessfully submitted. Click OK to finish the exam.`
);
if (ret) {
window.saveSession();
window.answers_submitted = true;
if (config.exam_results_url != "") {
let url = config.exam_results_url;
@@ -131,9 +130,6 @@ function postAnswers(ans) {
$("#options-panel").show();
} else {
}
} else {
alert(`Answers sucessfully submitted.`);
}
} else {
alert(`Error submitting answers: ${data.error}`);
}
@@ -152,6 +148,7 @@ function postAnswers(ans) {
height: 20px;
margin: 0px;
margin-bottom: -5px;
float: right;
}
.truefalse-switch input {
@@ -165,7 +162,7 @@ function postAnswers(ans) {
left: 0;
right: 0;
bottom: 0;
background-color: rgba(255, 0, 0, 0.5);
background-color: rgba(0, 4, 255, 0.5);
-webkit-transition: .4s;
transition: .4s;
border-radius: 20px;
@@ -185,7 +182,7 @@ function postAnswers(ans) {
}
input:checked+.slider {
background-color: rgba(0, 255, 0, 0.5);
background-color: rgba(162, 0, 255, 0.5);
}
input:focus+.slider {
@@ -200,7 +197,6 @@ function postAnswers(ans) {
/*------ ADDED CSS ---------*/
.slider:after {
content: 'FALSE';
color: white;
display: block;
position: absolute;
@@ -211,12 +207,55 @@ function postAnswers(ans) {
font-family: Verdana, sans-serif;
}
input:checked+.slider:after {
content: 'TRUE';
.a.slider:after {
content: 'a) FALSE';
}
.b.slider:after {
content: 'b) FALSE';
}
.c.slider:after {
content: 'c) FALSE';
}
.d.slider:after {
content: 'd) FALSE';
}
.e.slider:after {
content: 'e) FALSE';
}
input:checked+.slider.a:after {
content: 'a )TRUE';
}
input:checked+.slider.b:after {
content: 'b )TRUE';
}
input:checked+.slider.c:after {
content: 'c )TRUE';
}
input:checked+.slider.d:after {
content: 'd )TRUE';
}
input:checked+.slider.e:after {
content: 'e )TRUE';
}
.question-text {
display: inline-block;
vertical-align: text-top;
clear: both;
width: 600px;
}
.abcde {
clear: both;
}
</style>
{% endblock %}
+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,