From 321343d45bc1f4d20cd348773bd8b214d9c4d692 Mon Sep 17 00:00:00 2001 From: maheshgudi Date: Fri, 3 Feb 2017 23:42:30 +0530 Subject: added float based questions --- yaksh/forms.py | 4 ++++ yaksh/models.py | 25 +++++++++++++++++++++++++ yaksh/templates/yaksh/add_question.html | 1 + yaksh/templates/yaksh/question.html | 10 +++++++++- yaksh/views.py | 6 ++++++ 5 files changed, 45 insertions(+), 1 deletion(-) diff --git a/yaksh/forms.py b/yaksh/forms.py index df590de..fdc881f 100644 --- a/yaksh/forms.py +++ b/yaksh/forms.py @@ -36,6 +36,8 @@ question_types = ( ("code", "Code"), ("upload", "Assignment Upload"), ("integer", "Answer in Integer"), + ("string", "Answer in String"), + ("float", "Answer in Decimal"), ) test_case_types = ( @@ -44,6 +46,8 @@ test_case_types = ( ("mcqtestcase", "MCQ Testcase"), ("hooktestcase", "Hook Testcase"), ("integertestcase", "Integer Testcase"), + ("stringtestcase", "String Testcase"), + ("floattestcase", "Float Testcase"), ) UNAME_CHARS = letters + "._" + digits diff --git a/yaksh/models.py b/yaksh/models.py index 6381d4b..12c4a1c 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -42,6 +42,7 @@ question_types = ( ("upload", "Assignment Upload"), ("integer", "Answer in Integer"), ("string", "Answer in String"), + ("float", "Answer in Decimal"), ) enrollment_methods = ( @@ -56,6 +57,7 @@ test_case_types = ( ("hooktestcase", "Hook Testcase"), ("integertestcase", "Integer Testcase"), ("stringtestcase", "String Testcase"), + ("floattestcase", "Float Testcase"), ) string_check_type = ( @@ -1160,6 +1162,14 @@ class AnswerPaper(models.Model): result['success'] = True result['error'] = ['Correct answer'] + elif question.type == 'float': + testcase = question.get_test_case() + if testcase.correct-testcase.error_margin\ + <= float(user_answer)\ + <= testcase.correct+testcase.error_margin: + result['success'] = True + result['error'] = ['Correct answer'] + elif question.type == 'code': user_dir = self.user.profile.get_user_dir() json_result = code_server.run_code( @@ -1328,3 +1338,18 @@ class StringTestCase(TestCase): def __str__(self): return u'String Testcase | Correct: {0}'.format(self.correct) + + +class FloatTestCase(TestCase): + correct = models.FloatField(default=None) + error_margin = models.FloatField(default=0.0, null=True, blank=True, + help_text="Margin of error") + + def get_field_value(self): + return {"test_case_type": "floattestcase", "correct": self.correct, + "error_margin":self.error_margin} + + def __str__(self): + return u'Testcase | Correct: {0} | Error Margin: +or- {1}'.format(self.correct, + self.error_margin + ) \ No newline at end of file diff --git a/yaksh/templates/yaksh/add_question.html b/yaksh/templates/yaksh/add_question.html index de3ce56..6bd96d3 100644 --- a/yaksh/templates/yaksh/add_question.html +++ b/yaksh/templates/yaksh/add_question.html @@ -58,6 +58,7 @@ +