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
1b4d400c
Commit
1b4d400c
authored
Jan 20, 2012
by
cjt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lab support
parent
6660646f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
6 deletions
+44
-6
courseware/capa/capa_problem.py
+5
-3
courseware/capa/inputtypes.py
+13
-1
courseware/capa/responsetypes.py
+26
-2
No files found.
courseware/capa/capa_problem.py
View file @
1b4d400c
...
@@ -11,11 +11,12 @@ import calc, eia
...
@@ -11,11 +11,12 @@ import calc, eia
from
util
import
contextualize_text
from
util
import
contextualize_text
from
inputtypes
import
textline
,
schematic
from
inputtypes
import
textline
,
schematic
from
responsetypes
import
numericalresponse
,
formularesponse
,
customresponse
from
responsetypes
import
numericalresponse
,
formularesponse
,
customresponse
,
schematicresponse
response_types
=
{
'numericalresponse'
:
numericalresponse
,
response_types
=
{
'numericalresponse'
:
numericalresponse
,
'formularesponse'
:
formularesponse
,
'formularesponse'
:
formularesponse
,
'customresponse'
:
customresponse
}
'customresponse'
:
customresponse
,
'schematicresponse'
:
schematicresponse
}
entry_types
=
[
'textline'
,
'schematic'
]
entry_types
=
[
'textline'
,
'schematic'
]
response_properties
=
[
"responseparam"
,
"answer"
]
response_properties
=
[
"responseparam"
,
"answer"
]
# How to convert from original XML to HTML
# How to convert from original XML to HTML
...
@@ -23,6 +24,7 @@ response_properties = ["responseparam", "answer"]
...
@@ -23,6 +24,7 @@ response_properties = ["responseparam", "answer"]
html_transforms
=
{
'problem'
:
{
'tag'
:
'div'
},
html_transforms
=
{
'problem'
:
{
'tag'
:
'div'
},
"numericalresponse"
:
{
'tag'
:
'span'
},
"numericalresponse"
:
{
'tag'
:
'span'
},
"customresponse"
:
{
'tag'
:
'span'
},
"customresponse"
:
{
'tag'
:
'span'
},
"schematicresponse"
:
{
'tag'
:
'span'
},
"formularesponse"
:
{
'tag'
:
'span'
},
"formularesponse"
:
{
'tag'
:
'span'
},
"text"
:
{
'tag'
:
'span'
}}
"text"
:
{
'tag'
:
'span'
}}
...
@@ -36,7 +38,7 @@ global_context={'random':random,
...
@@ -36,7 +38,7 @@ global_context={'random':random,
# These should be removed from HTML output, including all subelements
# These should be removed from HTML output, including all subelements
html_problem_semantics
=
[
"responseparam"
,
"answer"
,
"script"
]
html_problem_semantics
=
[
"responseparam"
,
"answer"
,
"script"
]
# These should be removed from HTML output, but keeping subelements
# These should be removed from HTML output, but keeping subelements
html_skip
=
[
"numericalresponse"
,
"customresponse"
,
"formularesponse"
,
"text"
]
html_skip
=
[
"numericalresponse"
,
"customresponse"
,
"
schematicresponse"
,
"
formularesponse"
,
"text"
]
# These should be transformed
# These should be transformed
html_special_response
=
{
"textline"
:
textline
.
render
,
html_special_response
=
{
"textline"
:
textline
.
render
,
"schematic"
:
schematic
.
render
}
"schematic"
:
schematic
.
render
}
...
...
courseware/capa/inputtypes.py
View file @
1b4d400c
...
@@ -17,7 +17,19 @@ class schematic(object):
...
@@ -17,7 +17,19 @@ class schematic(object):
eid
=
element
.
get
(
'id'
)
eid
=
element
.
get
(
'id'
)
height
=
element
.
get
(
'height'
)
height
=
element
.
get
(
'height'
)
width
=
element
.
get
(
'width'
)
width
=
element
.
get
(
'width'
)
context
=
{
'id'
:
eid
,
'value'
:
value
,
'state'
:
state
,
'width'
:
width
,
'height'
:
height
}
parts
=
element
.
get
(
'parts'
)
analyses
=
element
.
get
(
'analyses'
)
initial_value
=
element
.
get
(
'initial_value'
)
context
=
{
'id'
:
eid
,
'value'
:
value
,
'initial_value'
:
initial_value
,
'state'
:
state
,
'width'
:
width
,
'height'
:
height
,
'parts'
:
parts
,
'analyses'
:
analyses
,
}
html
=
render_to_string
(
"schematicinput.html"
,
context
)
html
=
render_to_string
(
"schematicinput.html"
,
context
)
return
etree
.
XML
(
html
)
return
etree
.
XML
(
html
)
...
...
courseware/capa/responsetypes.py
View file @
1b4d400c
import
random
,
numpy
,
math
,
scipy
import
random
,
numpy
,
math
,
scipy
,
json
from
util
import
contextualize_text
from
util
import
contextualize_text
from
calc
import
evaluator
from
calc
import
evaluator
import
random
,
math
import
random
,
math
...
@@ -63,7 +63,6 @@ class customresponse(object):
...
@@ -63,7 +63,6 @@ class customresponse(object):
# be handled by capa_problem
# be handled by capa_problem
return
{}
return
{}
class
formularesponse
(
object
):
class
formularesponse
(
object
):
def
__init__
(
self
,
xml
,
context
):
def
__init__
(
self
,
xml
,
context
):
self
.
xml
=
xml
self
.
xml
=
xml
...
@@ -114,3 +113,28 @@ class formularesponse(object):
...
@@ -114,3 +113,28 @@ class formularesponse(object):
def
get_answers
(
self
):
def
get_answers
(
self
):
return
{
self
.
answer_id
:
self
.
correct_answer
}
return
{
self
.
answer_id
:
self
.
correct_answer
}
class
schematicresponse
(
object
):
def
__init__
(
self
,
xml
,
context
):
self
.
xml
=
xml
self
.
answer_ids
=
xml
.
xpath
(
'//*[@id=$id]//schematic/@id'
,
id
=
xml
.
get
(
'id'
))
self
.
context
=
context
answer
=
xml
.
xpath
(
'//*[@id=$id]//answer'
,
id
=
xml
.
get
(
'id'
))[
0
]
answer_src
=
answer
.
get
(
'src'
)
if
answer_src
!=
None
:
self
.
code
=
open
(
settings
.
DATA_DIR
+
'src/'
+
answer_src
)
.
read
()
else
:
self
.
code
=
answer
.
text
def
grade
(
self
,
student_answers
):
submission
=
[
json
.
loads
(
student_answers
[
k
])
for
k
in
sorted
(
self
.
answer_ids
)]
self
.
context
.
update
({
'submission'
:
submission
})
exec
self
.
code
in
global_context
,
self
.
context
return
zip
(
sorted
(
self
.
answer_ids
),
self
.
context
[
'correct'
])
def
get_answers
(
self
):
# Since this is explicitly specified in the problem, this will
# be handled by capa_problem
return
{}
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