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
dacc1f3c
Commit
dacc1f3c
authored
Nov 28, 2016
by
Nimisha Asthagiri
Committed by
GitHub
Nov 28, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #14055 from edx/naa/fix-capa-max-score
Fix CAPA's max_score computation
parents
ca5c741f
562aeee0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
57 deletions
+61
-57
common/lib/capa/capa/capa_problem.py
+38
-35
common/lib/capa/capa/responsetypes.py
+23
-22
No files found.
common/lib/capa/capa/capa_problem.py
View file @
dacc1f3c
...
...
@@ -187,7 +187,7 @@ class LoncapaProblem(object):
# construct script processor context (eg for customresponse problems)
if
minimal_init
:
self
.
context
=
{
'script_code'
:
""
}
self
.
context
=
{}
else
:
self
.
context
=
self
.
_extract_context
(
self
.
tree
)
...
...
@@ -195,24 +195,24 @@ class LoncapaProblem(object):
# transformations. This also creates the dict (self.responders) of Response
# instances for each question in the problem. The dict has keys = xml subtree of
# Response, values = Response instance
self
.
problem_data
=
self
.
_preprocess_problem
(
self
.
tree
)
self
.
problem_data
=
self
.
_preprocess_problem
(
self
.
tree
,
minimal_init
)
if
not
self
.
student_answers
:
# True when student_answers is an empty dict
self
.
set_initial_display
()
if
not
minimal_init
:
if
not
self
.
student_answers
:
# True when student_answers is an empty dict
self
.
set_initial_display
()
# dictionary of InputType objects associated with this problem
# input_id string -> InputType object
self
.
inputs
=
{}
# dictionary of InputType objects associated with this problem
# input_id string -> InputType object
self
.
inputs
=
{}
# Run response late_transforms last (see MultipleChoiceResponse)
# Sort the responses to be in *_1 *_2 ... order.
responses
=
self
.
responders
.
values
()
responses
=
sorted
(
responses
,
key
=
lambda
resp
:
int
(
resp
.
id
[
resp
.
id
.
rindex
(
'_'
)
+
1
:]))
for
response
in
responses
:
if
hasattr
(
response
,
'late_transforms'
):
response
.
late_transforms
(
self
)
# Run response late_transforms last (see MultipleChoiceResponse)
# Sort the responses to be in *_1 *_2 ... order.
responses
=
self
.
responders
.
values
()
responses
=
sorted
(
responses
,
key
=
lambda
resp
:
int
(
resp
.
id
[
resp
.
id
.
rindex
(
'_'
)
+
1
:]))
for
response
in
responses
:
if
hasattr
(
response
,
'late_transforms'
):
response
.
late_transforms
(
self
)
if
not
minimal_init
:
self
.
extracted_tree
=
self
.
_extract_html
(
self
.
tree
)
def
make_xml_compatible
(
self
,
tree
):
...
...
@@ -869,7 +869,7 @@ class LoncapaProblem(object):
return
tree
def
_preprocess_problem
(
self
,
tree
):
# private
def
_preprocess_problem
(
self
,
tree
,
minimal_init
):
# private
"""
Assign IDs to all the responses
Assign sub-IDs to all entries (textline, schematic, etc.)
...
...
@@ -907,28 +907,31 @@ class LoncapaProblem(object):
# instantiate capa Response
responsetype_cls
=
responsetypes
.
registry
.
get_class_for_tag
(
response
.
tag
)
responder
=
responsetype_cls
(
response
,
inputfields
,
self
.
context
,
self
.
capa_system
,
self
.
capa_module
)
responder
=
responsetype_cls
(
response
,
inputfields
,
self
.
context
,
self
.
capa_system
,
self
.
capa_module
,
minimal_init
)
# save in list in self
self
.
responders
[
response
]
=
responder
# 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
]
=
self
.
responders
[
response
]
.
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
# TODO: We should make the namespaces consistent and unique (e.g. %s_problem_%i).
solution_id
=
1
for
solution
in
tree
.
findall
(
'.//solution'
):
solution
.
attrib
[
'id'
]
=
"
%
s_solution_
%
i"
%
(
self
.
problem_id
,
solution_id
)
solution_id
+=
1
if
not
minimal_init
:
# 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
]
=
self
.
responders
[
response
]
.
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
# TODO: We should make the namespaces consistent and unique (e.g. %s_problem_%i).
solution_id
=
1
for
solution
in
tree
.
findall
(
'.//solution'
):
solution
.
attrib
[
'id'
]
=
"
%
s_solution_
%
i"
%
(
self
.
problem_id
,
solution_id
)
solution_id
+=
1
return
problem_data
...
...
common/lib/capa/capa/responsetypes.py
View file @
dacc1f3c
...
...
@@ -154,7 +154,7 @@ class LoncapaResponse(object):
# By default, we set this to False, allowing subclasses to override as appropriate.
multi_device_support
=
False
def
__init__
(
self
,
xml
,
inputfields
,
context
,
system
,
capa_module
):
def
__init__
(
self
,
xml
,
inputfields
,
context
,
system
,
capa_module
,
minimal_init
):
"""
Init is passed the following arguments:
...
...
@@ -213,28 +213,29 @@ class LoncapaResponse(object):
maxpoints
=
inputfield
.
get
(
'points'
,
'1'
)
self
.
maxpoints
.
update
({
inputfield
.
get
(
'id'
):
int
(
maxpoints
)})
# dict for default answer map (provided in input elements)
self
.
default_answer_map
=
{}
for
entry
in
self
.
inputfields
:
answer
=
entry
.
get
(
'correct_answer'
)
if
answer
:
self
.
default_answer_map
[
entry
.
get
(
'id'
)]
=
contextualize_text
(
answer
,
self
.
context
)
# Does this problem have partial credit?
# If so, what kind? Get it as a list of strings.
partial_credit
=
xml
.
xpath
(
'.'
)[
0
]
.
get
(
'partial_credit'
,
default
=
False
)
if
str
(
partial_credit
)
.
lower
()
.
strip
()
==
'false'
:
self
.
has_partial_credit
=
False
self
.
credit_type
=
[]
else
:
self
.
has_partial_credit
=
True
self
.
credit_type
=
partial_credit
.
split
(
','
)
self
.
credit_type
=
[
word
.
strip
()
.
lower
()
for
word
in
self
.
credit_type
]
if
not
minimal_init
:
# dict for default answer map (provided in input elements)
self
.
default_answer_map
=
{}
for
entry
in
self
.
inputfields
:
answer
=
entry
.
get
(
'correct_answer'
)
if
answer
:
self
.
default_answer_map
[
entry
.
get
(
'id'
)]
=
contextualize_text
(
answer
,
self
.
context
)
# Does this problem have partial credit?
# If so, what kind? Get it as a list of strings.
partial_credit
=
xml
.
xpath
(
'.'
)[
0
]
.
get
(
'partial_credit'
,
default
=
False
)
if
str
(
partial_credit
)
.
lower
()
.
strip
()
==
'false'
:
self
.
has_partial_credit
=
False
self
.
credit_type
=
[]
else
:
self
.
has_partial_credit
=
True
self
.
credit_type
=
partial_credit
.
split
(
','
)
self
.
credit_type
=
[
word
.
strip
()
.
lower
()
for
word
in
self
.
credit_type
]
if
hasattr
(
self
,
'setup_response'
):
self
.
setup_response
()
if
hasattr
(
self
,
'setup_response'
):
self
.
setup_response
()
def
get_max_score
(
self
):
"""
...
...
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