diff options
author | mahesh | 2017-08-18 02:12:37 +0530 |
---|---|---|
committer | mahesh | 2017-08-18 02:12:37 +0530 |
commit | a9c4aab85fb9b8edce53212548f8d0c285832dc4 (patch) | |
tree | 3785643c0f510894aa5fb9359ba44cfe07039093 | |
parent | 5d37ce12b0fbd01756221abe2a001eb35415bccc (diff) | |
download | online_test-a9c4aab85fb9b8edce53212548f8d0c285832dc4.tar.gz online_test-a9c4aab85fb9b8edce53212548f8d0c285832dc4.tar.bz2 online_test-a9c4aab85fb9b8edce53212548f8d0c285832dc4.zip |
Adds tags in yaml files
-rw-r--r-- | yaksh/demo_templates/yaml_question_template | 399 | ||||
-rw-r--r-- | yaksh/fixtures/demo_questions.zip | bin | 8587 -> 3015 bytes | |||
-rw-r--r-- | yaksh/models.py | 8 |
3 files changed, 258 insertions, 149 deletions
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? <br/> <math xmlns="http://www.w3.org/1998/Math/MathML"> @@ -24,75 +35,106 @@ description: |- # Entire question description. <mo>=</mo> <mn>0</mn> </math> -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 <b>Python 2.x</b>: <br> <code> print(2, "Hello"*2, ":" ,"Bye") </code> -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 - <pre>3.4566+2.122 </pre><br/> -points: 1.0 +summary: |- + Adding decimals +grade_assignment_upload: false +--- testcase: - test_case_type: |- - floattestcase - correct: 5.5786 - error_margin: 0.0 -files: [] ---- -active: true + 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 -summary: |- - Extract columns from files +active: true type: |- code -grade_assignment_upload: false description: |- Write a bash script that takes exactly three file arguments. @@ -110,104 +152,78 @@ description: |- <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> -points: 2.0 -testcase: -- test_case: |- - #!/bin/bash - cat $1 | cut -d: -f2 | paste -d: $3 - $2 - weight: 1.0 - test_case_type: |- - standardtestcase - test_case_args: |- - file1.csv file2.csv file3.csv -files: -- - file1.csv - - false -- - file2.csv - - false -- - file3.csv - - false ---- -active: true -language: |- - python -partial_grading: false -snippet: |- - def is_palindrome(s): summary: |- - Check Palindrome -type: |- - code + Extract columns from files grade_assignment_upload: false -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> -points: 2.0 +--- testcase: -- test_case: |- +- test_case_type: |- + standardtestcase + test_case_args: '' + test_case: |- assert is_palindrome("hello") == False weight: 1.0 - test_case_type: |- +- test_case_type: |- standardtestcase test_case_args: '' -- test_case: |- + test_case: |- assert is_palindrome("nitin") == True weight: 1.0 - test_case_type: |- +- test_case_type: |- standardtestcase test_case_args: '' -- test_case: |- + test_case: |- assert is_palindrome("madaM") == False weight: 1.0 - test_case_type: |- - standardtestcase - test_case_args: '' files: [] ---- -active: true language: |- python -partial_grading: true -snippet: '' -summary: |- - For Loop over String +partial_grading: false +tags: +- python +- assertion +- palindrome +- reverse +- code +- '2' +- demo +points: 2.0 +snippet: |- + def is_palindrome(s): +active: true type: |- code -grade_assignment_upload: false description: |- - Write a python script that accepts a <b>string</b> as input + Write a function <code>is_palindrome(arg)</code> which will take one string argument. <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> -points: 1.0 + 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: -- expected_output: |- +- test_case_type: |- + stdiobasedtestcase + weight: 1 + expected_input: |- + string + expected_output: |- s t r i n g - weight: 1 - test_case_type: |- +- test_case_type: |- stdiobasedtestcase + weight: 1 expected_input: |- - string -- expected_output: |- + s t o p s i g n + expected_output: |- s t @@ -223,12 +239,9 @@ testcase: g n - weight: 1 - test_case_type: |- - stdiobasedtestcase - expected_input: |- - s t o p s i g n -- 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 @@ -247,35 +260,46 @@ testcase: err = "Correct Answer" mark_fraction = 1.0 return success, err, mark_fraction - test_case_type: |- - hooktestcase weight: 1.0 files: [] ---- -active: true language: |- - c -partial_grading: false + python +partial_grading: true +tags: +- python +- stdio +- demo +- '1' +- code +- for +points: 1.0 snippet: '' -summary: |- - Add 3 numbers +active: true type: |- code -grade_assignment_upload: false description: |- - Write a program to add 3 numbers. - <br> - Function Name is to be called <b>add</b> + Write a python script that accepts a <b>string</b> as input <br> - <br><br> + The script must print each character of the string using a for loop. + + For example; <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> + <b>Input:</b> + box + <b>Output</b> + b + o + x </pre> -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 <stdio.h> #include <stdlib.h> @@ -307,26 +331,43 @@ testcase: printf("All Correct\n"); } weight: 1.0 - test_case_type: |- - standardtestcase - test_case_args: '' files: [] ---- -active: true language: |- - python + c partial_grading: false +tags: +- c++ +- c +- demo +- code +- '2' +- addition +- cpp +- numbers +points: 2.0 snippet: '' -summary: |- - Hello World in File +active: true type: |- - upload -grade_assignment_upload: true + code description: |- - Upload a file called <code>new.txt</code> which contains the string <code>Hello, World!</code> in it. -points: 1.0 + 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: -- 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 <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 Binary files differindex 08b06c4..063d2da 100644 --- a/yaksh/fixtures/demo_questions.zip +++ b/yaksh/fixtures/demo_questions.zip 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: |