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
7f92606e
Commit
7f92606e
authored
May 10, 2012
by
Lyla Fischer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
responses to code review
parent
4c0cc81d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
21 deletions
+25
-21
djangoapps/courseware/capa/responsetypes.py
+18
-14
djangoapps/courseware/test_files/multichoice.xml
+6
-6
djangoapps/courseware/tests.py
+1
-1
No files found.
djangoapps/courseware/capa/responsetypes.py
View file @
7f92606e
...
@@ -6,6 +6,7 @@ import random
...
@@ -6,6 +6,7 @@ import random
import
scipy
import
scipy
import
traceback
import
traceback
import
copy
import
copy
import
abc
from
calc
import
evaluator
,
UndefinedVariable
from
calc
import
evaluator
,
UndefinedVariable
from
django.conf
import
settings
from
django.conf
import
settings
...
@@ -38,10 +39,17 @@ def compare_with_tolerance(v1, v2, tol):
...
@@ -38,10 +39,17 @@ def compare_with_tolerance(v1, v2, tol):
return
abs
(
v1
-
v2
)
<=
tolerance
return
abs
(
v1
-
v2
)
<=
tolerance
class
GenericResponse
(
object
):
class
GenericResponse
(
object
):
__metaclass__
=
abc
.
ABCMeta
@abc.abstractmethod
def
grade
(
self
,
student_answers
):
def
grade
(
self
,
student_answers
):
pass
pass
@abc.abstractmethod
def
get_answers
(
self
):
def
get_answers
(
self
):
pass
pass
#not an abstract method because plenty of responses will not want to preprocess anything, and we should not require that they override this method.
def
preprocess_response
(
self
):
def
preprocess_response
(
self
):
pass
pass
...
@@ -57,7 +65,8 @@ class MultipleChoiceResponse(GenericResponse):
...
@@ -57,7 +65,8 @@ class MultipleChoiceResponse(GenericResponse):
self
.
answer_id
=
xml
.
xpath
(
'//*[@id=$id]//choicegroup/@id'
,
self
.
answer_id
=
xml
.
xpath
(
'//*[@id=$id]//choicegroup/@id'
,
id
=
xml
.
get
(
'id'
))
id
=
xml
.
get
(
'id'
))
assert
len
(
self
.
answer_id
)
==
1
,
"should have exactly one choice group per multiplechoicceresponse"
if
not
len
(
self
.
answer_id
)
==
1
:
raise
Exception
(
"should have exactly one choice group per multiplechoicceresponse"
)
self
.
answer_id
=
self
.
answer_id
[
0
]
self
.
answer_id
=
self
.
answer_id
[
0
]
def
grade
(
self
,
student_answers
):
def
grade
(
self
,
student_answers
):
...
@@ -79,19 +88,14 @@ class TrueFalseResponse(MultipleChoiceResponse):
...
@@ -79,19 +88,14 @@ class TrueFalseResponse(MultipleChoiceResponse):
response
.
set
(
"type"
,
"TrueFalse"
)
response
.
set
(
"type"
,
"TrueFalse"
)
def
grade
(
self
,
student_answers
):
def
grade
(
self
,
student_answers
):
correct
=
copy
.
deepcopy
(
self
.
correct_choices
)
correct
=
set
(
self
.
correct_choices
)
if
self
.
answer_id
in
student_answers
and
student_answers
[
self
.
answer_id
]:
answers
=
set
(
student_answers
.
get
(
self
.
answer_id
,
[]))
for
answer
in
student_answers
[
self
.
answer_id
]:
if
answer
in
correct
:
if
correct
==
answers
:
correct
.
remove
(
answer
)
return
{
self
.
answer_id
:
'correct'
}
else
:
return
{
self
.
answer_id
:
'incorrect'
}
return
{
self
.
answer_id
:
'incorrect'
}
if
len
(
correct
)
!=
0
:
return
{
self
.
answer_id
:
'incorrect'
}
else
:
return
{
self
.
answer_id
:
'correct'
}
else
:
return
{
self
.
answer_id
:
'incorrect'
}
class
NumericalResponse
(
GenericResponse
):
class
NumericalResponse
(
GenericResponse
):
def
__init__
(
self
,
xml
,
context
):
def
__init__
(
self
,
xml
,
context
):
...
...
djangoapps/courseware/test_files/multichoice.xml
View file @
7f92606e
<problem>
<problem>
<multiplechoiceresponse
max=
"10"
randomize=
"yes"
>
<multiplechoiceresponse>
<choicegroup>
<choicegroup>
<choice
location=
"random"
correct=
"false"
name=
"foil1"
>
<choice
correct=
"false"
name=
"foil1"
>
<startouttext
/>
This is foil One.
<endouttext
/>
<startouttext
/>
This is foil One.
<endouttext
/>
</choice>
</choice>
<choice
location=
"random"
correct=
"false"
name=
"foil2"
>
<choice
correct=
"false"
name=
"foil2"
>
<startouttext
/>
This is foil Two.
<endouttext
/>
<startouttext
/>
This is foil Two.
<endouttext
/>
</choice>
</choice>
<choice
location=
"random"
correct=
"true"
name=
"foil3"
>
<choice
correct=
"true"
name=
"foil3"
>
<startouttext
/>
This is foil Three.
<endouttext
/>
<startouttext
/>
This is foil Three.
<endouttext
/>
</choice>
</choice>
<choice
location=
"random"
correct=
"false"
name=
"foil4"
>
<choice
correct=
"false"
name=
"foil4"
>
<startouttext
/>
This is foil Four.
<endouttext
/>
<startouttext
/>
This is foil Four.
<endouttext
/>
</choice>
</choice>
<choice
location=
"random"
correct=
"false"
name=
"foil5"
>
<choice
correct=
"false"
name=
"foil5"
>
<startouttext
/>
This is foil Five.
<endouttext
/>
<startouttext
/>
This is foil Five.
<endouttext
/>
</choice>
</choice>
</choicegroup>
</choicegroup>
...
...
djangoapps/courseware/tests.py
View file @
7f92606e
...
@@ -63,7 +63,7 @@ class ModelsTest(unittest.TestCase):
...
@@ -63,7 +63,7 @@ class ModelsTest(unittest.TestCase):
class
MultiChoiceTest
(
unittest
.
TestCase
):
class
MultiChoiceTest
(
unittest
.
TestCase
):
def
test_MC_grade
(
self
):
def
test_MC_grade
(
self
):
multichoice_file
=
os
.
getcwd
()
+
"/djangoapps/courseware
/test_files/multichoice.xml"
multichoice_file
=
os
.
path
.
dirname
(
__file__
)
+
"
/test_files/multichoice.xml"
test_lcp
=
lcp
.
LoncapaProblem
(
multichoice_file
,
'1'
)
test_lcp
=
lcp
.
LoncapaProblem
(
multichoice_file
,
'1'
)
correct_answers
=
{
'1_2_1'
:
'foil3'
}
correct_answers
=
{
'1_2_1'
:
'foil3'
}
self
.
assertEquals
(
test_lcp
.
grade_answers
(
correct_answers
)[
'1_2_1'
],
'correct'
)
self
.
assertEquals
(
test_lcp
.
grade_answers
(
correct_answers
)[
'1_2_1'
],
'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