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
b814e6a0
Commit
b814e6a0
authored
Jul 19, 2012
by
ichuang
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #221 from MITx/kimth/lms-coderesponse
CodeResponse restricted to only one answer field
parents
49ee1296
ff4716ef
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
23 deletions
+18
-23
common/lib/capa/capa/responsetypes.py
+18
-23
No files found.
common/lib/capa/capa/responsetypes.py
View file @
b814e6a0
...
...
@@ -705,6 +705,7 @@ class CodeResponse(LoncapaResponse):
response_tag
=
'coderesponse'
allowed_inputfields
=
[
'textline'
,
'textbox'
]
max_inputfields
=
1
def
setup_response
(
self
):
xml
=
self
.
xml
...
...
@@ -717,10 +718,10 @@ class CodeResponse(LoncapaResponse):
self
.
code
=
self
.
system
.
filesystem
.
open
(
'src/'
+
answer_src
)
.
read
()
else
:
self
.
code
=
answer
.
text
else
:
# no <answer> stanza; get code from <script>
else
:
# no <answer> stanza; get code from <script>
self
.
code
=
self
.
context
[
'script_code'
]
if
not
self
.
code
:
msg
=
'
%
s: Missing answer script code for
external
response'
%
unicode
(
self
)
msg
=
'
%
s: Missing answer script code for
code
response'
%
unicode
(
self
)
msg
+=
"
\n
See XML source line
%
s"
%
getattr
(
self
.
xml
,
'sourceline'
,
'<unavailable>'
)
raise
LoncapaProblemError
(
msg
)
...
...
@@ -745,12 +746,10 @@ class CodeResponse(LoncapaResponse):
raise
Exception
(
err
)
def
get_score
(
self
,
student_answers
):
idset
=
sorted
(
self
.
answer_ids
)
try
:
submission
=
[
student_answers
[
k
]
for
k
in
idset
]
submission
=
[
student_answers
[
self
.
answer_id
]
]
except
Exception
as
err
:
log
.
error
(
'Error in CodeResponse
%
s: cannot get student answer for
%
s; student_answers=
%
s'
%
(
err
,
self
.
answer_id
s
,
student_answers
))
log
.
error
(
'Error in CodeResponse
%
s: cannot get student answer for
%
s; student_answers=
%
s'
%
(
err
,
self
.
answer_id
,
student_answers
))
raise
Exception
(
err
)
self
.
context
.
update
({
'submission'
:
submission
})
...
...
@@ -760,8 +759,7 @@ class CodeResponse(LoncapaResponse):
# Non-null CorrectMap['queuekey'] indicates that the problem has been submitted
cmap
=
CorrectMap
()
for
answer_id
in
idset
:
cmap
.
set
(
answer_id
,
queuekey
=
queuekey
,
msg
=
'Submitted to queue'
)
cmap
.
set
(
self
.
answer_id
,
queuekey
=
queuekey
,
msg
=
'Submitted to queue'
)
return
cmap
...
...
@@ -774,35 +772,32 @@ class CodeResponse(LoncapaResponse):
raise
Exception
(
err
)
# The following process is lifted directly from ExternalResponse
idset
=
sorted
(
self
.
answer_ids
)
ad
=
rxml
.
find
(
'awarddetail'
)
.
text
admap
=
{
'EXACT_ANS'
:
'correct'
,
# TODO: handle other loncapa responses
admap
=
{
'EXACT_ANS'
:
'correct'
,
# TODO: handle other loncapa responses
'WRONG_FORMAT'
:
'incorrect'
,
}
self
.
context
[
'correct'
]
=
[
'correct'
]
if
ad
in
admap
:
self
.
context
[
'correct'
][
0
]
=
admap
[
ad
]
# Replace 'oldcmap' with new grading results if queuekey matches
# Replace 'oldcmap' with new grading results if queuekey matches
.
# If queuekey does not match, we keep waiting for the score_msg that will match
for
answer_id
in
idset
:
if
oldcmap
.
is_right_queuekey
(
answer_id
,
queuekey
):
# If answer_id is not queued, will return False
idx
=
idset
.
index
(
answer_id
)
msg
=
rxml
.
find
(
'message'
)
.
text
.
replace
(
' '
,
' '
)
if
idx
==
0
else
None
oldcmap
.
set
(
answer_id
,
self
.
context
[
'correct'
][
idx
],
msg
=
msg
,
queuekey
=
None
)
# Queuekey is consumed
else
:
# Queuekey does not match
log
.
debug
(
'CodeResponse: queuekey
%
d does not match for answer_id=
%
s.'
%
(
queuekey
,
answer_id
))
if
oldcmap
.
is_right_queuekey
(
self
.
answer_id
,
queuekey
):
msg
=
rxml
.
find
(
'message'
)
.
text
.
replace
(
' '
,
' '
)
oldcmap
.
set
(
self
.
answer_id
,
correctness
=
self
.
context
[
'correct'
][
0
],
msg
=
msg
,
queuekey
=
None
)
# Queuekey is consumed
else
:
log
.
debug
(
'CodeResponse: queuekey
%
d does not match for answer_id=
%
s.'
%
(
queuekey
,
self
.
answer_id
))
return
oldcmap
# CodeResponse differentiates from ExternalResponse in the behavior of 'get_answers'. CodeResponse.get_answers
# does NOT require a queue submission, and the answer is computed (extracted from problem XML) locally.
def
get_answers
(
self
):
anshtml
=
'<font color="blue"><span class="code-answer"><br/><pre>
%
s</pre><br/></span></font>'
%
self
.
answer
return
dict
(
zip
(
self
.
answer_ids
,[
anshtml
]))
return
{
self
.
answer_id
:
anshtml
}
def
get_initial_display
(
self
):
return
dict
(
zip
(
self
.
answer_ids
,[
self
.
initial_display
]))
return
{
self
.
answer_id
:
self
.
initial_display
}
# CodeResponse._send_to_queue implements the same interface as defined for ExternalResponse's 'get_score'
def
_send_to_queue
(
self
,
extra_payload
):
...
...
@@ -810,9 +805,9 @@ class CodeResponse(LoncapaResponse):
xmlstr
=
etree
.
tostring
(
self
.
xml
,
pretty_print
=
True
)
header
=
{
'return_url'
:
self
.
system
.
xqueue_callback_url
}
# Queuekey generation
h
=
hashlib
.
md5
()
if
self
.
system
is
not
None
:
h
.
update
(
str
(
self
.
system
.
get
(
'seed'
)))
h
.
update
(
str
(
self
.
system
.
seed
))
h
.
update
(
str
(
time
.
time
()))
queuekey
=
int
(
h
.
hexdigest
(),
16
)
header
.
update
({
'queuekey'
:
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