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
bc315c11
Commit
bc315c11
authored
Jul 09, 2013
by
Felix Sun
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #328 from edx/felix/hinter2
Felix/hinter2
parents
4121f393
6c557261
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
27 deletions
+37
-27
common/lib/xmodule/xmodule/crowdsource_hinter.py
+25
-20
common/lib/xmodule/xmodule/tests/test_crowdsource_hinter.py
+0
-0
common/templates/hinter_display.html
+12
-7
No files found.
common/lib/xmodule/xmodule/crowdsource_hinter.py
View file @
bc315c11
...
...
@@ -107,18 +107,18 @@ class CrowdsourceHinterModule(CrowdsourceHinterFields, XModule):
"""
return
str
(
float
(
answer
.
values
()[
0
]))
def
handle_ajax
(
self
,
dispatch
,
get
):
def
handle_ajax
(
self
,
dispatch
,
data
):
"""
This is the landing method for AJAX calls.
"""
if
dispatch
==
'get_hint'
:
out
=
self
.
get_hint
(
get
)
out
=
self
.
get_hint
(
data
)
elif
dispatch
==
'get_feedback'
:
out
=
self
.
get_feedback
(
get
)
out
=
self
.
get_feedback
(
data
)
elif
dispatch
==
'vote'
:
out
=
self
.
tally_vote
(
get
)
out
=
self
.
tally_vote
(
data
)
elif
dispatch
==
'submit_hint'
:
out
=
self
.
submit_hint
(
get
)
out
=
self
.
submit_hint
(
data
)
else
:
return
json
.
dumps
({
'contents'
:
'Error - invalid operation.'
})
...
...
@@ -128,19 +128,24 @@ class CrowdsourceHinterModule(CrowdsourceHinterFields, XModule):
out
.
update
({
'op'
:
dispatch
})
return
json
.
dumps
({
'contents'
:
self
.
system
.
render_template
(
'hinter_display.html'
,
out
)})
def
get_hint
(
self
,
get
):
def
get_hint
(
self
,
data
):
"""
The student got the incorrect answer found in
get
. Give him a hint.
The student got the incorrect answer found in
data
. Give him a hint.
Called by hinter javascript after a problem is graded as incorrect.
Args:
`
get
` -- must be interpretable by capa_answer_to_str.
`
data
` -- must be interpretable by capa_answer_to_str.
Output keys:
- 'best_hint' is the hint text with the most votes.
- 'rand_hint_1' and 'rand_hint_2' are two random hints to the answer in `
get
`.
- 'rand_hint_1' and 'rand_hint_2' are two random hints to the answer in `
data
`.
- 'answer' is the parsed answer that was submitted.
"""
answer
=
self
.
capa_answer_to_str
(
get
)
try
:
answer
=
self
.
capa_answer_to_str
(
data
)
except
ValueError
:
# Sometimes, we get an answer that's just not parsable. Do nothing.
log
.
exception
(
'Answer not parsable: '
+
str
(
data
))
return
# Look for a hint to give.
# Make a local copy of self.hints - this means we only need to do one json unpacking.
# (This is because xblocks storage makes the following command a deep copy.)
...
...
@@ -176,12 +181,12 @@ class CrowdsourceHinterModule(CrowdsourceHinterFields, XModule):
'rand_hint_2'
:
rand_hint_2
,
'answer'
:
answer
}
def
get_feedback
(
self
,
get
):
def
get_feedback
(
self
,
data
):
"""
The student got it correct. Ask him to vote on hints, or submit a hint.
Args:
`
get
` -- not actually used. (It is assumed that the answer is correct.)
`
data
` -- not actually used. (It is assumed that the answer is correct.)
Output keys:
- 'index_to_hints' maps previous answer indices to hints that the user saw earlier.
- 'index_to_answer' maps previous answer indices to the actual answer submitted.
...
...
@@ -216,20 +221,20 @@ class CrowdsourceHinterModule(CrowdsourceHinterFields, XModule):
return
{
'index_to_hints'
:
index_to_hints
,
'index_to_answer'
:
index_to_answer
}
def
tally_vote
(
self
,
get
):
def
tally_vote
(
self
,
data
):
"""
Tally a user's vote on his favorite hint.
Args:
`
get
` -- expected to have the following keys:
`
data
` -- expected to have the following keys:
'answer': ans_no (index in previous_answers)
'hint': hint_pk
Returns key 'hint_and_votes', a list of (hint_text, #votes) pairs.
"""
if
self
.
user_voted
:
return
{}
ans_no
=
int
(
get
[
'answer'
])
hint_no
=
str
(
get
[
'hint'
])
ans_no
=
int
(
data
[
'answer'
])
hint_no
=
str
(
data
[
'hint'
])
answer
=
self
.
previous_answers
[
ans_no
][
0
]
# We use temp_dict because we need to do a direct write for the database to update.
temp_dict
=
self
.
hints
...
...
@@ -249,19 +254,19 @@ class CrowdsourceHinterModule(CrowdsourceHinterFields, XModule):
self
.
previous_answers
=
[]
return
{
'hint_and_votes'
:
hint_and_votes
}
def
submit_hint
(
self
,
get
):
def
submit_hint
(
self
,
data
):
"""
Take a hint submission and add it to the database.
Args:
`
get
` -- expected to have the following keys:
`
data
` -- expected to have the following keys:
'answer': answer index in previous_answers
'hint': text of the new hint that the user is adding
Returns a thank-you message.
"""
# Do html escaping. Perhaps in the future do profanity filtering, etc. as well.
hint
=
escape
(
get
[
'hint'
])
answer
=
self
.
previous_answers
[
int
(
get
[
'answer'
])][
0
]
hint
=
escape
(
data
[
'hint'
])
answer
=
self
.
previous_answers
[
int
(
data
[
'answer'
])][
0
]
# Only allow a student to vote or submit a hint once.
if
self
.
user_voted
:
return
{
'message'
:
'Sorry, but you have already voted!'
}
...
...
common/lib/xmodule/xmodule/tests/test_crowdsource_hinter.py
View file @
bc315c11
This diff is collapsed.
Click to expand it.
common/templates/hinter_display.html
View file @
bc315c11
...
...
@@ -95,13 +95,17 @@ What would you say to help someone who got this wrong answer?
</
%
def>
<
%
def
name=
"show_votes()"
>
Thank you for voting!
<br
/>
% for hint, votes in hint_and_votes:
<span
style=
"color:green"
>
${votes} votes.
</span>
${hint}
<br
/>
% endfor
% if hint_and_votes is UNDEFINED:
Sorry, but you've already voted!
% else:
Thank you for voting!
<br
/>
% for hint, votes in hint_and_votes:
<span
style=
"color:green"
>
${votes} votes.
</span>
${hint}
<br
/>
% endfor
% endif
</
%
def>
<
%
def
name=
"simple_message()"
>
...
...
@@ -123,3 +127,4 @@ What would you say to help someone who got this wrong answer?
% if op == "vote":
${show_votes()}
% endif
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