Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
crowdsourcehinter
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
crowdsourcehinter
Commits
5a4e103d
Commit
5a4e103d
authored
Sep 28, 2015
by
Piotr Mitros
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Starting to make data structures a little bit more sensible
parent
5650a335
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
16 deletions
+19
-16
crowdsourcehinter/crowdsourcehinter.py
+18
-15
crowdsourcehinter/static/js/src/crowdsourcehinter.js
+1
-1
No files found.
crowdsourcehinter/crowdsourcehinter.py
View file @
5a4e103d
...
@@ -26,8 +26,7 @@ class CrowdsourceHinter(XBlock):
...
@@ -26,8 +26,7 @@ class CrowdsourceHinter(XBlock):
# Each key (incorrect answer) has a corresponding dictionary (in
# Each key (incorrect answer) has a corresponding dictionary (in
# which hints are keys and the hints' ratings are the values).
# which hints are keys and the hints' ratings are the values).
# For example:
# For example:
# {"computerr": {"You misspelled computer, remove the last r.": 5}}
# {"computerr": {"You misspelled computer, remove the last r.": {'upvotes':5, 'downvotes':3}}}
# TODO: We should store upvotes and downvotes independently.
hint_database
=
Dict
(
default
=
{},
scope
=
Scope
.
user_state_summary
)
hint_database
=
Dict
(
default
=
{},
scope
=
Scope
.
user_state_summary
)
# Database of initial hints, set by the course
# Database of initial hints, set by the course
...
@@ -112,10 +111,14 @@ class CrowdsourceHinter(XBlock):
...
@@ -112,10 +111,14 @@ class CrowdsourceHinter(XBlock):
studio view.
studio view.
The Studio view is not yet complete.
The Studio view is not yet complete.
TODO: How do we make this handler Studio-specific? We don't
want students being able to call this.
"""
"""
initial_hints
=
json
.
loads
(
data
[
'initial_hints'
])
initial_hints
=
json
.
loads
(
data
[
'initial_hints'
])
generic_hints
=
json
.
loads
(
data
[
'generic_hints'
])
generic_hints
=
json
.
loads
(
data
[
'generic_hints'
])
# Validate input
if
not
isinstance
(
generic_hints
,
list
):
if
not
isinstance
(
generic_hints
,
list
):
return
{
'success'
:
False
,
return
{
'success'
:
False
,
'error'
:
'Generic hints should be a list.'
}
'error'
:
'Generic hints should be a list.'
}
...
@@ -341,10 +344,10 @@ class CrowdsourceHinter(XBlock):
...
@@ -341,10 +344,10 @@ class CrowdsourceHinter(XBlock):
if
any
(
data_hint
in
generic_hints
for
generic_hints
in
self
.
generic_hints
):
if
any
(
data_hint
in
generic_hints
for
generic_hints
in
self
.
generic_hints
):
return
return
if
data_rating
==
'upvote'
:
if
data_rating
==
'upvote'
:
self
.
hint_database
[
str
(
answer_data
)][
str
(
data_hint
)]
+=
1
self
.
hint_database
[
str
(
answer_data
)][
str
(
data_hint
)]
[
'upvotes'
]
+=
1
return
self
.
hint_database
[
str
(
answer_data
)][
str
(
data_hint
)]
return
self
.
hint_database
[
str
(
answer_data
)][
str
(
data_hint
)]
else
:
else
:
self
.
hint_database
[
str
(
answer_data
)][
str
(
data_hint
)]
-
=
1
self
.
hint_database
[
str
(
answer_data
)][
str
(
data_hint
)]
[
'downvotes'
]
+
=
1
return
self
.
hint_database
[
str
(
answer_data
)][
str
(
data_hint
)]
return
self
.
hint_database
[
str
(
answer_data
)][
str
(
data_hint
)]
@XBlock.json_handler
@XBlock.json_handler
...
@@ -352,21 +355,21 @@ class CrowdsourceHinter(XBlock):
...
@@ -352,21 +355,21 @@ class CrowdsourceHinter(XBlock):
"""
"""
This function adds a new hint submitted by the student into the hint_database.
This function adds a new hint submitted by the student into the hint_database.
Args:
Args:
data['submission']: This is the text of the new hint that the student has submitted.
data['
new_hint_
submission']: This is the text of the new hint that the student has submitted.
data['answer']: This is the incorrect answer for which the student is submitting a new hint.
data['answer']: This is the incorrect answer for which the student is submitting a new hint.
"""
"""
submission
=
data
[
'submission'
]
submission
=
data
[
'
new_hint_
submission'
]
answer
=
data
[
'answer'
]
answer
=
data
[
'answer'
]
# If we don't have the hint already, add it
if
str
(
submission
)
not
in
self
.
hint_database
[
str
(
answer
)]:
if
str
(
submission
)
not
in
self
.
hint_database
[
str
(
answer
)]:
self
.
hint_database
[
str
(
answer
)]
.
update
({
submission
:
0
})
self
.
hint_database
[
str
(
answer
)]
.
update
({
submission
:
{
'upvotes'
:
0
,
'downvotes'
:
0
}})
return
return
{
'success'
:
True
,
else
:
'result'
:
'Hint added'
}
# if the hint exists already, simply upvote the previously entered hint
if
str
(
submission
)
in
self
.
generic_hints
:
self
.
hint_database
[
str
(
answer
)][
str
(
submission
)][
'upvotes'
]
+=
1
return
return
{
'success'
:
True
,
else
:
'result'
:
'We already had this hint. We gave it an upvote'
}
self
.
hint_database
[
str
(
answer
)][
str
(
submission
)]
+=
1
return
@XBlock.json_handler
@XBlock.json_handler
def
studiodata
(
self
,
data
,
suffix
=
''
):
def
studiodata
(
self
,
data
,
suffix
=
''
):
...
...
crowdsourcehinter/static/js/src/crowdsourcehinter.js
View file @
5a4e103d
...
@@ -219,7 +219,7 @@ function CrowdsourceHinter(runtime, element, data){
...
@@ -219,7 +219,7 @@ function CrowdsourceHinter(runtime, element, data){
$
.
ajax
({
$
.
ajax
({
type
:
"POST"
,
type
:
"POST"
,
url
:
runtime
.
handlerUrl
(
element
,
'add_new_hint'
),
url
:
runtime
.
handlerUrl
(
element
,
'add_new_hint'
),
data
:
JSON
.
stringify
({
"submission"
:
newHint
,
"answer"
:
studentAnswer
}),
data
:
JSON
.
stringify
({
"
new_hint_
submission"
:
newHint
,
"answer"
:
studentAnswer
}),
success
:
function
()
{
success
:
function
()
{
$
(
'.csh_student_text_input'
,
element
).
attr
(
'style'
,
'display: none;'
);
$
(
'.csh_student_text_input'
,
element
).
attr
(
'style'
,
'display: none;'
);
$
(
submitHintButtonHTML
.
currentTarget
).
attr
(
'style'
,
'display: none;'
);
$
(
submitHintButtonHTML
.
currentTarget
).
attr
(
'style'
,
'display: none;'
);
...
...
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