summaryrefslogtreecommitdiff
path: root/yaksh/models.py
diff options
context:
space:
mode:
authormaheshgudi2017-02-03 23:42:30 +0530
committermaheshgudi2017-03-02 20:38:41 +0530
commit321343d45bc1f4d20cd348773bd8b214d9c4d692 (patch)
treebae4022c3090cc78f4d421f4aa5afa40fd7beebd /yaksh/models.py
parentddf3e13669f7232acf6019a0f2f33f397a6e6d51 (diff)
downloadonline_test-321343d45bc1f4d20cd348773bd8b214d9c4d692.tar.gz
online_test-321343d45bc1f4d20cd348773bd8b214d9c4d692.tar.bz2
online_test-321343d45bc1f4d20cd348773bd8b214d9c4d692.zip
added float based questions
Diffstat (limited to 'yaksh/models.py')
-rw-r--r--yaksh/models.py25
1 files changed, 25 insertions, 0 deletions
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