diff options
Diffstat (limited to 'yaksh')
-rw-r--r-- | yaksh/forms.py | 4 | ||||
-rw-r--r-- | yaksh/models.py | 25 | ||||
-rw-r--r-- | yaksh/templates/yaksh/add_question.html | 1 | ||||
-rw-r--r-- | yaksh/templates/yaksh/question.html | 10 | ||||
-rw-r--r-- | yaksh/views.py | 6 |
5 files changed, 45 insertions, 1 deletions
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 @@ <option value="hooktestcase">Hook </option> <option value="integertestcase">Integer </option> <option value="stringtestcase"> String </option> + <option value="floattestcase"> Float </option> </select></p> <center> <button class="btn" type="submit" name="save_question">Save</button> diff --git a/yaksh/templates/yaksh/question.html b/yaksh/templates/yaksh/question.html index 13726c0..161db5a 100644 --- a/yaksh/templates/yaksh/question.html +++ b/yaksh/templates/yaksh/question.html @@ -153,6 +153,8 @@ function call_skip(url) (ANSWER IN INTEGER) {% elif question.type == "string" %} (ANSWER IN STRING) + {% elif question.type == "float" %} + (ANSWER IN DECIMAL) {% endif %} </u> <font class=pull-right>(Marks : {{ question.points }}) </font> @@ -175,7 +177,7 @@ function call_skip(url) {% if question.type == "integer" %} Enter Integer: <input name="answer" type="textbox" id="integer" /> - <br/> + <br/><br/> {% endif %} {% if question.type == "string" %} @@ -184,6 +186,12 @@ function call_skip(url) <br/><br/> {% endif %} + {% if question.type == "float" %} + Enter Decimal Value : + <input name="answer" type="textbox" id="float" /> + <br/><br/> + {% endif %} + {% if question.type == "mcc" %} {% for test_case in test_cases %} <input name="answer" type="checkbox" value="{{ test_case.options }}"> {{ test_case.options|safe }} diff --git a/yaksh/views.py b/yaksh/views.py index 6a19744..d067393 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -476,6 +476,12 @@ def check(request, q_id, attempt_num=None, questionpaper_id=None): except ValueError: msg = ["Please enter an Integer Value"] return show_question(request, current_question, paper, msg) + elif current_question.type == 'float': + try: + user_answer = float(request.POST.get('answer')) + except ValueError: + msg = ["Please enter a Decimal Value"] + return show_question(request, current_question, paper, msg) elif current_question.type == 'string': user_answer = str(request.POST.get('answer')) |