Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
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
edx
edx-platform
Commits
314c5728
Commit
314c5728
authored
Jul 10, 2012
by
ichuang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix capa_problem to call each responder's get_answers() just once
parent
7a5d645b
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
10 deletions
+18
-10
common/lib/capa/capa/capa_problem.py
+18
-10
No files found.
common/lib/capa/capa/capa_problem.py
View file @
314c5728
...
@@ -147,7 +147,7 @@ class LoncapaProblem(object):
...
@@ -147,7 +147,7 @@ class LoncapaProblem(object):
used to give complex problems (eg programming questions) multiple points.
used to give complex problems (eg programming questions) multiple points.
'''
'''
maxscore
=
0
maxscore
=
0
for
respon
der
in
self
.
responders
.
value
s
():
for
respon
se
,
responder
in
self
.
responders
.
iteritem
s
():
if
hasattr
(
responder
,
'get_max_score'
):
if
hasattr
(
responder
,
'get_max_score'
):
try
:
try
:
maxscore
+=
responder
.
get_max_score
()
maxscore
+=
responder
.
get_max_score
()
...
@@ -155,11 +155,7 @@ class LoncapaProblem(object):
...
@@ -155,11 +155,7 @@ class LoncapaProblem(object):
log
.
debug
(
'responder
%
s failed to properly return from get_max_score()'
%
responder
)
# FIXME
log
.
debug
(
'responder
%
s failed to properly return from get_max_score()'
%
responder
)
# FIXME
raise
raise
else
:
else
:
try
:
maxscore
+=
len
(
self
.
responder_answers
[
response
])
maxscore
+=
len
(
responder
.
get_answers
())
except
:
log
.
debug
(
'responder
%
s failed to properly return get_answers()'
%
responder
)
# FIXME
raise
return
maxscore
return
maxscore
def
get_score
(
self
):
def
get_score
(
self
):
...
@@ -211,8 +207,8 @@ class LoncapaProblem(object):
...
@@ -211,8 +207,8 @@ class LoncapaProblem(object):
(see capa_module)
(see capa_module)
"""
"""
answer_map
=
dict
()
answer_map
=
dict
()
for
respon
der
in
self
.
responders
.
value
s
():
for
respon
se
in
self
.
responders
.
key
s
():
results
=
responder
.
get_answers
()
results
=
self
.
responder_answers
[
response
]
answer_map
.
update
(
results
)
# dict of (id,correct_answer)
answer_map
.
update
(
results
)
# dict of (id,correct_answer)
# include solutions from <solution>...</solution> stanzas
# include solutions from <solution>...</solution> stanzas
...
@@ -228,8 +224,9 @@ class LoncapaProblem(object):
...
@@ -228,8 +224,9 @@ class LoncapaProblem(object):
the dicts returned by grade_answers and get_question_answers. (Though
the dicts returned by grade_answers and get_question_answers. (Though
get_question_answers may only return a subset of these."""
get_question_answers may only return a subset of these."""
answer_ids
=
[]
answer_ids
=
[]
for
responder
in
self
.
responders
.
values
():
for
response
in
self
.
responders
.
keys
():
answer_ids
.
append
(
responder
.
get_answers
()
.
keys
())
results
=
self
.
responder_answers
[
response
]
answer_ids
.
append
(
results
.
keys
())
return
answer_ids
return
answer_ids
def
get_html
(
self
):
def
get_html
(
self
):
...
@@ -382,6 +379,8 @@ class LoncapaProblem(object):
...
@@ -382,6 +379,8 @@ class LoncapaProblem(object):
In-place transformation
In-place transformation
Also create capa Response instances for each responsetype and save as self.responders
Also create capa Response instances for each responsetype and save as self.responders
Obtain all responder answers and save as self.responder_answers dict (key = response)
'''
'''
response_id
=
1
response_id
=
1
self
.
responders
=
{}
self
.
responders
=
{}
...
@@ -402,6 +401,15 @@ class LoncapaProblem(object):
...
@@ -402,6 +401,15 @@ class LoncapaProblem(object):
responder
=
response_tag_dict
[
response
.
tag
](
response
,
inputfields
,
self
.
context
,
self
.
system
)
# instantiate capa Response
responder
=
response_tag_dict
[
response
.
tag
](
response
,
inputfields
,
self
.
context
,
self
.
system
)
# instantiate capa Response
self
.
responders
[
response
]
=
responder
# save in list in self
self
.
responders
[
response
]
=
responder
# save in list in self
# get responder answers (do this only once, since there may be a performance cost, eg with externalresponse)
self
.
responder_answers
=
{}
for
response
in
self
.
responders
.
keys
():
try
:
self
.
responder_answers
[
response
]
=
responder
.
get_answers
()
except
:
log
.
debug
(
'responder
%
s failed to properly return get_answers()'
%
self
.
responders
[
response
])
# FIXME
raise
# <solution>...</solution> may not be associated with any specific response; give IDs for those separately
# <solution>...</solution> may not be associated with any specific response; give IDs for those separately
# TODO: We should make the namespaces consistent and unique (e.g. %s_problem_%i).
# TODO: We should make the namespaces consistent and unique (e.g. %s_problem_%i).
solution_id
=
1
solution_id
=
1
...
...
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