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
bd7c00ea
Commit
bd7c00ea
authored
Oct 08, 2012
by
Victor Shnayder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
formatting cleanup in correctmap.py
parent
775456b9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
18 deletions
+40
-18
common/lib/capa/capa/correctmap.py
+40
-18
No files found.
common/lib/capa/capa/correctmap.py
View file @
bd7c00ea
...
...
@@ -5,23 +5,26 @@
class
CorrectMap
(
object
):
'''
"""
Stores map between answer_id and response evaluation result for each question
in a capa problem. The response evaluation result for each answer_id includes
(correctness, npoints, msg, hint, hintmode).
- correctness : either 'correct' or 'incorrect'
- npoints : None, or integer specifying number of points awarded for this answer_id
- msg : string (may have HTML) giving extra message response (displayed below textline or textbox)
- hint : string (may have HTML) giving optional hint (displayed below textline or textbox, above msg)
- msg : string (may have HTML) giving extra message response
(displayed below textline or textbox)
- hint : string (may have HTML) giving optional hint
(displayed below textline or textbox, above msg)
- hintmode : one of (None,'on_request','always') criteria for displaying hint
- queuestate : Dict {key:'', time:''} where key is a secret string, and time is a string dump
of a DateTime object in the format '
%
Y
%
m
%
d
%
H
%
M
%
S'. Is None when not queued
Behaves as a dict.
'''
"""
def
__init__
(
self
,
*
args
,
**
kwargs
):
self
.
cmap
=
dict
()
# start with empty dict
# start with empty dict
self
.
cmap
=
dict
()
self
.
items
=
self
.
cmap
.
items
self
.
keys
=
self
.
cmap
.
keys
self
.
set
(
*
args
,
**
kwargs
)
...
...
@@ -33,7 +36,15 @@ class CorrectMap(object):
return
self
.
cmap
.
__iter__
()
# See the documentation for 'set_dict' for the use of kwargs
def
set
(
self
,
answer_id
=
None
,
correctness
=
None
,
npoints
=
None
,
msg
=
''
,
hint
=
''
,
hintmode
=
None
,
queuestate
=
None
,
**
kwargs
):
def
set
(
self
,
answer_id
=
None
,
correctness
=
None
,
npoints
=
None
,
msg
=
''
,
hint
=
''
,
hintmode
=
None
,
queuestate
=
None
,
**
kwargs
):
if
answer_id
is
not
None
:
self
.
cmap
[
answer_id
]
=
{
'correctness'
:
correctness
,
'npoints'
:
npoints
,
...
...
@@ -56,12 +67,13 @@ class CorrectMap(object):
'''
Set internal dict of CorrectMap to provided correct_map dict
correct_map is saved by LMS as a plaintext JSON dump of the correctmap dict. This means that
when the definition of CorrectMap (e.g. its properties) are altered, existing correct_map dict
not coincide with the newest CorrectMap format as defined by self.set.
correct_map is saved by LMS as a plaintext JSON dump of the correctmap dict. This
means that when the definition of CorrectMap (e.g. its properties) are altered,
an existing correct_map dict not coincide with the newest CorrectMap format as
defined by self.set.
For graceful migration, feed the contents of each correct map to self.set, rather than
making a direct copy of the given correct_map dict. This way, the common keys between
making a direct copy of the given correct_map dict. This way, the common keys between
the incoming correct_map dict and the new CorrectMap instance will be written, while
mismatched keys will be gracefully ignored.
...
...
@@ -69,14 +81,20 @@ class CorrectMap(object):
If correct_map is a one-level dict, then convert it to the new dict of dicts format.
'''
if
correct_map
and
not
(
type
(
correct_map
[
correct_map
.
keys
()[
0
]])
==
dict
):
self
.
__init__
()
# empty current dict
for
k
in
correct_map
:
self
.
set
(
k
,
correct_map
[
k
])
# create new dict entries
# empty current dict
self
.
__init__
()
# create new dict entries
for
k
in
correct_map
:
self
.
set
(
k
,
correct_map
[
k
])
else
:
self
.
__init__
()
for
k
in
correct_map
:
self
.
set
(
k
,
**
correct_map
[
k
])
for
k
in
correct_map
:
self
.
set
(
k
,
**
correct_map
[
k
])
def
is_correct
(
self
,
answer_id
):
if
answer_id
in
self
.
cmap
:
return
self
.
cmap
[
answer_id
][
'correctness'
]
==
'correct'
if
answer_id
in
self
.
cmap
:
return
self
.
cmap
[
answer_id
][
'correctness'
]
==
'correct'
return
None
def
is_queued
(
self
,
answer_id
):
...
...
@@ -94,14 +112,18 @@ class CorrectMap(object):
return
npoints
elif
self
.
is_correct
(
answer_id
):
return
1
return
0
# if not correct and no points have been assigned, return 0
# if not correct and no points have been assigned, return 0
return
0
def
set_property
(
self
,
answer_id
,
property
,
value
):
if
answer_id
in
self
.
cmap
:
self
.
cmap
[
answer_id
][
property
]
=
value
else
:
self
.
cmap
[
answer_id
]
=
{
property
:
value
}
if
answer_id
in
self
.
cmap
:
self
.
cmap
[
answer_id
][
property
]
=
value
else
:
self
.
cmap
[
answer_id
]
=
{
property
:
value
}
def
get_property
(
self
,
answer_id
,
property
,
default
=
None
):
if
answer_id
in
self
.
cmap
:
return
self
.
cmap
[
answer_id
]
.
get
(
property
,
default
)
if
answer_id
in
self
.
cmap
:
return
self
.
cmap
[
answer_id
]
.
get
(
property
,
default
)
return
default
def
get_correctness
(
self
,
answer_id
):
...
...
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