fix physics scores
This commit is contained in:
@@ -95,7 +95,7 @@ button a {
|
|||||||
color: inherit;
|
color: inherit;
|
||||||
}
|
}
|
||||||
|
|
||||||
#admin-link, #logout-link, #profile-link {
|
#admin-link, #logout-link, #profile-link, #physics-link, #anatomy-link {
|
||||||
float: right;
|
float: right;
|
||||||
padding-left: 10px;
|
padding-left: 10px;
|
||||||
}
|
}
|
||||||
@@ -327,6 +327,7 @@ img.uploading:hover {
|
|||||||
#full-question-list-physics .abcde li {
|
#full-question-list-physics .abcde li {
|
||||||
padding: 0px;
|
padding: 0px;
|
||||||
clear: right;
|
clear: right;
|
||||||
|
vertical-align: text-top;
|
||||||
}
|
}
|
||||||
|
|
||||||
#full-question-list-physics li {
|
#full-question-list-physics li {
|
||||||
@@ -335,7 +336,16 @@ img.uploading:hover {
|
|||||||
|
|
||||||
|
|
||||||
#full-question-list-physics {
|
#full-question-list-physics {
|
||||||
|
width: 800px;
|
||||||
user-select: none;
|
user-select: none;
|
||||||
-moz-user-select: none;
|
-moz-user-select: none;
|
||||||
-webkit-user-select: none;
|
-webkit-user-select: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.answer-1 {
|
||||||
|
color: green;
|
||||||
|
}
|
||||||
|
|
||||||
|
.answer-0 {
|
||||||
|
color: red;
|
||||||
}
|
}
|
||||||
+41
-1
@@ -92,6 +92,13 @@ class Question(models.Model):
|
|||||||
if self.e:
|
if self.e:
|
||||||
self.e = self.e.strip()
|
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):
|
class Exam(models.Model):
|
||||||
name = models.CharField(max_length=200)
|
name = models.CharField(max_length=200)
|
||||||
exam_questions = SortedManyToManyField(
|
exam_questions = SortedManyToManyField(
|
||||||
@@ -142,4 +149,37 @@ class CidUserAnswer(models.Model):
|
|||||||
updated = models.DateTimeField(auto_now=True)
|
updated = models.DateTimeField(auto_now=True)
|
||||||
|
|
||||||
def __str__(self):
|
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 %}
|
||||||
@@ -21,32 +21,32 @@
|
|||||||
<ol type="a" class="abcde">
|
<ol type="a" class="abcde">
|
||||||
<li>
|
<li>
|
||||||
<span class="question-text">{{ question.a }}:</span> <label class="truefalse-switch"> <input
|
<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">
|
type="checkbox" class="question a" id="{{question.pk}}-a-checkbox" data-q="{{question.pk}}" data-a="a">
|
||||||
<div class="slider round"></div>
|
<div class="slider round a"></div>
|
||||||
</label>
|
</label>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<span class="question-text">{{ question.b }}:</span> <label class="truefalse-switch"> <input
|
<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">
|
type="checkbox" class="question b" id="{{question.pk}}-b-checkbox" data-q="{{question.pk}}" data-a="b">
|
||||||
<div class="slider round"></div>
|
<div class="slider round b"></div>
|
||||||
</label>
|
</label>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<span class="question-text">{{ question.c }}:</span> <label class="truefalse-switch"> <input
|
<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">
|
type="checkbox" class="question c" id="{{question.pk}}-c-checkbox" data-q="{{question.pk}}" data-a="c">
|
||||||
<div class="slider round"></div>
|
<div class="slider round c"></div>
|
||||||
</label>
|
</label>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<span class="question-text">{{ question.d }}:</span> <label class="truefalse-switch"> <input
|
<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">
|
type="checkbox" class="question d" id="{{question.pk}}-d-checkbox" data-q="{{question.pk}}" data-a="d">
|
||||||
<div class="slider round"></div>
|
<div class="slider round d"></div>
|
||||||
</label>
|
</label>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<span class="question-text">{{ question.e }}:</span> <label class="truefalse-switch"> <input
|
<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">
|
type="checkbox" class="question e" id="{{question.pk}}-e-checkbox" data-q="{{question.pk}}" data-a="e">
|
||||||
<div class="slider round"></div>
|
<div class="slider round e"></div>
|
||||||
</label>
|
</label>
|
||||||
</li>
|
</li>
|
||||||
</ol>
|
</ol>
|
||||||
@@ -108,14 +108,13 @@ function postAnswers(ans) {
|
|||||||
$.post("{% url 'physics:exam_answers_submit' %}", JSON.stringify(ans)).done((data) => {
|
$.post("{% url 'physics:exam_answers_submit' %}", JSON.stringify(ans)).done((data) => {
|
||||||
console.log(data);
|
console.log(data);
|
||||||
if (data.success) {
|
if (data.success) {
|
||||||
if (data.question_count == window.number_of_questions) {
|
|
||||||
let ret = confirm(
|
let ret = confirm(
|
||||||
`${data.question_count} answers sucessfully submitted. Click OK to finish the exam.`
|
`Answers sucessfully submitted. Click OK to finish the exam.`
|
||||||
window.answers_submitted = true;
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if (ret) {
|
if (ret) {
|
||||||
window.saveSession();
|
window.saveSession();
|
||||||
|
window.answers_submitted = true;
|
||||||
if (config.exam_results_url != "") {
|
if (config.exam_results_url != "") {
|
||||||
let url = config.exam_results_url;
|
let url = config.exam_results_url;
|
||||||
|
|
||||||
@@ -131,9 +130,6 @@ function postAnswers(ans) {
|
|||||||
$("#options-panel").show();
|
$("#options-panel").show();
|
||||||
} else {
|
} else {
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
alert(`Answers sucessfully submitted.`);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
alert(`Error submitting answers: ${data.error}`);
|
alert(`Error submitting answers: ${data.error}`);
|
||||||
}
|
}
|
||||||
@@ -152,6 +148,7 @@ function postAnswers(ans) {
|
|||||||
height: 20px;
|
height: 20px;
|
||||||
margin: 0px;
|
margin: 0px;
|
||||||
margin-bottom: -5px;
|
margin-bottom: -5px;
|
||||||
|
float: right;
|
||||||
}
|
}
|
||||||
|
|
||||||
.truefalse-switch input {
|
.truefalse-switch input {
|
||||||
@@ -165,7 +162,7 @@ function postAnswers(ans) {
|
|||||||
left: 0;
|
left: 0;
|
||||||
right: 0;
|
right: 0;
|
||||||
bottom: 0;
|
bottom: 0;
|
||||||
background-color: rgba(255, 0, 0, 0.5);
|
background-color: rgba(0, 4, 255, 0.5);
|
||||||
-webkit-transition: .4s;
|
-webkit-transition: .4s;
|
||||||
transition: .4s;
|
transition: .4s;
|
||||||
border-radius: 20px;
|
border-radius: 20px;
|
||||||
@@ -185,7 +182,7 @@ function postAnswers(ans) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
input:checked+.slider {
|
input:checked+.slider {
|
||||||
background-color: rgba(0, 255, 0, 0.5);
|
background-color: rgba(162, 0, 255, 0.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
input:focus+.slider {
|
input:focus+.slider {
|
||||||
@@ -200,7 +197,6 @@ function postAnswers(ans) {
|
|||||||
|
|
||||||
/*------ ADDED CSS ---------*/
|
/*------ ADDED CSS ---------*/
|
||||||
.slider:after {
|
.slider:after {
|
||||||
content: 'FALSE';
|
|
||||||
color: white;
|
color: white;
|
||||||
display: block;
|
display: block;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
@@ -211,12 +207,55 @@ function postAnswers(ans) {
|
|||||||
font-family: Verdana, sans-serif;
|
font-family: Verdana, sans-serif;
|
||||||
}
|
}
|
||||||
|
|
||||||
input:checked+.slider:after {
|
.a.slider:after {
|
||||||
content: 'TRUE';
|
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 {
|
.question-text {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
|
vertical-align: text-top;
|
||||||
|
clear: both;
|
||||||
|
width: 600px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.abcde {
|
||||||
|
clear: both;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
+18
-30
@@ -154,18 +154,16 @@ def exam_scores_cid(request, pk):
|
|||||||
user_answers[cid].append("")
|
user_answers[cid].append("")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
ans = s.answer
|
ans = s.get_answers()
|
||||||
answer_score = s.get_answer_score()
|
answer_scores = s.get_answer_scores()
|
||||||
if answer_score == "unmarked":
|
|
||||||
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_marks[cid].append(answer_scores)
|
||||||
user_answers_and_marks[cid].append((ans, answer_score))
|
user_answers_and_marks[cid].append((ans, answer_scores))
|
||||||
|
|
||||||
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([sum(i) for i in user_answers_marks[user]])
|
||||||
|
|
||||||
user_scores_list = list(user_scores.values())
|
user_scores_list = list(user_scores.values())
|
||||||
|
|
||||||
@@ -223,35 +221,25 @@ def exam_scores_cid_user(request, pk, sk):
|
|||||||
for q in questions:
|
for q in questions:
|
||||||
# Get user answer
|
# Get user answer
|
||||||
user_answer = q.cid_user_answers.filter(cid=cid).first()
|
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:
|
if not exam.publish_results:
|
||||||
correct_answer = "*****"
|
correct_answers = ("*****", "*****", "*****", "*****", "*****")
|
||||||
answer_score = 0
|
answer_scores = (0, 0, 0, 0, 0)
|
||||||
answers.append(ans)
|
answers.append(ans)
|
||||||
answers_marks.append(answer_score)
|
answers_marks.append(answer_scores)
|
||||||
answers_and_marks.append((ans, answer_score, correct_answer))
|
|
||||||
|
|
||||||
if "unmarked" in answers_marks:
|
merged_ans = zip(q.get_questions(), ans, answer_scores, correct_answers)
|
||||||
answered = [i for i in answers_marks if type(i) == int]
|
answers_and_marks.append((q, merged_ans))
|
||||||
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)
|
|
||||||
|
|
||||||
max_score = len(questions) * 2
|
total_score = sum(sum(i) for i in answers_marks)
|
||||||
|
|
||||||
|
max_score = len(questions) * 5
|
||||||
|
|
||||||
return render(
|
return render(
|
||||||
request,
|
request,
|
||||||
|
|||||||
Reference in New Issue
Block a user