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
e9819ffb
Commit
e9819ffb
authored
Jan 11, 2012
by
Piotr Mitros
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
customresponse basically works
parent
53155d22
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
11 deletions
+42
-11
courseware/capa/capa_problem.py
+8
-2
courseware/capa/responsetypes.py
+29
-5
courseware/capa_module.py
+5
-4
No files found.
courseware/capa/capa_problem.py
View file @
e9819ffb
...
@@ -10,11 +10,11 @@ from content_parser import xpath_remove
...
@@ -10,11 +10,11 @@ from content_parser import xpath_remove
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
from
responsetypes
import
numericalresponse
,
formularesponse
,
customresponse
response_types
=
{
'numericalresponse'
:
numericalresponse
,
response_types
=
{
'numericalresponse'
:
numericalresponse
,
'formularesponse'
:
formularesponse
,
'formularesponse'
:
formularesponse
,
'customresponse'
:
Non
e
}
'customresponse'
:
customrespons
e
}
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
...
@@ -124,6 +124,12 @@ class LoncapaProblem(object):
...
@@ -124,6 +124,12 @@ class LoncapaProblem(object):
responder
=
response_types
[
response
.
tag
](
response
,
self
.
context
)
responder
=
response_types
[
response
.
tag
](
response
,
self
.
context
)
results
=
responder
.
get_answers
()
results
=
responder
.
get_answers
()
answer_map
.
update
(
results
)
answer_map
.
update
(
results
)
for
entry
in
problems_simple
.
xpath
(
"//"
+
"|//"
.
join
(
response_properties
+
entry_types
)):
answer
=
entry
.
get
(
'correct_answer'
)
if
answer
!=
None
:
answer_map
[
entry
.
get
(
'id'
)]
=
contextualize_text
(
answer
,
self
.
context
())
return
answer_map
return
answer_map
# ======= Private ========
# ======= Private ========
...
...
courseware/capa/responsetypes.py
View file @
e9819ffb
import
random
,
numpy
,
math
,
scipy
from
util
import
contextualize_text
from
util
import
contextualize_text
from
calc
import
evaluator
from
calc
import
evaluator
import
random
,
math
import
random
,
math
from
django.conf
import
settings
# TODO: Should be the same object as in capa_problem
global_context
=
{
'random'
:
random
,
'numpy'
:
numpy
,
'math'
:
math
,
'scipy'
:
scipy
}
class
numericalresponse
(
object
):
class
numericalresponse
(
object
):
def
__init__
(
self
,
xml
,
context
):
def
__init__
(
self
,
xml
,
context
):
...
@@ -30,15 +38,31 @@ class numericalresponse(object):
...
@@ -30,15 +38,31 @@ class numericalresponse(object):
class
customresponse
(
object
):
class
customresponse
(
object
):
def
__init__
(
self
,
xml
,
context
):
def
__init__
(
self
,
xml
,
context
):
self
.
xml
=
xml
self
.
xml
=
xml
self
.
answer_id
=
xml
.
xpath
(
'//*[@id=$id]//textline/@id'
,
## CRITICAL TODO: Should cover all entrytypes
id
=
xml
.
get
(
'id'
))[
0
]
self
.
answer_ids
=
xml
.
xpath
(
'//*[@id=$id]//textline/@id'
,
return
{
self
.
answer_id
:
'correct'
}
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
):
def
grade
(
self
,
student_answers
):
return
{
self
.
answer_id
:
'correct'
}
print
"YY"
,
self
.
answer_ids
print
"XX"
,
student_answers
submission
=
[
student_answers
[
k
]
for
k
in
sorted
(
self
.
answer_ids
)]
self
.
context
.
update
({
'submission'
:
submission
})
print
self
.
code
exec
self
.
code
in
global_context
,
self
.
context
return
zip
(
sorted
(
self
.
answer_ids
),
self
.
context
[
'correct'
])
def
get_answers
(
self
):
def
get_answers
(
self
):
return
{
self
.
answer_id
:
'correct'
}
# Since this is explicitly specified in the problem, this will
# be handled by capa_problem
return
{}
class
formularesponse
(
object
):
class
formularesponse
(
object
):
...
...
courseware/capa_module.py
View file @
e9819ffb
...
@@ -237,14 +237,15 @@ class LoncapaModule(XModule):
...
@@ -237,14 +237,15 @@ class LoncapaModule(XModule):
for
key
in
get
:
for
key
in
get
:
answers
[
'_'
.
join
(
key
.
split
(
'_'
)[
1
:])]
=
get
[
key
]
answers
[
'_'
.
join
(
key
.
split
(
'_'
)[
1
:])]
=
get
[
key
]
try
:
#try:
if
True
:
old_state
=
self
.
lcp
.
get_state
()
old_state
=
self
.
lcp
.
get_state
()
lcp_id
=
self
.
lcp
.
problem_id
lcp_id
=
self
.
lcp
.
problem_id
filename
=
self
.
lcp
.
filename
filename
=
self
.
lcp
.
filename
correct_map
=
self
.
lcp
.
grade_answers
(
answers
)
correct_map
=
self
.
lcp
.
grade_answers
(
answers
)
except
:
#
except:
self
.
lcp
=
LoncapaProblem
(
filename
,
id
=
lcp_id
,
state
=
old_state
)
#
self.lcp = LoncapaProblem(filename, id=lcp_id, state=old_state)
return
json
.
dumps
({
'success'
:
'syntax'
})
#
return json.dumps({'success':'syntax'})
self
.
attempts
=
self
.
attempts
+
1
self
.
attempts
=
self
.
attempts
+
1
self
.
lcp
.
done
=
True
self
.
lcp
.
done
=
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