From ae5e8ca5eb5d47afb14ba83e665de6f10e46bdac Mon Sep 17 00:00:00 2001
From: CruiseDevice
Date: Sun, 11 Nov 2018 01:03:11 +0530
Subject: Fix #525
- Categorize questions into objectives, blanks, upload and programming.
---
yaksh/static/yaksh/css/exam.css | 8 +++-
yaksh/static/yaksh/css/yakshcustom.css | 2 -
yaksh/templates/exam.html | 77 ++++++++++++++++++++++------------
yaksh/templatetags/custom_filters.py | 5 ---
yaksh/views.py | 58 ++++++++++++++++++++++++-
5 files changed, 114 insertions(+), 36 deletions(-)
diff --git a/yaksh/static/yaksh/css/exam.css b/yaksh/static/yaksh/css/exam.css
index b0bb379..e420166 100644
--- a/yaksh/static/yaksh/css/exam.css
+++ b/yaksh/static/yaksh/css/exam.css
@@ -1,7 +1,13 @@
-table td, table th { border: #ff8295 solid 1px !important;
+#assertion td, #assertion th, #stdio td, #stdio th { border: #ff8295 solid 1px !important;
word-wrap: break-word !important;
white-space: pre-wrap !important;
}
#stdio, #assertion {
table-layout: fixed
}
+.table{
+ border: 1px solid;
+ background-color: white;
+ border-spacing: 5px;
+ border-collapse: collapse;
+}
diff --git a/yaksh/static/yaksh/css/yakshcustom.css b/yaksh/static/yaksh/css/yakshcustom.css
index 86403ac..a9b4349 100644
--- a/yaksh/static/yaksh/css/yakshcustom.css
+++ b/yaksh/static/yaksh/css/yakshcustom.css
@@ -228,5 +228,3 @@ html {
overflow-y: auto;
-ms-overflow-style: -ms-autohiding-scrollbar;
}
-
-/*---------------------*/
\ No newline at end of file
diff --git a/yaksh/templates/exam.html b/yaksh/templates/exam.html
index c452929..8c65e2b 100644
--- a/yaksh/templates/exam.html
+++ b/yaksh/templates/exam.html
@@ -1,9 +1,4 @@
{% extends "base.html" %}
-{% load custom_filters %}
-
-
-
-
{% load custom_filters %}
{% block nav %}
@@ -83,28 +78,56 @@
Question(s) left: {{ paper.questions_left }}
-
-
-
- {% for types in question_types %}
- {% get_questions_by_type paper.get_all_ordered_questions types as questions_by_type %}
- {% if types == "mcq" %} Single Correct Choice
- {% elif types == "mcc" %} Multiple Correct Choice
- {% elif types == "code" %} Programming
- {% elif types == "upload" %} Assignment Upload
- {% elif types == "integer" %} Integer Blanks
- {% elif types == "string" %} String Blanks
- {% elif types == "float" %} Float Blanks
- {% elif types == "arrange" %} Arranging Options
- {% endif %}
- --->
- {% for question in questions_by_type %} {{question.id}} {%endfor%}
-
- {%endfor%}
-
-
-
-
+
+
+
+ Category |
+ Question No. |
+
+
+
+ {% if index.objectives_index %}
+
+
+ Objectives:
+ |
+
+ {{index.objectives_index|join:", "}}
+ |
+
+ {% endif %}
+ {% if index.blanks_index %}
+
+
+ Blanks:
+ |
+
+ {{index.blanks_index|join:", "}}
+ |
+
+ {% endif %}
+ {% if index.upload_index %}
+
+
+ Upload:
+ |
+
+ {{index.upload_index|join:", "}}
+ |
+
+ {% endif %}
+ {% if index.programming_index %}
+
+
+ Programming:
+ |
+
+ {{index.programming_index|join:", "}}
+ |
+
+ {% endif %}
+
+
diff --git a/yaksh/templatetags/custom_filters.py b/yaksh/templatetags/custom_filters.py
index dcae7f9..29f4b59 100644
--- a/yaksh/templatetags/custom_filters.py
+++ b/yaksh/templatetags/custom_filters.py
@@ -84,11 +84,6 @@ def replace_spaces(name):
return name.replace(" ", "_")
-@register.simple_tag
-def get_questions_by_type(all_questions, question_type):
- return [question for question in all_questions if question.type == question_type]
-
-
@register.simple_tag
def course_grade(course, user):
return course.get_grade(user)
diff --git a/yaksh/views.py b/yaksh/views.py
index 0f81931..af4eec1 100644
--- a/yaksh/views.py
+++ b/yaksh/views.py
@@ -561,6 +561,20 @@ def start(request, questionpaper_id=None, attempt_num=None, course_id=None,
raise Http404(msg)
+def _get_question_by_index(all_ordered_questions, questions_by_type):
+ return [index+1 for index, item in enumerate(all_ordered_questions)
+ if item in set(questions_by_type)]
+
+
+def _get_questions_by_type(all_ordered_questions, objective_types):
+ questions_by_type = []
+ for types in objective_types:
+ for question in all_ordered_questions:
+ if question.type == types:
+ questions_by_type.append(question)
+ return _get_question_by_index(all_ordered_questions, questions_by_type)
+
+
@login_required
@email_verified
def show_question(request, question, paper, error_message=None,
@@ -568,6 +582,7 @@ def show_question(request, question, paper, error_message=None,
previous_question=None):
"""Show a question if possible."""
quiz = paper.question_paper.quiz
+ questions = paper.questions.all()
quiz_type = 'Exam'
can_skip = False
if previous_question:
@@ -616,6 +631,46 @@ def show_question(request, question, paper, error_message=None,
module = course.learning_module.get(id=module_id)
all_modules = course.get_learning_modules()
all_question_types = [types[0] for types in question_types]
+ types = {}
+ categories = {}
+ categories["objectives"] = questions.filter(Q(type="mcq") |
+ Q(type="mcc") |
+ Q(type="arrange"))
+ categories["blanks"] = questions.filter(Q(type="integer") |
+ Q(type="string") |
+ Q(type="float"))
+ categories["programming"] = questions.filter(Q(type="code"))
+ categories["upload"] = questions.filter(Q(type="upload"))
+ types["objective_types"] = set([type_.type
+ for type_ in categories["objectives"]])
+ types["blank_types"] = set([type_.type
+ for type_ in categories["blanks"]])
+ types["programming_types"] = set([type_.type
+ for type_ in categories["programming"]])
+ types["upload_types"] = set([type_.type
+ for type_ in categories["upload"]])
+ all_ordered_questions = paper.get_all_ordered_questions()
+ objectives_index = _get_questions_by_type(
+ all_ordered_questions,
+ types["objective_types"]
+ )
+ blanks_index = _get_questions_by_type(
+ all_ordered_questions,
+ types["blank_types"]
+ )
+ programming_index = _get_questions_by_type(
+ all_ordered_questions,
+ types["programming_types"]
+ )
+ upload_index = _get_questions_by_type(
+ all_ordered_questions,
+ types["upload_types"]
+ )
+ index = {}
+ index["objectives_index"] = objectives_index
+ index["blanks_index"] = blanks_index
+ index["programming_index"] = programming_index
+ index["upload_index"] = upload_index
context = {
'question': question,
'paper': paper,
@@ -631,7 +686,8 @@ def show_question(request, question, paper, error_message=None,
'delay_time': delay_time,
'quiz_type': quiz_type,
'all_modules': all_modules,
- "question_types": all_question_types
+ "question_types": all_question_types,
+ "index": index,
}
answers = paper.get_previous_answers(question)
if answers:
--
cgit
From f72b744db670d88c095200832a638b69f514f55c Mon Sep 17 00:00:00 2001
From: CruiseDevice
Date: Thu, 3 Jan 2019 16:08:50 +0530
Subject: Code refactor - Move get_question_by_index() and
get_question_by_type() from views.py to models.py . - Change variable names.
---
yaksh/models.py | 15 ++++++++++++
yaksh/views.py | 74 ++++++++++++++++++++++++++-------------------------------
2 files changed, 49 insertions(+), 40 deletions(-)
diff --git a/yaksh/models.py b/yaksh/models.py
index 427b584..98a63b0 100644
--- a/yaksh/models.py
+++ b/yaksh/models.py
@@ -2091,6 +2091,21 @@ class AnswerPaper(models.Model):
def get_previous_answers(self, question):
return self.answers.filter(question=question).order_by('-id')
+ def get_question_by_index(self, all_ordered_questions, questions_by_type):
+ return [index+1 for index, item in enumerate(all_ordered_questions)
+ if item in set(questions_by_type)]
+
+ def get_questions_by_type(self, all_ordered_questions, objective_types):
+ questions_by_type = []
+ for types in objective_types:
+ for question in all_ordered_questions:
+ if question.type == types:
+ questions_by_type.append(question)
+ return self.get_question_by_index(
+ all_ordered_questions,
+ questions_by_type
+ )
+
def validate_answer(self, user_answer, question, json_data=None, uid=None,
server_port=SERVER_POOL_PORT):
"""
diff --git a/yaksh/views.py b/yaksh/views.py
index af4eec1..4c23ba6 100644
--- a/yaksh/views.py
+++ b/yaksh/views.py
@@ -561,20 +561,6 @@ def start(request, questionpaper_id=None, attempt_num=None, course_id=None,
raise Http404(msg)
-def _get_question_by_index(all_ordered_questions, questions_by_type):
- return [index+1 for index, item in enumerate(all_ordered_questions)
- if item in set(questions_by_type)]
-
-
-def _get_questions_by_type(all_ordered_questions, objective_types):
- questions_by_type = []
- for types in objective_types:
- for question in all_ordered_questions:
- if question.type == types:
- questions_by_type.append(question)
- return _get_question_by_index(all_ordered_questions, questions_by_type)
-
-
@login_required
@email_verified
def show_question(request, question, paper, error_message=None,
@@ -632,45 +618,53 @@ def show_question(request, question, paper, error_message=None,
all_modules = course.get_learning_modules()
all_question_types = [types[0] for types in question_types]
types = {}
- categories = {}
- categories["objectives"] = questions.filter(Q(type="mcq") |
- Q(type="mcc") |
- Q(type="arrange"))
- categories["blanks"] = questions.filter(Q(type="integer") |
- Q(type="string") |
- Q(type="float"))
- categories["programming"] = questions.filter(Q(type="code"))
- categories["upload"] = questions.filter(Q(type="upload"))
- types["objective_types"] = set([type_.type
- for type_ in categories["objectives"]])
- types["blank_types"] = set([type_.type
- for type_ in categories["blanks"]])
- types["programming_types"] = set([type_.type
- for type_ in categories["programming"]])
- types["upload_types"] = set([type_.type
- for type_ in categories["upload"]])
+ categorized_questions = {}
+ categorized_questions["objectives"] = questions.filter(Q(type="mcq") |
+ Q(type="mcc") |
+ Q(type="arrange"))
+ categorized_questions["blanks"] = questions.filter(Q(type="integer") |
+ Q(type="string") |
+ Q(type="float"))
+ categorized_questions["programming"] = questions.filter(Q(type="code"))
+ categorized_questions["upload"] = questions.filter(Q(type="upload"))
+
+ types["objective_types"] = set([_type.type
+ for _type in
+ categorized_questions["objectives"]])
+ types["blank_types"] = set([_type.type
+ for _type in
+ categorized_questions["blanks"]])
+ types["programming_types"] = set([_type.type
+ for _type in
+ categorized_questions["programming"]])
+ types["upload_types"] = set([_type.type
+ for _type in categorized_questions["upload"]])
+
all_ordered_questions = paper.get_all_ordered_questions()
- objectives_index = _get_questions_by_type(
+
+ objectives_index = paper.get_questions_by_type(
all_ordered_questions,
types["objective_types"]
)
- blanks_index = _get_questions_by_type(
+ blanks_index = paper.get_questions_by_type(
all_ordered_questions,
types["blank_types"]
)
- programming_index = _get_questions_by_type(
+ programming_index = paper.get_questions_by_type(
all_ordered_questions,
types["programming_types"]
)
- upload_index = _get_questions_by_type(
+ upload_index = paper.get_questions_by_type(
all_ordered_questions,
types["upload_types"]
)
- index = {}
- index["objectives_index"] = objectives_index
- index["blanks_index"] = blanks_index
- index["programming_index"] = programming_index
- index["upload_index"] = upload_index
+
+ index = {
+ 'objectives_index': objectives_index,
+ 'blanks_index': blanks_index,
+ 'programming_index': programming_index,
+ 'upload_index': upload_index
+ }
context = {
'question': question,
'paper': paper,
--
cgit
From a4c6a0a3c013f02c7cdd1d365a180ff6de121d6e Mon Sep 17 00:00:00 2001
From: CruiseDevice
Date: Fri, 4 Jan 2019 16:33:26 +0530
Subject: Code refactor and resolves requested changes.
---
yaksh/models.py | 36 +++++++++++++++++------------
yaksh/static/yaksh/css/exam.css | 3 ++-
yaksh/templates/exam.html | 40 ++++----------------------------
yaksh/views.py | 51 -----------------------------------------
4 files changed, 28 insertions(+), 102 deletions(-)
diff --git a/yaksh/models.py b/yaksh/models.py
index 98a63b0..0f20605 100644
--- a/yaksh/models.py
+++ b/yaksh/models.py
@@ -6,7 +6,8 @@ import ruamel.yaml
from ruamel.yaml.scalarstring import PreservedScalarString
from ruamel.yaml.comments import CommentedMap
from random import sample
-from collections import Counter
+from collections import Counter, defaultdict
+
from django.db import models
from django.contrib.auth.models import User, Group, Permission
from django.contrib.contenttypes.models import ContentType
@@ -80,6 +81,17 @@ string_check_type = (
("exact", "Case Sensitive"),
)
+legend_display_types = {
+ "mcq": {"category": "objective", "label": "Objective Type"},
+ "mcc": {"category": "objective", "label": "Objective Type"},
+ "code": {"category": "programming", "label": "Programming"},
+ "upload": {"category": "upload", "label": "Upload"},
+ "integer": {"category": "objective", "label": "Objective Type"},
+ "string": {"category": "objective", "label": "Objective Type"},
+ "float": {"category": "objective", "label": "Objective Type"},
+ "arrange": {"category": "objective", "label": "Objective Type"},
+ }
+
attempts = [(i, i) for i in range(1, 6)]
attempts.append((-1, 'Infinite'))
@@ -2091,20 +2103,14 @@ class AnswerPaper(models.Model):
def get_previous_answers(self, question):
return self.answers.filter(question=question).order_by('-id')
- def get_question_by_index(self, all_ordered_questions, questions_by_type):
- return [index+1 for index, item in enumerate(all_ordered_questions)
- if item in set(questions_by_type)]
-
- def get_questions_by_type(self, all_ordered_questions, objective_types):
- questions_by_type = []
- for types in objective_types:
- for question in all_ordered_questions:
- if question.type == types:
- questions_by_type.append(question)
- return self.get_question_by_index(
- all_ordered_questions,
- questions_by_type
- )
+ def get_categorized_question_indices(self):
+
+ category_question_map = defaultdict(lambda: [])
+ for index, question in enumerate(self.get_all_ordered_questions(), 1):
+ category_question_map[
+ legend_display_types[question.type]["label"]
+ ].append(index)
+ return dict(category_question_map)
def validate_answer(self, user_answer, question, json_data=None, uid=None,
server_port=SERVER_POOL_PORT):
diff --git a/yaksh/static/yaksh/css/exam.css b/yaksh/static/yaksh/css/exam.css
index e420166..a246141 100644
--- a/yaksh/static/yaksh/css/exam.css
+++ b/yaksh/static/yaksh/css/exam.css
@@ -5,8 +5,9 @@
#stdio, #assertion {
table-layout: fixed
}
-.table{
+.legend_table{
border: 1px solid;
+ width: 15em;
background-color: white;
border-spacing: 5px;
border-collapse: collapse;
diff --git a/yaksh/templates/exam.html b/yaksh/templates/exam.html
index 8c65e2b..29ad167 100644
--- a/yaksh/templates/exam.html
+++ b/yaksh/templates/exam.html
@@ -78,7 +78,7 @@
Question(s) left: {{ paper.questions_left }}
-
+
Category |
@@ -86,46 +86,16 @@
- {% if index.objectives_index %}
+ {% for category, question_number in paper.get_categorized_question_indices.items %}
- Objectives:
+ {{category}}
|
- {{index.objectives_index|join:", "}}
+ {{question_number| join:", "}}
|
- {% endif %}
- {% if index.blanks_index %}
-
-
- Blanks:
- |
-
- {{index.blanks_index|join:", "}}
- |
-
- {% endif %}
- {% if index.upload_index %}
-
-
- Upload:
- |
-
- {{index.upload_index|join:", "}}
- |
-
- {% endif %}
- {% if index.programming_index %}
-
-
- Programming:
- |
-
- {{index.programming_index|join:", "}}
- |
-
- {% endif %}
+ {% endfor %}
diff --git a/yaksh/views.py b/yaksh/views.py
index 4c23ba6..3eaa165 100644
--- a/yaksh/views.py
+++ b/yaksh/views.py
@@ -616,55 +616,6 @@ def show_question(request, question, paper, error_message=None,
course = Course.objects.get(id=course_id)
module = course.learning_module.get(id=module_id)
all_modules = course.get_learning_modules()
- all_question_types = [types[0] for types in question_types]
- types = {}
- categorized_questions = {}
- categorized_questions["objectives"] = questions.filter(Q(type="mcq") |
- Q(type="mcc") |
- Q(type="arrange"))
- categorized_questions["blanks"] = questions.filter(Q(type="integer") |
- Q(type="string") |
- Q(type="float"))
- categorized_questions["programming"] = questions.filter(Q(type="code"))
- categorized_questions["upload"] = questions.filter(Q(type="upload"))
-
- types["objective_types"] = set([_type.type
- for _type in
- categorized_questions["objectives"]])
- types["blank_types"] = set([_type.type
- for _type in
- categorized_questions["blanks"]])
- types["programming_types"] = set([_type.type
- for _type in
- categorized_questions["programming"]])
- types["upload_types"] = set([_type.type
- for _type in categorized_questions["upload"]])
-
- all_ordered_questions = paper.get_all_ordered_questions()
-
- objectives_index = paper.get_questions_by_type(
- all_ordered_questions,
- types["objective_types"]
- )
- blanks_index = paper.get_questions_by_type(
- all_ordered_questions,
- types["blank_types"]
- )
- programming_index = paper.get_questions_by_type(
- all_ordered_questions,
- types["programming_types"]
- )
- upload_index = paper.get_questions_by_type(
- all_ordered_questions,
- types["upload_types"]
- )
-
- index = {
- 'objectives_index': objectives_index,
- 'blanks_index': blanks_index,
- 'programming_index': programming_index,
- 'upload_index': upload_index
- }
context = {
'question': question,
'paper': paper,
@@ -680,8 +631,6 @@ def show_question(request, question, paper, error_message=None,
'delay_time': delay_time,
'quiz_type': quiz_type,
'all_modules': all_modules,
- "question_types": all_question_types,
- "index": index,
}
answers = paper.get_previous_answers(question)
if answers:
--
cgit
From 0a106ab44ec983f4ebebea9b6b1e4b49fedcb473 Mon Sep 17 00:00:00 2001
From: CruiseDevice
Date: Mon, 7 Jan 2019 15:32:31 +0530
Subject: Add test for new model function
- Adds test for get_categorized_question_indices function in models.
---
yaksh/test_models.py | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/yaksh/test_models.py b/yaksh/test_models.py
index aea47de..3ae181c 100644
--- a/yaksh/test_models.py
+++ b/yaksh/test_models.py
@@ -4,7 +4,7 @@ from yaksh.models import User, Profile, Question, Quiz, QuestionPaper,\
QuestionSet, AnswerPaper, Answer, Course, StandardTestCase,\
StdIOBasedTestCase, FileUpload, McqTestCase, AssignmentUpload,\
LearningModule, LearningUnit, Lesson, LessonFile, CourseStatus, \
- create_group
+ create_group, legend_display_types
from yaksh.code_server import (
ServerPool, get_result as get_result_from_code_server
)
@@ -21,6 +21,7 @@ import os
import shutil
import tempfile
from threading import Thread
+from collections import Counter, defaultdict
from yaksh import settings
@@ -1583,6 +1584,20 @@ class AnswerPaperTestCases(unittest.TestCase):
course=self.answerpaper.course
)
+ def test_get_categorized_question_indices(self):
+ all_questions = self.answerpaper.get_all_ordered_questions()
+ categorized_question_indices = \
+ self.answerpaper.get_categorized_question_indices()
+ questions = all_questions[0:4]
+ category_question_map = defaultdict(lambda: [])
+ for index, question in enumerate(questions, 1):
+ category_question_map[
+ legend_display_types[question.type]["label"]
+ ].append(index)
+ category_question_map = dict(category_question_map)
+ self.assertDictEqual(
+ category_question_map, categorized_question_indices)
+
###############################################################################
class CourseTestCases(unittest.TestCase):
--
cgit
From 461cfcd6c736a016636932e019476558135f0ccf Mon Sep 17 00:00:00 2001
From: CruiseDevice
Date: Mon, 14 Jan 2019 14:42:01 +0530
Subject: Remove unused variables and imports
---
yaksh/test_models.py | 2 +-
yaksh/views.py | 1 -
2 files changed, 1 insertion(+), 2 deletions(-)
diff --git a/yaksh/test_models.py b/yaksh/test_models.py
index 3ae181c..8b9aa37 100644
--- a/yaksh/test_models.py
+++ b/yaksh/test_models.py
@@ -21,7 +21,7 @@ import os
import shutil
import tempfile
from threading import Thread
-from collections import Counter, defaultdict
+from collections import defaultdict
from yaksh import settings
diff --git a/yaksh/views.py b/yaksh/views.py
index 3eaa165..68d2b8a 100644
--- a/yaksh/views.py
+++ b/yaksh/views.py
@@ -568,7 +568,6 @@ def show_question(request, question, paper, error_message=None,
previous_question=None):
"""Show a question if possible."""
quiz = paper.question_paper.quiz
- questions = paper.questions.all()
quiz_type = 'Exam'
can_skip = False
if previous_question:
--
cgit
From 85427fceb1c06cf036f2351ebdc0a051b5d4acb6 Mon Sep 17 00:00:00 2001
From: CruiseDevice
Date: Mon, 14 Jan 2019 15:24:48 +0530
Subject: Fix PEP8 errors in views.py
---
yaksh/views.py | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/yaksh/views.py b/yaksh/views.py
index 68d2b8a..6c7a12e 100644
--- a/yaksh/views.py
+++ b/yaksh/views.py
@@ -903,8 +903,10 @@ def complete(request, reason=None, attempt_num=None, questionpaper_id=None,
"""Show a page to inform user that the quiz has been completed."""
user = request.user
if questionpaper_id is None:
- message = (reason or "An Unexpected Error occurred. Please contact your"
- " instructor/administrator.")
+ message = (
+ reason or "An Unexpected Error occurred."
+ " Please contact your instructor/administrator."
+ )
context = {'message': message}
return my_render_to_response(request, 'yaksh/complete.html', context)
else:
--
cgit
From 5550bdd39df0b5569e6e690bbd715dcd4b8259e7 Mon Sep 17 00:00:00 2001
From: CruiseDevice
Date: Wed, 16 Jan 2019 14:59:41 +0530
Subject: Made requested changes in models.py and test_models.py
- Remove 'category' key from legend_display_types dictionary.
- Add a condition to check if question type exists before creating category_question_map.
- Add test.
- Change lambda to list in defaultdict.
---
yaksh/models.py | 27 ++++++++++++++-------------
yaksh/test_models.py | 12 ++----------
2 files changed, 16 insertions(+), 23 deletions(-)
diff --git a/yaksh/models.py b/yaksh/models.py
index 0f20605..cce90e7 100644
--- a/yaksh/models.py
+++ b/yaksh/models.py
@@ -82,14 +82,14 @@ string_check_type = (
)
legend_display_types = {
- "mcq": {"category": "objective", "label": "Objective Type"},
- "mcc": {"category": "objective", "label": "Objective Type"},
- "code": {"category": "programming", "label": "Programming"},
- "upload": {"category": "upload", "label": "Upload"},
- "integer": {"category": "objective", "label": "Objective Type"},
- "string": {"category": "objective", "label": "Objective Type"},
- "float": {"category": "objective", "label": "Objective Type"},
- "arrange": {"category": "objective", "label": "Objective Type"},
+ "mcq": {"label": "Objective Type"},
+ "mcc": {"label": "Objective Type"},
+ "code": {"label": "Programming"},
+ "upload": {"label": "Upload"},
+ "integer": {"label": "Objective Type"},
+ "string": {"label": "Objective Type"},
+ "float": {"label": "Objective Type"},
+ "arrange": {"label": "Objective Type"},
}
attempts = [(i, i) for i in range(1, 6)]
@@ -2104,12 +2104,13 @@ class AnswerPaper(models.Model):
return self.answers.filter(question=question).order_by('-id')
def get_categorized_question_indices(self):
-
- category_question_map = defaultdict(lambda: [])
+ category_question_map = defaultdict(list)
for index, question in enumerate(self.get_all_ordered_questions(), 1):
- category_question_map[
- legend_display_types[question.type]["label"]
- ].append(index)
+ question_category = legend_display_types.get(question.type)
+ if question_category:
+ category_question_map[
+ question_category["label"]
+ ].append(index)
return dict(category_question_map)
def validate_answer(self, user_answer, question, json_data=None, uid=None,
diff --git a/yaksh/test_models.py b/yaksh/test_models.py
index 8b9aa37..2e136d5 100644
--- a/yaksh/test_models.py
+++ b/yaksh/test_models.py
@@ -1585,18 +1585,10 @@ class AnswerPaperTestCases(unittest.TestCase):
)
def test_get_categorized_question_indices(self):
- all_questions = self.answerpaper.get_all_ordered_questions()
+ question_indices = {'Programming': [1], 'Objective Type': [2, 3]}
categorized_question_indices = \
self.answerpaper.get_categorized_question_indices()
- questions = all_questions[0:4]
- category_question_map = defaultdict(lambda: [])
- for index, question in enumerate(questions, 1):
- category_question_map[
- legend_display_types[question.type]["label"]
- ].append(index)
- category_question_map = dict(category_question_map)
- self.assertDictEqual(
- category_question_map, categorized_question_indices)
+ self.assertDictEqual(question_indices, categorized_question_indices)
###############################################################################
--
cgit
From 6d5b5d32ff8d179dae7e07767b700dec6acd7ef4 Mon Sep 17 00:00:00 2001
From: CruiseDevice
Date: Fri, 18 Jan 2019 16:21:30 +0530
Subject: More test cases for model method get_categorized_question_indices
---
yaksh/test_models.py | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 72 insertions(+)
diff --git a/yaksh/test_models.py b/yaksh/test_models.py
index 2e136d5..0ef62b2 100644
--- a/yaksh/test_models.py
+++ b/yaksh/test_models.py
@@ -983,7 +983,11 @@ class AnswerPaperTestCases(unittest.TestCase):
self.profile = self.user.profile
self.quiz = Quiz.objects.get(description='demo quiz 1')
self.question_paper = QuestionPaper(quiz=self.quiz, total_marks=3)
+ self.question_paper2 = QuestionPaper(quiz=self.quiz, total_marks=3)
+ self.question_paper3 = QuestionPaper(quiz=self.quiz, total_marks=3)
self.question_paper.save()
+ self.question_paper2.save()
+ self.question_paper3.save()
self.quiz2 = Quiz.objects.get(description='demo quiz 2')
self.qtn_paper_with_single_question = QuestionPaper(
quiz=self.quiz2, total_marks=3
@@ -992,12 +996,17 @@ class AnswerPaperTestCases(unittest.TestCase):
all_questions = Question.objects.filter(user=self.user).order_by("id")
self.questions = all_questions[0:3]
+ self.questions2 = all_questions[4:7]
+ self.questions3 = []
self.start_time = timezone.now()
self.end_time = self.start_time + timedelta(minutes=20)
self.question1 = all_questions[0]
self.question2 = all_questions[1]
self.question3 = all_questions[2]
self.question4 = all_questions[3]
+ self.question5 = self.questions2[0]
+ self.question6 = self.questions2[1]
+ self.question7 = self.questions2[2]
# create answerpaper
self.answerpaper = AnswerPaper(
@@ -1022,6 +1031,7 @@ class AnswerPaperTestCases(unittest.TestCase):
)
self.answerpaper.questions_unanswered.add(*self.questions)
self.answerpaper.save()
+
# answers for the Answer Paper
self.answer_right = Answer(
question=self.question1,
@@ -1115,6 +1125,56 @@ class AnswerPaperTestCases(unittest.TestCase):
)
self.mcc_based_testcase.save()
+ # create answerpaper2
+ self.answerpaper2 = AnswerPaper(
+ user=self.user,
+ question_paper=self.question_paper2,
+ start_time=self.start_time,
+ end_time=self.end_time,
+ user_ip=self.ip,
+ course=self.course
+ )
+
+ self.attempted_papers2 = AnswerPaper.objects.filter(
+ question_paper=self.question_paper2,
+ user=self.user
+ )
+
+ self.question_paper2.fixed_questions.add(*self.questions2)
+ already_attempted2 = self.attempted_papers2.count()
+ self.answerpaper2.attempt_number = already_attempted2 + 1
+ self.answerpaper2.save()
+
+ self.answerpaper2.questions.add(*self.questions2)
+ self.answerpaper2.questions_order = ",".join(
+ [str(question.id) for question in self.questions2]
+ )
+ self.answerpaper2.questions_unanswered.add(*self.questions2)
+ self.answerpaper2.save()
+
+ # create answerpaper3 with no questions
+ self.answerpaper3 = AnswerPaper(
+ user=self.user,
+ question_paper=self.question_paper3,
+ start_time=self.start_time,
+ end_time=self.end_time,
+ user_ip=self.ip,
+ course=self.course
+ )
+
+ self.attempted_papers3 = AnswerPaper.objects.filter(
+ question_paper=self.question_paper3,
+ user=self.user
+ )
+ self.question_paper3.fixed_questions.add(*self.questions3)
+ already_attempted3 = self.attempted_papers3.count()
+ self.answerpaper3.attempt_number = already_attempted3 + 1
+ self.answerpaper3.save()
+ self.answerpaper3.questions.add(*self.questions3)
+ self.answerpaper3.question_order = ""
+ self.answerpaper3.questions_unanswered.add(*self.questions3)
+ self.answerpaper3.save()
+
# Setup quiz where questions are shuffled
# Create Quiz and Question Paper
self.quiz2 = Quiz.objects.get(description="demo quiz 2")
@@ -1590,6 +1650,18 @@ class AnswerPaperTestCases(unittest.TestCase):
self.answerpaper.get_categorized_question_indices()
self.assertDictEqual(question_indices, categorized_question_indices)
+ def test_get_categorized_question_indices_for_only_one_category(self):
+ question_indices = {'Programming': [1, 2, 3]}
+ categorized_question_indices = \
+ self.answerpaper2.get_categorized_question_indices()
+ self.assertDictEqual(question_indices, categorized_question_indices)
+
+ def test_get_categorized_question_indices_for_no_questions(self):
+ question_indices = {}
+ categorized_question_indices = \
+ self.answerpaper3.get_categorized_question_indices()
+ self.assertDictEqual(question_indices, categorized_question_indices)
+
###############################################################################
class CourseTestCases(unittest.TestCase):
--
cgit
From 2648dd45b5b014e1c75ea154b51b6835bc157afc Mon Sep 17 00:00:00 2001
From: CruiseDevice
Date: Tue, 22 Jan 2019 13:07:49 +0530
Subject: Resolve comments
- Removes redundant code.
---
yaksh/test_models.py | 89 +++++++++++++++-------------------------------------
1 file changed, 26 insertions(+), 63 deletions(-)
diff --git a/yaksh/test_models.py b/yaksh/test_models.py
index 0ef62b2..8416e8d 100644
--- a/yaksh/test_models.py
+++ b/yaksh/test_models.py
@@ -983,30 +983,20 @@ class AnswerPaperTestCases(unittest.TestCase):
self.profile = self.user.profile
self.quiz = Quiz.objects.get(description='demo quiz 1')
self.question_paper = QuestionPaper(quiz=self.quiz, total_marks=3)
- self.question_paper2 = QuestionPaper(quiz=self.quiz, total_marks=3)
- self.question_paper3 = QuestionPaper(quiz=self.quiz, total_marks=3)
self.question_paper.save()
- self.question_paper2.save()
- self.question_paper3.save()
self.quiz2 = Quiz.objects.get(description='demo quiz 2')
self.qtn_paper_with_single_question = QuestionPaper(
quiz=self.quiz2, total_marks=3
)
self.qtn_paper_with_single_question.save()
-
all_questions = Question.objects.filter(user=self.user).order_by("id")
self.questions = all_questions[0:3]
- self.questions2 = all_questions[4:7]
- self.questions3 = []
self.start_time = timezone.now()
self.end_time = self.start_time + timedelta(minutes=20)
self.question1 = all_questions[0]
self.question2 = all_questions[1]
self.question3 = all_questions[2]
self.question4 = all_questions[3]
- self.question5 = self.questions2[0]
- self.question6 = self.questions2[1]
- self.question7 = self.questions2[2]
# create answerpaper
self.answerpaper = AnswerPaper(
@@ -1125,56 +1115,6 @@ class AnswerPaperTestCases(unittest.TestCase):
)
self.mcc_based_testcase.save()
- # create answerpaper2
- self.answerpaper2 = AnswerPaper(
- user=self.user,
- question_paper=self.question_paper2,
- start_time=self.start_time,
- end_time=self.end_time,
- user_ip=self.ip,
- course=self.course
- )
-
- self.attempted_papers2 = AnswerPaper.objects.filter(
- question_paper=self.question_paper2,
- user=self.user
- )
-
- self.question_paper2.fixed_questions.add(*self.questions2)
- already_attempted2 = self.attempted_papers2.count()
- self.answerpaper2.attempt_number = already_attempted2 + 1
- self.answerpaper2.save()
-
- self.answerpaper2.questions.add(*self.questions2)
- self.answerpaper2.questions_order = ",".join(
- [str(question.id) for question in self.questions2]
- )
- self.answerpaper2.questions_unanswered.add(*self.questions2)
- self.answerpaper2.save()
-
- # create answerpaper3 with no questions
- self.answerpaper3 = AnswerPaper(
- user=self.user,
- question_paper=self.question_paper3,
- start_time=self.start_time,
- end_time=self.end_time,
- user_ip=self.ip,
- course=self.course
- )
-
- self.attempted_papers3 = AnswerPaper.objects.filter(
- question_paper=self.question_paper3,
- user=self.user
- )
- self.question_paper3.fixed_questions.add(*self.questions3)
- already_attempted3 = self.attempted_papers3.count()
- self.answerpaper3.attempt_number = already_attempted3 + 1
- self.answerpaper3.save()
- self.answerpaper3.questions.add(*self.questions3)
- self.answerpaper3.question_order = ""
- self.answerpaper3.questions_unanswered.add(*self.questions3)
- self.answerpaper3.save()
-
# Setup quiz where questions are shuffled
# Create Quiz and Question Paper
self.quiz2 = Quiz.objects.get(description="demo quiz 2")
@@ -1196,6 +1136,29 @@ class AnswerPaperTestCases(unittest.TestCase):
self.user2_answerpaper2 = self.question_paper.make_answerpaper(
self.user2, self.ip, 1, self.course.id
)
+ self.questions_list = Question.objects.filter(summary__in=summary_list[0:5])
+ # create question_paper3
+ self.question_paper3 = QuestionPaper(
+ quiz=self.quiz2, total_marks=3, shuffle_questions=True)
+ self.question_paper3.save()
+ question_list_with_only_one_category = \
+ [question for question in self.questions_list
+ if question.type == 'code']
+ self.question_paper3.fixed_questions.add(*question_list_with_only_one_category)
+ # create anspaper for user1 with questions of only one category
+ self.user1_answerpaper2 = self.question_paper3.make_answerpaper(
+ self.user, self.ip, 1, self.course.id
+ )
+ # create question_paper4
+ self.question_paper4 = QuestionPaper(
+ quiz=self.quiz, total_marks=3, shuffle_questions=True
+ )
+ self.question_paper4.save()
+ question_list_with_no_questions = []
+ self.question_paper4.fixed_questions.add(*question_list_with_no_questions)
+ # create anspaper for user1 with no questions
+ self.user1_answerpaper3 = self.question_paper4.make_answerpaper(self.user, self.ip, 1, self.course.id)
+
settings.code_evaluators['python']['standardtestcase'] = \
"yaksh.python_assertion_evaluator.PythonAssertionEvaluator"
self.SERVER_POOL_PORT = 4000
@@ -1644,7 +1607,7 @@ class AnswerPaperTestCases(unittest.TestCase):
course=self.answerpaper.course
)
- def test_get_categorized_question_indices(self):
+ def test_get_categorized_question_indices_with_multiple_categories(self):
question_indices = {'Programming': [1], 'Objective Type': [2, 3]}
categorized_question_indices = \
self.answerpaper.get_categorized_question_indices()
@@ -1653,13 +1616,13 @@ class AnswerPaperTestCases(unittest.TestCase):
def test_get_categorized_question_indices_for_only_one_category(self):
question_indices = {'Programming': [1, 2, 3]}
categorized_question_indices = \
- self.answerpaper2.get_categorized_question_indices()
+ self.user1_answerpaper2.get_categorized_question_indices()
self.assertDictEqual(question_indices, categorized_question_indices)
def test_get_categorized_question_indices_for_no_questions(self):
question_indices = {}
categorized_question_indices = \
- self.answerpaper3.get_categorized_question_indices()
+ self.user1_answerpaper3.get_categorized_question_indices()
self.assertDictEqual(question_indices, categorized_question_indices)
--
cgit
From fb2afe0f1f631aebadd12baf87278891fd857ae7 Mon Sep 17 00:00:00 2001
From: CruiseDevice
Date: Tue, 22 Jan 2019 14:22:20 +0530
Subject: Fix PEP8 issues
---
yaksh/test_models.py | 31 +++++++++++++++++++------------
1 file changed, 19 insertions(+), 12 deletions(-)
diff --git a/yaksh/test_models.py b/yaksh/test_models.py
index 8416e8d..2110f1b 100644
--- a/yaksh/test_models.py
+++ b/yaksh/test_models.py
@@ -1136,28 +1136,35 @@ class AnswerPaperTestCases(unittest.TestCase):
self.user2_answerpaper2 = self.question_paper.make_answerpaper(
self.user2, self.ip, 1, self.course.id
)
- self.questions_list = Question.objects.filter(summary__in=summary_list[0:5])
+ self.questions_list = Question.objects.filter(
+ summary__in=summary_list[0:5])
# create question_paper3
self.question_paper3 = QuestionPaper(
- quiz=self.quiz2, total_marks=3, shuffle_questions=True)
+ quiz=self.quiz2, total_marks=3, shuffle_questions=True)
self.question_paper3.save()
- question_list_with_only_one_category = \
- [question for question in self.questions_list
- if question.type == 'code']
- self.question_paper3.fixed_questions.add(*question_list_with_only_one_category)
+ question_list_with_only_one_category = [
+ question for question in self.questions_list
+ if question.type == 'code']
+ self.question_paper3.fixed_questions.add(
+ *question_list_with_only_one_category
+ )
# create anspaper for user1 with questions of only one category
self.user1_answerpaper2 = self.question_paper3.make_answerpaper(
- self.user, self.ip, 1, self.course.id
- )
+ self.user, self.ip, 1, self.course.id
+ )
# create question_paper4
self.question_paper4 = QuestionPaper(
- quiz=self.quiz, total_marks=3, shuffle_questions=True
- )
+ quiz=self.quiz, total_marks=3, shuffle_questions=True
+ )
self.question_paper4.save()
question_list_with_no_questions = []
- self.question_paper4.fixed_questions.add(*question_list_with_no_questions)
+ self.question_paper4.fixed_questions.add(
+ *question_list_with_no_questions
+ )
# create anspaper for user1 with no questions
- self.user1_answerpaper3 = self.question_paper4.make_answerpaper(self.user, self.ip, 1, self.course.id)
+ self.user1_answerpaper3 = self.question_paper4.make_answerpaper(
+ self.user, self.ip, 1, self.course.id
+ )
settings.code_evaluators['python']['standardtestcase'] = \
"yaksh.python_assertion_evaluator.PythonAssertionEvaluator"
--
cgit
From 4db850b16d1445cfb8a58fce28e1e7582421b3b7 Mon Sep 17 00:00:00 2001
From: CruiseDevice
Date: Mon, 28 Jan 2019 13:01:42 +0530
Subject: Resolve comments
---
yaksh/test_models.py | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/yaksh/test_models.py b/yaksh/test_models.py
index 2110f1b..f94c67c 100644
--- a/yaksh/test_models.py
+++ b/yaksh/test_models.py
@@ -1154,13 +1154,10 @@ class AnswerPaperTestCases(unittest.TestCase):
)
# create question_paper4
self.question_paper4 = QuestionPaper(
- quiz=self.quiz, total_marks=3, shuffle_questions=True
+ quiz=self.quiz, total_marks=0, shuffle_questions=True
)
self.question_paper4.save()
- question_list_with_no_questions = []
- self.question_paper4.fixed_questions.add(
- *question_list_with_no_questions
- )
+
# create anspaper for user1 with no questions
self.user1_answerpaper3 = self.question_paper4.make_answerpaper(
self.user, self.ip, 1, self.course.id
--
cgit
From 010d302e9b925736674ce5c5eda4f6a7ffbebb98 Mon Sep 17 00:00:00 2001
From: CruiseDevice
Date: Mon, 28 Jan 2019 22:03:13 +0530
Subject: Fix PEP8 issues
---
yaksh/test_models.py | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/yaksh/test_models.py b/yaksh/test_models.py
index f94c67c..1f38d03 100644
--- a/yaksh/test_models.py
+++ b/yaksh/test_models.py
@@ -288,9 +288,10 @@ class ProfileTestCases(unittest.TestCase):
def setUp(self):
self.creator = User.objects.get(username='creator')
self.profile = Profile.objects.get(user=self.creator)
- self.teacher = User.objects.create_user(username='teacher_profile',
- password='teacher_profile',
- email='teacher_profile@test.com')
+ self.teacher = User.objects.create_user(
+ username='teacher_profile',
+ password='teacher_profile',
+ email='teacher_profile@test.com')
Profile.objects.create(
user=self.teacher, roll_number=123, institute='IIT',
is_moderator=True, department='Chemical', position='Teacher'
@@ -330,6 +331,7 @@ class ProfileTestCases(unittest.TestCase):
self.teacher.delete()
self.course.delete()
+
###############################################################################
class QuestionTestCases(unittest.TestCase):
def setUp(self):
--
cgit