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
948f8090
Commit
948f8090
authored
Oct 17, 2012
by
Александр
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
grading for vsepr
parent
5185df38
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
8 deletions
+35
-8
common/lib/capa/capa/chem/chemtools.py
+35
-8
No files found.
common/lib/capa/capa/chem/chemtools.py
View file @
948f8090
from
collections
import
OrderedDict
from
collections
import
OrderedDict
import
json
def
vsepr_parse_user_answer
(
user_input
):
def
vsepr_parse_user_answer
(
user_input
):
d
=
OrderedDict
(
eval
(
user_input
))
d
=
OrderedDict
(
json
.
loads
(
user_input
))
d
[
'atoms'
]
=
OrderedDict
(
sorted
(
d
[
'atoms'
]
.
items
()))
d
[
'atoms'
]
=
OrderedDict
(
sorted
(
d
[
'atoms'
]
.
items
()))
return
d
return
d
...
@@ -10,16 +11,42 @@ def vsepr_parse_user_answer(user_input):
...
@@ -10,16 +11,42 @@ def vsepr_parse_user_answer(user_input):
def
vsepr_build_correct_answer
(
geometry
,
atoms
):
def
vsepr_build_correct_answer
(
geometry
,
atoms
):
correct_answer
=
OrderedDict
()
correct_answer
=
OrderedDict
()
correct_answer
[
'geometry'
]
=
geometry
correct_answer
[
'geometry'
]
=
geometry
correct_answer
[
'atoms'
]
=
OrderedDict
(
atoms
)
correct_answer
[
'atoms'
]
=
OrderedDict
(
sorted
(
atoms
.
items
())
)
return
correct_answer
return
correct_answer
def
vsepr_grade
(
user_input
,
correct_answer
):
def
vsepr_grade
(
user_input
,
correct_answer
,
ignore_p_order
=
False
,
ignore_a_order
=
False
,
ignore_e_order
=
False
):
print
user_input
,
type
(
user_input
)
""" Flags ignore_(a,p,e)_order are for checking order in axial, perepherial or equatorial positions
print
correct_answer
,
type
(
correct_answer
)
"""
# print user_input, type(user_input)
# print correct_answer, type(correct_answer)
if
user_input
[
'geometry'
]
!=
correct_answer
[
'geometry'
]:
if
user_input
[
'geometry'
]
!=
correct_answer
[
'geometry'
]:
return
False
return
False
if
user_input
[
'atoms'
]
.
values
()
!=
correct_answer
[
'atoms'
]
.
values
():
return
False
return
True
# not order-aware comparisons
for
ignore
in
[(
ignore_p_order
,
'p'
),
(
ignore_e_order
,
'e'
),
(
ignore_a_order
,
'a'
)]:
if
ignore
[
0
]:
# collecting atoms:
a_user
=
[
v
for
k
,
v
in
user_input
[
'atoms'
]
.
items
()
if
k
.
startswith
(
ignore
[
1
])]
a_correct
=
[
v
for
k
,
v
in
correct_answer
[
'atoms'
]
.
items
()
if
k
.
startswith
(
ignore
[
1
])]
# print ignore[0], ignore[1], a_user, a_correct
if
len
(
a_user
)
!=
len
(
a_correct
):
return
False
if
sorted
(
a_user
)
!=
sorted
(
a_correct
):
return
False
# order-aware comparisons
for
ignore
in
[(
ignore_p_order
,
'p'
),
(
ignore_e_order
,
'e'
),
(
ignore_a_order
,
'a'
)]:
if
not
ignore
[
0
]:
# collecting atoms:
a_user
=
[
v
for
k
,
v
in
user_input
[
'atoms'
]
.
items
()
if
k
.
startswith
(
ignore
[
1
])]
a_correct
=
[
v
for
k
,
v
in
correct_answer
[
'atoms'
]
.
items
()
if
k
.
startswith
(
ignore
[
1
])]
# print '2nd', ignore[0], ignore[1], a_user, a_correct
if
len
(
a_user
)
!=
len
(
a_correct
):
return
False
if
len
(
a_correct
)
==
0
:
continue
if
a_user
!=
a_correct
:
return
False
return
True
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