From 9c5464a6edaaf2aaafc0e42fe88c8734fd952e12 Mon Sep 17 00:00:00 2001 From: mahesh Date: Mon, 15 Jan 2018 17:40:06 +0530 Subject: Add shuffle testcases option to questions --- yaksh/models.py | 51 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 4 deletions(-) (limited to 'yaksh/models.py') diff --git a/yaksh/models.py b/yaksh/models.py index f065190..6ba4589 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -815,8 +815,14 @@ class Question(models.Model): min_time = models.IntegerField("time in minutes", default=0) + #Solution for the question. solution = models.TextField(blank=True) + # Shuffle testcase order. + shuffle_testcases = models.BooleanField("Shuffle testcase for each user", + default=False + ) + def consolidate_answer_data(self, user_answer, user=None): question_data = {} metadata = {} @@ -928,6 +934,17 @@ class Question(models.Model): return test_case + def get_ordered_test_cases(self, answerpaper): + try: + order = TestcaseOrder.objects.get(answer_paper=answerpaper, + question = self + ).testcase_order.split(",") + return [self.get_test_cases(id=int(tc_id))[0]\ + for tc_id in order + ] + except TestcaseOrder.DoesNotExist: + return self.get_test_cases() + def get_maximum_test_case_weight(self, **kwargs): max_weight = 0.0 for test_case in self.get_test_cases(): @@ -1197,7 +1214,17 @@ class QuestionPaper(models.Model): ans_paper.save() questions = self._get_questions_for_answerpaper() ans_paper.questions.add(*questions) - question_ids = [str(que.id) for que in questions] + question_ids = [] + for question in questions: + question_ids.append(str(question.id)) + testcases = question.get_test_cases() + if question.shuffle_testcases: + random.shuffle(testcases) + testcases_ids = ",".join([str(tc.id) for tc in testcases]) + testcases_order = TestcaseOrder.objects.create( + answer_paper=ans_paper, + question=question, + testcase_order=testcases_ids) ans_paper.questions_order = ",".join(question_ids) ans_paper.save() ans_paper.questions_unanswered.add(*questions) @@ -1829,7 +1856,7 @@ class AnswerPaper(models.Model): .format(u.first_name, u.last_name, q.description) -################################################################################ +############################################################################## class AssignmentUploadManager(models.Manager): def get_assignments(self, qp, que_id=None, user_id=None): @@ -1851,7 +1878,7 @@ class AssignmentUploadManager(models.Manager): return assignment_files, file_name -################################################################################ +############################################################################## class AssignmentUpload(models.Model): user = models.ForeignKey(User) assignmentQuestion = models.ForeignKey(Question) @@ -1860,7 +1887,7 @@ class AssignmentUpload(models.Model): objects = AssignmentUploadManager() -############################################################################### +############################################################################## class TestCase(models.Model): question = models.ForeignKey(Question, blank=True, null=True) type = models.CharField(max_length=24, choices=test_case_types, null=True) @@ -1978,3 +2005,19 @@ class FloatTestCase(TestCase): return u'Testcase | Correct: {0} | Error Margin: +or- {1}'.format( self.correct, self.error_margin ) + + +############################################################################## +class TestcaseOrder(models.Model): + """Testcase order contains a set of ordered test cases for a given question + for each user. + """ + + # Answerpaper of the user. + answer_paper= models.ForeignKey(AnswerPaper,related_name="answer_paper") + + # Question in an answerpaper. + question = models.ForeignKey(Question) + + #Order of the test case for a question. + testcase_order = models.TextField() -- cgit From 009d6fb6e373ec9e24bb13924372ad77b4e3ccc5 Mon Sep 17 00:00:00 2001 From: mahesh Date: Thu, 1 Feb 2018 15:05:47 +0530 Subject: Change TestcaseOrder to TestCaseOrder --- yaksh/models.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'yaksh/models.py') diff --git a/yaksh/models.py b/yaksh/models.py index 6ba4589..f823cda 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -936,13 +936,13 @@ class Question(models.Model): def get_ordered_test_cases(self, answerpaper): try: - order = TestcaseOrder.objects.get(answer_paper=answerpaper, + order = TestCaseOrder.objects.get(answer_paper=answerpaper, question = self - ).testcase_order.split(",") + ).order.split(",") return [self.get_test_cases(id=int(tc_id))[0]\ for tc_id in order ] - except TestcaseOrder.DoesNotExist: + except TestCaseOrder.DoesNotExist: return self.get_test_cases() def get_maximum_test_case_weight(self, **kwargs): @@ -1221,10 +1221,10 @@ class QuestionPaper(models.Model): if question.shuffle_testcases: random.shuffle(testcases) testcases_ids = ",".join([str(tc.id) for tc in testcases]) - testcases_order = TestcaseOrder.objects.create( + testcases_order = TestCaseOrder.objects.create( answer_paper=ans_paper, question=question, - testcase_order=testcases_ids) + order=testcases_ids) ans_paper.questions_order = ",".join(question_ids) ans_paper.save() ans_paper.questions_unanswered.add(*questions) @@ -2008,16 +2008,16 @@ class FloatTestCase(TestCase): ############################################################################## -class TestcaseOrder(models.Model): +class TestCaseOrder(models.Model): """Testcase order contains a set of ordered test cases for a given question for each user. """ # Answerpaper of the user. - answer_paper= models.ForeignKey(AnswerPaper,related_name="answer_paper") + answer_paper = models.ForeignKey(AnswerPaper, related_name="answer_paper") # Question in an answerpaper. question = models.ForeignKey(Question) #Order of the test case for a question. - testcase_order = models.TextField() + order = models.TextField() -- cgit From 366f9adce899b4cfd1e7a0e9a74dd5602fb0345a Mon Sep 17 00:00:00 2001 From: mahesh Date: Thu, 8 Feb 2018 15:19:27 +0530 Subject: Improve test cases for TestCaseOrder model --- 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 f823cda..0bb1e66 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -939,7 +939,7 @@ class Question(models.Model): order = TestCaseOrder.objects.get(answer_paper=answerpaper, question = self ).order.split(",") - return [self.get_test_cases(id=int(tc_id))[0]\ + return [self.get_test_case(id=int(tc_id)) for tc_id in order ] except TestCaseOrder.DoesNotExist: -- cgit From 140b6c6a06269cc39eae192605f623c7818e9260 Mon Sep 17 00:00:00 2001 From: mahesh Date: Fri, 16 Feb 2018 16:30:55 +0530 Subject: Add shuffle_testcases to QuestionPaper model instead of Question --- yaksh/models.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'yaksh/models.py') diff --git a/yaksh/models.py b/yaksh/models.py index 0bb1e66..8e0bb4d 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -818,10 +818,6 @@ class Question(models.Model): #Solution for the question. solution = models.TextField(blank=True) - # Shuffle testcase order. - shuffle_testcases = models.BooleanField("Shuffle testcase for each user", - default=False - ) def consolidate_answer_data(self, user_answer, user=None): question_data = {} @@ -1151,6 +1147,11 @@ class QuestionPaper(models.Model): # Sequence or Order of fixed questions fixed_question_order = models.CharField(max_length=255, blank=True) + # Shuffle testcase order. + shuffle_testcases = models.BooleanField("Shuffle testcase for each user", + default=True + ) + objects = QuestionPaperManager() def get_question_bank(self): @@ -1218,7 +1219,8 @@ class QuestionPaper(models.Model): for question in questions: question_ids.append(str(question.id)) testcases = question.get_test_cases() - if question.shuffle_testcases: + if self.shuffle_testcases and \ + question.type in ["mcq", "mcc"]: random.shuffle(testcases) testcases_ids = ",".join([str(tc.id) for tc in testcases]) testcases_order = TestCaseOrder.objects.create( -- cgit From 4a5463d753c9af41d85a6be33257012c17d2ab15 Mon Sep 17 00:00:00 2001 From: mahesh Date: Tue, 20 Feb 2018 12:41:59 +0530 Subject: TestCaseOrder created only mcc/mcq questions --- yaksh/models.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'yaksh/models.py') diff --git a/yaksh/models.py b/yaksh/models.py index 8e0bb4d..ecc0fc4 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -1218,15 +1218,17 @@ class QuestionPaper(models.Model): question_ids = [] for question in questions: question_ids.append(str(question.id)) - testcases = question.get_test_cases() if self.shuffle_testcases and \ question.type in ["mcq", "mcc"]: + testcases = question.get_test_cases() random.shuffle(testcases) - testcases_ids = ",".join([str(tc.id) for tc in testcases]) - testcases_order = TestCaseOrder.objects.create( + testcases_ids = ",".join([str(tc.id) for tc in testcases] + ) + testcases_order = TestCaseOrder.objects.create( answer_paper=ans_paper, question=question, order=testcases_ids) + ans_paper.questions_order = ",".join(question_ids) ans_paper.save() ans_paper.questions_unanswered.add(*questions) -- cgit