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
a0f99ac3
Commit
a0f99ac3
authored
Jan 02, 2013
by
Alexander Kryklia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added case for extra draggables
parent
590e6363
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
86 additions
and
8 deletions
+86
-8
common/lib/capa/capa/graders/draganddrop.py
+20
-8
common/lib/capa/capa/graders/tests.py
+66
-0
No files found.
common/lib/capa/capa/graders/draganddrop.py
View file @
a0f99ac3
...
@@ -107,6 +107,7 @@ class DragAndDrop(object):
...
@@ -107,6 +107,7 @@ class DragAndDrop(object):
self
.
correct_positions
=
OrderedDict
()
# positions of comparing
self
.
correct_positions
=
OrderedDict
()
# positions of comparing
self
.
user_groups
=
OrderedDict
()
self
.
user_groups
=
OrderedDict
()
self
.
user_positions
=
OrderedDict
()
self
.
user_positions
=
OrderedDict
()
self
.
incorrect
=
False
def
grade
(
self
):
def
grade
(
self
):
'''
'''
...
@@ -129,9 +130,12 @@ class DragAndDrop(object):
...
@@ -129,9 +130,12 @@ class DragAndDrop(object):
Returns:
Returns:
True or False.
True or False.
'''
'''
if
sorted
(
self
.
correct_groups
.
keys
())
!=
sorted
(
self
.
user_groups
.
keys
()):
if
self
.
incorrect
:
return
False
return
False
if
sorted
(
self
.
correct_groups
.
keys
())
!=
sorted
(
self
.
user_groups
.
keys
()):
return
False
for
groupname
,
draggable_ids
in
self
.
correct_groups
.
items
():
for
groupname
,
draggable_ids
in
self
.
correct_groups
.
items
():
if
sorted
(
draggable_ids
)
!=
sorted
(
self
.
user_groups
[
groupname
]):
if
sorted
(
draggable_ids
)
!=
sorted
(
self
.
user_groups
[
groupname
]):
return
False
return
False
...
@@ -142,11 +146,10 @@ class DragAndDrop(object):
...
@@ -142,11 +146,10 @@ class DragAndDrop(object):
# with positions
# with positions
# 'denied' rule
# 'denied' rule
# import ipdb; ipdb.set_trace()
denied_positions
=
[
item
for
g
in
self
.
correct_groups
.
keys
()
denied_positions
=
[
self
.
correct_positions
[
g
]
.
get
(
'denied'
,
[])
for
item
in
self
.
correct_positions
[
g
]
.
get
(
'denied'
,
[])]
for
g
in
self
.
correct_groups
.
keys
()]
all_user_positions
=
[
item
for
g
in
self
.
correct_groups
.
keys
()
all_user_positions
=
[
self
.
user_positions
[
g
][
'user'
]
for
item
in
self
.
user_positions
[
g
][
'user'
]]
for
g
in
self
.
correct_groups
.
keys
()]
if
not
self
.
compare_positions
(
denied_positions
,
if
not
self
.
compare_positions
(
denied_positions
,
all_user_positions
,
flag
=
'denied'
):
all_user_positions
,
flag
=
'denied'
):
return
False
return
False
...
@@ -229,10 +232,12 @@ class DragAndDrop(object):
...
@@ -229,10 +232,12 @@ class DragAndDrop(object):
user_answer
=
json
.
loads
(
user_answer
)
user_answer
=
json
.
loads
(
user_answer
)
self
.
use_targets
=
user_answer
.
get
(
'use_targets'
)
self
.
use_targets
=
user_answer
.
get
(
'use_targets'
)
# check if we have draggables that are not in correct answer:
check_extra_draggables
=
{}
# create identical data structures
# create identical data structures
# user groups must mirror correct_groups
# user groups must mirror correct_groups
# and positions must reflect order in groups
# and positions must reflect order in group
for
groupname
in
self
.
correct_groups
:
for
groupname
in
self
.
correct_groups
:
self
.
user_groups
[
groupname
]
=
[]
self
.
user_groups
[
groupname
]
=
[]
self
.
user_positions
[
groupname
]
=
{
'user'
:
[]}
self
.
user_positions
[
groupname
]
=
{
'user'
:
[]}
...
@@ -243,7 +248,14 @@ class DragAndDrop(object):
...
@@ -243,7 +248,14 @@ class DragAndDrop(object):
self
.
user_groups
[
groupname
]
.
append
(
draggable_name
)
self
.
user_groups
[
groupname
]
.
append
(
draggable_name
)
self
.
user_positions
[
groupname
][
'user'
]
.
append
(
self
.
user_positions
[
groupname
][
'user'
]
.
append
(
draggable_dict
[
draggable_name
])
draggable_dict
[
draggable_name
])
check_extra_draggables
[
draggable_name
]
=
True
else
:
check_extra_draggables
[
draggable_name
]
=
\
check_extra_draggables
.
get
(
draggable_name
,
False
)
for
draggable
in
check_extra_draggables
:
if
not
check_extra_draggables
[
draggable
]:
self
.
incorrect
=
True
# import ipdb; ipdb.set_trace()
# import ipdb; ipdb.set_trace()
...
...
common/lib/capa/capa/graders/tests.py
View file @
a0f99ac3
...
@@ -86,6 +86,72 @@ class Test_DragAndDrop(unittest.TestCase):
...
@@ -86,6 +86,72 @@ class Test_DragAndDrop(unittest.TestCase):
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
):
"""Describe carbon molecule in LCAO-MO"""
user_input
=
'{"use_targets":true,"draggables":[{"1":"s_left"},
\
{"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"},
\
{"2":"p_pi_1"},{"3":"p_pi_2"},{"11":"s_sigma_name"},
\
{"13":"s_sigma_star_name"},{"15":"p_pi_name"},{"16":"p_pi_star_name"},
\
{"12":"p_sigma_name"},{"14":"p_sigma_star_name"}]}'
correct_answer
=
draganddrop
.
DragAndDrop
()
correct_answer
.
correct_groups
[
'filled_levels'
]
=
[
'1'
,
'2'
,
'3'
,
'4'
,
'5'
,
'6'
]
correct_answer
.
correct_positions
[
'filled_levels'
]
=
{
'allowed'
:
[
's_left'
,
's_right'
,
's_sigma'
,
's_sigma_star'
,
'p_pi_1'
,
'p_pi_2'
]}
correct_answer
.
correct_groups
[
'spin_up'
]
=
[
'7'
,
'8'
,
'9'
,
'10'
]
correct_answer
.
correct_positions
[
'spin_up'
]
=
{
'allowed'
:
[
'p_left_1'
,
'p_left_2'
,
'p_right_1'
,
'p_right_2'
]}
correct_answer
.
correct_groups
[
'sigma'
]
=
[
'11'
,
'12'
]
correct_answer
.
correct_positions
[
'sigma'
]
=
{
'allowed'
:
[
's_sigma_name'
,
'p_sigma_name'
]}
correct_answer
.
correct_groups
[
'sigma_star'
]
=
[
'13'
,
'14'
]
correct_answer
.
correct_positions
[
'sigma_star'
]
=
{
'allowed'
:
[
's_sigma_star_name'
,
'p_sigma_star_name'
]}
correct_answer
.
correct_groups
[
'pi'
]
=
[
'15'
]
correct_answer
.
correct_positions
[
'pi'
]
=
{
'allowed'
:
[
'p_pi_name'
]}
correct_answer
.
correct_groups
[
'pi_star'
]
=
[
'16'
]
correct_answer
.
correct_positions
[
'pi_star'
]
=
{
'allowed'
:
[
'p_pi_star_name'
]}
self
.
assertTrue
(
draganddrop
.
grade
(
user_input
,
correct_answer
))
def
test_lcao_extra_element_incorrect
(
self
):
"""Describe carbon molecule in LCAO-MO"""
user_input
=
'{"use_targets":true,"draggables":[{"1":"s_left"},
\
{"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"},
\
{"2":"p_pi_1"},{"3":"p_pi_2"},{"11":"s_sigma_name"},
\
{"13":"s_sigma_star_name"},{"15":"p_pi_name"},{"16":"p_pi_star_name"},
\
{"12":"p_sigma_name"},{"14":"p_sigma_star_name"}]}'
correct_answer
=
draganddrop
.
DragAndDrop
()
correct_answer
.
correct_groups
[
'filled_levels'
]
=
[
'1'
,
'2'
,
'3'
,
'4'
,
'5'
,
'6'
]
correct_answer
.
correct_positions
[
'filled_levels'
]
=
{
'allowed'
:
[
's_left'
,
's_right'
,
's_sigma'
,
's_sigma_star'
,
'p_pi_1'
,
'p_pi_2'
]}
correct_answer
.
correct_groups
[
'spin_up'
]
=
[
'7'
,
'8'
,
'9'
,
'10'
]
correct_answer
.
correct_positions
[
'spin_up'
]
=
{
'allowed'
:
[
'p_left_1'
,
'p_left_2'
,
'p_right_1'
,
'p_right_2'
]}
correct_answer
.
correct_groups
[
'sigma'
]
=
[
'11'
,
'12'
]
correct_answer
.
correct_positions
[
'sigma'
]
=
{
'allowed'
:
[
's_sigma_name'
,
'p_sigma_name'
]}
correct_answer
.
correct_groups
[
'sigma_star'
]
=
[
'13'
,
'14'
]
correct_answer
.
correct_positions
[
'sigma_star'
]
=
{
'allowed'
:
[
's_sigma_star_name'
,
'p_sigma_star_name'
]}
correct_answer
.
correct_groups
[
'pi'
]
=
[
'15'
]
correct_answer
.
correct_positions
[
'pi'
]
=
{
'allowed'
:
[
'p_pi_name'
]}
correct_answer
.
correct_groups
[
'pi_star'
]
=
[
'16'
]
correct_answer
.
correct_positions
[
'pi_star'
]
=
{
'allowed'
:
[
'p_pi_star_name'
]}
self
.
assertFalse
(
draganddrop
.
grade
(
user_input
,
correct_answer
))
def
suite
():
def
suite
():
...
...
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