From 80a4feef3c209e044e8cbe31e44c81d69136e100 Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Thu, 15 Dec 2016 16:34:18 +0530 Subject: Add further changes to code evaluator --- yaksh/models.py | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) (limited to 'yaksh/models.py') diff --git a/yaksh/models.py b/yaksh/models.py index 7fae305..4951836 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -255,6 +255,7 @@ class Question(models.Model): def consolidate_answer_data(self, user_answer): question_data = {} + metadata = {} test_case_data = [] test_cases = self.get_test_cases() @@ -264,12 +265,15 @@ class Question(models.Model): test_case_data.append(test_case_as_dict) question_data['test_case_data'] = test_case_data - question_data['user_answer'] = user_answer - question_data['partial_grading'] = self.partial_grading + metadata['user_answer'] = user_answer + metadata['language'] = self.language + metadata['partial_grading'] = self.partial_grading files = FileUpload.objects.filter(question=self) if files: - question_data['file_paths'] = [(file.file.path, file.extract) + metadata['file_paths'] = [(file.file.path, file.extract) for file in files] + question_data['metadata'] = metadata + return json.dumps(question_data) @@ -309,15 +313,20 @@ class Question(models.Model): delete_files(files_list, file_path) def get_test_cases(self, **kwargs): - test_case_ctype = ContentType.objects.get(app_label="yaksh", - model=self.test_case_type - ) - test_cases = test_case_ctype.get_all_objects_for_this_type( - question=self, - **kwargs - ) - - return test_cases + # test_case_ctype = ContentType.objects.get(app_label="yaksh", + # model=self.test_case_type + # ) + # test_cases = test_case_ctype.get_all_objects_for_this_type( + # question=self, + # **kwargs + # ) + tc_list = [] + for tc in self.testcase_set.all(): + tc_type = tc.type + obj = getattr(tc, tc_type) + tc_list.append(obj) + + return tc_list def get_test_case(self, **kwargs): test_case_ctype = ContentType.objects.get(app_label="yaksh", @@ -1137,7 +1146,8 @@ class StandardTestCase(TestCase): weight = models.FloatField(default=1.0) def get_field_value(self): - return {"test_case": self.test_case, + return {"test_case_type": "standardtestcase", + "test_case": self.test_case, "weight": self.weight} def __str__(self): @@ -1152,7 +1162,8 @@ class StdioBasedTestCase(TestCase): weight = models.IntegerField(default=1.0) def get_field_value(self): - return {"expected_output": self.expected_output, + return {"test_case_type": "stdiobasedtestcase", + "expected_output": self.expected_output, "expected_input": self.expected_input, "weight": self.weight} @@ -1167,7 +1178,7 @@ class McqTestCase(TestCase): correct = models.BooleanField(default=False) def get_field_value(self): - return {"options": self.options, "correct": self.correct} + return {"test_case_type": "mcqtestcase", "options": self.options, "correct": self.correct} def __str__(self): return u'Question: {0} | Correct: {1}'.format(self.question, -- cgit From 81d373983806b78d651e17b966bae0a8ccf3c4bb Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Mon, 19 Dec 2016 17:43:41 +0530 Subject: Fix model test cases --- yaksh/models.py | 56 ++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 44 insertions(+), 12 deletions(-) (limited to 'yaksh/models.py') diff --git a/yaksh/models.py b/yaksh/models.py index 4951836..272ec75 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -306,9 +306,13 @@ class Question(models.Model): que, result = Question.objects.get_or_create(**question) if file_names: que._add_files_to_db(file_names, file_path) - model_class = get_model_class(que.test_case_type) for test_case in test_cases: - model_class.objects.get_or_create(question=que, **test_case) + test_case_type = test_case.pop('test_case_type') + model_class = get_model_class(test_case_type) + # TestCase.objects.get_or_create(question=que, type=) + new_test_case, obj_create_status = model_class.objects.get_or_create(question=que, **test_case) + new_test_case.type = test_case_type + new_test_case.save() if files_list: delete_files(files_list, file_path) @@ -320,22 +324,50 @@ class Question(models.Model): # question=self, # **kwargs # ) + # tc_list = [] + # for tc in self.testcase_set.filter(**kwargs): + # tc_type = str(tc.type) + # obj = getattr(tc, tc_type) + # tc_list.append(obj) + + # return tc_list + tc_list = [] for tc in self.testcase_set.all(): - tc_type = tc.type - obj = getattr(tc, tc_type) - tc_list.append(obj) + test_case_type = tc.type + test_case_ctype = ContentType.objects.get(app_label="yaksh", + model=test_case_type + ) + test_case = test_case_ctype.get_object_for_this_type( + question=self, + **kwargs + ) + tc_list.append(test_case) return tc_list def get_test_case(self, **kwargs): - test_case_ctype = ContentType.objects.get(app_label="yaksh", - model=self.test_case_type - ) - test_case = test_case_ctype.get_object_for_this_type( - question=self, - **kwargs - ) + # test_case_ctype = ContentType.objects.get(app_label="yaksh", + # model=self.test_case_type + # ) + # test_case = test_case_ctype.get_object_for_this_type( + # question=self, + # **kwargs + # ) + # tc = self.testcase_set.get(**kwargs) + # tc_type = str(tc.type) + # test_case = getattr(tc, tc_type) + + # return test_case + for tc in self.testcase_set.all(): + test_case_type = tc.type + test_case_ctype = ContentType.objects.get(app_label="yaksh", + model=self.test_case_type + ) + test_case = test_case_ctype.get_object_for_this_type( + question=self, + **kwargs + ) return test_case -- cgit From 4a0f94084bc26559ef3e26470619e87314f9d70e Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Mon, 19 Dec 2016 19:18:35 +0530 Subject: Remove commented code --- yaksh/models.py | 28 ---------------------------- 1 file changed, 28 deletions(-) (limited to 'yaksh/models.py') diff --git a/yaksh/models.py b/yaksh/models.py index 272ec75..9ba85ba 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -309,7 +309,6 @@ class Question(models.Model): for test_case in test_cases: test_case_type = test_case.pop('test_case_type') model_class = get_model_class(test_case_type) - # TestCase.objects.get_or_create(question=que, type=) new_test_case, obj_create_status = model_class.objects.get_or_create(question=que, **test_case) new_test_case.type = test_case_type new_test_case.save() @@ -317,21 +316,6 @@ class Question(models.Model): delete_files(files_list, file_path) def get_test_cases(self, **kwargs): - # test_case_ctype = ContentType.objects.get(app_label="yaksh", - # model=self.test_case_type - # ) - # test_cases = test_case_ctype.get_all_objects_for_this_type( - # question=self, - # **kwargs - # ) - # tc_list = [] - # for tc in self.testcase_set.filter(**kwargs): - # tc_type = str(tc.type) - # obj = getattr(tc, tc_type) - # tc_list.append(obj) - - # return tc_list - tc_list = [] for tc in self.testcase_set.all(): test_case_type = tc.type @@ -347,18 +331,6 @@ class Question(models.Model): return tc_list def get_test_case(self, **kwargs): - # test_case_ctype = ContentType.objects.get(app_label="yaksh", - # model=self.test_case_type - # ) - # test_case = test_case_ctype.get_object_for_this_type( - # question=self, - # **kwargs - # ) - # tc = self.testcase_set.get(**kwargs) - # tc_type = str(tc.type) - # test_case = getattr(tc, tc_type) - - # return test_case for tc in self.testcase_set.all(): test_case_type = tc.type test_case_ctype = ContentType.objects.get(app_label="yaksh", -- cgit From bf5b4e7607bae0b81ceeb99e8bf5d750433e92e8 Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Tue, 20 Dec 2016 12:42:44 +0530 Subject: Fix errors and rename resources - code_evaluator module and class renamed to grader - Test cases fixed - Comments removed - weight variable renamed to mark --- yaksh/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'yaksh/models.py') diff --git a/yaksh/models.py b/yaksh/models.py index 9ba85ba..6e1744c 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -1160,7 +1160,7 @@ class StandardTestCase(TestCase): ) -class StdioBasedTestCase(TestCase): +class StdIOBasedTestCase(TestCase): expected_input = models.CharField(max_length=100, blank=True) expected_output = models.CharField(max_length=100) weight = models.IntegerField(default=1.0) -- cgit