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
6a50da3d
Commit
6a50da3d
authored
Aug 13, 2012
by
Tom Giannattasio
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into feature/tomg/fall-design
parents
7b4cd3e4
32924d8b
Hide whitespace changes
Inline
Side-by-side
Showing
26 changed files
with
1259 additions
and
40 deletions
+1259
-40
common/lib/capa/capa/capa_problem.py
+2
-13
common/lib/capa/capa/inputtypes.py
+29
-0
common/lib/capa/capa/javascript_problem_generator.js
+30
-0
common/lib/capa/capa/javascript_problem_grader.js
+26
-0
common/lib/capa/capa/responsetypes.py
+215
-9
common/lib/capa/capa/templates/javascriptinput.html
+10
-0
common/lib/xmodule/xmodule/capa_module.py
+1
-1
common/lib/xmodule/xmodule/js/src/capa/display.coffee
+79
-11
common/lib/xmodule/xmodule/tests/__init__.py
+19
-3
common/lib/xmodule/xmodule/tests/test_files/javascriptresponse.xml
+13
-0
common/lib/xmodule/xmodule/tests/test_files/js/compiled/c9a9cd4242d84c924fe5f8324e9ae79d.js
+50
-0
common/lib/xmodule/xmodule/tests/test_files/js/mersenne-twister-min.js
+202
-0
common/lib/xmodule/xmodule/tests/test_files/js/test_problem_display.coffee
+21
-0
common/lib/xmodule/xmodule/tests/test_files/js/test_problem_display.js
+49
-0
common/lib/xmodule/xmodule/tests/test_files/js/test_problem_generator.coffee
+14
-0
common/lib/xmodule/xmodule/tests/test_files/js/test_problem_generator.js
+29
-0
common/lib/xmodule/xmodule/tests/test_files/js/test_problem_grader.coffee
+27
-0
common/lib/xmodule/xmodule/tests/test_files/js/test_problem_grader.js
+50
-0
common/lib/xmodule/xmodule/tests/test_files/js/xproblem.coffee
+47
-0
common/lib/xmodule/xmodule/tests/test_files/js/xproblem.js
+78
-0
common/lib/xmodule/xmodule/x_module.py
+3
-1
common/static/coffee/src/xproblem.coffee
+47
-0
common/static/js/vendor/mersenne-twister-min.js
+202
-0
lms/djangoapps/courseware/module_render.py
+1
-0
lms/envs/common.py
+14
-1
run_watch_data.py
+1
-1
No files found.
common/lib/capa/capa/capa_problem.py
View file @
6a50da3d
...
...
@@ -39,7 +39,7 @@ import responsetypes
# dict of tagname, Response Class -- this should come from auto-registering
response_tag_dict
=
dict
([(
x
.
response_tag
,
x
)
for
x
in
responsetypes
.
__all__
])
entry_types
=
[
'textline'
,
'schematic'
,
'textbox'
,
'imageinput'
,
'optioninput'
,
'choicegroup'
,
'radiogroup'
,
'checkboxgroup'
,
'filesubmission'
]
entry_types
=
[
'textline'
,
'schematic'
,
'textbox'
,
'imageinput'
,
'optioninput'
,
'choicegroup'
,
'radiogroup'
,
'checkboxgroup'
,
'filesubmission'
,
'javascriptinput'
]
solution_types
=
[
'solution'
]
# extra things displayed after "show answers" is pressed
response_properties
=
[
"responseparam"
,
"answer"
]
# these get captured as student responses
...
...
@@ -154,21 +154,10 @@ class LoncapaProblem(object):
def
get_max_score
(
self
):
'''
Return maximum score for this problem.
We do this by counting the number of answers available for each question
in the problem. If the Response for a question has a get_max_score() method
then we call that and add its return value to the count. That can be
used to give complex problems (eg programming questions) multiple points.
'''
maxscore
=
0
for
response
,
responder
in
self
.
responders
.
iteritems
():
if
hasattr
(
responder
,
'get_max_score'
):
try
:
maxscore
+=
responder
.
get_max_score
()
except
Exception
:
log
.
debug
(
'responder
%
s failed to properly return from get_max_score()'
%
responder
)
# FIXME
raise
else
:
maxscore
+=
len
(
self
.
responder_answers
[
response
])
maxscore
+=
responder
.
get_max_score
()
return
maxscore
def
get_score
(
self
):
...
...
common/lib/capa/capa/inputtypes.py
View file @
6a50da3d
...
...
@@ -11,6 +11,7 @@ Module containing the problem elements which render into input objects
- choicegroup
- radiogroup
- checkboxgroup
- javascriptinput
- imageinput (for clickable image)
- optioninput (for option list)
- filesubmission (upload a file)
...
...
@@ -246,6 +247,34 @@ def checkboxgroup(element, value, status, render_template, msg=''):
html
=
render_template
(
"choicegroup.html"
,
context
)
return
etree
.
XML
(
html
)
@register_render_function
def
javascriptinput
(
element
,
value
,
status
,
render_template
,
msg
=
'null'
):
'''
Hidden field for javascript to communicate via; also loads the required
scripts for rendering the problem and passes data to the problem.
'''
eid
=
element
.
get
(
'id'
)
params
=
element
.
get
(
'params'
)
problem_state
=
element
.
get
(
'problem_state'
)
display_class
=
element
.
get
(
'display_class'
)
display_file
=
element
.
get
(
'display_file'
)
# Need to provide a value that JSON can parse if there is no
# student-supplied value yet.
if
value
==
""
:
value
=
'null'
escapedict
=
{
'"'
:
'"'
}
value
=
saxutils
.
escape
(
value
,
escapedict
)
msg
=
saxutils
.
escape
(
msg
,
escapedict
)
context
=
{
'id'
:
eid
,
'params'
:
params
,
'display_file'
:
display_file
,
'display_class'
:
display_class
,
'problem_state'
:
problem_state
,
'value'
:
value
,
'evaluation'
:
msg
,
}
html
=
render_template
(
"javascriptinput.html"
,
context
)
return
etree
.
XML
(
html
)
@register_render_function
def
textline
(
element
,
value
,
status
,
render_template
,
msg
=
""
):
...
...
common/lib/capa/capa/javascript_problem_generator.js
0 → 100644
View file @
6a50da3d
require
(
'coffee-script'
);
var
importAll
=
function
(
modulePath
)
{
module
=
require
(
modulePath
);
for
(
key
in
module
){
global
[
key
]
=
module
[
key
];
}
}
importAll
(
"mersenne-twister-min"
);
importAll
(
"xproblem"
);
generatorModulePath
=
process
.
argv
[
2
];
dependencies
=
JSON
.
parse
(
process
.
argv
[
3
]);
seed
=
process
.
argv
[
4
];
params
=
JSON
.
parse
(
process
.
argv
[
5
]);
if
(
seed
==
null
){
seed
=
4
;
}
else
{
seed
=
parseInt
(
seed
);
}
for
(
var
i
=
0
;
i
<
dependencies
.
length
;
i
++
){
importAll
(
dependencies
[
i
]);
}
generatorModule
=
require
(
generatorModulePath
);
generatorClass
=
generatorModule
.
generatorClass
;
generator
=
new
generatorClass
(
seed
,
params
);
console
.
log
(
JSON
.
stringify
(
generator
.
generate
()));
common/lib/capa/capa/javascript_problem_grader.js
0 → 100644
View file @
6a50da3d
require
(
'coffee-script'
);
var
importAll
=
function
(
modulePath
)
{
module
=
require
(
modulePath
);
for
(
key
in
module
){
global
[
key
]
=
module
[
key
];
}
}
importAll
(
"xproblem"
);
graderModulePath
=
process
.
argv
[
2
];
dependencies
=
JSON
.
parse
(
process
.
argv
[
3
]);
submission
=
JSON
.
parse
(
process
.
argv
[
4
]);
problemState
=
JSON
.
parse
(
process
.
argv
[
5
]);
params
=
JSON
.
parse
(
process
.
argv
[
6
]);
for
(
var
i
=
0
;
i
<
dependencies
.
length
;
i
++
){
importAll
(
dependencies
[
i
]);
}
graderModule
=
require
(
graderModulePath
);
graderClass
=
graderModule
.
graderClass
;
grader
=
new
graderClass
(
submission
,
problemState
,
params
);
console
.
log
(
JSON
.
stringify
(
grader
.
grade
()));
console
.
log
(
JSON
.
stringify
(
grader
.
evaluation
));
console
.
log
(
JSON
.
stringify
(
grader
.
solution
));
common/lib/capa/capa/responsetypes.py
View file @
6a50da3d
...
...
@@ -17,7 +17,11 @@ import random
import
re
import
requests
import
traceback
import
hashlib
import
abc
import
os
import
subprocess
import
xml.sax.saxutils
as
saxutils
# specific library imports
from
calc
import
evaluator
,
UndefinedVariable
...
...
@@ -71,7 +75,6 @@ class LoncapaResponse(object):
In addition, these methods are optional:
- get_max_score : if defined, this is called to obtain the maximum score possible for this question
- setup_response : find and note the answer input field IDs for the response; called by __init__
- check_hint_condition : check to see if the student's answers satisfy a particular condition for a hint to be displayed
- render_html : render this Response as HTML (must return XHTML compliant string)
...
...
@@ -130,6 +133,11 @@ class LoncapaResponse(object):
if
self
.
max_inputfields
==
1
:
self
.
answer_id
=
self
.
answer_ids
[
0
]
# for convenience
self
.
maxpoints
=
dict
()
for
inputfield
in
self
.
inputfields
:
maxpoints
=
inputfield
.
get
(
'points'
,
'1'
)
# By default, each answerfield is worth 1 point
self
.
maxpoints
.
update
({
inputfield
.
get
(
'id'
):
int
(
maxpoints
)})
self
.
default_answer_map
=
{}
# dict for default answer map (provided in input elements)
for
entry
in
self
.
inputfields
:
answer
=
entry
.
get
(
'correct_answer'
)
...
...
@@ -139,6 +147,12 @@ class LoncapaResponse(object):
if
hasattr
(
self
,
'setup_response'
):
self
.
setup_response
()
def
get_max_score
(
self
):
'''
Return the total maximum points of all answer fields under this Response
'''
return
sum
(
self
.
maxpoints
.
values
())
def
render_html
(
self
,
renderer
):
'''
Return XHTML Element tree representation of this Response.
...
...
@@ -272,9 +286,190 @@ class LoncapaResponse(object):
#-----------------------------------------------------------------------------
class
JavascriptResponse
(
LoncapaResponse
):
'''
This response type is used when the student's answer is graded via
Javascript using Node.js.
'''
response_tag
=
'javascriptresponse'
max_inputfields
=
1
allowed_inputfields
=
[
'javascriptinput'
]
def
setup_response
(
self
):
# Sets up generator, grader, display, and their dependencies.
self
.
parse_xml
()
self
.
compile_display_javascript
()
self
.
params
=
self
.
extract_params
()
if
self
.
generator
:
self
.
problem_state
=
self
.
generate_problem_state
()
else
:
self
.
problem_state
=
None
self
.
solution
=
None
self
.
prepare_inputfield
()
def
compile_display_javascript
(
self
):
latestTimestamp
=
0
basepath
=
self
.
system
.
filestore
.
root_path
+
'/js/'
for
filename
in
(
self
.
display_dependencies
+
[
self
.
display
]):
filepath
=
basepath
+
filename
timestamp
=
os
.
stat
(
filepath
)
.
st_mtime
if
timestamp
>
latestTimestamp
:
latestTimestamp
=
timestamp
h
=
hashlib
.
md5
()
h
.
update
(
self
.
answer_id
+
str
(
self
.
display_dependencies
))
compiled_filename
=
'compiled/'
+
h
.
hexdigest
()
+
'.js'
compiled_filepath
=
basepath
+
compiled_filename
if
not
os
.
path
.
exists
(
compiled_filepath
)
or
os
.
stat
(
compiled_filepath
)
.
st_mtime
<
latestTimestamp
:
outfile
=
open
(
compiled_filepath
,
'w'
)
for
filename
in
(
self
.
display_dependencies
+
[
self
.
display
]):
filepath
=
basepath
+
filename
infile
=
open
(
filepath
,
'r'
)
outfile
.
write
(
infile
.
read
())
outfile
.
write
(
';
\n
'
)
infile
.
close
()
outfile
.
close
()
self
.
display_filename
=
compiled_filename
def
parse_xml
(
self
):
self
.
generator_xml
=
self
.
xml
.
xpath
(
'//*[@id=$id]//generator'
,
id
=
self
.
xml
.
get
(
'id'
))[
0
]
self
.
grader_xml
=
self
.
xml
.
xpath
(
'//*[@id=$id]//grader'
,
id
=
self
.
xml
.
get
(
'id'
))[
0
]
self
.
display_xml
=
self
.
xml
.
xpath
(
'//*[@id=$id]//display'
,
id
=
self
.
xml
.
get
(
'id'
))[
0
]
self
.
xml
.
remove
(
self
.
generator_xml
)
self
.
xml
.
remove
(
self
.
grader_xml
)
self
.
xml
.
remove
(
self
.
display_xml
)
self
.
generator
=
self
.
generator_xml
.
get
(
"src"
)
self
.
grader
=
self
.
grader_xml
.
get
(
"src"
)
self
.
display
=
self
.
display_xml
.
get
(
"src"
)
if
self
.
generator_xml
.
get
(
"dependencies"
):
self
.
generator_dependencies
=
self
.
generator_xml
.
get
(
"dependencies"
)
.
split
()
else
:
self
.
generator_dependencies
=
[]
if
self
.
grader_xml
.
get
(
"dependencies"
):
self
.
grader_dependencies
=
self
.
grader_xml
.
get
(
"dependencies"
)
.
split
()
else
:
self
.
grader_dependencies
=
[]
if
self
.
display_xml
.
get
(
"dependencies"
):
self
.
display_dependencies
=
self
.
display_xml
.
get
(
"dependencies"
)
.
split
()
else
:
self
.
display_dependencies
=
[]
self
.
display_class
=
self
.
display_xml
.
get
(
"class"
)
def
get_node_env
(
self
):
js_dir
=
os
.
path
.
join
(
self
.
system
.
filestore
.
root_path
,
'js'
)
tmp_env
=
os
.
environ
.
copy
()
node_path
=
self
.
system
.
node_path
+
":"
+
os
.
path
.
normpath
(
js_dir
)
tmp_env
[
"NODE_PATH"
]
=
node_path
return
tmp_env
def
generate_problem_state
(
self
):
generator_file
=
os
.
path
.
dirname
(
os
.
path
.
normpath
(
__file__
))
+
'/javascript_problem_generator.js'
output
=
subprocess
.
check_output
([
"node"
,
generator_file
,
self
.
generator
,
json
.
dumps
(
self
.
generator_dependencies
),
json
.
dumps
(
str
(
self
.
system
.
seed
)),
json
.
dumps
(
self
.
params
)
],
env
=
self
.
get_node_env
())
.
strip
()
return
json
.
loads
(
output
)
def
extract_params
(
self
):
params
=
{}
for
param
in
self
.
xml
.
xpath
(
'//*[@id=$id]//responseparam'
,
id
=
self
.
xml
.
get
(
'id'
)):
params
[
param
.
get
(
"name"
)]
=
json
.
loads
(
param
.
get
(
"value"
))
return
params
def
prepare_inputfield
(
self
):
for
inputfield
in
self
.
xml
.
xpath
(
'//*[@id=$id]//javascriptinput'
,
id
=
self
.
xml
.
get
(
'id'
)):
escapedict
=
{
'"'
:
'"'
}
encoded_params
=
json
.
dumps
(
self
.
params
)
encoded_params
=
saxutils
.
escape
(
encoded_params
,
escapedict
)
inputfield
.
set
(
"params"
,
encoded_params
)
encoded_problem_state
=
json
.
dumps
(
self
.
problem_state
)
encoded_problem_state
=
saxutils
.
escape
(
encoded_problem_state
,
escapedict
)
inputfield
.
set
(
"problem_state"
,
encoded_problem_state
)
inputfield
.
set
(
"display_file"
,
self
.
display_filename
)
inputfield
.
set
(
"display_class"
,
self
.
display_class
)
def
get_score
(
self
,
student_answers
):
json_submission
=
student_answers
[
self
.
answer_id
]
(
all_correct
,
evaluation
,
solution
)
=
self
.
run_grader
(
json_submission
)
self
.
solution
=
solution
correctness
=
'correct'
if
all_correct
else
'incorrect'
return
CorrectMap
(
self
.
answer_id
,
correctness
,
msg
=
evaluation
)
def
run_grader
(
self
,
submission
):
if
submission
is
None
or
submission
==
''
:
submission
=
json
.
dumps
(
None
)
grader_file
=
os
.
path
.
dirname
(
os
.
path
.
normpath
(
__file__
))
+
'/javascript_problem_grader.js'
outputs
=
subprocess
.
check_output
([
"node"
,
grader_file
,
self
.
grader
,
json
.
dumps
(
self
.
grader_dependencies
),
submission
,
json
.
dumps
(
self
.
problem_state
),
json
.
dumps
(
self
.
params
)
],
env
=
self
.
get_node_env
())
.
split
(
'
\n
'
)
all_correct
=
json
.
loads
(
outputs
[
0
]
.
strip
())
evaluation
=
outputs
[
1
]
.
strip
()
solution
=
outputs
[
2
]
.
strip
()
return
(
all_correct
,
evaluation
,
solution
)
def
get_answers
(
self
):
if
self
.
solution
is
None
:
(
_
,
_
,
self
.
solution
)
=
self
.
run_grader
(
None
)
return
{
self
.
answer_id
:
self
.
solution
}
#-----------------------------------------------------------------------------
class
ChoiceResponse
(
LoncapaResponse
):
'''
This
R
esponse type is used when the student chooses from a discrete set of
This
r
esponse type is used when the student chooses from a discrete set of
choices. Currently, to be marked correct, all "correct" choices must be
supplied by the student, and no extraneous choices may be included.
...
...
@@ -313,6 +508,11 @@ class ChoiceResponse(LoncapaResponse):
In the above example, radiogroup can be replaced with checkboxgroup to allow
the student to select more than one choice.
TODO: In order for the inputtypes to render properly, this response type
must run setup_response prior to the input type rendering. Specifically, the
choices must be given names. This behavior seems like a leaky abstraction,
and it'd be nice to change this at some point.
'''
response_tag
=
'choiceresponse'
...
...
@@ -877,7 +1077,10 @@ class CodeResponse(LoncapaResponse):
(
err
,
self
.
answer_id
,
convert_files_to_filenames
(
student_answers
)))
raise
Exception
(
err
)
self
.
context
.
update
({
'submission'
:
unicode
(
submission
)})
if
is_file
(
submission
):
self
.
context
.
update
({
'submission'
:
submission
.
name
})
else
:
self
.
context
.
update
({
'submission'
:
submission
})
# Prepare xqueue request
#------------------------------------------------------------
...
...
@@ -924,21 +1127,24 @@ class CodeResponse(LoncapaResponse):
def
update_score
(
self
,
score_msg
,
oldcmap
,
queuekey
):
(
valid_score_msg
,
correct
,
score
,
msg
)
=
self
.
_parse_score_msg
(
score_msg
)
(
valid_score_msg
,
correct
,
points
,
msg
)
=
self
.
_parse_score_msg
(
score_msg
)
if
not
valid_score_msg
:
oldcmap
.
set
(
self
.
answer_id
,
msg
=
'Error: Invalid grader reply.'
)
return
oldcmap
correctness
=
'incorrect'
if
correct
:
correctness
=
'correct'
correctness
=
'correct'
if
correct
else
'incorrect'
self
.
context
[
'correct'
]
=
correctness
# TODO: Find out how this is used elsewhere, if any
# Replace 'oldcmap' with new grading results if queuekey matches.
# If queuekey does not match, we keep waiting for the score_msg whose key actually matches
if
oldcmap
.
is_right_queuekey
(
self
.
answer_id
,
queuekey
):
oldcmap
.
set
(
self
.
answer_id
,
correctness
=
correctness
,
msg
=
msg
.
replace
(
' '
,
' '
),
queuekey
=
None
)
# Queuekey is consumed
# Sanity check on returned points
if
points
<
0
:
points
=
0
elif
points
>
self
.
maxpoints
[
self
.
answer_id
]:
points
=
self
.
maxpoints
[
self
.
answer_id
]
oldcmap
.
set
(
self
.
answer_id
,
npoints
=
points
,
correctness
=
correctness
,
msg
=
msg
.
replace
(
' '
,
' '
),
queuekey
=
None
)
# Queuekey is consumed
else
:
log
.
debug
(
'CodeResponse: queuekey
%
s does not match for answer_id=
%
s.'
%
(
queuekey
,
self
.
answer_id
))
...
...
@@ -1361,4 +1567,4 @@ class ImageResponse(LoncapaResponse):
# TEMPORARY: List of all response subclasses
# FIXME: To be replaced by auto-registration
__all__
=
[
CodeResponse
,
NumericalResponse
,
FormulaResponse
,
CustomResponse
,
SchematicResponse
,
ExternalResponse
,
ImageResponse
,
OptionResponse
,
SymbolicResponse
,
StringResponse
,
ChoiceResponse
,
MultipleChoiceResponse
,
TrueFalseResponse
]
__all__
=
[
CodeResponse
,
NumericalResponse
,
FormulaResponse
,
CustomResponse
,
SchematicResponse
,
ExternalResponse
,
ImageResponse
,
OptionResponse
,
SymbolicResponse
,
StringResponse
,
ChoiceResponse
,
MultipleChoiceResponse
,
TrueFalseResponse
,
JavascriptResponse
]
common/lib/capa/capa/templates/javascriptinput.html
0 → 100644
View file @
6a50da3d
<form
class=
"javascriptinput capa_inputtype"
>
<input
type=
"hidden"
name=
"input_${id}"
id=
"input_${id}"
class=
"javascriptinput_input"
/>
<div
class=
"javascriptinput_data"
data-display_class=
"${display_class}"
data-problem_state=
"${problem_state}"
data-params=
"${params}"
data-submission=
"${value}"
data-evaluation=
"${evaluation}"
>
</div>
<div
class=
"script_placeholder"
data-src=
"/static/js/${display_file}"
></div>
<div
class=
"javascriptinput_container"
></div>
</form>
common/lib/xmodule/xmodule/capa_module.py
View file @
6a50da3d
...
...
@@ -464,7 +464,7 @@ class CapaModule(XModule):
return
{
'success'
:
msg
}
log
.
exception
(
"Error in capa_module problem checking"
)
raise
Exception
(
"error in capa_module"
)
self
.
attempts
=
self
.
attempts
+
1
self
.
lcp
.
done
=
True
...
...
common/lib/xmodule/xmodule/js/src/capa/display.coffee
View file @
6a50da3d
class
@
Problem
constructor
:
(
element
)
->
@
el
=
$
(
element
).
find
(
'.problems-wrapper'
)
@
id
=
@
el
.
data
(
'problem-id'
)
...
...
@@ -52,24 +53,71 @@ class @Problem
render
:
(
content
)
->
if
content
@
el
.
html
(
content
)
@
bind
()
@
queueing
()
@
executeProblemScripts
()
=>
@
setupInputTypes
()
@
bind
()
@
queueing
()
else
$
.
postWithPrefix
"
#{
@
url
}
/problem_get"
,
(
response
)
=>
@
el
.
html
(
response
.
html
)
@
executeProblemScripts
()
@
bind
()
@
queueing
()
@
executeProblemScripts
()
=>
@
setupInputTypes
()
@
bind
()
@
queueing
()
# TODO add hooks for problem types here by inspecting response.html and doing
# stuff if a div w a class is found
setupInputTypes
:
=>
@
el
.
find
(
".capa_inputtype"
).
each
(
index
,
inputtype
)
=>
classes
=
$
(
inputtype
).
attr
(
'class'
).
split
(
' '
)
for
cls
in
classes
setupMethod
=
@
inputtypeSetupMethods
[
cls
]
setupMethod
(
inputtype
)
if
setupMethod
?
executeProblemScripts
:
(
callback
=
null
)
->
executeProblemScripts
:
->
@
el
.
find
(
".script_placeholder"
).
each
(
index
,
placeholder
)
->
s
=
$
(
"<script>"
)
s
.
attr
(
"type"
,
"text/javascript"
)
s
.
attr
(
"src"
,
$
(
placeholder
).
attr
(
"data-src"
))
placeholders
=
@
el
.
find
(
".script_placeholder"
)
if
placeholders
.
length
==
0
callback
()
return
completed
=
(
false
for
i
in
[
1
..
placeholders
.
length
])
callbackCalled
=
false
# This is required for IE8 support.
completionHandlerGeneratorIE
=
(
index
)
=>
return
()
->
if
(
this
.
readyState
==
'complete'
||
this
.
readyState
==
'loaded'
)
#completionHandlerGenerator.call(self, index)()
completionHandlerGenerator
(
index
)()
completionHandlerGenerator
=
(
index
)
=>
return
()
=>
allComplete
=
true
completed
[
index
]
=
true
for
flag
in
completed
if
not
flag
allComplete
=
false
break
if
allComplete
and
not
callbackCalled
callbackCalled
=
true
callback
()
if
callback
?
placeholders
.
each
(
index
,
placeholder
)
->
s
=
document
.
createElement
(
'script'
)
s
.
setAttribute
(
'src'
,
$
(
placeholder
).
attr
(
"data-src"
))
s
.
setAttribute
(
'type'
,
"text/javascript"
)
s
.
onload
=
completionHandlerGenerator
(
index
)
# s.onload does not fire in IE8; this does.
s
.
onreadystatechange
=
completionHandlerGeneratorIE
(
index
)
# Need to use the DOM elements directly or the scripts won't execute
# properly.
$
(
'head'
)[
0
].
appendChild
(
s
[
0
]
)
$
(
'head'
)[
0
].
appendChild
(
s
)
$
(
placeholder
).
remove
()
###
...
...
@@ -133,6 +181,9 @@ class @Problem
@
render
(
response
.
html
)
@
updateProgress
response
# TODO this needs modification to deal with javascript responses; perhaps we
# need something where responsetypes can define their own behavior when show
# is called.
show
:
=>
if
!
@
el
.
hasClass
'showed'
Logger
.
log
'problem_show'
,
problem
:
@
id
...
...
@@ -182,3 +233,20 @@ class @Problem
@
$
(
".CodeMirror"
).
each
(
index
,
element
)
->
element
.
CodeMirror
.
save
()
if
element
.
CodeMirror
.
save
@
answers
=
@
inputs
.
serialize
()
inputtypeSetupMethods
:
javascriptinput
:
(
element
)
=>
data
=
$
(
element
).
find
(
".javascriptinput_data"
)
params
=
data
.
data
(
"params"
)
submission
=
data
.
data
(
"submission"
)
evaluation
=
data
.
data
(
"evaluation"
)
problemState
=
data
.
data
(
"problem_state"
)
displayClass
=
window
[
data
.
data
(
'display_class'
)]
container
=
$
(
element
).
find
(
".javascriptinput_container"
)
submissionField
=
$
(
element
).
find
(
".javascriptinput_input"
)
display
=
new
displayClass
(
problemState
,
submission
,
evaluation
,
container
,
submissionField
,
params
)
display
.
render
()
common/lib/xmodule/xmodule/tests/__init__.py
View file @
6a50da3d
...
...
@@ -8,6 +8,7 @@
import
unittest
import
os
import
fs
import
json
import
json
import
numpy
...
...
@@ -31,10 +32,11 @@ i4xs = ModuleSystem(
render_template
=
Mock
(),
replace_urls
=
Mock
(),
user
=
Mock
(),
filestore
=
fs
.
osfs
.
OSFS
(
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))),
filestore
=
fs
.
osfs
.
OSFS
(
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
+
"/test_files"
),
debug
=
True
,
xqueue
=
{
'interface'
:
None
,
'callback_url'
:
'/'
,
'default_queuename'
:
'testqueue'
},
is_staff
=
False
is_staff
=
False
,
node_path
=
os
.
environ
.
get
(
"NODE_PATH"
,
"/usr/local/lib/node_modules"
)
)
...
...
@@ -323,7 +325,8 @@ class CodeResponseTest(unittest.TestCase):
new_cmap
=
CorrectMap
()
new_cmap
.
update
(
old_cmap
)
new_cmap
.
set
(
answer_id
=
answer_ids
[
i
],
correctness
=
correctness
,
msg
=
'MESSAGE'
,
queuekey
=
None
)
npoints
=
1
if
correctness
==
'correct'
else
0
new_cmap
.
set
(
answer_id
=
answer_ids
[
i
],
npoints
=
npoints
,
correctness
=
correctness
,
msg
=
'MESSAGE'
,
queuekey
=
None
)
test_lcp
.
update_score
(
xserver_msgs
[
correctness
],
queuekey
=
1000
+
i
)
self
.
assertEquals
(
test_lcp
.
correct_map
.
get_dict
(),
new_cmap
.
get_dict
())
...
...
@@ -373,6 +376,19 @@ class ChoiceResponseTest(unittest.TestCase):
self
.
assertEquals
(
test_lcp
.
grade_answers
(
test_answers
)
.
get_correctness
(
'1_3_1'
),
'incorrect'
)
self
.
assertEquals
(
test_lcp
.
grade_answers
(
test_answers
)
.
get_correctness
(
'1_4_1'
),
'correct'
)
class
JavascriptResponseTest
(
unittest
.
TestCase
):
def
test_jr_grade
(
self
):
problem_file
=
os
.
path
.
dirname
(
__file__
)
+
"/test_files/javascriptresponse.xml"
coffee_file_path
=
os
.
path
.
dirname
(
__file__
)
+
"/test_files/js/*.coffee"
os
.
system
(
"coffee -c
%
s"
%
(
coffee_file_path
))
test_lcp
=
lcp
.
LoncapaProblem
(
open
(
problem_file
)
.
read
(),
'1'
,
system
=
i4xs
)
correct_answers
=
{
'1_2_1'
:
json
.
dumps
({
0
:
4
})}
incorrect_answers
=
{
'1_2_1'
:
json
.
dumps
({
0
:
5
})}
self
.
assertEquals
(
test_lcp
.
grade_answers
(
incorrect_answers
)
.
get_correctness
(
'1_2_1'
),
'incorrect'
)
self
.
assertEquals
(
test_lcp
.
grade_answers
(
correct_answers
)
.
get_correctness
(
'1_2_1'
),
'correct'
)
#-----------------------------------------------------------------------------
# Grading tests
...
...
common/lib/xmodule/xmodule/tests/test_files/javascriptresponse.xml
0 → 100644
View file @
6a50da3d
<problem>
<javascriptresponse>
<generator
src=
"test_problem_generator.js"
/>
<grader
src=
"test_problem_grader.js"
/>
<display
class=
"TestProblemDisplay"
src=
"test_problem_display.js"
/>
<responseparam
name=
"value"
value=
"4"
/>
<javascriptinput>
</javascriptinput>
</javascriptresponse>
</problem>
common/lib/xmodule/xmodule/tests/test_files/js/compiled/c9a9cd4242d84c924fe5f8324e9ae79d.js
0 → 100644
View file @
6a50da3d
// Generated by CoffeeScript 1.3.3
(
function
()
{
var
MinimaxProblemDisplay
,
root
,
__hasProp
=
{}.
hasOwnProperty
,
__extends
=
function
(
child
,
parent
)
{
for
(
var
key
in
parent
)
{
if
(
__hasProp
.
call
(
parent
,
key
))
child
[
key
]
=
parent
[
key
];
}
function
ctor
()
{
this
.
constructor
=
child
;
}
ctor
.
prototype
=
parent
.
prototype
;
child
.
prototype
=
new
ctor
();
child
.
__super__
=
parent
.
prototype
;
return
child
;
};
MinimaxProblemDisplay
=
(
function
(
_super
)
{
__extends
(
MinimaxProblemDisplay
,
_super
);
function
MinimaxProblemDisplay
(
state
,
submission
,
evaluation
,
container
,
submissionField
,
parameters
)
{
this
.
state
=
state
;
this
.
submission
=
submission
;
this
.
evaluation
=
evaluation
;
this
.
container
=
container
;
this
.
submissionField
=
submissionField
;
this
.
parameters
=
parameters
!=
null
?
parameters
:
{};
MinimaxProblemDisplay
.
__super__
.
constructor
.
call
(
this
,
this
.
state
,
this
.
submission
,
this
.
evaluation
,
this
.
container
,
this
.
submissionField
,
this
.
parameters
);
}
MinimaxProblemDisplay
.
prototype
.
render
=
function
()
{};
MinimaxProblemDisplay
.
prototype
.
createSubmission
=
function
()
{
var
id
,
value
,
_ref
,
_results
;
this
.
newSubmission
=
{};
if
(
this
.
submission
!=
null
)
{
_ref
=
this
.
submission
;
_results
=
[];
for
(
id
in
_ref
)
{
value
=
_ref
[
id
];
_results
.
push
(
this
.
newSubmission
[
id
]
=
value
);
}
return
_results
;
}
};
MinimaxProblemDisplay
.
prototype
.
getCurrentSubmission
=
function
()
{
return
this
.
newSubmission
;
};
return
MinimaxProblemDisplay
;
})(
XProblemDisplay
);
root
=
typeof
exports
!==
"undefined"
&&
exports
!==
null
?
exports
:
this
;
root
.
TestProblemDisplay
=
TestProblemDisplay
;
}).
call
(
this
);
;
common/lib/xmodule/xmodule/tests/test_files/js/mersenne-twister-min.js
0 → 100644
View file @
6a50da3d
/*
I've wrapped Makoto Matsumoto and Takuji Nishimura's code in a namespace
so it's better encapsulated. Now you can have multiple random number generators
and they won't stomp all over eachother's state.
If you want to use this as a substitute for Math.random(), use the random()
method like so:
var m = new MersenneTwister();
var randomNumber = m.random();
You can also call the other genrand_{foo}() methods on the instance.
If you want to use a specific seed in order to get a repeatable random
sequence, pass an integer into the constructor:
var m = new MersenneTwister(123);
and that will always produce the same random sequence.
Sean McCullough (banksean@gmail.com)
*/
/*
A C-program for MT19937, with initialization improved 2002/1/26.
Coded by Takuji Nishimura and Makoto Matsumoto.
Before using, initialize the state by using init_genrand(seed)
or init_by_array(init_key, key_length).
Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The names of its contributors may not be used to endorse or promote
products derived from this software without specific prior written
permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Any feedback is very welcome.
http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html
email: m-mat @ math.sci.hiroshima-u.ac.jp (remove space)
*/
var
MersenneTwister
=
function
(
seed
)
{
if
(
seed
==
undefined
)
{
seed
=
new
Date
().
getTime
();
}
/* Period parameters */
this
.
N
=
624
;
this
.
M
=
397
;
this
.
MATRIX_A
=
0x9908b0df
;
/* constant vector a */
this
.
UPPER_MASK
=
0x80000000
;
/* most significant w-r bits */
this
.
LOWER_MASK
=
0x7fffffff
;
/* least significant r bits */
this
.
mt
=
new
Array
(
this
.
N
);
/* the array for the state vector */
this
.
mti
=
this
.
N
+
1
;
/* mti==N+1 means mt[N] is not initialized */
this
.
init_genrand
(
seed
);
}
/* initializes mt[N] with a seed */
MersenneTwister
.
prototype
.
init_genrand
=
function
(
s
)
{
this
.
mt
[
0
]
=
s
>>>
0
;
for
(
this
.
mti
=
1
;
this
.
mti
<
this
.
N
;
this
.
mti
++
)
{
var
s
=
this
.
mt
[
this
.
mti
-
1
]
^
(
this
.
mt
[
this
.
mti
-
1
]
>>>
30
);
this
.
mt
[
this
.
mti
]
=
(((((
s
&
0xffff0000
)
>>>
16
)
*
1812433253
)
<<
16
)
+
(
s
&
0x0000ffff
)
*
1812433253
)
+
this
.
mti
;
/* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */
/* In the previous versions, MSBs of the seed affect */
/* only MSBs of the array mt[]. */
/* 2002/01/09 modified by Makoto Matsumoto */
this
.
mt
[
this
.
mti
]
>>>=
0
;
/* for >32 bit machines */
}
}
/* initialize by an array with array-length */
/* init_key is the array for initializing keys */
/* key_length is its length */
/* slight change for C++, 2004/2/26 */
MersenneTwister
.
prototype
.
init_by_array
=
function
(
init_key
,
key_length
)
{
var
i
,
j
,
k
;
this
.
init_genrand
(
19650218
);
i
=
1
;
j
=
0
;
k
=
(
this
.
N
>
key_length
?
this
.
N
:
key_length
);
for
(;
k
;
k
--
)
{
var
s
=
this
.
mt
[
i
-
1
]
^
(
this
.
mt
[
i
-
1
]
>>>
30
)
this
.
mt
[
i
]
=
(
this
.
mt
[
i
]
^
(((((
s
&
0xffff0000
)
>>>
16
)
*
1664525
)
<<
16
)
+
((
s
&
0x0000ffff
)
*
1664525
)))
+
init_key
[
j
]
+
j
;
/* non linear */
this
.
mt
[
i
]
>>>=
0
;
/* for WORDSIZE > 32 machines */
i
++
;
j
++
;
if
(
i
>=
this
.
N
)
{
this
.
mt
[
0
]
=
this
.
mt
[
this
.
N
-
1
];
i
=
1
;
}
if
(
j
>=
key_length
)
j
=
0
;
}
for
(
k
=
this
.
N
-
1
;
k
;
k
--
)
{
var
s
=
this
.
mt
[
i
-
1
]
^
(
this
.
mt
[
i
-
1
]
>>>
30
);
this
.
mt
[
i
]
=
(
this
.
mt
[
i
]
^
(((((
s
&
0xffff0000
)
>>>
16
)
*
1566083941
)
<<
16
)
+
(
s
&
0x0000ffff
)
*
1566083941
))
-
i
;
/* non linear */
this
.
mt
[
i
]
>>>=
0
;
/* for WORDSIZE > 32 machines */
i
++
;
if
(
i
>=
this
.
N
)
{
this
.
mt
[
0
]
=
this
.
mt
[
this
.
N
-
1
];
i
=
1
;
}
}
this
.
mt
[
0
]
=
0x80000000
;
/* MSB is 1; assuring non-zero initial array */
}
/* generates a random number on [0,0xffffffff]-interval */
MersenneTwister
.
prototype
.
genrand_int32
=
function
()
{
var
y
;
var
mag01
=
new
Array
(
0x0
,
this
.
MATRIX_A
);
/* mag01[x] = x * MATRIX_A for x=0,1 */
if
(
this
.
mti
>=
this
.
N
)
{
/* generate N words at one time */
var
kk
;
if
(
this
.
mti
==
this
.
N
+
1
)
/* if init_genrand() has not been called, */
this
.
init_genrand
(
5489
);
/* a default initial seed is used */
for
(
kk
=
0
;
kk
<
this
.
N
-
this
.
M
;
kk
++
)
{
y
=
(
this
.
mt
[
kk
]
&
this
.
UPPER_MASK
)
|
(
this
.
mt
[
kk
+
1
]
&
this
.
LOWER_MASK
);
this
.
mt
[
kk
]
=
this
.
mt
[
kk
+
this
.
M
]
^
(
y
>>>
1
)
^
mag01
[
y
&
0x1
];
}
for
(;
kk
<
this
.
N
-
1
;
kk
++
)
{
y
=
(
this
.
mt
[
kk
]
&
this
.
UPPER_MASK
)
|
(
this
.
mt
[
kk
+
1
]
&
this
.
LOWER_MASK
);
this
.
mt
[
kk
]
=
this
.
mt
[
kk
+
(
this
.
M
-
this
.
N
)]
^
(
y
>>>
1
)
^
mag01
[
y
&
0x1
];
}
y
=
(
this
.
mt
[
this
.
N
-
1
]
&
this
.
UPPER_MASK
)
|
(
this
.
mt
[
0
]
&
this
.
LOWER_MASK
);
this
.
mt
[
this
.
N
-
1
]
=
this
.
mt
[
this
.
M
-
1
]
^
(
y
>>>
1
)
^
mag01
[
y
&
0x1
];
this
.
mti
=
0
;
}
y
=
this
.
mt
[
this
.
mti
++
];
/* Tempering */
y
^=
(
y
>>>
11
);
y
^=
(
y
<<
7
)
&
0x9d2c5680
;
y
^=
(
y
<<
15
)
&
0xefc60000
;
y
^=
(
y
>>>
18
);
return
y
>>>
0
;
}
/* generates a random number on [0,0x7fffffff]-interval */
MersenneTwister
.
prototype
.
genrand_int31
=
function
()
{
return
(
this
.
genrand_int32
()
>>>
1
);
}
/* generates a random number on [0,1]-real-interval */
MersenneTwister
.
prototype
.
genrand_real1
=
function
()
{
return
this
.
genrand_int32
()
*
(
1.0
/
4294967295.0
);
/* divided by 2^32-1 */
}
/* generates a random number on [0,1)-real-interval */
MersenneTwister
.
prototype
.
random
=
function
()
{
return
this
.
genrand_int32
()
*
(
1.0
/
4294967296.0
);
/* divided by 2^32 */
}
/* generates a random number on (0,1)-real-interval */
MersenneTwister
.
prototype
.
genrand_real3
=
function
()
{
return
(
this
.
genrand_int32
()
+
0.5
)
*
(
1.0
/
4294967296.0
);
/* divided by 2^32 */
}
/* generates a random number on [0,1) with 53-bit resolution*/
MersenneTwister
.
prototype
.
genrand_res53
=
function
()
{
var
a
=
this
.
genrand_int32
()
>>>
5
,
b
=
this
.
genrand_int32
()
>>>
6
;
return
(
a
*
67108864.0
+
b
)
*
(
1.0
/
9007199254740992.0
);
}
/* These real versions are due to Isaku Wada, 2002/01/09 added */
if
(
typeof
exports
==
'undefined'
){
var
root
=
this
;
}
else
{
var
root
=
exports
;
}
root
.
MersenneTwister
=
MersenneTwister
;
common/lib/xmodule/xmodule/tests/test_files/js/test_problem_display.coffee
0 → 100644
View file @
6a50da3d
class
MinimaxProblemDisplay
extends
XProblemDisplay
constructor
:
(
@
state
,
@
submission
,
@
evaluation
,
@
container
,
@
submissionField
,
@
parameters
=
{})
->
super
(
@
state
,
@
submission
,
@
evaluation
,
@
container
,
@
submissionField
,
@
parameters
)
render
:
()
->
createSubmission
:
()
->
@
newSubmission
=
{}
if
@
submission
?
for
id
,
value
of
@
submission
@
newSubmission
[
id
]
=
value
getCurrentSubmission
:
()
->
return
@
newSubmission
root
=
exports
?
this
root
.
TestProblemDisplay
=
TestProblemDisplay
common/lib/xmodule/xmodule/tests/test_files/js/test_problem_display.js
0 → 100644
View file @
6a50da3d
// Generated by CoffeeScript 1.3.3
(
function
()
{
var
MinimaxProblemDisplay
,
root
,
__hasProp
=
{}.
hasOwnProperty
,
__extends
=
function
(
child
,
parent
)
{
for
(
var
key
in
parent
)
{
if
(
__hasProp
.
call
(
parent
,
key
))
child
[
key
]
=
parent
[
key
];
}
function
ctor
()
{
this
.
constructor
=
child
;
}
ctor
.
prototype
=
parent
.
prototype
;
child
.
prototype
=
new
ctor
();
child
.
__super__
=
parent
.
prototype
;
return
child
;
};
MinimaxProblemDisplay
=
(
function
(
_super
)
{
__extends
(
MinimaxProblemDisplay
,
_super
);
function
MinimaxProblemDisplay
(
state
,
submission
,
evaluation
,
container
,
submissionField
,
parameters
)
{
this
.
state
=
state
;
this
.
submission
=
submission
;
this
.
evaluation
=
evaluation
;
this
.
container
=
container
;
this
.
submissionField
=
submissionField
;
this
.
parameters
=
parameters
!=
null
?
parameters
:
{};
MinimaxProblemDisplay
.
__super__
.
constructor
.
call
(
this
,
this
.
state
,
this
.
submission
,
this
.
evaluation
,
this
.
container
,
this
.
submissionField
,
this
.
parameters
);
}
MinimaxProblemDisplay
.
prototype
.
render
=
function
()
{};
MinimaxProblemDisplay
.
prototype
.
createSubmission
=
function
()
{
var
id
,
value
,
_ref
,
_results
;
this
.
newSubmission
=
{};
if
(
this
.
submission
!=
null
)
{
_ref
=
this
.
submission
;
_results
=
[];
for
(
id
in
_ref
)
{
value
=
_ref
[
id
];
_results
.
push
(
this
.
newSubmission
[
id
]
=
value
);
}
return
_results
;
}
};
MinimaxProblemDisplay
.
prototype
.
getCurrentSubmission
=
function
()
{
return
this
.
newSubmission
;
};
return
MinimaxProblemDisplay
;
})(
XProblemDisplay
);
root
=
typeof
exports
!==
"undefined"
&&
exports
!==
null
?
exports
:
this
;
root
.
TestProblemDisplay
=
TestProblemDisplay
;
}).
call
(
this
);
common/lib/xmodule/xmodule/tests/test_files/js/test_problem_generator.coffee
0 → 100644
View file @
6a50da3d
class
TestProblemGenerator
extends
XProblemGenerator
constructor
:
(
seed
,
@
parameters
=
{})
->
super
(
seed
,
@
parameters
)
generate
:
()
->
@
problemState
.
value
=
@
parameters
.
value
return
@
problemState
root
=
exports
?
this
root
.
generatorClass
=
TestProblemGenerator
common/lib/xmodule/xmodule/tests/test_files/js/test_problem_generator.js
0 → 100644
View file @
6a50da3d
// Generated by CoffeeScript 1.3.3
(
function
()
{
var
TestProblemGenerator
,
root
,
__hasProp
=
{}.
hasOwnProperty
,
__extends
=
function
(
child
,
parent
)
{
for
(
var
key
in
parent
)
{
if
(
__hasProp
.
call
(
parent
,
key
))
child
[
key
]
=
parent
[
key
];
}
function
ctor
()
{
this
.
constructor
=
child
;
}
ctor
.
prototype
=
parent
.
prototype
;
child
.
prototype
=
new
ctor
();
child
.
__super__
=
parent
.
prototype
;
return
child
;
};
TestProblemGenerator
=
(
function
(
_super
)
{
__extends
(
TestProblemGenerator
,
_super
);
function
TestProblemGenerator
(
seed
,
parameters
)
{
this
.
parameters
=
parameters
!=
null
?
parameters
:
{};
TestProblemGenerator
.
__super__
.
constructor
.
call
(
this
,
seed
,
this
.
parameters
);
}
TestProblemGenerator
.
prototype
.
generate
=
function
()
{
this
.
problemState
.
value
=
this
.
parameters
.
value
;
return
this
.
problemState
;
};
return
TestProblemGenerator
;
})(
XProblemGenerator
);
root
=
typeof
exports
!==
"undefined"
&&
exports
!==
null
?
exports
:
this
;
root
.
generatorClass
=
TestProblemGenerator
;
}).
call
(
this
);
common/lib/xmodule/xmodule/tests/test_files/js/test_problem_grader.coffee
0 → 100644
View file @
6a50da3d
class
TestProblemGrader
extends
XProblemGrader
constructor
:
(
@
submission
,
@
problemState
,
@
parameters
=
{})
->
super
(
@
submission
,
@
problemState
,
@
parameters
)
solve
:
()
->
@
solution
=
{
0
:
@
problemState
.
value
}
grade
:
()
->
if
not
@
solution
?
@
solve
()
allCorrect
=
true
for
id
,
value
of
@
solution
valueCorrect
=
if
@
submission
?
then
(
value
==
@
submission
[
id
])
else
false
@
evaluation
[
id
]
=
valueCorrect
if
not
valueCorrect
allCorrect
=
false
return
allCorrect
root
=
exports
?
this
root
.
graderClass
=
TestProblemGrader
common/lib/xmodule/xmodule/tests/test_files/js/test_problem_grader.js
0 → 100644
View file @
6a50da3d
// Generated by CoffeeScript 1.3.3
(
function
()
{
var
TestProblemGrader
,
root
,
__hasProp
=
{}.
hasOwnProperty
,
__extends
=
function
(
child
,
parent
)
{
for
(
var
key
in
parent
)
{
if
(
__hasProp
.
call
(
parent
,
key
))
child
[
key
]
=
parent
[
key
];
}
function
ctor
()
{
this
.
constructor
=
child
;
}
ctor
.
prototype
=
parent
.
prototype
;
child
.
prototype
=
new
ctor
();
child
.
__super__
=
parent
.
prototype
;
return
child
;
};
TestProblemGrader
=
(
function
(
_super
)
{
__extends
(
TestProblemGrader
,
_super
);
function
TestProblemGrader
(
submission
,
problemState
,
parameters
)
{
this
.
submission
=
submission
;
this
.
problemState
=
problemState
;
this
.
parameters
=
parameters
!=
null
?
parameters
:
{};
TestProblemGrader
.
__super__
.
constructor
.
call
(
this
,
this
.
submission
,
this
.
problemState
,
this
.
parameters
);
}
TestProblemGrader
.
prototype
.
solve
=
function
()
{
return
this
.
solution
=
{
0
:
this
.
problemState
.
value
};
};
TestProblemGrader
.
prototype
.
grade
=
function
()
{
var
allCorrect
,
id
,
value
,
valueCorrect
,
_ref
;
if
(
!
(
this
.
solution
!=
null
))
{
this
.
solve
();
}
allCorrect
=
true
;
_ref
=
this
.
solution
;
for
(
id
in
_ref
)
{
value
=
_ref
[
id
];
valueCorrect
=
this
.
submission
!=
null
?
value
===
this
.
submission
[
id
]
:
false
;
this
.
evaluation
[
id
]
=
valueCorrect
;
if
(
!
valueCorrect
)
{
allCorrect
=
false
;
}
}
return
allCorrect
;
};
return
TestProblemGrader
;
})(
XProblemGrader
);
root
=
typeof
exports
!==
"undefined"
&&
exports
!==
null
?
exports
:
this
;
root
.
graderClass
=
TestProblemGrader
;
}).
call
(
this
);
common/lib/xmodule/xmodule/tests/test_files/js/xproblem.coffee
0 → 100644
View file @
6a50da3d
class
XProblemGenerator
constructor
:
(
seed
,
@
parameters
=
{})
->
@
random
=
new
MersenneTwister
(
seed
)
@
problemState
=
{}
generate
:
()
->
console
.
error
(
"Abstract method called: XProblemGenerator.generate"
)
class
XProblemDisplay
constructor
:
(
@
state
,
@
submission
,
@
evaluation
,
@
container
,
@
submissionField
,
@
parameters
=
{})
->
render
:
()
->
console
.
error
(
"Abstract method called: XProblemDisplay.render"
)
updateSubmission
:
()
->
@
submissionField
.
val
(
JSON
.
stringify
(
@
getCurrentSubmission
()))
getCurrentSubmission
:
()
->
console
.
error
(
"Abstract method called: XProblemDisplay.getCurrentSubmission"
)
class
XProblemGrader
constructor
:
(
@
submission
,
@
problemState
,
@
parameters
=
{})
->
@
solution
=
null
@
evaluation
=
{}
solve
:
()
->
console
.
error
(
"Abstract method called: XProblemGrader.solve"
)
grade
:
()
->
console
.
error
(
"Abstract method called: XProblemGrader.grade"
)
root
=
exports
?
this
root
.
XProblemGenerator
=
XProblemGenerator
root
.
XProblemDisplay
=
XProblemDisplay
root
.
XProblemGrader
=
XProblemGrader
common/lib/xmodule/xmodule/tests/test_files/js/xproblem.js
0 → 100644
View file @
6a50da3d
// Generated by CoffeeScript 1.3.3
(
function
()
{
var
XProblemDisplay
,
XProblemGenerator
,
XProblemGrader
,
root
;
XProblemGenerator
=
(
function
()
{
function
XProblemGenerator
(
seed
,
parameters
)
{
this
.
parameters
=
parameters
!=
null
?
parameters
:
{};
this
.
random
=
new
MersenneTwister
(
seed
);
this
.
problemState
=
{};
}
XProblemGenerator
.
prototype
.
generate
=
function
()
{
return
console
.
error
(
"Abstract method called: XProblemGenerator.generate"
);
};
return
XProblemGenerator
;
})();
XProblemDisplay
=
(
function
()
{
function
XProblemDisplay
(
state
,
submission
,
evaluation
,
container
,
submissionField
,
parameters
)
{
this
.
state
=
state
;
this
.
submission
=
submission
;
this
.
evaluation
=
evaluation
;
this
.
container
=
container
;
this
.
submissionField
=
submissionField
;
this
.
parameters
=
parameters
!=
null
?
parameters
:
{};
}
XProblemDisplay
.
prototype
.
render
=
function
()
{
return
console
.
error
(
"Abstract method called: XProblemDisplay.render"
);
};
XProblemDisplay
.
prototype
.
updateSubmission
=
function
()
{
return
this
.
submissionField
.
val
(
JSON
.
stringify
(
this
.
getCurrentSubmission
()));
};
XProblemDisplay
.
prototype
.
getCurrentSubmission
=
function
()
{
return
console
.
error
(
"Abstract method called: XProblemDisplay.getCurrentSubmission"
);
};
return
XProblemDisplay
;
})();
XProblemGrader
=
(
function
()
{
function
XProblemGrader
(
submission
,
problemState
,
parameters
)
{
this
.
submission
=
submission
;
this
.
problemState
=
problemState
;
this
.
parameters
=
parameters
!=
null
?
parameters
:
{};
this
.
solution
=
null
;
this
.
evaluation
=
{};
}
XProblemGrader
.
prototype
.
solve
=
function
()
{
return
console
.
error
(
"Abstract method called: XProblemGrader.solve"
);
};
XProblemGrader
.
prototype
.
grade
=
function
()
{
return
console
.
error
(
"Abstract method called: XProblemGrader.grade"
);
};
return
XProblemGrader
;
})();
root
=
typeof
exports
!==
"undefined"
&&
exports
!==
null
?
exports
:
this
;
root
.
XProblemGenerator
=
XProblemGenerator
;
root
.
XProblemDisplay
=
XProblemDisplay
;
root
.
XProblemGrader
=
XProblemGrader
;
}).
call
(
this
);
common/lib/xmodule/xmodule/x_module.py
View file @
6a50da3d
...
...
@@ -675,7 +675,8 @@ class ModuleSystem(object):
filestore
=
None
,
debug
=
False
,
xqueue
=
None
,
is_staff
=
False
):
is_staff
=
False
,
node_path
=
""
):
'''
Create a closure around the system environment.
...
...
@@ -718,6 +719,7 @@ class ModuleSystem(object):
self
.
seed
=
user
.
id
if
user
is
not
None
else
0
self
.
replace_urls
=
replace_urls
self
.
is_staff
=
is_staff
self
.
node_path
=
node_path
def
get
(
self
,
attr
):
''' provide uniform access to attributes (like etree).'''
...
...
common/static/coffee/src/xproblem.coffee
0 → 100644
View file @
6a50da3d
class
XProblemGenerator
constructor
:
(
seed
,
@
parameters
=
{})
->
@
random
=
new
MersenneTwister
(
seed
)
@
problemState
=
{}
generate
:
()
->
console
.
error
(
"Abstract method called: XProblemGenerator.generate"
)
class
XProblemDisplay
constructor
:
(
@
state
,
@
submission
,
@
evaluation
,
@
container
,
@
submissionField
,
@
parameters
=
{})
->
render
:
()
->
console
.
error
(
"Abstract method called: XProblemDisplay.render"
)
updateSubmission
:
()
->
@
submissionField
.
val
(
JSON
.
stringify
(
@
getCurrentSubmission
()))
getCurrentSubmission
:
()
->
console
.
error
(
"Abstract method called: XProblemDisplay.getCurrentSubmission"
)
class
XProblemGrader
constructor
:
(
@
submission
,
@
problemState
,
@
parameters
=
{})
->
@
solution
=
null
@
evaluation
=
{}
solve
:
()
->
console
.
error
(
"Abstract method called: XProblemGrader.solve"
)
grade
:
()
->
console
.
error
(
"Abstract method called: XProblemGrader.grade"
)
root
=
exports
?
this
root
.
XProblemGenerator
=
XProblemGenerator
root
.
XProblemDisplay
=
XProblemDisplay
root
.
XProblemGrader
=
XProblemGrader
common/static/js/vendor/mersenne-twister-min.js
0 → 100644
View file @
6a50da3d
/*
I've wrapped Makoto Matsumoto and Takuji Nishimura's code in a namespace
so it's better encapsulated. Now you can have multiple random number generators
and they won't stomp all over eachother's state.
If you want to use this as a substitute for Math.random(), use the random()
method like so:
var m = new MersenneTwister();
var randomNumber = m.random();
You can also call the other genrand_{foo}() methods on the instance.
If you want to use a specific seed in order to get a repeatable random
sequence, pass an integer into the constructor:
var m = new MersenneTwister(123);
and that will always produce the same random sequence.
Sean McCullough (banksean@gmail.com)
*/
/*
A C-program for MT19937, with initialization improved 2002/1/26.
Coded by Takuji Nishimura and Makoto Matsumoto.
Before using, initialize the state by using init_genrand(seed)
or init_by_array(init_key, key_length).
Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The names of its contributors may not be used to endorse or promote
products derived from this software without specific prior written
permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Any feedback is very welcome.
http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html
email: m-mat @ math.sci.hiroshima-u.ac.jp (remove space)
*/
var
MersenneTwister
=
function
(
seed
)
{
if
(
seed
==
undefined
)
{
seed
=
new
Date
().
getTime
();
}
/* Period parameters */
this
.
N
=
624
;
this
.
M
=
397
;
this
.
MATRIX_A
=
0x9908b0df
;
/* constant vector a */
this
.
UPPER_MASK
=
0x80000000
;
/* most significant w-r bits */
this
.
LOWER_MASK
=
0x7fffffff
;
/* least significant r bits */
this
.
mt
=
new
Array
(
this
.
N
);
/* the array for the state vector */
this
.
mti
=
this
.
N
+
1
;
/* mti==N+1 means mt[N] is not initialized */
this
.
init_genrand
(
seed
);
}
/* initializes mt[N] with a seed */
MersenneTwister
.
prototype
.
init_genrand
=
function
(
s
)
{
this
.
mt
[
0
]
=
s
>>>
0
;
for
(
this
.
mti
=
1
;
this
.
mti
<
this
.
N
;
this
.
mti
++
)
{
var
s
=
this
.
mt
[
this
.
mti
-
1
]
^
(
this
.
mt
[
this
.
mti
-
1
]
>>>
30
);
this
.
mt
[
this
.
mti
]
=
(((((
s
&
0xffff0000
)
>>>
16
)
*
1812433253
)
<<
16
)
+
(
s
&
0x0000ffff
)
*
1812433253
)
+
this
.
mti
;
/* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */
/* In the previous versions, MSBs of the seed affect */
/* only MSBs of the array mt[]. */
/* 2002/01/09 modified by Makoto Matsumoto */
this
.
mt
[
this
.
mti
]
>>>=
0
;
/* for >32 bit machines */
}
}
/* initialize by an array with array-length */
/* init_key is the array for initializing keys */
/* key_length is its length */
/* slight change for C++, 2004/2/26 */
MersenneTwister
.
prototype
.
init_by_array
=
function
(
init_key
,
key_length
)
{
var
i
,
j
,
k
;
this
.
init_genrand
(
19650218
);
i
=
1
;
j
=
0
;
k
=
(
this
.
N
>
key_length
?
this
.
N
:
key_length
);
for
(;
k
;
k
--
)
{
var
s
=
this
.
mt
[
i
-
1
]
^
(
this
.
mt
[
i
-
1
]
>>>
30
)
this
.
mt
[
i
]
=
(
this
.
mt
[
i
]
^
(((((
s
&
0xffff0000
)
>>>
16
)
*
1664525
)
<<
16
)
+
((
s
&
0x0000ffff
)
*
1664525
)))
+
init_key
[
j
]
+
j
;
/* non linear */
this
.
mt
[
i
]
>>>=
0
;
/* for WORDSIZE > 32 machines */
i
++
;
j
++
;
if
(
i
>=
this
.
N
)
{
this
.
mt
[
0
]
=
this
.
mt
[
this
.
N
-
1
];
i
=
1
;
}
if
(
j
>=
key_length
)
j
=
0
;
}
for
(
k
=
this
.
N
-
1
;
k
;
k
--
)
{
var
s
=
this
.
mt
[
i
-
1
]
^
(
this
.
mt
[
i
-
1
]
>>>
30
);
this
.
mt
[
i
]
=
(
this
.
mt
[
i
]
^
(((((
s
&
0xffff0000
)
>>>
16
)
*
1566083941
)
<<
16
)
+
(
s
&
0x0000ffff
)
*
1566083941
))
-
i
;
/* non linear */
this
.
mt
[
i
]
>>>=
0
;
/* for WORDSIZE > 32 machines */
i
++
;
if
(
i
>=
this
.
N
)
{
this
.
mt
[
0
]
=
this
.
mt
[
this
.
N
-
1
];
i
=
1
;
}
}
this
.
mt
[
0
]
=
0x80000000
;
/* MSB is 1; assuring non-zero initial array */
}
/* generates a random number on [0,0xffffffff]-interval */
MersenneTwister
.
prototype
.
genrand_int32
=
function
()
{
var
y
;
var
mag01
=
new
Array
(
0x0
,
this
.
MATRIX_A
);
/* mag01[x] = x * MATRIX_A for x=0,1 */
if
(
this
.
mti
>=
this
.
N
)
{
/* generate N words at one time */
var
kk
;
if
(
this
.
mti
==
this
.
N
+
1
)
/* if init_genrand() has not been called, */
this
.
init_genrand
(
5489
);
/* a default initial seed is used */
for
(
kk
=
0
;
kk
<
this
.
N
-
this
.
M
;
kk
++
)
{
y
=
(
this
.
mt
[
kk
]
&
this
.
UPPER_MASK
)
|
(
this
.
mt
[
kk
+
1
]
&
this
.
LOWER_MASK
);
this
.
mt
[
kk
]
=
this
.
mt
[
kk
+
this
.
M
]
^
(
y
>>>
1
)
^
mag01
[
y
&
0x1
];
}
for
(;
kk
<
this
.
N
-
1
;
kk
++
)
{
y
=
(
this
.
mt
[
kk
]
&
this
.
UPPER_MASK
)
|
(
this
.
mt
[
kk
+
1
]
&
this
.
LOWER_MASK
);
this
.
mt
[
kk
]
=
this
.
mt
[
kk
+
(
this
.
M
-
this
.
N
)]
^
(
y
>>>
1
)
^
mag01
[
y
&
0x1
];
}
y
=
(
this
.
mt
[
this
.
N
-
1
]
&
this
.
UPPER_MASK
)
|
(
this
.
mt
[
0
]
&
this
.
LOWER_MASK
);
this
.
mt
[
this
.
N
-
1
]
=
this
.
mt
[
this
.
M
-
1
]
^
(
y
>>>
1
)
^
mag01
[
y
&
0x1
];
this
.
mti
=
0
;
}
y
=
this
.
mt
[
this
.
mti
++
];
/* Tempering */
y
^=
(
y
>>>
11
);
y
^=
(
y
<<
7
)
&
0x9d2c5680
;
y
^=
(
y
<<
15
)
&
0xefc60000
;
y
^=
(
y
>>>
18
);
return
y
>>>
0
;
}
/* generates a random number on [0,0x7fffffff]-interval */
MersenneTwister
.
prototype
.
genrand_int31
=
function
()
{
return
(
this
.
genrand_int32
()
>>>
1
);
}
/* generates a random number on [0,1]-real-interval */
MersenneTwister
.
prototype
.
genrand_real1
=
function
()
{
return
this
.
genrand_int32
()
*
(
1.0
/
4294967295.0
);
/* divided by 2^32-1 */
}
/* generates a random number on [0,1)-real-interval */
MersenneTwister
.
prototype
.
random
=
function
()
{
return
this
.
genrand_int32
()
*
(
1.0
/
4294967296.0
);
/* divided by 2^32 */
}
/* generates a random number on (0,1)-real-interval */
MersenneTwister
.
prototype
.
genrand_real3
=
function
()
{
return
(
this
.
genrand_int32
()
+
0.5
)
*
(
1.0
/
4294967296.0
);
/* divided by 2^32 */
}
/* generates a random number on [0,1) with 53-bit resolution*/
MersenneTwister
.
prototype
.
genrand_res53
=
function
()
{
var
a
=
this
.
genrand_int32
()
>>>
5
,
b
=
this
.
genrand_int32
()
>>>
6
;
return
(
a
*
67108864.0
+
b
)
*
(
1.0
/
9007199254740992.0
);
}
/* These real versions are due to Isaku Wada, 2002/01/09 added */
if
(
typeof
exports
==
'undefined'
){
var
root
=
this
;
}
else
{
var
root
=
exports
;
}
root
.
MersenneTwister
=
MersenneTwister
;
lms/djangoapps/courseware/module_render.py
View file @
6a50da3d
...
...
@@ -196,6 +196,7 @@ def get_module(user, request, location, student_module_cache, position=None):
# by the replace_static_urls code below
replace_urls
=
replace_urls
,
is_staff
=
has_staff_access_to_location
(
user
,
location
),
node_path
=
settings
.
NODE_PATH
)
# pass position specified in URL to module through ModuleSystem
system
.
set
(
'position'
,
position
)
...
...
lms/envs/common.py
View file @
6a50da3d
...
...
@@ -89,6 +89,18 @@ sys.path.append(PROJECT_ROOT / 'lib')
sys
.
path
.
append
(
COMMON_ROOT
/
'djangoapps'
)
sys
.
path
.
append
(
COMMON_ROOT
/
'lib'
)
# For Node.js
system_node_path
=
os
.
environ
.
get
(
"NODE_PATH"
,
None
)
if
system_node_path
is
None
:
system_node_path
=
"/usr/local/lib/node_modules"
node_paths
=
[
COMMON_ROOT
/
"static/js/vendor"
,
COMMON_ROOT
/
"static/coffee/src"
,
system_node_path
]
NODE_PATH
=
':'
.
join
(
node_paths
)
################################## MITXWEB #####################################
# This is where we stick our compiled template files. Most of the app uses Mako
# templates
...
...
@@ -337,7 +349,7 @@ PIPELINE_ALWAYS_RECOMPILE = ['sass/application.scss', 'sass/ie.scss', 'sass/cour
courseware_only_js
=
[
PROJECT_ROOT
/
'static/coffee/src/'
+
pth
+
'.coffee'
for
pth
in
[
'courseware'
,
'histogram'
,
'navigation'
,
'time'
,
]
in
[
'courseware'
,
'histogram'
,
'navigation'
,
'time'
]
]
courseware_only_js
+=
[
pth
for
pth
...
...
@@ -465,6 +477,7 @@ if os.path.isdir(DATA_DIR):
js_timestamp
=
os
.
stat
(
js_dir
/
new_filename
)
.
st_mtime
if
coffee_timestamp
<=
js_timestamp
:
continue
os
.
system
(
"rm
%
s"
%
(
js_dir
/
new_filename
))
os
.
system
(
"coffee -c
%
s"
%
(
js_dir
/
filename
))
PIPELINE_COMPILERS
=
[
...
...
run_watch_data.py
View file @
6a50da3d
...
...
@@ -17,7 +17,7 @@ from watchdog.events import LoggingEventHandler, FileSystemEventHandler
# watch fewer or more extensions, you can change EXTENSIONS. To watch all
# extensions, add "*" to EXTENSIONS.
WATCH_DIRS
=
[
"../data"
]
WATCH_DIRS
=
[
"../data"
,
"common/lib/xmodule/xmodule/js"
]
EXTENSIONS
=
[
"*"
,
"xml"
,
"js"
,
"css"
,
"coffee"
,
"scss"
,
"html"
]
WATCH_DIRS
=
[
os
.
path
.
abspath
(
os
.
path
.
normpath
(
dir
))
for
dir
in
WATCH_DIRS
]
...
...
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