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
308ab901
Commit
308ab901
authored
Oct 13, 2014
by
Sola
Committed by
Piotr Mitros
Oct 12, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
flagged hint moderation functional
parent
b0c13118
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
79 additions
and
43 deletions
+79
-43
crowdxblock/crowdxblock.py
+21
-5
crowdxblock/static/js/src/crowdxblock.js
+58
-38
No files found.
crowdxblock/crowdxblock.py
View file @
308ab901
...
...
@@ -215,12 +215,15 @@ class CrowdXBlock(XBlock):
for
answer_keys
in
self
.
hint_database
:
if
str
(
len
(
self
.
hint_database
[
str
(
answer_keys
)]))
!=
str
(
0
):
for
hints
in
self
.
hint_database
[
str
(
answer_keys
)]:
if
list
(
self
.
Flagged
)
!=
0
:
for
flagged_hints
in
self
.
Flagged
:
if
str
(
hints
)
!=
self
.
Flagged
[
flagged_hints
]:
feedback_data
[
str
(
hints
)]
=
str
(
answer_keys
)
else
:
feedback_data
[
str
(
hints
)]
=
str
(
"Flagged"
)
else
:
feedback_data
[
str
(
hints
)]
=
str
(
answer_keys
)
else
:
feedback_data
[
str
(
"There are no hints for"
+
" "
+
str
(
answer_keys
))]
=
str
(
answer_keys
)
elif
len
(
self
.
WrongAnswers
)
==
0
:
return
...
...
@@ -313,21 +316,34 @@ class CrowdXBlock(XBlock):
# might arise due to certain symbols. I don't think I have this fully working but am not sure.
data_rating
=
data
[
'student_rating'
]
data_hint
=
data
[
'used_hint'
]
answer_data
=
self
.
remove_symbols
(
answer_data
)
if
str
(
data
[
'student_rating'
])
==
str
(
2
):
for
flagged_hints
in
self
.
Flagged
:
if
self
.
Flagged
[
str
(
flagged_hints
)]
==
data_hint
:
del
self
.
Flagged
[
flagged_hints
]
return
{
'rating'
:
'unflagged'
}
if
str
(
data
[
'student_rating'
])
==
str
(
-
2
):
for
flagged_answer
in
self
.
Flagged
:
if
self
.
Flagged
[
flagged_answer
]
==
data_hint
:
temporary_dict
=
str
(
self
.
hint_database
[
str
(
flagged_answer
)])
temporary_dict
=
(
ast
.
literal_eval
(
temporary_dict
))
temporary_dict
.
pop
(
data_hint
,
None
)
self
.
hint_database
[
str
(
flagged_answer
)]
=
temporary_dict
del
self
.
Flagged
[
flagged_answer
]
return
{
'rating'
:
'removed'
}
if
str
(
data
[
'student_rating'
])
==
str
(
0
):
# if student flagged hint
self
.
hint_flagged
(
data
[
'used_hint'
],
answer_data
)
return
{
"rating"
:
'thiswasflagged'
,
'used_hint'
:
data_hint
}
if
str
(
answer_data
)
not
in
self
.
Voted
:
self
.
Voted
.
append
(
str
(
answer_data
))
# add data to Voted to prevent multiple votes
if
str
(
data_hint
)
not
in
self
.
Voted
:
self
.
Voted
.
append
(
str
(
data_hint
))
# add data to Voted to prevent multiple votes
rating
=
self
.
change_rating
(
data_hint
,
int
(
data_rating
),
answer_data
)
# change hint rating
if
str
(
rating
)
==
str
(
0
):
# if the rating is "0", return "zzeerroo" instead. "0" showed up as "null" in JS
return
{
"rating"
:
str
(
'zzeerroo'
),
'used_hint'
:
data_hint
}
return
{
"rating"
:
str
(
0
),
'used_hint'
:
data_hint
}
else
:
return
{
"rating"
:
str
(
rating
),
'used_hint'
:
data_hint
}
else
:
return
{
"rating"
:
str
(
'
You have already voted on this hint!
'
),
'used_hint'
:
data_hint
}
return
{
"rating"
:
str
(
'
voted
'
),
'used_hint'
:
data_hint
}
def
hint_flagged
(
self
,
data_hint
,
answer_data
):
"""
...
...
crowdxblock/static/js/src/crowdxblock.js
View file @
308ab901
...
...
@@ -99,21 +99,20 @@ function CrowdXBlock(runtime, element){
$
(
".student_answer"
,
element
).
each
(
function
(){
if
(
$
(
this
).
find
(
"span"
).
text
()
==
result
.
student_answer
){
$
(
this
).
append
(
"<div class=
\"
hint_value
\"
value =
\"
"
+
result
.
hint_used
+
"
\"
>"
+
"<div role=
\"
button
\"
class=
\"
upvo
te_hint
\"
data-rate=
\"
1
\"
data-icon=
\"
arrow-u
\"
aria-label=
\"
upvote
\"
><b>↑</b></div>"
+
"<div role=
\"
button
\"
class=
\"
ra
te_hint
\"
data-rate=
\"
1
\"
data-icon=
\"
arrow-u
\"
aria-label=
\"
upvote
\"
><b>↑</b></div>"
+
"<div class =
\"
rating
\"
>"
+
result
.
rating
+
"</div><div class=
\"
hint_used
\"
>"
+
""
+
result
.
hint_used
+
"</div>"
+
"<div role=
\"
button
\"
class=
\"
downvo
te_hint
\"
data-rate=
\"
-1
\"
aria-label=
\"
downvote
\"
><b>↓</b></div> </div>"
);
"<div role=
\"
button
\"
class=
\"
ra
te_hint
\"
data-rate=
\"
-1
\"
aria-label=
\"
downvote
\"
><b>↓</b></div> </div>"
);
}
});
}
function
appendFlagged
(
result
){
$
(
".flagged_hints"
,
element
).
append
(
"<div class=
\"
hint_value
\"
value =
\"
"
+
result
.
hint_used
+
"
\"
>"
+
"<div role=
\"
button
\"
class=
\"
upvote_hint
\"
data-rate=
\"
1
\"
data-icon=
\"
arrow-u
\"
aria-label=
\"
upvote
\"
><b>↑
</b></div>"
+
"<div class
=
\"
rating
\"
>"
+
result
.
rating
+
"</div><div class
=
\"
hint_used
\"
>"
+
""
+
result
.
hint_used
+
"</div>"
+
"<div role=
\"
button
\"
class=
\"
downvote_hint
\"
data-rate=
\"
-1
\"
aria-label=
\"
downvote
\"
><b>↓
</b></div> </div>"
);
"<div role=
\"
button
\"
class=
\"
staff_rate
\"
data-rate=
\"
2
\"
aria-label=
\"
unflag
\"
><b>O
</b></div>"
+
"<div class=
\"
hint_used
\"
>"
+
""
+
result
.
hint_used
+
"</div>"
+
"<div role=
\"
button
\"
class=
\"
staff_rate
\"
data-rate=
\"
-2
\"
aria-label=
\"
remove
\"
><b>X
</b></div> </div>"
);
}
function
getFeedback
(
result
){
if
(
isStaff
){
$
(
'.feedback'
,
element
).
append
(
"<div class=
\"
flagged_hints
\"
><span>Flagged</span></div>"
);
...
...
@@ -125,11 +124,34 @@ function CrowdXBlock(runtime, element){
hint_used
=
index
;
//check if div for a student answer already exists (if length = 0, it doesn't)
if
(
student_answer
!=
"Flagged"
){
if
(
$
(
".student_answer"
,
element
).
find
(
"span"
).
text
()
!=
student_answer
){
$
(
'.feedback'
,
element
).
append
(
"<div class=
\"
student_answer
\"
><span>"
+
student_answer
+
"</span></div>"
);
if
(
$
(
'.student_answer'
,
element
).
length
==
0
){
$
(
'.feedback'
,
element
).
append
(
"<div class=
\"
student_answer
\"
><span><b>"
+
student_answer
+
"</b></span>"
+
"<div><input type =
\"
button
\"
class=
\"
submit_hint
\"
value=
\"
Submit a new hint for this answer.
\"
</input></div></div>"
);
}
else
{
//cycle through each .student_answer to check if this answer has been accounted for
answerShown
=
false
;
$
(
".student_answer"
,
element
).
each
(
function
(){
console
.
log
(
$
(
this
).
find
(
"span"
).
text
());
if
(
$
(
this
).
find
(
"span"
).
text
()
==
student_answer
){
answerShown
=
true
;
}
if
(
student_answer
!=
"Flagged"
){
});
if
(
answerShown
==
false
){
$
(
'.feedback'
,
element
).
append
(
"<div class=
\"
student_answer
\"
><span><b>"
+
student_answer
+
"</b></span>"
+
"<div><input type =
\"
button
\"
class=
\"
submit_hint
\"
value=
\"
Submit a new hint for this answer.
\"
</input></div></div>"
);
}
}
}
//check first part of the hint to see if a hint was actually used
if
(
hint_used
.
substring
(
0
,
22
)
==
"There are no hints for"
){
$
(
".student_answer"
,
element
).
each
(
function
(){
if
(
$
(
this
).
find
(
"span"
).
text
()
==
student_answer
){
$
(
this
).
append
(
"<div class=
\"
hint_value
\"
value=
\"
There are no answer-specific hints for this answer.
\"
></div>"
);
}
});
}
else
if
(
student_answer
!=
"Flagged"
){
$
.
ajax
({
type
:
"POST"
,
url
:
runtime
.
handlerUrl
(
element
,
'get_ratings'
),
...
...
@@ -148,28 +170,13 @@ function CrowdXBlock(runtime, element){
});
}
function
show_ratings
(
result
)
{
$
.
each
(
result
,
function
(
index
,
value
)
{
$
(
"."
+
index
+
"rating"
).
append
(
value
+
" "
+
index
);
})
}
$
(
document
).
on
(
'click'
,
'.submitbutton'
,
function
(){
//upvote
issubmittinghint
=
0
;
issubmitting
+=
1
;
if
(
issubmitting
==
repeatcounter
){
id
=
this
.
id
;
//the id of the button is "submitbuttonfor"+student_answer
//slice to determine which answer for which a submission is being made
//this should be made more dynamic
id
=
id
.
slice
(
15
);
//value = document.getElementById(id).getAttribute('data-value');
$
(
'.submitbutton'
).
show
();
$
(
'.math'
).
remove
();
$
(
'#submit'
).
remove
();
$
(
this
).
hide
();
$
(
'.showHintsFor'
+
id
,
element
).
prepend
(
"<p><input type=
\"
text
\"
name=
\"
studentinput
\"
id=
\"
"
+
id
+
"
\"
class=
\"
math
\"
size=
\"
40
\"
><input id=
\"
submit
\"
type=
\"
button
\"
data-is=
\"
"
+
id
+
"
\"
class=
\"
button
\"
value=
\"
Submit Hint
\"
> </p>"
);
$
(
document
).
on
(
'click'
,
'.submit_hint'
,
function
(){
student_answer
=
$
(
this
).
parent
().
parent
().
find
(
"span"
).
text
();
$
(
".student_answer"
,
element
).
each
(
function
(){
if
(
$
(
this
).
find
(
"span"
).
text
()
==
student_answer
){
$
(
this
).
prepend
(
"<p><input type=
\"
text
\"
name=
\"
studentinput
\"
class=
\"
math
\"
size=
\"
40
\"
><input type=
\"
button
\"
class=
\"
button
\"
value=
\"
Submit Hint
\"
> </p>"
);
}
});
})
$
(
document
).
on
(
'click'
,
'#submit'
,
function
(){
...
...
@@ -199,25 +206,39 @@ function CrowdXBlock(runtime, element){
}
})
$
(
document
).
on
(
'click'
,
'.
upvo
te_hint'
,
function
(){
$
(
document
).
on
(
'click'
,
'.
ra
te_hint'
,
function
(){
used_hint
=
$
(
this
).
parent
().
find
(
".hint_used"
).
text
();
student_answer
=
$
(
this
).
parent
().
parent
().
find
(
"span"
).
text
();
$
.
ajax
({
type
:
"POST"
,
url
:
runtime
.
handlerUrl
(
element
,
'rate_hint'
),
data
:
JSON
.
stringify
({
"student_rating"
:
$
(
this
).
attr
(
'data-rate'
),
"used_hint"
:
used_hint
,
"student_answer"
:
student_answer
}),
success
:
finish
success
:
function
(
result
){
if
(
result
.
rating
!=
"voted"
){
$
(
".hint_used"
,
element
).
each
(
function
(){
if
(
$
(
this
).
parent
().
find
(
".hint_used"
).
text
()
==
used_hint
&&
$
(
this
).
parent
().
parent
().
find
(
"span"
).
text
()
==
student_answer
){
$
(
this
).
parent
().
find
(
'.rating'
).
text
(
result
.
rating
);
}
})
}
}
});
})
$
(
document
).
on
(
'click'
,
'.
downvote_hint
'
,
function
(){
canhint
=
0
;
id
=
this
.
id
;
$
(
document
).
on
(
'click'
,
'.
staff_rate
'
,
function
(){
used_hint
=
$
(
this
).
parent
().
find
(
".hint_used"
).
text
()
;
student_answer
=
$
(
this
).
parent
().
parent
().
find
(
"span"
).
text
()
;
$
.
ajax
({
type
:
"POST"
,
url
:
runtime
.
handlerUrl
(
element
,
'rate_hint'
),
data
:
JSON
.
stringify
({
"student_rating"
:
$
(
this
).
attr
(
'data-rate'
),
"used_hint"
:
$
(
this
).
attr
(
'id'
),
"student_answer"
:
$
(
this
).
attr
(
'data-value'
)}),
success
:
finish
data
:
JSON
.
stringify
({
"student_rating"
:
$
(
this
).
attr
(
'data-rate'
),
"used_hint"
:
used_hint
,
"student_answer"
:
student_answer
}),
success
:
function
(
result
){
$
(
'.hint_value'
,
element
).
each
(
function
(){
if
(
$
(
this
).
attr
(
'value'
)
==
used_hint
){
$
(
this
).
remove
();
}
});
}
});
})
...
...
@@ -237,7 +258,6 @@ function CrowdXBlock(runtime, element){
});
})
function
finish
(
result
){
if
(
canhint
==
0
){
canhint
=
1
;
...
...
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