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
e05e05f4
Commit
e05e05f4
authored
Feb 13, 2012
by
Piotr Mitros
Browse files
Options
Browse Files
Download
Plain Diff
merge in tolerance bug fix
parents
7b49f21e
fca78b83
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
10 deletions
+21
-10
courseware/capa/responsetypes.py
+21
-10
No files found.
courseware/capa/responsetypes.py
View file @
e05e05f4
...
...
@@ -19,24 +19,36 @@ global_context={'random':random,
'calc'
:
calc
,
'eia'
:
eia
}
def
compare_with_tolerance
(
v1
,
v2
,
tol
):
''' Compare v1 to v2 with maximum tolerance tol
tol is relative if it ends in
%
; otherwise, it is absolute
'''
relative
=
"
%
"
in
tol
if
relative
:
tolerance_rel
=
evaluator
(
dict
(),
dict
(),
tol
[:
-
1
])
*
0.01
tolerance
=
tolerance_rel
*
max
(
abs
(
v1
),
abs
(
v2
))
else
:
tolerance
=
evaluator
(
dict
(),
dict
(),
tol
)
return
abs
(
v1
-
v2
)
<=
tolerance
class
numericalresponse
(
object
):
def
__init__
(
self
,
xml
,
context
):
self
.
xml
=
xml
self
.
correct_answer
=
contextualize_text
(
xml
.
get
(
'answer'
),
context
)
self
.
correct_answer
=
float
(
self
.
correct_answer
)
self
.
tolerance
=
xml
.
xpath
(
'//*[@id=$id]//responseparam[@type="tolerance"]/@default'
,
self
.
tolerance
_xml
=
xml
.
xpath
(
'//*[@id=$id]//responseparam[@type="tolerance"]/@default'
,
id
=
xml
.
get
(
'id'
))[
0
]
self
.
tolerance
=
contextualize_text
(
self
.
tolerance
,
context
)
self
.
tolerance
=
evaluator
(
dict
(),
dict
(),
self
.
tolerance
)
self
.
tolerance
=
contextualize_text
(
self
.
tolerance_xml
,
context
)
self
.
answer_id
=
xml
.
xpath
(
'//*[@id=$id]//textline/@id'
,
id
=
xml
.
get
(
'id'
))[
0
]
def
grade
(
self
,
student_answers
):
''' Display HTML for a numeric response '''
student_answer
=
student_answers
[
self
.
answer_id
]
error
=
abs
(
evaluator
(
dict
(),
dict
(),
student_answer
)
-
self
.
correct_answer
)
allowed_error
=
abs
(
self
.
correct_answer
*
self
.
tolerance
)
if
error
<=
allowed_error
:
correct
=
compare_with_tolerance
(
evaluator
(
dict
(),
dict
(),
student_answer
),
self
.
correct_answer
,
self
.
tolerance
)
if
correct
:
return
{
self
.
answer_id
:
'correct'
}
else
:
return
{
self
.
answer_id
:
'incorrect'
}
...
...
@@ -77,10 +89,9 @@ class formularesponse(object):
self
.
xml
=
xml
self
.
correct_answer
=
contextualize_text
(
xml
.
get
(
'answer'
),
context
)
self
.
samples
=
contextualize_text
(
xml
.
get
(
'samples'
),
context
)
self
.
tolerance
=
xml
.
xpath
(
'//*[@id=$id]//responseparam[@type="tolerance"]/@default'
,
self
.
tolerance
_xml
=
xml
.
xpath
(
'//*[@id=$id]//responseparam[@type="tolerance"]/@default'
,
id
=
xml
.
get
(
'id'
))[
0
]
self
.
tolerance
=
contextualize_text
(
self
.
tolerance
,
context
)
self
.
tolerance
=
evaluator
(
dict
(),
dict
(),
self
.
tolerance
)
self
.
tolerance
=
contextualize_text
(
self
.
tolerance_xml
,
context
)
self
.
answer_id
=
xml
.
xpath
(
'//*[@id=$id]//textline/@id'
,
id
=
xml
.
get
(
'id'
))[
0
]
self
.
context
=
context
...
...
@@ -105,7 +116,7 @@ class formularesponse(object):
student_result
=
evaluator
(
student_variables
,
dict
(),
student_answers
[
self
.
answer_id
])
if
math
.
isnan
(
student_result
)
or
math
.
isinf
(
student_result
):
return
{
self
.
answer_id
:
"incorrect"
}
if
abs
(
student_result
-
instructor_result
)
>
self
.
tolerance
:
if
not
compare_with_tolerance
(
student_result
,
instructor_result
,
self
.
tolerance
)
:
return
{
self
.
answer_id
:
"incorrect"
}
return
{
self
.
answer_id
:
"correct"
}
...
...
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