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
e2bbaf08
Commit
e2bbaf08
authored
Jan 15, 2013
by
Alexander Kryklia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
removed use_targets flag
parent
0349e157
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
30 deletions
+23
-30
common/lib/capa/capa/verifiers/draganddrop.py
+6
-12
common/lib/capa/capa/verifiers/tests.py
+17
-18
No files found.
common/lib/capa/capa/verifiers/draganddrop.py
View file @
e2bbaf08
""" Grader of drag and drop input.
""" Grader of drag and drop input.
Client side behavior: user can drag and drop images from list on base image.
Client side behavior: user can drag and drop images from list on base image.
Parameter 'use_targets' in xml can control two use cases.
if use_targets is true (defaut), then json returned from client is:
Then json returned from client is:
{
{
"use_targets": true,
"draggable": [
"draggable": [
{ "image1": "t1" },
{ "image1": "t1" },
{ "ant": "t2" },
{ "ant": "t2" },
...
@@ -14,9 +13,8 @@ if use_targets is true (defaut), then json returned from client is:
...
@@ -14,9 +13,8 @@ if use_targets is true (defaut), then json returned from client is:
}
}
values are target names.
values are target names.
If use_targets is false
:
or
:
{
{
"use_targets": false,
"draggable": [
"draggable": [
{ "image1": "[10, 20]" },
{ "image1": "[10, 20]" },
{ "ant": "[30, 40]" },
{ "ant": "[30, 40]" },
...
@@ -112,10 +110,7 @@ class DragAndDrop(object):
...
@@ -112,10 +110,7 @@ class DragAndDrop(object):
def
grade
(
self
):
def
grade
(
self
):
''' Grader user answer.
''' Grader user answer.
If use_targets is True - checks if every draggable isplaced on proper
Checks if every draggable isplaced on proper target or on proper
target.
If use_targets is False - checks if every draggable is placed on proper
coordinates within radius of forgiveness (default is 10).
coordinates within radius of forgiveness (default is 10).
Returns: bool.
Returns: bool.
...
@@ -260,7 +255,6 @@ class DragAndDrop(object):
...
@@ -260,7 +255,6 @@ class DragAndDrop(object):
correct_answer
=
tmp
correct_answer
=
tmp
user_answer
=
json
.
loads
(
user_answer
)
user_answer
=
json
.
loads
(
user_answer
)
self
.
use_targets
=
user_answer
.
get
(
'use_targets'
)
# check if we have draggables that are not in correct answer:
# check if we have draggables that are not in correct answer:
self
.
excess_draggables
=
{}
self
.
excess_draggables
=
{}
...
@@ -295,12 +289,12 @@ def grade(user_input, correct_answer):
...
@@ -295,12 +289,12 @@ def grade(user_input, correct_answer):
Args:
Args:
user_input: json. Format::
user_input: json. Format::
{
"use_targets": false,
"draggables":
{ "draggables":
[{"1": [10, 10]}, {"name_with_icon": [20, 20]}]}'
[{"1": [10, 10]}, {"name_with_icon": [20, 20]}]}'
or
or
{"
use_targets": true, "
draggables": [{"1": "t1"},
\
{"draggables": [{"1": "t1"},
\
{"name_with_icon": "t2"}]}
{"name_with_icon": "t2"}]}
correct_answer: dict or list.
correct_answer: dict or list.
...
...
common/lib/capa/capa/verifiers/tests.py
View file @
e2bbaf08
...
@@ -41,73 +41,72 @@ class Test_PositionsCompare(unittest.TestCase):
...
@@ -41,73 +41,72 @@ class Test_PositionsCompare(unittest.TestCase):
class
Test_DragAndDrop_Grade
(
unittest
.
TestCase
):
class
Test_DragAndDrop_Grade
(
unittest
.
TestCase
):
def
test_targets_true
(
self
):
def
test_targets_true
(
self
):
user_input
=
'{"
use_targets": true, "
draggables": [{"1": "t1"},
\
user_input
=
'{"draggables": [{"1": "t1"},
\
{"name_with_icon": "t2"}]}'
{"name_with_icon": "t2"}]}'
correct_answer
=
{
'1'
:
't1'
,
'name_with_icon'
:
't2'
}
correct_answer
=
{
'1'
:
't1'
,
'name_with_icon'
:
't2'
}
self
.
assertTrue
(
draganddrop
.
grade
(
user_input
,
correct_answer
))
self
.
assertTrue
(
draganddrop
.
grade
(
user_input
,
correct_answer
))
def
test_targets_false
(
self
):
def
test_targets_false
(
self
):
user_input
=
'{"
use_targets": true, "
draggables": [{"1": "t1"},
\
user_input
=
'{"draggables": [{"1": "t1"},
\
{"name_with_icon": "t2"}]}'
{"name_with_icon": "t2"}]}'
correct_answer
=
{
'1'
:
't3'
,
'name_with_icon'
:
't2'
}
correct_answer
=
{
'1'
:
't3'
,
'name_with_icon'
:
't2'
}
self
.
assertFalse
(
draganddrop
.
grade
(
user_input
,
correct_answer
))
self
.
assertFalse
(
draganddrop
.
grade
(
user_input
,
correct_answer
))
def
test_multiple_images_per_target_true
(
self
):
def
test_multiple_images_per_target_true
(
self
):
user_input
=
'{
"use_targets": true,
\
user_input
=
'{
\
"draggables": [{"1": "t1"}, {"name_with_icon": "t1"}]}'
"draggables": [{"1": "t1"}, {"name_with_icon": "t1"}]}'
correct_answer
=
{
'1'
:
't1'
,
'name_with_icon'
:
't1'
}
correct_answer
=
{
'1'
:
't1'
,
'name_with_icon'
:
't1'
}
self
.
assertTrue
(
draganddrop
.
grade
(
user_input
,
correct_answer
))
self
.
assertTrue
(
draganddrop
.
grade
(
user_input
,
correct_answer
))
def
test_multiple_images_per_target_false
(
self
):
def
test_multiple_images_per_target_false
(
self
):
user_input
=
'{
"use_targets": true,
\
user_input
=
'{
\
"draggables": [{"1": "t1"}, {"name_with_icon": "t1"}]}'
"draggables": [{"1": "t1"}, {"name_with_icon": "t1"}]}'
correct_answer
=
{
'1'
:
't2'
,
'name_with_icon'
:
't1'
}
correct_answer
=
{
'1'
:
't2'
,
'name_with_icon'
:
't1'
}
self
.
assertFalse
(
draganddrop
.
grade
(
user_input
,
correct_answer
))
self
.
assertFalse
(
draganddrop
.
grade
(
user_input
,
correct_answer
))
def
test_targets_and_positions
(
self
):
def
test_targets_and_positions
(
self
):
user_input
=
'{"
use_targets": true, "
draggables": [{"1": [10,10]},
\
user_input
=
'{"draggables": [{"1": [10,10]},
\
{"name_with_icon": [[10,10],4]}]}'
{"name_with_icon": [[10,10],4]}]}'
correct_answer
=
{
'1'
:
[
10
,
10
],
'name_with_icon'
:
[[
10
,
10
],
4
]}
correct_answer
=
{
'1'
:
[
10
,
10
],
'name_with_icon'
:
[[
10
,
10
],
4
]}
self
.
assertFalse
(
draganddrop
.
grade
(
user_input
,
correct_answer
))
self
.
assertFalse
(
draganddrop
.
grade
(
user_input
,
correct_answer
))
def
test_position_and_targets
(
self
):
def
test_position_and_targets
(
self
):
user_input
=
'{"use_targets": false,
\
user_input
=
'{"draggables": [{"1": "t1"}, {"name_with_icon": "t2"}]}'
"draggables": [{"1": "t1"}, {"name_with_icon": "t2"}]}'
correct_answer
=
{
'1'
:
't1'
,
'name_with_icon'
:
't2'
}
correct_answer
=
{
'1'
:
't1'
,
'name_with_icon'
:
't2'
}
self
.
assertTrue
(
draganddrop
.
grade
(
user_input
,
correct_answer
))
self
.
assertTrue
(
draganddrop
.
grade
(
user_input
,
correct_answer
))
def
test_positions_exact
(
self
):
def
test_positions_exact
(
self
):
user_input
=
'{"
use_targets": false, "
draggables":
\
user_input
=
'{"draggables":
\
[{"1": [10, 10]}, {"name_with_icon": [20, 20]}]}'
[{"1": [10, 10]}, {"name_with_icon": [20, 20]}]}'
correct_answer
=
{
'1'
:
[
10
,
10
],
'name_with_icon'
:
[
20
,
20
]}
correct_answer
=
{
'1'
:
[
10
,
10
],
'name_with_icon'
:
[
20
,
20
]}
self
.
assertTrue
(
draganddrop
.
grade
(
user_input
,
correct_answer
))
self
.
assertTrue
(
draganddrop
.
grade
(
user_input
,
correct_answer
))
def
test_positions_false
(
self
):
def
test_positions_false
(
self
):
user_input
=
'{"
use_targets": false, "
draggables":
\
user_input
=
'{"draggables":
\
[{"1": [10, 10]}, {"name_with_icon": [20, 20]}]}'
[{"1": [10, 10]}, {"name_with_icon": [20, 20]}]}'
correct_answer
=
{
'1'
:
[
25
,
25
],
'name_with_icon'
:
[
20
,
20
]}
correct_answer
=
{
'1'
:
[
25
,
25
],
'name_with_icon'
:
[
20
,
20
]}
self
.
assertFalse
(
draganddrop
.
grade
(
user_input
,
correct_answer
))
self
.
assertFalse
(
draganddrop
.
grade
(
user_input
,
correct_answer
))
def
test_positions_true_in_radius
(
self
):
def
test_positions_true_in_radius
(
self
):
user_input
=
'{"
use_targets": false, "
draggables":
\
user_input
=
'{"draggables":
\
[{"1": [10, 10]}, {"name_with_icon": [20, 20]}]}'
[{"1": [10, 10]}, {"name_with_icon": [20, 20]}]}'
correct_answer
=
{
'1'
:
[
14
,
14
],
'name_with_icon'
:
[
20
,
20
]}
correct_answer
=
{
'1'
:
[
14
,
14
],
'name_with_icon'
:
[
20
,
20
]}
self
.
assertTrue
(
draganddrop
.
grade
(
user_input
,
correct_answer
))
self
.
assertTrue
(
draganddrop
.
grade
(
user_input
,
correct_answer
))
def
test_positions_true_in_manual_radius
(
self
):
def
test_positions_true_in_manual_radius
(
self
):
user_input
=
'{"
use_targets": false, "
draggables":
\
user_input
=
'{"draggables":
\
[{"1": [10, 10]}, {"name_with_icon": [20, 20]}]}'
[{"1": [10, 10]}, {"name_with_icon": [20, 20]}]}'
correct_answer
=
{
'1'
:
[[
40
,
10
],
30
],
'name_with_icon'
:
[
20
,
20
]}
correct_answer
=
{
'1'
:
[[
40
,
10
],
30
],
'name_with_icon'
:
[
20
,
20
]}
self
.
assertTrue
(
draganddrop
.
grade
(
user_input
,
correct_answer
))
self
.
assertTrue
(
draganddrop
.
grade
(
user_input
,
correct_answer
))
def
test_positions_false_in_manual_radius
(
self
):
def
test_positions_false_in_manual_radius
(
self
):
user_input
=
'{"
use_targets": false, "
draggables":
\
user_input
=
'{"draggables":
\
[{"1": [10, 10]}, {"name_with_icon": [20, 20]}]}'
[{"1": [10, 10]}, {"name_with_icon": [20, 20]}]}'
correct_answer
=
{
'1'
:
[[
40
,
10
],
29
],
'name_with_icon'
:
[
20
,
20
]}
correct_answer
=
{
'1'
:
[[
40
,
10
],
29
],
'name_with_icon'
:
[
20
,
20
]}
self
.
assertFalse
(
draganddrop
.
grade
(
user_input
,
correct_answer
))
self
.
assertFalse
(
draganddrop
.
grade
(
user_input
,
correct_answer
))
def
test_correct_answer_not_has_key_from_user_answer
(
self
):
def
test_correct_answer_not_has_key_from_user_answer
(
self
):
user_input
=
'{"
use_targets": true, "
draggables": [{"1": "t1"},
\
user_input
=
'{"draggables": [{"1": "t1"},
\
{"name_with_icon": "t2"}]}'
{"name_with_icon": "t2"}]}'
correct_answer
=
{
'3'
:
't3'
,
'name_with_icon'
:
't2'
}
correct_answer
=
{
'3'
:
't3'
,
'name_with_icon'
:
't2'
}
self
.
assertFalse
(
draganddrop
.
grade
(
user_input
,
correct_answer
))
self
.
assertFalse
(
draganddrop
.
grade
(
user_input
,
correct_answer
))
...
@@ -116,14 +115,14 @@ class Test_DragAndDrop_Grade(unittest.TestCase):
...
@@ -116,14 +115,14 @@ class Test_DragAndDrop_Grade(unittest.TestCase):
"""Draggables can be places anywhere on base image.
"""Draggables can be places anywhere on base image.
Place grass in the middle of the image and ant in the
Place grass in the middle of the image and ant in the
right upper corner."""
right upper corner."""
user_input
=
'{"
use_targets": false, "
draggables":
\
user_input
=
'{"draggables":
\
[{"ant":[610.5,57.449951171875]},{"grass":[322.5,199.449951171875]}]}'
[{"ant":[610.5,57.449951171875]},{"grass":[322.5,199.449951171875]}]}'
correct_answer
=
{
'grass'
:
[[
300
,
200
],
200
],
'ant'
:
[[
500
,
0
],
200
]}
correct_answer
=
{
'grass'
:
[[
300
,
200
],
200
],
'ant'
:
[[
500
,
0
],
200
]}
self
.
assertTrue
(
draganddrop
.
grade
(
user_input
,
correct_answer
))
self
.
assertTrue
(
draganddrop
.
grade
(
user_input
,
correct_answer
))
def
test_lcao_correct
(
self
):
def
test_lcao_correct
(
self
):
"""Describe carbon molecule in LCAO-MO"""
"""Describe carbon molecule in LCAO-MO"""
user_input
=
'{"
use_targets":true,"
draggables":[{"1":"s_left"},
\
user_input
=
'{"draggables":[{"1":"s_left"},
\
{"5":"s_right"},{"4":"s_sigma"},{"6":"s_sigma_star"},{"7":"p_left_1"},
\
{"5":"s_right"},{"4":"s_sigma"},{"6":"s_sigma_star"},{"7":"p_left_1"},
\
{"8":"p_left_2"},{"10":"p_right_1"},{"9":"p_right_2"},
\
{"8":"p_left_2"},{"10":"p_right_1"},{"9":"p_right_2"},
\
{"2":"p_pi_1"},{"3":"p_pi_2"},{"11":"s_sigma_name"},
\
{"2":"p_pi_1"},{"3":"p_pi_2"},{"11":"s_sigma_name"},
\
...
@@ -162,7 +161,7 @@ class Test_DragAndDrop_Grade(unittest.TestCase):
...
@@ -162,7 +161,7 @@ class Test_DragAndDrop_Grade(unittest.TestCase):
def
test_lcao_extra_element_incorrect
(
self
):
def
test_lcao_extra_element_incorrect
(
self
):
"""Describe carbon molecule in LCAO-MO"""
"""Describe carbon molecule in LCAO-MO"""
user_input
=
'{"
use_targets":true,"
draggables":[{"1":"s_left"},
\
user_input
=
'{"draggables":[{"1":"s_left"},
\
{"5":"s_right"},{"4":"s_sigma"},{"6":"s_sigma_star"},{"7":"p_left_1"},
\
{"5":"s_right"},{"4":"s_sigma"},{"6":"s_sigma_star"},{"7":"p_left_1"},
\
{"8":"p_left_2"},{"17":"p_left_3"},{"10":"p_right_1"},{"9":"p_right_2"},
\
{"8":"p_left_2"},{"17":"p_left_3"},{"10":"p_right_1"},{"9":"p_right_2"},
\
{"2":"p_pi_1"},{"3":"p_pi_2"},{"11":"s_sigma_name"},
\
{"2":"p_pi_1"},{"3":"p_pi_2"},{"11":"s_sigma_name"},
\
...
@@ -177,7 +176,7 @@ class Test_DragAndDrop_Grade(unittest.TestCase):
...
@@ -177,7 +176,7 @@ class Test_DragAndDrop_Grade(unittest.TestCase):
'rule'
:
'anyof'
'rule'
:
'anyof'
},
{
},
{
'draggables'
:
[
'7'
,
'8'
,
'9'
,
'10'
],
'draggables'
:
[
'7'
,
'8'
,
'9'
,
'10'
],
'targets'
:
[
'p_left_1'
,
'p_left_2'
,
'p_right_1'
,
'p_right_2'
],
'targets'
:
[
'p_left_1'
,
'p_left_2'
,
'p_right_1'
,
'p_right_2'
],
'rule'
:
'anyof'
'rule'
:
'anyof'
},
{
},
{
'draggables'
:
[
'11'
,
'12'
],
'draggables'
:
[
'11'
,
'12'
],
...
@@ -205,7 +204,7 @@ class Test_DragAndDrop_Populate(unittest.TestCase):
...
@@ -205,7 +204,7 @@ class Test_DragAndDrop_Populate(unittest.TestCase):
def
test_1
(
self
):
def
test_1
(
self
):
dnd
=
draganddrop
.
DragAndDrop
()
dnd
=
draganddrop
.
DragAndDrop
()
correct_answer
=
{
'1'
:
[[
40
,
10
],
29
],
'name_with_icon'
:
[
20
,
20
]}
correct_answer
=
{
'1'
:
[[
40
,
10
],
29
],
'name_with_icon'
:
[
20
,
20
]}
user_input
=
'{"
use_targets": false, "
draggables":
\
user_input
=
'{"draggables":
\
[{"1": [10, 10]}, {"name_with_icon": [20, 20]}]}'
[{"1": [10, 10]}, {"name_with_icon": [20, 20]}]}'
dnd
.
populate
(
correct_answer
,
user_input
)
dnd
.
populate
(
correct_answer
,
user_input
)
...
...
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