From a9c4aab85fb9b8edce53212548f8d0c285832dc4 Mon Sep 17 00:00:00 2001
From: mahesh
Date: Fri, 18 Aug 2017 02:12:37 +0530
Subject: Adds tags in yaml files
---
yaksh/demo_templates/yaml_question_template | 399 ++++++++++++++++++----------
yaksh/fixtures/demo_questions.zip | Bin 8587 -> 3015 bytes
yaksh/models.py | 8 +-
3 files changed, 258 insertions(+), 149 deletions(-)
(limited to 'yaksh')
diff --git a/yaksh/demo_templates/yaml_question_template b/yaksh/demo_templates/yaml_question_template
index 065072c..1309c06 100644
--- a/yaksh/demo_templates/yaml_question_template
+++ b/yaksh/demo_templates/yaml_question_template
@@ -1,15 +1,26 @@
---
-active: true # question status = true or false
+testcase:
+- test_case_type: |-
+ integertestcase
+ correct: 2
+- test_case_type: |-
+ integertestcase
+ correct: -3
+files: []
language: |- # bash, scilab, python, c/c++, java
- python
+ python
partial_grading: false
+tags:
+- python
+- quadratic
+- demo
+- integer
+points: 1.0
snippet: ''
-summary: |-
- Roots of quadratic equation
+active: true
type: |-
integer
-grade_assignment_upload: false
-description: |- # Entire question description.
+description: |-
Type in the box below, one of the roots to the following quadratic equation?
-points: 1.0
+summary: |-
+ Roots of quadratic equation
+grade_assignment_upload: false
+---
testcase:
- test_case_type: |-
- integertestcase
- correct: 2
-- test_case_type: |-
- integertestcase
- correct: -3
+ stringtestcase
+ correct: |-
+ (2, 'HelloHello', ':', 'Bye')
+ string_check: |- # exact or lower
+ exact
files: []
----
-active: true
language: |-
python
partial_grading: false
+tags:
+- python
+- demo
+- print
+- string
+- '1'
+- case_sensitive
+- casesensitive
+- python2
+points: 1.0
snippet: ''
-summary: |-
- Print Output
+active: true
type: |-
string
-grade_assignment_upload: false
description: |-
What is the output for the following code in Python 2.x:
print(2, "Hello"*2, ":" ,"Bye")
-points: 1.0
+summary: |-
+ Print Output
+grade_assignment_upload: false
+---
testcase:
-- string_check: |- #exact or lower
- exact
- test_case_type: |-
- stringtestcase
- correct: |-
- (2, 'HelloHello', ':', 'Bye')
+- test_case_type: |-
+ floattestcase
+ correct: 5.5786
+ error_margin: 0.0
files: []
----
-active: true
language: |-
python
partial_grading: false
+tags:
+- float
+- '1'
+- python
+- decimal
+- demo
+points: 1.0
snippet: ''
-summary: |-
- Adding decimals
+active: true
type: |-
float
-grade_assignment_upload: false
description: |-
Write down the resultant value of the following -
3.4566+2.122
is_palindrome(arg)
which will take one string argument.
- is_palindrome("Hello")
should return False
is_palindrome(arg)
which will take one string argument.
- Input: - box - Output - b - o - x --points: 1.0 + Return True if the argument is palindrome & False otherwise. +
is_palindrome("Hello")
should return False
- Note: You do not have to print anything, neither you have to make the function call. - Just define the function to perform the required operation, return the output & click on check answer. - Also, note that the function name should exactly be as mentioned above. + Input: + box + Output + b + o + x-points: 2.0 +summary: |- + For Loop over String +grade_assignment_upload: false +--- testcase: -- test_case: |- +- test_case_type: |- + standardtestcase + test_case_args: '' + test_case: |- #include
new.txt
which contains the string Hello, World!
in it.
-points: 1.0
+ Write a program to add 3 numbers.
+ + Note: You do not have to print anything, neither you have to make the function call. + Just define the function to perform the required operation, return the output & click on check answer. + Also, note that the function name should exactly be as mentioned above. ++summary: |- + Add 3 numbers +grade_assignment_upload: false +--- testcase: -- hook_code: |- +- test_case_type: |- + hooktestcase + hook_code: |- def check_answer(user_answer): ''' Evaluates user answer to return - success - Boolean, indicating if code was executed correctly @@ -351,7 +392,71 @@ testcase: except IOError: err = "File new.txt not found." return success, err, mark_fraction - test_case_type: |- - hooktestcase weight: 1.0 files: [] +language: |- + python +partial_grading: false +tags: +- python +- '1' +- file +- hook +- hello +- world +- grade +- assignment +- upload +- demo +points: 1.0 +snippet: '' +active: true +type: |- + upload +description: |- + Upload a file called
new.txt
which contains the string Hello, World!
in it.
+summary: |-
+ Hello World in File
+grade_assignment_upload: true
+---
+testcase:
+- test_case_type: |-
+ mcqtestcase
+ correct: false
+ options: |-
+ s.reverse()
+- test_case_type: |-
+ mcqtestcase
+ correct: true
+ options: |-
+ s[::-1]
+- test_case_type: |-
+ mcqtestcase
+ correct: false
+ options: |-
+ reversed(s)
+- test_case_type: |-
+ mcqtestcase
+ correct: true
+ options: |-
+ "''.join(reversed(s))
+files: []
+language: |-
+ python
+partial_grading: false
+tags:
+- python
+- '2'
+- reverse
+- mcc
+- demo
+points: 2.0
+snippet: ''
+active: true
+type: |-
+ mcc
+description: |-
+ Which of the following options would reverse the string?
+summary: |-
+ Reverse a string
+grade_assignment_upload: false
diff --git a/yaksh/fixtures/demo_questions.zip b/yaksh/fixtures/demo_questions.zip
index 08b06c4..063d2da 100644
Binary files a/yaksh/fixtures/demo_questions.zip and b/yaksh/fixtures/demo_questions.zip differ
diff --git a/yaksh/models.py b/yaksh/models.py
index 4113a62..476bc16 100644
--- a/yaksh/models.py
+++ b/yaksh/models.py
@@ -409,12 +409,13 @@ class Question(models.Model):
for question in questions:
test_case = question.get_test_cases()
file_names = question._add_and_get_files(zip_file)
- q_dict = model_to_dict(question, exclude=['id', 'user','tags'])
+ q_dict = model_to_dict(question, exclude=['id', 'user'])
testcases = []
for case in test_case:
testcases.append(case.get_field_value())
q_dict['testcase'] = testcases
q_dict['files'] = file_names
+ q_dict['tags'] = [tags.tag.name for tags in q_dict['tags']]
questions_dict.append(q_dict)
question._add_yaml_to_zip(zip_file, questions_dict)
return zip_file_name
@@ -428,10 +429,12 @@ class Question(models.Model):
question['user'] = user
file_names = question.pop('files')
test_cases = question.pop('testcase')
+ tags = question.pop('tags')
que, result = Question.objects.get_or_create(**question)
if file_names:
que._add_files_to_db(file_names, file_path)
-
+ if tags:
+ que.tags.add(*tags)
for test_case in test_cases:
try:
test_case_type = test_case.pop('test_case_type')
@@ -442,6 +445,7 @@ class Question(models.Model):
)
new_test_case.type = test_case_type
new_test_case.save()
+
except:
msg = "File not correct."
except Exception as exc_msg:
--
cgit