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
1cba122d
Commit
1cba122d
authored
Apr 01, 2013
by
Will Daly
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Undid accidental commit of pylint fixes to responsetypes
parent
87d8a56a
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
46 deletions
+24
-46
common/lib/capa/capa/responsetypes.py
+24
-46
No files found.
common/lib/capa/capa/responsetypes.py
View file @
1cba122d
...
@@ -2,8 +2,7 @@
...
@@ -2,8 +2,7 @@
# File: courseware/capa/responsetypes.py
# File: courseware/capa/responsetypes.py
#
#
'''
'''
Problem response evaluation. Handles checking of
Problem response evaluation. Handles checking of student responses, of a variety of types.
student responses, of a variety of types.
Used by capa_problem.py
Used by capa_problem.py
'''
'''
...
@@ -11,6 +10,7 @@ Used by capa_problem.py
...
@@ -11,6 +10,7 @@ Used by capa_problem.py
# standard library imports
# standard library imports
import
abc
import
abc
import
cgi
import
cgi
import
hashlib
import
inspect
import
inspect
import
json
import
json
import
logging
import
logging
...
@@ -34,10 +34,7 @@ from .correctmap import CorrectMap
...
@@ -34,10 +34,7 @@ from .correctmap import CorrectMap
from
datetime
import
datetime
from
datetime
import
datetime
from
.util
import
*
from
.util
import
*
from
lxml
import
etree
from
lxml
import
etree
from
lxml.html.soupparser
import
fromstring
as
fromstring_bs
# uses Beautiful Soup!!! FIXME?
# uses Beautiful Soup!!! FIXME?
from
lxml.html.soupparser
import
fromstring
as
fromstring_bs
import
xqueue_interface
import
xqueue_interface
log
=
logging
.
getLogger
(
__name__
)
log
=
logging
.
getLogger
(
__name__
)
...
@@ -246,17 +243,13 @@ class LoncapaResponse(object):
...
@@ -246,17 +243,13 @@ class LoncapaResponse(object):
# hint specified by function?
# hint specified by function?
hintfn
=
hintgroup
.
get
(
'hintfn'
)
hintfn
=
hintgroup
.
get
(
'hintfn'
)
if
hintfn
:
if
hintfn
:
# Hint is determined by a function defined
# Hint is determined by a function defined in the <script> context; evaluate
# in the <script> context; evaluate
# that function to obtain list of hint, hintmode for each answer_id.
# that function to obtain list of hint,
# hintmode for each answer_id.
# The function should take arguments
# The function should take arguments (answer_ids, student_answers, new_cmap, old_cmap)
# (answer_ids, student_answers, new_cmap, old_cmap)
# and it should modify new_cmap as appropriate.
# and it should modify new_cmap as appropriate.
# We may extend this in the future to add
# We may extend this in the future to add another argument which provides a
# another argument which provides a
# callback procedure to a social hint generation system.
# callback procedure to a social hint generation system.
if
not
hintfn
in
self
.
context
:
if
not
hintfn
in
self
.
context
:
msg
=
'missing specified hint function
%
s in script context'
%
hintfn
msg
=
'missing specified hint function
%
s in script context'
%
hintfn
...
@@ -274,8 +267,7 @@ class LoncapaResponse(object):
...
@@ -274,8 +267,7 @@ class LoncapaResponse(object):
raise
ResponseError
(
msg
)
raise
ResponseError
(
msg
)
return
return
# hint specified by conditions and text dependent
# hint specified by conditions and text dependent on conditions (a-la Loncapa design)
# on conditions (a-la Loncapa design)
# see http://help.loncapa.org/cgi-bin/fom?file=291
# see http://help.loncapa.org/cgi-bin/fom?file=291
#
#
# Example:
# Example:
...
@@ -283,12 +275,10 @@ class LoncapaResponse(object):
...
@@ -283,12 +275,10 @@ class LoncapaResponse(object):
# <formularesponse samples="x@-5:5#11" id="11" answer="$answer">
# <formularesponse samples="x@-5:5#11" id="11" answer="$answer">
# <textline size="25" />
# <textline size="25" />
# <hintgroup>
# <hintgroup>
# <formulahint samples="x@-5:5#11" answer="$wrongans"
# <formulahint samples="x@-5:5#11" answer="$wrongans" name="inversegrad"></formulahint>
# name="inversegrad"></formulahint>
# <hintpart on="inversegrad">
# <hintpart on="inversegrad">
# <text>You have inverted the slope in the question. The slope is
# <text>You have inverted the slope in the question. The slope is
# (y2-y1)/(x2 - x1) you have the slope
# (y2-y1)/(x2 - x1) you have the slope as (x2-x1)/(y2-y1).</text>
# as (x2-x1)/(y2-y1).</text>
# </hintpart>
# </hintpart>
# </hintgroup>
# </hintgroup>
# </formularesponse>
# </formularesponse>
...
@@ -543,8 +533,7 @@ class JavascriptResponse(LoncapaResponse):
...
@@ -543,8 +533,7 @@ class JavascriptResponse(LoncapaResponse):
points
=
self
.
get_max_score
()
points
=
self
.
get_max_score
()
else
:
else
:
points
=
0
points
=
0
return
CorrectMap
(
self
.
answer_id
,
correctness
,
return
CorrectMap
(
self
.
answer_id
,
correctness
,
npoints
=
points
,
msg
=
evaluation
)
npoints
=
points
,
msg
=
evaluation
)
def
run_grader
(
self
,
submission
):
def
run_grader
(
self
,
submission
):
if
submission
is
None
or
submission
==
''
:
if
submission
is
None
or
submission
==
''
:
...
@@ -964,8 +953,7 @@ def sympy_check2():
...
@@ -964,8 +953,7 @@ def sympy_check2():
log
.
debug
(
'answer_ids=
%
s'
%
self
.
answer_ids
)
log
.
debug
(
'answer_ids=
%
s'
%
self
.
answer_ids
)
# the <answer>...</answer> stanza should be
# the <answer>...</answer> stanza should be local to the current <customresponse>.
# local to the current <customresponse>.
# So try looking there first.
# So try looking there first.
self
.
code
=
None
self
.
code
=
None
answer
=
None
answer
=
None
...
@@ -974,8 +962,7 @@ def sympy_check2():
...
@@ -974,8 +962,7 @@ def sympy_check2():
except
IndexError
:
except
IndexError
:
# print "xml = ",etree.tostring(xml,pretty_print=True)
# print "xml = ",etree.tostring(xml,pretty_print=True)
# if we have a "cfn" attribute then look for the
# if we have a "cfn" attribute then look for the function specified by cfn, in
# function specified by cfn, in
# the problem context ie the comparison function is defined in the
# the problem context ie the comparison function is defined in the
# <script>...</script> stanza instead
# <script>...</script> stanza instead
cfn
=
xml
.
get
(
'cfn'
)
cfn
=
xml
.
get
(
'cfn'
)
...
@@ -986,8 +973,8 @@ def sympy_check2():
...
@@ -986,8 +973,8 @@ def sympy_check2():
else
:
else
:
msg
=
"
%
s: can't find cfn
%
s in context"
%
(
msg
=
"
%
s: can't find cfn
%
s in context"
%
(
unicode
(
self
),
cfn
)
unicode
(
self
),
cfn
)
msg
+=
(
"
\n
See XML source line
%
s"
%
msg
+=
"
\n
See XML source line
%
s"
%
getattr
(
self
.
xml
,
'sourceline'
,
getattr
(
self
.
xml
,
'sourceline'
,
'<unavailable>'
)
)
'<unavailable>'
)
raise
LoncapaProblemError
(
msg
)
raise
LoncapaProblemError
(
msg
)
if
not
self
.
code
:
if
not
self
.
code
:
...
@@ -1023,17 +1010,14 @@ def sympy_check2():
...
@@ -1023,17 +1010,14 @@ def sympy_check2():
log
.
error
(
msg
)
log
.
error
(
msg
)
raise
Exception
(
msg
)
raise
Exception
(
msg
)
# global variable in context which holds the
# global variable in context which holds the Presentation MathML from dynamic math input
# Presentation MathML from dynamic math input
# ordered list of dynamath responses
# ordered list of dynamath responses
dynamath
=
[
student_answers
.
get
(
k
+
'_dynamath'
,
None
)
for
k
in
idset
]
dynamath
=
[
student_answers
.
get
(
k
+
'_dynamath'
,
None
)
for
k
in
idset
]
# if there is only one box, and it's empty, then don't evaluate
# if there is only one box, and it's empty, then don't evaluate
if
len
(
idset
)
==
1
and
not
submission
[
0
]:
if
len
(
idset
)
==
1
and
not
submission
[
0
]:
# default to no error message on empty answer
# default to no error message on empty answer (to be consistent with other
# (to be consistent with other
# responsetypes) but allow author to still have the old behavior by setting
# responsetypes) but allow author to still
# have the old behavior by setting
# empty_answer_err attribute
# empty_answer_err attribute
msg
=
(
'<span class="inline-error">No answer entered!</span>'
msg
=
(
'<span class="inline-error">No answer entered!</span>'
if
self
.
xml
.
get
(
'empty_answer_err'
)
else
''
)
if
self
.
xml
.
get
(
'empty_answer_err'
)
else
''
)
...
@@ -1108,8 +1092,7 @@ def sympy_check2():
...
@@ -1108,8 +1092,7 @@ def sympy_check2():
try
:
try
:
answer_given
=
submission
[
0
]
if
(
answer_given
=
submission
[
0
]
if
(
len
(
idset
)
==
1
)
else
submission
len
(
idset
)
==
1
)
else
submission
# handle variable number of arguments in check function,
# handle variable number of arguments in check function, for backwards compatibility
# for backwards compatibility
# with various Tutor2 check functions
# with various Tutor2 check functions
args
=
[
self
.
expect
,
answer_given
,
args
=
[
self
.
expect
,
answer_given
,
student_answers
,
self
.
answer_ids
[
0
]]
student_answers
,
self
.
answer_ids
[
0
]]
...
@@ -1141,8 +1124,7 @@ def sympy_check2():
...
@@ -1141,8 +1124,7 @@ def sympy_check2():
msg
=
ret
.
get
(
'msg'
,
None
)
msg
=
ret
.
get
(
'msg'
,
None
)
msg
=
self
.
clean_message_html
(
msg
)
msg
=
self
.
clean_message_html
(
msg
)
# If there is only one input, apply the message to
# If there is only one input, apply the message to that input
# that input
# Otherwise, apply the message to the whole problem
# Otherwise, apply the message to the whole problem
if
len
(
idset
)
>
1
:
if
len
(
idset
)
>
1
:
overall_message
=
msg
overall_message
=
msg
...
@@ -1155,8 +1137,7 @@ def sympy_check2():
...
@@ -1155,8 +1137,7 @@ def sympy_check2():
# 'input_list': [{ 'ok': BOOLEAN, 'msg': STRING }, ...] }
# 'input_list': [{ 'ok': BOOLEAN, 'msg': STRING }, ...] }
#
#
# This allows the function to return an 'overall message'
# This allows the function to return an 'overall message'
# that applies to the entire problem, as well as
# that applies to the entire problem, as well as correct/incorrect
# correct/incorrect
# status and messages for individual inputs
# status and messages for individual inputs
elif
'input_list'
in
ret
:
elif
'input_list'
in
ret
:
overall_message
=
ret
.
get
(
'overall_message'
,
''
)
overall_message
=
ret
.
get
(
'overall_message'
,
''
)
...
@@ -1389,8 +1370,7 @@ class CodeResponse(LoncapaResponse):
...
@@ -1389,8 +1370,7 @@ class CodeResponse(LoncapaResponse):
tests
=
self
.
xml
.
get
(
'tests'
)
tests
=
self
.
xml
.
get
(
'tests'
)
# Extract 'answer' and 'initial_display' from XML.
# Extract 'answer' and 'initial_display' from XML. Note that the code to be exec'ed here is:
# Note that the code to be exec'ed here is:
# (1) Internal edX code, i.e. NOT student submissions, and
# (1) Internal edX code, i.e. NOT student submissions, and
# (2) The code should only define the strings 'initial_display', 'answer',
# (2) The code should only define the strings 'initial_display', 'answer',
# 'preamble', 'test_program'
# 'preamble', 'test_program'
...
@@ -1411,8 +1391,7 @@ class CodeResponse(LoncapaResponse):
...
@@ -1411,8 +1391,7 @@ class CodeResponse(LoncapaResponse):
" 'answer' and/or 'initial_display' in <answer>...</answer>"
%
err
)
" 'answer' and/or 'initial_display' in <answer>...</answer>"
%
err
)
raise
Exception
(
err
)
raise
Exception
(
err
)
# Finally, make the ExternalResponse input XML format
# Finally, make the ExternalResponse input XML format conform to the generic
# conform to the generic
# exteral grader interface
# exteral grader interface
# The XML tagging of grader_payload is pyxserver-specific
# The XML tagging of grader_payload is pyxserver-specific
grader_payload
=
'<pyxserver>'
grader_payload
=
'<pyxserver>'
...
@@ -1521,8 +1500,7 @@ class CodeResponse(LoncapaResponse):
...
@@ -1521,8 +1500,7 @@ class CodeResponse(LoncapaResponse):
# TODO: Find out how this is used elsewhere, if any
# TODO: Find out how this is used elsewhere, if any
self
.
context
[
'correct'
]
=
correctness
self
.
context
[
'correct'
]
=
correctness
# Replace 'oldcmap' with new grading results if queuekey matches.
# Replace 'oldcmap' with new grading results if queuekey matches. If queuekey
# If queuekey
# does not match, we keep waiting for the score_msg whose key actually
# does not match, we keep waiting for the score_msg whose key actually
# matches
# matches
if
oldcmap
.
is_right_queuekey
(
self
.
answer_id
,
queuekey
):
if
oldcmap
.
is_right_queuekey
(
self
.
answer_id
,
queuekey
):
...
...
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