Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
problem-builder
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
OpenEdx
problem-builder
Commits
3296ca71
Commit
3296ca71
authored
Oct 19, 2015
by
Tim Krones
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extend tests.
parent
c2fb804e
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
5 deletions
+15
-5
problem_builder/plot.py
+14
-4
problem_builder/tests/integration/test_step_builder.py
+0
-0
problem_builder/tests/integration/xml_templates/step_builder_plot.xml
+1
-1
No files found.
problem_builder/plot.py
View file @
3296ca71
...
@@ -186,7 +186,6 @@ class PlotBlock(StudioEditableXBlockMixin, StudioContainerWithNestedXBlocksMixin
...
@@ -186,7 +186,6 @@ class PlotBlock(StudioEditableXBlockMixin, StudioContainerWithNestedXBlocksMixin
return
claims
return
claims
def
_get_default_response
(
self
,
question
,
question_id
):
def
_get_default_response
(
self
,
question
,
question_id
):
from
.tasks
import
_get_answer
# Import here to avoid circular dependency
# 1. Obtain block_type for question
# 1. Obtain block_type for question
question_type
=
question
.
scope_ids
.
block_type
question_type
=
question
.
scope_ids
.
block_type
# 2. Obtain latest submission for question
# 2. Obtain latest submission for question
...
@@ -200,11 +199,10 @@ class PlotBlock(StudioEditableXBlockMixin, StudioContainerWithNestedXBlocksMixin
...
@@ -200,11 +199,10 @@ class PlotBlock(StudioEditableXBlockMixin, StudioContainerWithNestedXBlocksMixin
# 3. Extract response from latest submission for question
# 3. Extract response from latest submission for question
answer_cache
=
{}
answer_cache
=
{}
for
submission
in
submissions
:
for
submission
in
submissions
:
answer
=
_get_answer
(
question
,
submission
,
answer_cache
)
answer
=
self
.
_get_answer
(
question
,
submission
,
answer_cache
)
return
int
(
answer
)
return
int
(
answer
)
def
_get_average_response
(
self
,
question
,
question_id
):
def
_get_average_response
(
self
,
question
,
question_id
):
from
.tasks
import
_get_answer
# Import here to avoid circular dependency
# 1. Obtain block_type for question
# 1. Obtain block_type for question
question_type
=
question
.
scope_ids
.
block_type
question_type
=
question
.
scope_ids
.
block_type
# 2. Obtain latest submissions for question
# 2. Obtain latest submissions for question
...
@@ -214,13 +212,25 @@ class PlotBlock(StudioEditableXBlockMixin, StudioContainerWithNestedXBlocksMixin
...
@@ -214,13 +212,25 @@ class PlotBlock(StudioEditableXBlockMixin, StudioContainerWithNestedXBlocksMixin
response_total
=
0
response_total
=
0
num_submissions
=
0
# Can't use len(submissions) because submissions is a generator
num_submissions
=
0
# Can't use len(submissions) because submissions is a generator
for
submission
in
submissions
:
for
submission
in
submissions
:
answer
=
_get_answer
(
question
,
submission
,
answer_cache
)
answer
=
self
.
_get_answer
(
question
,
submission
,
answer_cache
)
response_total
+=
int
(
answer
)
response_total
+=
int
(
answer
)
num_submissions
+=
1
num_submissions
+=
1
# 4. Calculate average response for question
# 4. Calculate average response for question
if
num_submissions
:
if
num_submissions
:
return
response_total
/
float
(
num_submissions
)
return
response_total
/
float
(
num_submissions
)
def
_get_answer
(
self
,
block
,
submission
,
answer_cache
):
"""
Return answer associated with `submission` to `block`.
`answer_cache` is a dict that is reset for each block.
"""
answer
=
submission
[
'answer'
]
# Convert from answer ID to answer label
if
answer
not
in
answer_cache
:
answer_cache
[
answer
]
=
block
.
get_submission_display
(
answer
)
return
answer_cache
[
answer
]
def
default_claims_json
(
self
):
def
default_claims_json
(
self
):
return
json
.
dumps
(
self
.
default_claims
)
return
json
.
dumps
(
self
.
default_claims
)
...
...
problem_builder/tests/integration/test_step_builder.py
View file @
3296ca71
This diff is collapsed.
Click to expand it.
problem_builder/tests/integration/xml_templates/step_builder_plot.xml
View file @
3296ca71
...
@@ -38,7 +38,7 @@
...
@@ -38,7 +38,7 @@
q2_label=
"Custom Q2 label"
q2_label=
"Custom Q2 label"
q3_label=
"Custom Q3 label"
q3_label=
"Custom Q3 label"
q4_label=
"Custom Q4 label"
q4_label=
"Custom Q4 label"
claims=
"2 + 2 = 5, rating_1_1, rating_1_2
\n
The answer to everything is 42, rating_2_1, rating_2_2"
>
claims=
"2 + 2 = 5, rating_1_1, rating_1_2
The answer to everything is 42, rating_2_1, rating_2_2"
>
</sb-plot>
</sb-plot>
</sb-step>
</sb-step>
...
...
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