From f5701e1c6ba3700b834257a4b84388485cb8818d Mon Sep 17 00:00:00 2001 From: maheshgudi Date: Thu, 5 Oct 2017 20:39:22 +0530 Subject: Use MCQ/MCC testcases id instead of options to validate answer --- yaksh/models.py | 6 +++--- yaksh/templates/yaksh/grade_user.html | 26 +++++++++++++++++++++----- yaksh/templates/yaksh/question.html | 12 ++++++------ yaksh/templates/yaksh/user_data.html | 18 ++++++++++++++++++ yaksh/templates/yaksh/view_answerpaper.html | 29 ++++++++++++++++++++++++----- yaksh/test_models.py | 4 ++-- yaksh/test_views.py | 10 +++++----- 7 files changed, 79 insertions(+), 26 deletions(-) diff --git a/yaksh/models.py b/yaksh/models.py index b5bde04..4859d3e 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -1321,15 +1321,15 @@ class AnswerPaper(models.Model): 'weight': 0.0} if user_answer is not None: if question.type == 'mcq': - expected_answer = question.get_test_case(correct=True).options - if user_answer.strip() == expected_answer.strip(): + expected_answer = question.get_test_case(correct=True).id + if user_answer.strip() == str(expected_answer).strip(): result['success'] = True result['error'] = ['Correct answer'] elif question.type == 'mcc': expected_answers = [] for opt in question.get_test_cases(correct=True): - expected_answers.append(opt.options) + expected_answers.append(str(opt.id)) if set(user_answer) == set(expected_answers): result['success'] = True result['error'] = ['Correct answer'] diff --git a/yaksh/templates/yaksh/grade_user.html b/yaksh/templates/yaksh/grade_user.html index 2038210..37bc788 100644 --- a/yaksh/templates/yaksh/grade_user.html +++ b/yaksh/templates/yaksh/grade_user.html @@ -236,7 +236,7 @@ Status : Passed
- +
Line No.
Expected Output
User output
@@ -256,7 +256,7 @@ Status : Passed
- + @@ -268,12 +268,28 @@ Status : Passed
- {% if question.type != "code" %} + {% if question.type == "code" %} +
{{ ans.answer.answer.strip|safe }}
+ {% elif question.type == "mcc"%}
- {{ ans.answer.answer.strip|safe }} + {% for testcases in question.get_test_cases %} + {%if testcases.id|stringformat:"i" in ans.answer.answer.strip|safe %} +
  • {{ testcases.options.strip|safe }}
  • + {% endif %} + {% endfor %} +
    + {% elif question.type == "mcq"%} +
    + {% for testcases in question.get_test_cases %} + {%if testcases.id|stringformat:"i" == ans.answer.answer.strip|safe %} +
  • {{ testcases.options.strip|safe }}
  • + {% endif %} + {% endfor %}
    {% else %} -
    {{ ans.answer.answer.strip|safe }}
    +
    + {{ ans.answer.answer.strip|safe }} +
    {% endif %}
    diff --git a/yaksh/templates/yaksh/question.html b/yaksh/templates/yaksh/question.html index bc7acf1..1e1f38f 100644 --- a/yaksh/templates/yaksh/question.html +++ b/yaksh/templates/yaksh/question.html @@ -153,11 +153,11 @@ lang = "{{ question.language }}"
    {% if question.type == "mcq" %} {% for test_case in test_cases %} - {% if last_attempt and last_attempt|safe == test_case.options|safe %} - + {% if last_attempt and last_attempt|safe == test_case.id|safe %} + {{ test_case.options|safe }}
    {% else %} - + {{ test_case.options|safe }}
    {% endif %} {% endfor %} @@ -183,11 +183,11 @@ lang = "{{ question.language }}" {% if question.type == "mcc" %} {% for test_case in test_cases %} - {% if last_attempt and test_case.options|safe in last_attempt|safe %} - {{ test_case.options }} + {% if last_attempt and test_case.id|safe in last_attempt|safe %} + {{ test_case.options }}
    {% else %} - + {{ test_case.options}}
    {% endif %} diff --git a/yaksh/templates/yaksh/user_data.html b/yaksh/templates/yaksh/user_data.html index a8adc22..31a023d 100644 --- a/yaksh/templates/yaksh/user_data.html +++ b/yaksh/templates/yaksh/user_data.html @@ -104,11 +104,29 @@ User IP address: {{ paper.user_ip }}
    Student answer:
    + {% if question.type == "mcc"%} +
    + {% for testcases in question.get_test_cases %} + {%if testcases.id|stringformat:"i" in answers.0.answer|safe %} +
  • {{ testcases.options.strip|safe }}
  • + {% endif %} + {% endfor %} +
    + {% elif question.type == "mcq"%} +
    + {% for testcases in question.get_test_cases %} + {%if testcases.id|stringformat:"i" == answers.0.answer|safe %} +
  • {{ testcases.options.strip|safe }}
  • + {% endif %} + {% endfor %} +
    + {%else%}
    {{ answers.0.answer|safe }}
    + {% endif %} {% else %}
    Student answer:
    {% for answer in answers %} diff --git a/yaksh/templates/yaksh/view_answerpaper.html b/yaksh/templates/yaksh/view_answerpaper.html index 9edff5a..850d789 100644 --- a/yaksh/templates/yaksh/view_answerpaper.html +++ b/yaksh/templates/yaksh/view_answerpaper.html @@ -82,16 +82,35 @@ Autocheck: {{ answers.0.error_list.0 }}
    -
    Student answer:
    -
    - {{ answers.0.answer|safe }} - {% if question.type == "upload" and has_user_assignment %} + {% if question.type == "mcc"%} +
    + {% for testcases in question.get_test_cases %} + {%if testcases.id|stringformat:"i" in answers.0.answer|safe %} +
  • {{ testcases.options.strip|safe }}
  • + {% endif %} + {% endfor %} +
    + {% elif question.type == "mcq"%} +
    + {% for testcases in question.get_test_cases %} + {%if testcases.id|stringformat:"i" == answers.0.answer|safe %} +
  • {{ testcases.options.strip|safe }}
  • + {% endif %} + {% endfor %} +
    + {% elif question.type == "upload" and has_user_assignment %} + + {% else %} +
    Student answer:
    +
    + {{ answers.0.answer|safe }} +
    + {% endif %}
    {% else %} diff --git a/yaksh/test_models.py b/yaksh/test_models.py index ac90c53..2c83024 100644 --- a/yaksh/test_models.py +++ b/yaksh/test_models.py @@ -592,7 +592,7 @@ class AnswerPaperTestCases(unittest.TestCase): def test_validate_and_regrade_mcc_correct_answer(self): # Given - mcc_answer = ['a'] + mcc_answer = [str(self.mcc_based_testcase.id)] self.answer = Answer(question=self.question3, answer=mcc_answer, ) @@ -629,7 +629,7 @@ class AnswerPaperTestCases(unittest.TestCase): def test_validate_and_regrade_mcq_correct_answer(self): # Given - mcq_answer = 'a' + mcq_answer = str(self.mcq_based_testcase.id) self.answer = Answer(question=self.question2, answer=mcq_answer, ) diff --git a/yaksh/test_views.py b/yaksh/test_views.py index 5ef97d6..2d86b77 100644 --- a/yaksh/test_views.py +++ b/yaksh/test_views.py @@ -3535,7 +3535,7 @@ class TestQuestionPaper(TestCase): ) # Given Wrong Answer - wrong_user_answer = "b" + wrong_user_answer = "25" # When self.client.post( @@ -3550,7 +3550,7 @@ class TestQuestionPaper(TestCase): self.assertEqual(wrong_answer_paper.marks_obtained, 0) # Given Right Answer - right_user_answer = "a" + right_user_answer = str(self.mcq_based_testcase.id) # When self.client.post( @@ -3575,7 +3575,7 @@ class TestQuestionPaper(TestCase): ) # Given Right Answer - right_user_answer = "a" + right_user_answer = str(self.mcq_based_testcase.id) # When self.client.post( @@ -3590,7 +3590,7 @@ class TestQuestionPaper(TestCase): self.assertEqual(updated_answerpaper.marks_obtained, 1) # Given Wrong Answer - wrong_user_answer = "b" + wrong_user_answer = "25" # When self.client.post( @@ -3615,7 +3615,7 @@ class TestQuestionPaper(TestCase): ) # Given Right Answer - right_user_answer = "a" + right_user_answer = str(self.mcc_based_testcase.id) # When self.client.post( -- cgit
    Error: {{error.error_msg}}