diff options
Diffstat (limited to 'yaksh/models.py')
-rw-r--r-- | yaksh/models.py | 74 |
1 files changed, 72 insertions, 2 deletions
diff --git a/yaksh/models.py b/yaksh/models.py index 2d84622..d60a377 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -36,10 +36,13 @@ languages = ( ) question_types = ( - ("mcq", "Multiple Choice"), + ("mcq", "Single Correct Choice"), ("mcc", "Multiple Correct Choices"), ("code", "Code"), ("upload", "Assignment Upload"), + ("integer", "Answer in Integer"), + ("string", "Answer in String"), + ("float", "Answer in Float"), ) enrollment_methods = ( @@ -52,6 +55,14 @@ test_case_types = ( ("stdiobasedtestcase", "StdIO Based Testcase"), ("mcqtestcase", "MCQ Testcase"), ("hooktestcase", "Hook Testcase"), + ("integertestcase", "Integer Testcase"), + ("stringtestcase", "String Testcase"), + ("floattestcase", "Float Testcase"), + ) + +string_check_type = ( + ("lower", "Case Insensitive"), + ("exact", "Case Sensitive"), ) attempts = [(i, i) for i in range(1, 6)] @@ -672,7 +683,6 @@ class QuestionPaper(models.Model): # Total marks for the question paper. total_marks = models.FloatField(default=0.0, blank=True) - objects = QuestionPaperManager() def update_total_marks(self): @@ -1133,6 +1143,30 @@ class AnswerPaper(models.Model): if set(user_answer) == set(expected_answers): result['success'] = True result['error'] = ['Correct answer'] + + elif question.type == 'integer': + expected_answer = question.get_test_case().correct + if expected_answer == int(user_answer): + result['success'] = True + result['error'] = ['Correct answer'] + + elif question.type == 'string': + testcase = question.get_test_case() + if testcase.string_check == "lower": + if testcase.correct.lower().splitlines() == user_answer.lower().splitlines(): + result['success'] = True + result['error'] = ['Correct answer'] + else: + if testcase.correct.splitlines() == user_answer.splitlines(): + result['success'] = True + result['error'] = ['Correct answer'] + + elif question.type == 'float': + testcase = question.get_test_case() + if abs(testcase.correct-user_answer) <= 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( @@ -1280,3 +1314,39 @@ class HookTestCase(TestCase): def __str__(self): return u'Hook Testcase | Correct: {0}'.format(self.hook_code) + +class IntegerTestCase(TestCase): + correct = models.IntegerField(default=None) + + def get_field_value(self): + return {"test_case_type": "integertestcase", "correct": self.correct} + + def __str__(self): + return u'Integer Testcase | Correct: {0}'.format(self.correct) + + +class StringTestCase(TestCase): + correct = models.TextField(default=None) + string_check = models.CharField(max_length=200,choices=string_check_type) + + def get_field_value(self): + return {"test_case_type": "stringtestcase", "correct": self.correct, + "string_check":self.string_check} + + 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 + ) |