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
cd6e8373
Commit
cd6e8373
authored
Oct 31, 2012
by
Vik Paruchuri
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
working on self assessment
parent
0d2cfa7e
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
60 deletions
+60
-60
common/lib/xmodule/xmodule/capa_module.py
+60
-60
common/lib/xmodule/xmodule/self_assessment_module.py
+0
-0
No files found.
common/lib/xmodule/xmodule/capa_module.py
View file @
cd6e8373
...
@@ -29,10 +29,10 @@ TIMEDELTA_REGEX = re.compile(r'^((?P<days>\d+?) day(?:s?))?(\s)?((?P<hours>\d+?)
...
@@ -29,10 +29,10 @@ TIMEDELTA_REGEX = re.compile(r'^((?P<days>\d+?) day(?:s?))?(\s)?((?P<hours>\d+?)
def
only_one
(
lst
,
default
=
""
,
process
=
lambda
x
:
x
):
def
only_one
(
lst
,
default
=
""
,
process
=
lambda
x
:
x
):
"""
"""
If lst is empty, returns default
If lst is empty, returns default
If lst has a single element, applies process to that element and returns it
If lst has a single element, applies process to that element and returns it
Otherwise, raises an exeception
Otherwise, raises an exeception
"""
"""
if
len
(
lst
)
==
0
:
if
len
(
lst
)
==
0
:
return
default
return
default
elif
len
(
lst
)
==
1
:
elif
len
(
lst
)
==
1
:
...
@@ -43,14 +43,14 @@ def only_one(lst, default="", process=lambda x: x):
...
@@ -43,14 +43,14 @@ def only_one(lst, default="", process=lambda x: x):
def
parse_timedelta
(
time_str
):
def
parse_timedelta
(
time_str
):
"""
"""
time_str: A string with the following components:
time_str: A string with the following components:
<D> day[s] (optional)
<D> day[s] (optional)
<H> hour[s] (optional)
<H> hour[s] (optional)
<M> minute[s] (optional)
<M> minute[s] (optional)
<S> second[s] (optional)
<S> second[s] (optional)
Returns a datetime.timedelta parsed from the string
Returns a datetime.timedelta parsed from the string
"""
"""
parts
=
TIMEDELTA_REGEX
.
match
(
time_str
)
parts
=
TIMEDELTA_REGEX
.
match
(
time_str
)
if
not
parts
:
if
not
parts
:
return
return
...
@@ -71,9 +71,9 @@ class ComplexEncoder(json.JSONEncoder):
...
@@ -71,9 +71,9 @@ class ComplexEncoder(json.JSONEncoder):
class
CapaModule
(
XModule
):
class
CapaModule
(
XModule
):
'''
'''
An XModule implementing LonCapa format problems, implemented by way of
An XModule implementing LonCapa format problems, implemented by way of
capa.capa_problem.LoncapaProblem
capa.capa_problem.LoncapaProblem
'''
'''
icon_class
=
'problem'
icon_class
=
'problem'
js
=
{
'coffee'
:
[
resource_string
(
__name__
,
'js/src/capa/display.coffee'
),
js
=
{
'coffee'
:
[
resource_string
(
__name__
,
'js/src/capa/display.coffee'
),
...
@@ -175,9 +175,9 @@ class CapaModule(XModule):
...
@@ -175,9 +175,9 @@ class CapaModule(XModule):
@property
@property
def
rerandomize
(
self
):
def
rerandomize
(
self
):
"""
"""
Property accessor that returns self.metadata['rerandomize'] in a
Property accessor that returns self.metadata['rerandomize'] in a
canonical form
canonical form
"""
"""
rerandomize
=
self
.
metadata
.
get
(
'rerandomize'
,
'always'
)
rerandomize
=
self
.
metadata
.
get
(
'rerandomize'
,
'always'
)
if
rerandomize
in
(
""
,
"always"
,
"true"
):
if
rerandomize
in
(
""
,
"always"
,
"true"
):
return
"always"
return
"always"
...
@@ -203,7 +203,7 @@ class CapaModule(XModule):
...
@@ -203,7 +203,7 @@ class CapaModule(XModule):
def
get_progress
(
self
):
def
get_progress
(
self
):
''' For now, just return score / max_score
''' For now, just return score / max_score
'''
'''
d
=
self
.
get_score
()
d
=
self
.
get_score
()
score
=
d
[
'score'
]
score
=
d
[
'score'
]
total
=
d
[
'total'
]
total
=
d
[
'total'
]
...
@@ -224,7 +224,7 @@ class CapaModule(XModule):
...
@@ -224,7 +224,7 @@ class CapaModule(XModule):
def
get_problem_html
(
self
,
encapsulate
=
True
):
def
get_problem_html
(
self
,
encapsulate
=
True
):
'''Return html for the problem. Adds check, reset, save buttons
'''Return html for the problem. Adds check, reset, save buttons
as necessary based on the problem config and state.'''
as necessary based on the problem config and state.'''
try
:
try
:
html
=
self
.
lcp
.
get_html
()
html
=
self
.
lcp
.
get_html
()
...
@@ -266,7 +266,7 @@ class CapaModule(XModule):
...
@@ -266,7 +266,7 @@ class CapaModule(XModule):
# Prepend a scary warning to the student
# Prepend a scary warning to the student
warning
=
'<div class="capa_reset">'
\
warning
=
'<div class="capa_reset">'
\
'<h2>Warning: The problem has been reset to its initial state!</h2>'
\
'<h2>Warning: The problem has been reset to its initial state!</h2>'
\
'The problem
\'
s state was corrupted by an invalid submission. '
\
'The problem
\'
s state was corrupted by an invalid submission. '
\
'The submission consisted of:'
\
'The submission consisted of:'
\
'<ul>'
'<ul>'
for
student_answer
in
student_answers
.
values
():
for
student_answer
in
student_answers
.
values
():
...
@@ -358,14 +358,14 @@ class CapaModule(XModule):
...
@@ -358,14 +358,14 @@ class CapaModule(XModule):
def
handle_ajax
(
self
,
dispatch
,
get
):
def
handle_ajax
(
self
,
dispatch
,
get
):
'''
'''
This is called by courseware.module_render, to handle an AJAX call.
This is called by courseware.module_render, to handle an AJAX call.
"get" is request.POST.
"get" is request.POST.
Returns a json dictionary:
Returns a json dictionary:
{ 'progress_changed' : True/False,
{ 'progress_changed' : True/False,
'progress' : 'none'/'in_progress'/'done',
'progress' : 'none'/'in_progress'/'done',
<other request-specific values here > }
<other request-specific values here > }
'''
'''
handlers
=
{
handlers
=
{
'problem_get'
:
self
.
get_problem
,
'problem_get'
:
self
.
get_problem
,
'problem_check'
:
self
.
check_problem
,
'problem_check'
:
self
.
check_problem
,
...
@@ -398,7 +398,7 @@ class CapaModule(XModule):
...
@@ -398,7 +398,7 @@ class CapaModule(XModule):
def
answer_available
(
self
):
def
answer_available
(
self
):
''' Is the user allowed to see an answer?
''' Is the user allowed to see an answer?
'''
'''
if
self
.
show_answer
==
''
:
if
self
.
show_answer
==
''
:
return
False
return
False
...
@@ -425,14 +425,14 @@ class CapaModule(XModule):
...
@@ -425,14 +425,14 @@ class CapaModule(XModule):
def
update_score
(
self
,
get
):
def
update_score
(
self
,
get
):
"""
"""
Delivers grading response (e.g. from asynchronous code checking) to
Delivers grading response (e.g. from asynchronous code checking) to
the capa problem, so its score can be updated
the capa problem, so its score can be updated
'get' must have a field 'response' which is a string that contains the
'get' must have a field 'response' which is a string that contains the
grader's response
grader's response
No ajax return is needed. Return empty dict.
No ajax return is needed. Return empty dict.
"""
"""
queuekey
=
get
[
'queuekey'
]
queuekey
=
get
[
'queuekey'
]
score_msg
=
get
[
'xqueue_body'
]
score_msg
=
get
[
'xqueue_body'
]
self
.
lcp
.
update_score
(
score_msg
,
queuekey
)
self
.
lcp
.
update_score
(
score_msg
,
queuekey
)
...
@@ -441,10 +441,10 @@ class CapaModule(XModule):
...
@@ -441,10 +441,10 @@ class CapaModule(XModule):
def
get_answer
(
self
,
get
):
def
get_answer
(
self
,
get
):
'''
'''
For the "show answer" button.
For the "show answer" button.
Returns the answers: {'answers' : answers}
Returns the answers: {'answers' : answers}
'''
'''
event_info
=
dict
()
event_info
=
dict
()
event_info
[
'problem_id'
]
=
self
.
location
.
url
()
event_info
[
'problem_id'
]
=
self
.
location
.
url
()
self
.
system
.
track_function
(
'show_answer'
,
event_info
)
self
.
system
.
track_function
(
'show_answer'
,
event_info
)
...
@@ -469,18 +469,18 @@ class CapaModule(XModule):
...
@@ -469,18 +469,18 @@ class CapaModule(XModule):
# Figure out if we should move these to capa_problem?
# Figure out if we should move these to capa_problem?
def
get_problem
(
self
,
get
):
def
get_problem
(
self
,
get
):
''' Return results of get_problem_html, as a simple dict for json-ing.
''' Return results of get_problem_html, as a simple dict for json-ing.
{ 'html': <the-html> }
{ 'html': <the-html> }
Used if we want to reconfirm we have the right thing e.g. after
Used if we want to reconfirm we have the right thing e.g. after
several AJAX calls.
several AJAX calls.
'''
'''
return
{
'html'
:
self
.
get_problem_html
(
encapsulate
=
False
)}
return
{
'html'
:
self
.
get_problem_html
(
encapsulate
=
False
)}
@staticmethod
@staticmethod
def
make_dict_of_responses
(
get
):
def
make_dict_of_responses
(
get
):
'''Make dictionary of student responses (aka "answers")
'''Make dictionary of student responses (aka "answers")
get is POST dictionary.
get is POST dictionary.
'''
'''
answers
=
dict
()
answers
=
dict
()
for
key
in
get
:
for
key
in
get
:
# e.g. input_resistor_1 ==> resistor_1
# e.g. input_resistor_1 ==> resistor_1
...
@@ -500,11 +500,11 @@ class CapaModule(XModule):
...
@@ -500,11 +500,11 @@ class CapaModule(XModule):
def
check_problem
(
self
,
get
):
def
check_problem
(
self
,
get
):
''' Checks whether answers to a problem are correct, and
''' Checks whether answers to a problem are correct, and
returns a map of correct/incorrect answers:
returns a map of correct/incorrect answers:
{'success' : bool,
{'success' : bool,
'contents' : html}
'contents' : html}
'''
'''
event_info
=
dict
()
event_info
=
dict
()
event_info
[
'state'
]
=
self
.
lcp
.
get_state
()
event_info
[
'state'
]
=
self
.
lcp
.
get_state
()
event_info
[
'problem_id'
]
=
self
.
location
.
url
()
event_info
[
'problem_id'
]
=
self
.
location
.
url
()
...
@@ -567,20 +567,20 @@ class CapaModule(XModule):
...
@@ -567,20 +567,20 @@ class CapaModule(XModule):
# 'success' will always be incorrect
# 'success' will always be incorrect
event_info
[
'correct_map'
]
=
correct_map
.
get_dict
()
event_info
[
'correct_map'
]
=
correct_map
.
get_dict
()
event_info
[
'success'
]
=
success
event_info
[
'success'
]
=
success
event_info
[
'attempts'
]
=
self
.
attempts
event_info
[
'attempts'
]
=
self
.
attempts
self
.
system
.
track_function
(
'save_problem_check'
,
event_info
)
self
.
system
.
track_function
(
'save_problem_check'
,
event_info
)
if
hasattr
(
self
.
system
,
'psychometrics_handler'
):
# update PsychometricsData using callback
if
hasattr
(
self
.
system
,
'psychometrics_handler'
):
# update PsychometricsData using callback
self
.
system
.
psychometrics_handler
(
self
.
get_instance_state
())
self
.
system
.
psychometrics_handler
(
self
.
get_instance_state
())
# render problem into HTML
# render problem into HTML
html
=
self
.
get_problem_html
(
encapsulate
=
False
)
html
=
self
.
get_problem_html
(
encapsulate
=
False
)
return
{
'success'
:
success
,
return
{
'success'
:
success
,
'contents'
:
html
,
'contents'
:
html
,
}
}
def
save_problem
(
self
,
get
):
def
save_problem
(
self
,
get
):
'''
'''
Save the passed in answers.
Save the passed in answers.
Returns a dict { 'success' : bool, ['error' : error-msg]},
Returns a dict { 'success' : bool, ['error' : error-msg]},
...
@@ -614,7 +614,7 @@ class CapaModule(XModule):
...
@@ -614,7 +614,7 @@ class CapaModule(XModule):
self
.
system
.
track_function
(
'save_problem_fail'
,
event_info
)
self
.
system
.
track_function
(
'save_problem_fail'
,
event_info
)
return
{
'success'
:
True
}
return
{
'success'
:
True
}
def
reset_problem
(
self
,
get
):
def
reset_problem
(
self
,
get
):
''' Changes problem state to unfinished -- removes student answers,
''' Changes problem state to unfinished -- removes student answers,
and causes problem to rerender itself.
and causes problem to rerender itself.
...
@@ -654,9 +654,9 @@ class CapaModule(XModule):
...
@@ -654,9 +654,9 @@ class CapaModule(XModule):
class
CapaDescriptor
(
RawDescriptor
):
class
CapaDescriptor
(
RawDescriptor
):
"""
"""
Module implementing problems in the LON-CAPA format,
Module implementing problems in the LON-CAPA format,
as implemented by capa.capa_problem
as implemented by capa.capa_problem
"""
"""
module_class
=
CapaModule
module_class
=
CapaModule
...
...
common/lib/xmodule/xmodule/self_assessment_module.py
View file @
cd6e8373
This diff is collapsed.
Click to expand it.
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