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
8905343f
Commit
8905343f
authored
Mar 27, 2013
by
Victor Shnayder
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1744 from MITx/fix/diana/image-response-show-answer
Fix 500 errors for bug #289
parents
2cf815ae
967cf7e6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
5 deletions
+48
-5
common/lib/capa/capa/responsetypes.py
+37
-5
common/lib/capa/capa/tests/test_responsetypes.py
+11
-0
No files found.
common/lib/capa/capa/responsetypes.py
View file @
8905343f
...
...
@@ -1961,9 +1961,10 @@ class ImageResponse(LoncapaResponse):
self
.
ielements
=
self
.
inputfields
self
.
answer_ids
=
[
ie
.
get
(
'id'
)
for
ie
in
self
.
ielements
]
def
get_score
(
self
,
student_answers
):
correct_map
=
CorrectMap
()
expectedset
=
self
.
get_answers
()
expectedset
=
self
.
get_
mapped_
answers
()
for
aid
in
self
.
answer_ids
:
# loop through IDs of <imageinput>
# fields in our stanza
given
=
student_answers
[
...
...
@@ -2018,11 +2019,42 @@ class ImageResponse(LoncapaResponse):
break
return
correct_map
def
get_answers
(
self
):
return
(
def
get_mapped_answers
(
self
):
'''
Returns the internal representation of the answers
Input:
None
Returns:
tuple (dict, dict) -
rectangles (dict) - a map of inputs to the defined rectangle for that input
regions (dict) - a map of inputs to the defined region for that input
'''
answers
=
(
dict
([(
ie
.
get
(
'id'
),
ie
.
get
(
'rectangle'
))
for
ie
in
self
.
ielements
]),
dict
([(
ie
.
get
(
'id'
),
ie
.
get
(
'regions'
))
for
ie
in
self
.
ielements
]))
return
answers
def
get_answers
(
self
):
'''
Returns the external representation of the answers
Input:
None
Returns:
dict (str, (str, str)) - a map of inputs to a tuple of their rectange
and their regions
'''
answers
=
{}
for
ie
in
self
.
ielements
:
ie_id
=
ie
.
get
(
'id'
)
answers
[
ie_id
]
=
(
ie
.
get
(
'rectangle'
),
ie
.
get
(
'regions'
))
return
answers
#-----------------------------------------------------------------------------
...
...
@@ -2087,8 +2119,8 @@ class AnnotationResponse(LoncapaResponse):
correct_option
=
self
.
_find_option_with_choice
(
inputfield
,
'correct'
)
if
correct_option
is
not
None
:
answer_map
[
inputfield
.
get
(
'id'
)
]
=
correct_option
.
get
(
'description'
)
input_id
=
inputfield
.
get
(
'id'
)
answer_map
[
input_id
]
=
correct_option
.
get
(
'description'
)
return
answer_map
def
_get_max_points
(
self
):
...
...
common/lib/capa/capa/tests/test_responsetypes.py
View file @
8905343f
...
...
@@ -36,6 +36,10 @@ class ResponseTest(unittest.TestCase):
correct_map
=
problem
.
grade_answers
(
input_dict
)
self
.
assertEquals
(
correct_map
.
get_correctness
(
'1_2_1'
),
expected_correctness
)
def
assert_answer_format
(
self
,
problem
):
answers
=
problem
.
get_question_answers
()
self
.
assertTrue
(
answers
[
'1_2_1'
]
is
not
None
)
def
assert_multiple_grade
(
self
,
problem
,
correct_answers
,
incorrect_answers
):
for
input_str
in
correct_answers
:
result
=
problem
.
grade_answers
({
'1_2_1'
:
input_str
})
.
get_correctness
(
'1_2_1'
)
...
...
@@ -166,6 +170,13 @@ class ImageResponseTest(ResponseTest):
incorrect_inputs
=
[
"[0,0]"
,
"[600,300]"
]
self
.
assert_multiple_grade
(
problem
,
correct_inputs
,
incorrect_inputs
)
def
test_show_answer
(
self
):
rectangle_str
=
"(100,100)-(200,200)"
region_str
=
"[[10,10], [20,10], [20, 30]]"
problem
=
self
.
build_problem
(
regions
=
region_str
,
rectangle
=
rectangle_str
)
self
.
assert_answer_format
(
problem
)
class
SymbolicResponseTest
(
unittest
.
TestCase
):
def
test_sr_grade
(
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