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
4add868d
Commit
4add868d
authored
Dec 26, 2011
by
Piotr Mitros
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Bug fixes based on Jerry's problems
parent
10e3d8b9
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
68 additions
and
42 deletions
+68
-42
courseware/calc.py
+2
-1
courseware/capa_module.py
+57
-40
courseware/capa_problem.py
+9
-1
No files found.
courseware/calc.py
View file @
4add868d
...
...
@@ -69,7 +69,7 @@ def evaluator(variables, functions, string):
(
dot
,
minus
,
plus
,
times
,
div
,
lpar
,
rpar
,
exp
)
=
map
(
Literal
,
".-+*/()^"
)
number_part
=
Word
(
nums
)
number
=
Optional
(
"+-"
)
+
number_part
+
Optional
(
"."
+
number_part
)
+
\
number
=
Optional
(
minus
|
plus
)
+
number_part
+
Optional
(
"."
+
number_part
)
+
\
Optional
(
CaselessLiteral
(
"E"
)
+
Optional
(
"-"
)
+
number_part
)
+
\
Optional
(
number_suffix
)
number
=
number
.
setParseAction
(
number_parse_action
)
...
...
@@ -114,3 +114,4 @@ if __name__=='__main__':
print
evaluator
({
'R1'
:
2.0
,
'R3'
:
4.0
},
{},
"13"
)
#
print
evaluator
({
'a'
:
2.2997471478310274
,
'k'
:
9
,
'm'
:
8
,
'x'
:
0.66009498411213041
},
{},
"5"
)
print
evaluator
({},{},
"-1"
)
courseware/capa_module.py
View file @
4add868d
# For calculator:
# http://pyparsing.wikispaces.com/file/view/fourFn.py
import
random
,
numpy
,
math
,
scipy
,
sys
,
StringIO
,
os
,
struct
,
json
from
x_module
import
XModule
...
...
@@ -53,37 +50,41 @@ class LoncapaModule(XModule):
html
=
self
.
lcp
.
get_html
()
content
=
{
'name'
:
self
.
name
,
'html'
:
html
}
closed
=
False
if
self
.
lcp
.
done
:
check_button
=
"Reset"
else
:
check_button
=
"Check"
check_button
=
True
reset_button
=
True
save_button
=
True
if
self
.
max_attempts
==
None
:
pass
elif
self
.
max_attempts
==
self
.
attempts
:
save_button
=
False
# If we're after deadline, or user has exhuasted attempts,
# question is read-only.
if
self
.
closed
():
check_button
=
False
else
:
check_button
=
check_button
+
\
" ({a}/{m})"
.
format
(
a
=
self
.
attempts
,
m
=
self
.
max_attempts
)
if
self
.
due_date
!=
None
and
datetime
.
datetime
.
utcnow
()
>
self
.
due_date
:
reset_button
=
False
save_button
=
False
# User submitted a problem, and hasn't reset. We don't want
# more submissions.
if
self
.
lcp
.
done
:
check_button
=
False
results
=
True
save_button
=
False
# User hasn't submitted an answer yet -- we don't want resets
if
not
self
.
lcp
.
done
:
reset_button
=
False
attempts_str
=
""
if
self
.
max_attempts
!=
None
:
attempts_str
=
" ({a}/{m})"
.
format
(
a
=
self
.
attempts
,
m
=
self
.
max_attempts
)
html
=
render_to_string
(
'problem.html'
,
{
'problem'
:
content
,
'id'
:
self
.
filename
,
'check_button'
:
check_button
,
'save_button'
:
save_button
,
'answer_available'
:
self
.
answer_available
(),
'ajax_url'
:
self
.
ajax_url
,
{
'problem'
:
content
,
'id'
:
self
.
filename
,
'check_button'
:
check_button
,
'reset_button'
:
reset_button
,
'save_button'
:
save_button
,
'answer_available'
:
self
.
answer_available
(),
'ajax_url'
:
self
.
ajax_url
,
})
if
encapsulate
:
html
=
'<div id="main_{id}">'
.
format
(
id
=
self
.
item_id
)
+
html
+
"</div>"
...
...
@@ -194,17 +195,24 @@ class LoncapaModule(XModule):
# Figure out if we should move these to capa_problem?
def
get_problem
(
self
,
get
):
''' Same as get_problem_html -- if we want to reconfirm we
have the right
thing e.g. after several AJAX calls.
'''
''' Same as get_problem_html -- if we want to reconfirm we
have the right thing e.g. after several AJAX calls.
'''
return
self
.
get_problem_html
(
encapsulate
=
False
)
def
check_problem
(
self
,
get
):
''' Checks whether answers to a problem are correct, and returns
a map of correct/incorrect answers '''
''' Checks whether answers to a problem are correct, and
returns a map of correct/incorrect answers'''
# Too late. Cannot submit
if
self
.
closed
():
print
"cp"
raise
Http404
# Problem submitted. Student should reset before checking
# again.
if
self
.
lcp
.
done
and
self
.
resettable
:
print
"cpdr"
raise
Http404
self
.
attempts
=
self
.
attempts
+
1
self
.
lcp
.
done
=
True
answers
=
dict
()
...
...
@@ -217,10 +225,17 @@ class LoncapaModule(XModule):
return
js
def
save_problem
(
self
,
get
):
# Too late. Cannot submit
if
self
.
closed
():
print
"sp"
r
aise
Http404
r
eturn
"Problem is closed"
# Problem submitted. Student should reset before saving
# again.
if
self
.
lcp
.
done
and
self
.
resettable
:
print
"spdr"
return
"Problem needs to be reset prior to save."
answers
=
dict
()
for
key
in
get
:
answers
[
'_'
.
join
(
key
.
split
(
'_'
)[
1
:])]
=
get
[
key
]
...
...
@@ -232,19 +247,21 @@ class LoncapaModule(XModule):
def
reset_problem
(
self
,
get
):
''' Changes problem state to unfinished -- removes student answers,
and causes problem to rerender itself. '''
if
self
.
attempts
==
self
.
max_attempts
:
return
"Too many attempts. You shouldn't be here."
if
self
.
due_date
!=
None
and
datetime
.
datetime
.
utcnow
()
>
self
.
due_date
:
return
"Too late. problem was due."
if
self
.
closed
():
return
"Problem is closed"
if
not
self
.
lcp
.
done
:
return
"Refresh the page and make an attempt before resetting."
self
.
lcp
.
done
=
False
self
.
lcp
.
answers
=
dict
()
self
.
lcp
.
context
=
dict
()
self
.
lcp
.
questions
=
dict
()
# Detailed info about questions in problem instance. TODO: Should be by id and not lid.
self
.
lcp
.
answers
=
dict
()
# Student answers
self
.
lcp
.
correct_map
=
dict
()
self
.
lcp
.
seed
=
None
if
self
.
resettable
:
self
.
lcp
.
context
=
dict
()
self
.
lcp
.
questions
=
dict
()
# Detailed info about questions in problem instance. TODO: Should be by id and not lid.
self
.
lcp
.
seed
=
None
filename
=
settings
.
DATA_DIR
+
self
.
filename
+
".xml"
self
.
lcp
=
LoncapaProblem
(
filename
,
self
.
item_id
,
self
.
lcp
.
get_state
())
return
json
.
dumps
(
self
.
get_problem_html
(
encapsulate
=
False
))
courseware/capa_problem.py
View file @
4add868d
...
...
@@ -75,8 +75,13 @@ class LoncapaProblem():
self
.
answers
=
state
[
'answers'
]
if
'correct_map'
in
state
:
self
.
correct_map
=
state
[
'correct_map'
]
random
.
seed
(
self
.
seed
)
dom
=
parse
(
filename
)
.
childNodes
[
0
]
dom
=
parse
(
filename
)
for
d
in
dom
.
childNodes
:
if
d
.
localName
==
'problem'
:
dom
=
d
g
=
{
'random'
:
random
,
'numpy'
:
numpy
,
'math'
:
math
,
'scipy'
:
scipy
}
...
...
@@ -85,8 +90,11 @@ class LoncapaProblem():
ot
=
False
## Are we in an outtext context?
print
"Here"
,
dom
# Loop through the nodes of the problem, and
for
e
in
dom
.
childNodes
:
#print e.localName
if
e
.
localName
==
'script'
:
exec
e
.
childNodes
[
0
]
.
data
in
g
,
self
.
context
elif
e
.
localName
==
'endouttext'
:
...
...
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