summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormahesh2017-08-25 01:33:08 +0530
committermahesh2017-08-25 01:43:59 +0530
commit30b48c30abebf75ed4b51fd034600e0c7d58c95b (patch)
tree53ad33f61c239271f62ee2054ad79cb76688645d
parenteb90ab2fbc1bf86c1549e391aa6cc461aaea699d (diff)
downloadonline_test-30b48c30abebf75ed4b51fd034600e0c7d58c95b.tar.gz
online_test-30b48c30abebf75ed4b51fd034600e0c7d58c95b.tar.bz2
online_test-30b48c30abebf75ed4b51fd034600e0c7d58c95b.zip
Fixes order in demo_questions.zip
- Template yaml is now generated on the fly. - Removes yaml_question_template files. - Fixes order for yaml file inside demo_questions.zip
-rw-r--r--yaksh/demo_templates/yaml_question_template462
-rw-r--r--yaksh/fixtures/demo_questions.zipbin3015 -> 3055 bytes
-rw-r--r--yaksh/models.py27
-rw-r--r--yaksh/views.py13
4 files changed, 21 insertions, 481 deletions
diff --git a/yaksh/demo_templates/yaml_question_template b/yaksh/demo_templates/yaml_question_template
deleted file mode 100644
index 1309c06..0000000
--- a/yaksh/demo_templates/yaml_question_template
+++ /dev/null
@@ -1,462 +0,0 @@
----
-testcase:
-- test_case_type: |-
- integertestcase
- correct: 2
-- test_case_type: |-
- integertestcase
- correct: -3
-files: []
-language: |- # bash, scilab, python, c/c++, java
- python
-partial_grading: false
-tags:
-- python
-- quadratic
-- demo
-- integer
-points: 1.0
-snippet: ''
-active: true
-type: |-
- integer
-description: |-
- Type in the box below, one of the roots to the following quadratic equation?
- <br/>
- <math xmlns="http://www.w3.org/1998/Math/MathML">
- <msup>
- <mi>x</mi>
- <mn>2</mn>
- </msup>
- <mo>+</mo>
- <mi>x</mi>
- <mo>-</mo>
- <mi>6</mi>
- <mo>=</mo>
- <mn>0</mn>
- </math>
-summary: |-
- Roots of quadratic equation
-grade_assignment_upload: false
----
-testcase:
-- test_case_type: |-
- stringtestcase
- correct: |-
- (2, 'HelloHello', ':', 'Bye')
- string_check: |- # exact or lower
- exact
-files: []
-language: |-
- python
-partial_grading: false
-tags:
-- python
-- demo
-- print
-- string
-- '1'
-- case_sensitive
-- casesensitive
-- python2
-points: 1.0
-snippet: ''
-active: true
-type: |-
- string
-description: |-
- What is the output for the following code in <b>Python 2.x</b>:
- <br>
- <code>
- print(2, "Hello"*2, ":" ,"Bye")
- </code>
-summary: |-
- Print Output
-grade_assignment_upload: false
----
-testcase:
-- test_case_type: |-
- floattestcase
- correct: 5.5786
- error_margin: 0.0
-files: []
-language: |-
- python
-partial_grading: false
-tags:
-- float
-- '1'
-- python
-- decimal
-- demo
-points: 1.0
-snippet: ''
-active: true
-type: |-
- float
-description: |-
- Write down the resultant value of the following -
- <pre>3.4566+2.122
- </pre><br/>
-summary: |-
- Adding decimals
-grade_assignment_upload: false
----
-testcase:
-- test_case_type: |-
- standardtestcase
- test_case_args: |-
- file1.csv file2.csv file3.csv
- test_case: |-
- #!/bin/bash
- cat $1 | cut -d: -f2 | paste -d: $3 - $2
- weight: 1.0
-files:
-- - file1.csv
- - false
-- - file2.csv
- - false
-- - file3.csv
- - false
-language: |-
- bash
-partial_grading: false
-tags:
-- demo
-- code
-- files
-- concatenate
-- bash
-- delimiter
-- '2'
-points: 2.0
-snippet: |-
- #!/bin/bash
-active: true
-type: |-
- code
-description: |-
- Write a bash script that takes exactly three file arguments.
-
- The first argument <b>(file1.csv)</b> would have 3 columns, the second argument <b>(file2.csv)</b> would have 2 columns. The third argument <b>(file3.csv) </b>would have 2 columns.
- <br><br>
- All files have columns delimited by <b>: (colon)</b>.
- <br><br>
- We need the <b>2nd column</b> from <b>file1.csv</b> to be removed and concatenated <b>BEFORE file2.csv</b> and this concatenated file should come <b>BESIDE file3.csv</b>.
-
- Left is <b>file3.csv</b>, and the <b>LATER</b> columns come from <b>file1.csv and file2.csv.</b>
- <br><br>
- <b>The delimiter while putting the files BESIDE each other should again be : (colon)</b>
- <br><br>
- <pre>
- <b>Note:</b> - <i>Do not hard-code the filenames. They will be passed in as arguments.
- Assume no headers (to avoid header-non-repetition issues).</i>
- </pre>
-summary: |-
- Extract columns from files
-grade_assignment_upload: false
----
-testcase:
-- test_case_type: |-
- standardtestcase
- test_case_args: ''
- test_case: |-
- assert is_palindrome("hello") == False
- weight: 1.0
-- test_case_type: |-
- standardtestcase
- test_case_args: ''
- test_case: |-
- assert is_palindrome("nitin") == True
- weight: 1.0
-- test_case_type: |-
- standardtestcase
- test_case_args: ''
- test_case: |-
- assert is_palindrome("madaM") == False
- weight: 1.0
-files: []
-language: |-
- python
-partial_grading: false
-tags:
-- python
-- assertion
-- palindrome
-- reverse
-- code
-- '2'
-- demo
-points: 2.0
-snippet: |-
- def is_palindrome(s):
-active: true
-type: |-
- code
-description: |-
- Write a function <code>is_palindrome(arg)</code> which will take one string argument.
- <br>
- Return True if the argument is palindrome & False otherwise.
- <br>
- The function should be case sensitive.
- <br><br>
- For Example:<br><code>is_palindrome("Hello")</code> should return <code>False</code><br>
-summary: |-
- Check Palindrome
-grade_assignment_upload: false
----
-testcase:
-- test_case_type: |-
- stdiobasedtestcase
- weight: 1
- expected_input: |-
- string
- expected_output: |-
- s
- t
- r
- i
- n
- g
-- test_case_type: |-
- stdiobasedtestcase
- weight: 1
- expected_input: |-
- s t o p s i g n
- expected_output: |-
- s
-
- t
-
- o
-
- p
-
- s
-
- i
-
- g
-
- n
-- test_case_type: |-
- hooktestcase
- hook_code: |-
- def check_answer(user_answer):
- ''' Evaluates user answer to return -
- success - Boolean, indicating if code was executed correctly
- mark_fraction - Float, indicating fraction of the
- weight to a test case
- error - String, error message if success is false
-
- In case of assignment upload there will be no user answer '''
-
- success = False
- err = "You are using while in your code."
- mark_fraction = 0.0
-
- if not 'while' in user_answer:
- success=True
- err = "Correct Answer"
- mark_fraction = 1.0
- return success, err, mark_fraction
- weight: 1.0
-files: []
-language: |-
- python
-partial_grading: true
-tags:
-- python
-- stdio
-- demo
-- '1'
-- code
-- for
-points: 1.0
-snippet: ''
-active: true
-type: |-
- code
-description: |-
- Write a python script that accepts a <b>string</b> as input
- <br>
- The script must print each character of the string using a for loop.
-
- For example;
- <pre>
- <b>Input:</b>
- box
- <b>Output</b>
- b
- o
- x
- </pre>
-summary: |-
- For Loop over String
-grade_assignment_upload: false
----
-testcase:
-- test_case_type: |-
- standardtestcase
- test_case_args: ''
- test_case: |-
- #include <stdio.h>
- #include <stdlib.h>
-
- extern int add(int, int, int);
-
- template <class T>
- void check(T expect,T result)
- {
- if (expect == result)
- {
- printf("\nCorrect:\n Expected %d got %d \n",expect,result);
- }
- else
- {
- printf("\nIncorrect:\n Expected %d got %d \n",expect,result);
- exit (1);
- }
- }
-
- int main(void)
- {
- int result;
- result = add(0,0,0);
- printf("Input submitted to the function: 0, 0, 0");
- check(0, result);
- result = add(2,3,3);
- printf("Input submitted to the function: 2, 3, 3");
- check(8,result);
- printf("All Correct\n");
- }
- weight: 1.0
-files: []
-language: |-
- c
-partial_grading: false
-tags:
-- c++
-- c
-- demo
-- code
-- '2'
-- addition
-- cpp
-- numbers
-points: 2.0
-snippet: ''
-active: true
-type: |-
- code
-description: |-
- Write a program to add 3 numbers.
- <br>
- Function Name is to be called <b>add</b>
- <br>
- <br><br>
- <pre>
- <b>Note:</b><i> 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.</i>
- </pre>
-summary: |-
- Add 3 numbers
-grade_assignment_upload: false
----
-testcase:
-- test_case_type: |-
- hooktestcase
- hook_code: |-
- def check_answer(user_answer):
- ''' Evaluates user answer to return -
- success - Boolean, indicating if code was executed correctly
- mark_fraction - Float, indicating fraction of the
- weight to a test case
- error - String, error message if success is false
-
- In case of assignment upload there will be no user answer '''
-
- success = False
- err = "Incorrect Answer" # Please make this more specific
- mark_fraction = 0.0
-
- try:
- with open('new.txt', 'r') as f:
- if "Hello, World!" in f.read():
- success = True
- err = "Correct Answer"
- mark_fraction = 1.0
- else:
- err = "Did not found string Hello, World! in file."
- except IOError:
- err = "File new.txt not found."
- return success, err, mark_fraction
- 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 <code>new.txt</code> which contains the string <code>Hello, World!</code> 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 063d2da..4e86485 100644
--- a/yaksh/fixtures/demo_questions.zip
+++ b/yaksh/fixtures/demo_questions.zip
Binary files differ
diff --git a/yaksh/models.py b/yaksh/models.py
index 044a164..979740d 100644
--- a/yaksh/models.py
+++ b/yaksh/models.py
@@ -102,7 +102,7 @@ def get_upload_dir(instance, filename):
'question_%s' % (instance.question.id), filename
))
-def dict_to_yaml(dictionary, path_to_file=None):
+def dict_to_yaml(dictionary):
for k,v in dictionary.items():
if isinstance(v, list):
for nested_v in v:
@@ -110,14 +110,10 @@ def dict_to_yaml(dictionary, path_to_file=None):
dict_to_yaml(nested_v)
elif v and isinstance(v,str):
dictionary[k] = PreservedScalarString(v)
- if path_to_file:
- with open(path_to_file, "a") as yaml_file:
- ruamel.yaml.round_trip_dump(dictionary, yaml_file,
- default_flow_style=False,
- explicit_start=True,
- allow_unicode=True,
- )
-
+ return ruamel.yaml.round_trip_dump(dictionary, explicit_start=True,
+ default_flow_style=False,
+ allow_unicode=True,
+ )
###############################################################################
class CourseManager(models.Manager):
@@ -502,12 +498,15 @@ class Question(models.Model):
file_upload.extract = extract
file_upload.file.save(file_name, django_file, save=True)
- def _add_yaml_to_zip(self, zip_file, q_dict):
+ def _add_yaml_to_zip(self, zip_file, q_dict,path_to_file=None):
+
tmp_file_path = tempfile.mkdtemp()
yaml_path = os.path.join(tmp_file_path, "questions_dump.yaml")
for elem in q_dict:
- commented_map = CommentedMap(sorted(elem.items(), key=lambda x:x[0]))
- dict_to_yaml(commented_map, yaml_path)
+ sorted_dict = CommentedMap(sorted(elem.items(), key=lambda x:x[0]))
+ yaml_block = dict_to_yaml(sorted_dict)
+ with open(yaml_path, "a") as yaml_file:
+ yaml_file.write(yaml_block)
zip_file.write(yaml_path, os.path.basename(yaml_path))
zip_file.close()
shutil.rmtree(tmp_file_path)
@@ -518,7 +517,9 @@ class Question(models.Model):
if os.path.exists(yaml_file):
with open(yaml_file, 'r') as q_file:
questions_list = q_file.read()
- msg = self.load_questions(questions_list, user, file_path, files)
+ msg = self.load_questions(questions_list, user,
+ file_path, files
+ )
else:
msg = "Please upload zip file with questions_dump.yaml in it."
diff --git a/yaksh/views.py b/yaksh/views.py
index 81d180b..3c7df4d 100644
--- a/yaksh/views.py
+++ b/yaksh/views.py
@@ -1622,13 +1622,14 @@ def download_yaml_template(request):
user = request.user
if not is_moderator(user):
raise Http404('You are not allowed to view this page!')
- template_path = os.path.join(os.path.dirname(__file__), "demo_templates",
- "yaml_question_template"
+ template_path = os.path.join(os.path.dirname(__file__), "fixtures",
+ "demo_questions.zip"
)
- with open(template_path, 'r') as f:
- yaml_str = f.read()
- response = HttpResponse(yaml_str, content_type='text/yaml')
- response['Content-Disposition'] = 'attachment; filename="questions_dump.yaml"'
+ yaml_file = zipfile.ZipFile(template_path, 'r')
+ template_yaml = yaml_file.open('questions_dump.yaml', 'r')
+ response = HttpResponse(template_yaml, content_type='text/yaml')
+ response['Content-Disposition'] = 'attachment;\
+ filename="questions_dump.yaml"'
return response