Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
problem-builder
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
problem-builder
Commits
dae27b34
Commit
dae27b34
authored
Jul 16, 2015
by
Tim Krones
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cache answer choices for MCQs.
parent
f57db139
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
13 deletions
+12
-13
problem_builder/tasks.py
+12
-13
No files found.
problem_builder/tasks.py
View file @
dae27b34
...
@@ -14,6 +14,7 @@ from xmodule.modulestore.exceptions import ItemNotFoundError
...
@@ -14,6 +14,7 @@ from xmodule.modulestore.exceptions import ItemNotFoundError
from
.mcq
import
MCQBlock
,
RatingBlock
from
.mcq
import
MCQBlock
,
RatingBlock
from
problem_builder
import
AnswerBlock
from
problem_builder
import
AnswerBlock
from
.questionnaire
import
QuestionnaireAbstractBlock
from
.sub_api
import
sub_api
from
.sub_api
import
sub_api
logger
=
get_task_logger
(
__name__
)
logger
=
get_task_logger
(
__name__
)
...
@@ -112,9 +113,10 @@ def _extract_data(course_key_str, block, user_id, match_string):
...
@@ -112,9 +113,10 @@ def _extract_data(course_key_str, block, user_id, match_string):
submissions
=
_get_submissions
(
course_key_str
,
block
,
user_id
)
submissions
=
_get_submissions
(
course_key_str
,
block
,
user_id
)
# - For each submission, look up student's username and answer:
# - For each submission, look up student's username and answer:
answer_cache
=
{}
for
submission
in
submissions
:
for
submission
in
submissions
:
username
=
_get_username
(
submission
,
user_id
)
username
=
_get_username
(
submission
,
user_id
)
answer
=
_get_answer
(
block
,
submission
)
answer
=
_get_answer
(
block
,
submission
,
answer_cache
)
# Short-circuit if answer does not match search criteria
# Short-circuit if answer does not match search criteria
if
not
match_string
.
lower
()
in
answer
.
lower
():
if
not
match_string
.
lower
()
in
answer
.
lower
():
...
@@ -177,19 +179,16 @@ def _get_username(submission, user_id):
...
@@ -177,19 +179,16 @@ def _get_username(submission, user_id):
return
user_by_anonymous_id
(
student_id
)
.
username
return
user_by_anonymous_id
(
student_id
)
.
username
def
_get_answer
(
block
,
submission
):
def
_get_answer
(
block
,
submission
,
answer_cache
):
"""
"""
Return answer associated with this `submission` to `block`.
Return answer associated with `submission` to `block`.
`answer_cache` is a dict that is reset for each block.
"""
"""
answer
=
submission
[
'answer'
]
answer
=
submission
[
'answer'
]
try
:
if
isinstance
(
block
,
QuestionnaireAbstractBlock
):
choices
=
block
.
children
# Convert from answer ID to answer label
except
AttributeError
:
if
answer
not
in
answer_cache
:
pass
answer_cache
[
answer
]
=
block
.
get_submission_display
(
answer
)
else
:
return
answer_cache
[
answer
]
for
choice
in
choices
:
choice_block
=
modulestore
()
.
get_item
(
choice
)
if
choice_block
.
value
==
answer
:
answer
=
choice_block
.
content
break
return
answer
return
answer
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment