summaryrefslogtreecommitdiff
path: root/yaksh/models.py
diff options
context:
space:
mode:
authorankitjavalkar2016-03-16 10:57:07 +0530
committerankitjavalkar2016-05-05 19:00:33 +0530
commit195aead9b0fab0d8cdb86a9fc884ac3edca5db84 (patch)
tree107355d17a248504726aed93bf0e4cb490f190bf /yaksh/models.py
parent1e993bee18028c59d809f49d853b60e41326991c (diff)
downloadonline_test-195aead9b0fab0d8cdb86a9fc884ac3edca5db84.tar.gz
online_test-195aead9b0fab0d8cdb86a9fc884ac3edca5db84.tar.bz2
online_test-195aead9b0fab0d8cdb86a9fc884ac3edca5db84.zip
- Connect test case type models to backend code server
- Support for Stdout test case and Standard assertion test case - Add MCQ Test case and support for validations - Remove tester dir
Diffstat (limited to 'yaksh/models.py')
-rw-r--r--yaksh/models.py115
1 files changed, 71 insertions, 44 deletions
diff --git a/yaksh/models.py b/yaksh/models.py
index 6fa96bf..331446f 100644
--- a/yaksh/models.py
+++ b/yaksh/models.py
@@ -5,6 +5,7 @@ from itertools import islice, cycle
from collections import Counter
from django.db import models
from django.contrib.auth.models import User
+from django.forms.models import model_to_dict
from taggit.managers import TaggableManager
@@ -31,9 +32,9 @@ enrollment_methods = (
)
test_case_types = (
- ("assert_based", "Assertion Based Testcase"),
- # ("argument_based", "Multiple Correct Choices"),
- ("stdout_based", "Stdout Based Testcase"),
+ ("standardtestcase", "Standard Testcase"),
+ ("stdoutbasedtestcase", "Stdout Based Testcase"),
+ # ("mcqtestcase", "MCQ Testcase"),
)
attempts = [(i, i) for i in range(1, 6)]
@@ -152,14 +153,14 @@ class Question(models.Model):
points = models.FloatField(default=1.0)
# Answer for MCQs.
- test = models.TextField(blank=True)
+ # test = models.TextField(blank=True)
# Test cases file paths (comma seperated for reference code path and test case code path)
# Applicable for CPP, C, Java and Scilab
- ref_code_path = models.TextField(blank=True)
+ # ref_code_path = models.TextField(blank=True)
- # Any multiple choice options. Place one option per line.
- options = models.TextField(blank=True)
+ # # Any multiple choice options. Place one option per line.
+ # options = models.TextField(blank=True)
# The language for question.
language = models.CharField(max_length=24,
@@ -176,7 +177,7 @@ class Question(models.Model):
active = models.BooleanField(default=True)
# Snippet of code provided to the user.
- snippet = models.CharField(max_length=256, blank=True)
+ # snippet = models.CharField(max_length=256)
# Tags for the Question.
tags = TaggableManager(blank=True)
@@ -184,41 +185,57 @@ class Question(models.Model):
# user for particular question
user = models.ForeignKey(User, related_name="user")
- def consolidate_answer_data(self, user_answer):
- test_case_data_dict = []
- question_info_dict = {}
+ # def consolidate_answer_data(self, test_cases, user_answer):
+ # def consolidate_answer_data(self, user_answer):
+ # test_case_data_dict = []
+ # question_info_dict = {}
+
+ # for test_case in test_cases:
+ # kw_args_dict = {}
+ # pos_args_list = []
+
+ # test_case_data = {}
+ # test_case_data['test_id'] = test_case.id
+ # test_case_data['func_name'] = test_case.func_name
+ # test_case_data['expected_answer'] = test_case.expected_answer
+
+ # if test_case.kw_args:
+ # for args in test_case.kw_args.split(","):
+ # arg_name, arg_value = args.split("=")
+ # kw_args_dict[arg_name.strip()] = arg_value.strip()
+
+ # if test_case.pos_args:
+ # for args in test_case.pos_args.split(","):
+ # pos_args_list.append(args.strip())
- # for test_case in test_cases:
- # kw_args_dict = {}
- # pos_args_list = []
+ # test_case_data['kw_args'] = kw_args_dict
+ # test_case_data['pos_args'] = pos_args_list
+ # test_case_data_dict.append(test_case_data)
- # test_case_data = {}
- # test_case_data['test_id'] = test_case.id
- # test_case_data['func_name'] = test_case.func_name
- # test_case_data['expected_answer'] = test_case.expected_answer
+ # question_info_dict['language'] = self.language
+ # question_info_dict['id'] = self.id
+ # question_info_dict['user_answer'] = user_answer
+ # question_info_dict['test_parameter'] = test_case_data_dict
+ # question_info_dict['ref_code_path'] = self.ref_code_path
+ # question_info_dict['test'] = self.test
+ # question_info_dict['test_case_type'] = self.test_case_type
- # if test_case.kw_args:
- # for args in test_case.kw_args.split(","):
- # arg_name, arg_value = args.split("=")
- # kw_args_dict[arg_name.strip()] = arg_value.strip()
+ # return json.dumps(question_info_dict)
- # if test_case.pos_args:
- # for args in test_case.pos_args.split(","):
- # pos_args_list.append(args.strip())
+ def consolidate_answer_data(self, user_answer):
+ question_data = {}
+ test_case_data = []
- # test_case_data['kw_args'] = kw_args_dict
- # test_case_data['pos_args'] = pos_args_list
- # test_case_data_dict.append(test_case_data)
+ test_cases = self.testcase_set.all()
+ for test in test_cases:
+ test_instance = test.get_child_instance(self.test_case_type)
+ test_case_field_value = test_instance.get_field_value()
+ test_case_data.append(test_case_field_value)
- # question_info_dict['language'] = self.language
- # question_info_dict['id'] = self.id
- question_info_dict['user_answer'] = user_answer
- # question_info_dict['test_parameter'] = test_case_data_dict
- question_info_dict['ref_code_path'] = self.ref_code_path
- question_info_dict['test'] = self.test
- # question_info_dict['test_case_type'] = self.test_case_type
+ question_data['test_case_data'] = test_case_data
+ question_data['user_answer'] = user_answer
- return json.dumps(question_info_dict)
+ return json.dumps(question_data)
def dump_into_json(self, question_ids, user):
questions = Question.objects.filter(id__in = question_ids, user_id = user.id)
@@ -755,14 +772,24 @@ class AssignmentUpload(models.Model):
class TestCase(models.Model):
question = models.ForeignKey(Question, blank=True, null = True)
- # Test case function name
- func_name = models.CharField(blank=True, null = True, max_length=200)
+ def get_child_instance(self, type):
+ return getattr(self, type)
+
+class StandardTestCase(TestCase):
+ test_case = models.TextField(blank=True)
+
+ def get_field_value(self):
+ return self.test_case
- # Test case Keyword arguments in dict form
- kw_args = models.TextField(blank=True, null = True)
+class StdoutBasedTestCase(TestCase):
+ output = models.TextField(blank=True)
- # Test case Positional arguments in list form
- pos_args = models.TextField(blank=True, null = True)
+ def get_field_value(self):
+ return self.output
+
+class McqTestCase(TestCase):
+ options = models.TextField()
+ correct = models.BooleanField(default=False)
- # Test case Expected answer in list form
- expected_answer = models.TextField(blank=True, null = True)
+ def validate(self, user_answer):
+ pass