diff --git a/anatomy/static/css/anatomy.css b/anatomy/static/css/anatomy.css index ed219ad5..72d3a53d 100644 --- a/anatomy/static/css/anatomy.css +++ b/anatomy/static/css/anatomy.css @@ -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; } \ No newline at end of file diff --git a/physics/models.py b/physics/models.py index 618d1af9..df435020 100644 --- a/physics/models.py +++ b/physics/models.py @@ -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) \ No newline at end of file + 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) \ No newline at end of file diff --git a/physics/templates/physics/exam_scores_user.html b/physics/templates/physics/exam_scores_user.html new file mode 100644 index 00000000..b3a52512 --- /dev/null +++ b/physics/templates/physics/exam_scores_user.html @@ -0,0 +1,23 @@ +{% extends 'physics/base.html' %} + +{% block content %} +
+

Exam: {{ exam.name }}

+

Candidate: {{ cid }}

+ Answers: + +
Total mark: {{ total_score }} / {{max_score}} +
+ Other exams +
+
+{% endblock %} \ No newline at end of file diff --git a/physics/templates/physics/exam_take.html b/physics/templates/physics/exam_take.html index 860d10fb..74a47840 100644 --- a/physics/templates/physics/exam_take.html +++ b/physics/templates/physics/exam_take.html @@ -21,32 +21,32 @@
  1. {{ question.a }}:
  2. {{ question.b }}:
  3. {{ question.c }}:
  4. {{ question.d }}:
  5. {{ question.e }}:
@@ -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; } {% endblock %} \ No newline at end of file diff --git a/physics/views.py b/physics/views.py index f7a82299..e63b0281 100644 --- a/physics/views.py +++ b/physics/views.py @@ -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,