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
a4dc0150
Commit
a4dc0150
authored
Feb 13, 2012
by
Piotr Mitros
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Bug fix. Not very tested
--HG-- branch : tolerance_bug
parent
7b49f21e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
6 deletions
+17
-6
courseware/capa/responsetypes.py
+17
-6
No files found.
courseware/capa/responsetypes.py
View file @
a4dc0150
...
...
@@ -19,6 +19,19 @@ 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
=
evaluator
(
dict
(),
dict
(),
tol
[:
-
1
])
*
0.01
tolerance
=
tolerance
*
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
...
...
@@ -27,16 +40,15 @@ class numericalresponse(object):
self
.
tolerance
=
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
.
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'
}
...
...
@@ -80,7 +92,6 @@ class formularesponse(object):
self
.
tolerance
=
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
.
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