Commit cd45bc0a by solashirai Committed by Piotr Mitros

fixing hint flagging

parent 4d6e4c0f
...@@ -38,10 +38,10 @@ class CrowdsourceHinter(XBlock): ...@@ -38,10 +38,10 @@ class CrowdsourceHinter(XBlock):
# i believe this will also prevent students from voting again on a particular hint if they were to return to # i believe this will also prevent students from voting again on a particular hint if they were to return to
# a particular problem later # a particular problem later
Voted = List(default=[], scope=Scope.user_state) Voted = List(default=[], scope=Scope.user_state)
# This is a dictionary of hints that have been flagged. the keys represent the incorrect answer submission, and the # This is a dictionary of hints that have been flagged. the values represent the incorrect answer submission, and the
# values are the hints the corresponding hints. even if a hint is flagged, if the hint shows up for a different # keys are the hints the corresponding hints. hints with identical text for differing answers will all not show up for the
# incorrect answer, i believe that the hint will still be able to show for a student # student.
Flagged = Dict(default={"answer2": "This is a hint that should be flagged"}, scope=Scope.user_state_summary) Flagged = Dict(default={"This is a hint that should be flagged": "answer2"}, scope=Scope.user_state_summary)
# This string determines whether or not to show only the best (highest rated) hint to a student # This string determines whether or not to show only the best (highest rated) hint to a student
# When set to 'True' only the best hint will be shown to the student. # When set to 'True' only the best hint will be shown to the student.
# Details on operation when set to 'False' are to be finalized. # Details on operation when set to 'False' are to be finalized.
...@@ -185,7 +185,7 @@ class CrowdsourceHinter(XBlock): ...@@ -185,7 +185,7 @@ class CrowdsourceHinter(XBlock):
return str(0) return str(0)
for hint_keys in self.hint_database[str(answer)]: for hint_keys in self.hint_database[str(answer)]:
for flagged_keys in self.Flagged: for flagged_keys in self.Flagged:
if str(hint_keys) == str(flagged_keys): if hint_keys == flagged_keys:
isflagged.append(hint_keys) isflagged.append(hint_keys)
if str(hint_keys) in self.Used: if str(hint_keys) in self.Used:
isused += 1 isused += 1
...@@ -218,11 +218,9 @@ class CrowdsourceHinter(XBlock): ...@@ -218,11 +218,9 @@ class CrowdsourceHinter(XBlock):
for hints in self.hint_database[str(answer_keys)]: for hints in self.hint_database[str(answer_keys)]:
if len(self.Flagged) != 0: if len(self.Flagged) != 0:
for flagged_hints in self.Flagged: for flagged_hints in self.Flagged:
if str(hints) != self.Flagged[flagged_hints]: if str(hints) == flagged_hints:
feedback_data[str(hints)] = str(answer_keys)
else:
feedback_data[str(hints)] = str("Flagged") feedback_data[str(hints)] = str("Flagged")
else: if hints not in feedback_data.keys():
feedback_data[str(hints)] = str(answer_keys) feedback_data[str(hints)] = str(answer_keys)
else: else:
feedback_data[None] = str(answer_keys) feedback_data[None] = str(answer_keys)
...@@ -308,27 +306,25 @@ class CrowdsourceHinter(XBlock): ...@@ -308,27 +306,25 @@ class CrowdsourceHinter(XBlock):
"rating": The rating of the hint. "rating": The rating of the hint.
""" """
answer_data = data['student_answer'] answer_data = data['student_answer']
# answer_data is manipulated to remove symbols to prevent errors that
# 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_rating = data['student_rating']
data_hint = data['hint'] data_hint = data['hint']
if data['student_rating'] == 'unflag': if data['student_rating'] == 'unflag':
for flagged_hints in self.Flagged: for flagged_hints in self.Flagged:
if self.Flagged[str(flagged_hints)] == data_hint: if flagged_hints == data_hint:
del self.Flagged[flagged_hints] self.Flagged.pop(data_hint, None)
return {'rating': 'unflagged'} return {'rating': 'unflagged'}
if data['student_rating'] == 'remove': if data['student_rating'] == 'remove':
for flagged_answer in self.Flagged: for flagged_hints in self.Flagged:
if self.Flagged[flagged_answer] == data_hint: if data_hint == flagged_hints:
temporary_dict = str(self.hint_database[str(flagged_answer)]) temporary_dict = str(self.hint_database[self.Flagged[data_hint]])
temporary_dict = (ast.literal_eval(temporary_dict)) temporary_dict = (ast.literal_eval(temporary_dict))
temporary_dict.pop(data_hint, None) temporary_dict.pop(data_hint, None)
self.hint_database[str(flagged_answer)] = temporary_dict self.hint_database[self.Flagged[data_hint]] = temporary_dict
del self.Flagged[flagged_answer] self.Flagged.pop(data_hint, None)
return {'rating': 'removed'} return {'rating': 'removed'}
if data['student_rating'] == 'flag': if data['student_rating'] == 'flag':
# add hint to Flagged dictionary # add hint to Flagged dictionary
self.Flagged[str(answer_data)] = data_hint self.Flagged[str(data_hint)] = answer_data
return {"rating": 'flagged', 'hint': data_hint} return {"rating": 'flagged', 'hint': data_hint}
if str(data_hint) not in self.Voted: if str(data_hint) not in self.Voted:
self.Voted.append(str(data_hint)) # add data to Voted to prevent multiple votes self.Voted.append(str(data_hint)) # add data to Voted to prevent multiple votes
...@@ -339,7 +335,6 @@ class CrowdsourceHinter(XBlock): ...@@ -339,7 +335,6 @@ class CrowdsourceHinter(XBlock):
return {"rating": str(rating), 'hint': data_hint} return {"rating": str(rating), 'hint': data_hint}
else: else:
return {"rating": str('voted'), 'hint': data_hint} return {"rating": str('voted'), 'hint': data_hint}
self.Flagged[str(data_hint)] = str(answer_data)
def change_rating(self, data_hint, data_rating, answer_data): def change_rating(self, data_hint, data_rating, answer_data):
""" """
......
...@@ -14,25 +14,30 @@ ...@@ -14,25 +14,30 @@
.csh_hint_value{ .csh_hint_value{
display: flex; display: flex;
margin-left: 10px; margin-left: 10px;
flex-flow: column; column-count: 2;
} }
.csh_hint_used{ .csh_rating_data{
flex-direction: row; width: 3%;
vertical-align: middle;
} }
.crowdsourcehinter_block .csh_HintsToUse { .crowdsourcehinter_block .csh_HintsToUse {
background-color: #FF8; background-color: #FF8;
} }
.csh_hint_data{
width: 97%;
}
.csh_rate_hint { .csh_rate_hint {
width: 100%; width: 100%;
margin-left:auto; margin-left:auto;
margin-right:auto; margin-right:auto;
} }
div[data-rate="flag"] { div[data-rate="flag"]{
float: right; float: center;
} }
div[data-rate="upvote"] { div[data-rate="upvote"] {
......
<script type='x-tmpl/mustache' id='show_hint_feedback'> <script type='x-tmpl/mustache' id='show_hint_feedback'>
<div class='csh_hint_value' value="{{hintvalue}}"> <div class='csh_hint_value' value="{{hintvalue}}">
<div class='csh_rating_data'>
<div role="button" class="csh_rate_hint" data-rate="upvote" data-icon="arrow-u" aria-label="upvote"> <div role="button" class="csh_rate_hint" data-rate="upvote" data-icon="arrow-u" aria-label="upvote">
<b></b> <b></b>
</div> </div>
<div class ="csh_rating"> {{rating}} </div> <div class ="csh_rating"> {{rating}} </div>
<div class="csh_hint">{{hint}}</div>
<div role="button" class="csh_rate_hint" data-rate="downvote" aria-label="downvote"> <div role="button" class="csh_rate_hint" data-rate="downvote" aria-label="downvote">
<b></b> <b></b>
</div> </div>
</div>
<div class='csh_hint_data'>
<div class="csh_hint">{{hint}}</div>
<div role="button" class="csh_rate_hint" data-rate="flag" data-icon="flag" aria-label="flag"> <div role="button" class="csh_rate_hint" data-rate="flag" data-icon="flag" aria-label="flag">
<b>Report this hint</b> <b>Report this hint</b>
</div> </div>
</div> </div>
</div>
</script> </script>
<script type="x-tmpl/mustache" id="show_flagged_feedback"> <script type="x-tmpl/mustache" id="show_flagged_feedback">
......
...@@ -147,7 +147,6 @@ function CrowdsourceHinter(runtime, element){ ...@@ -147,7 +147,6 @@ function CrowdsourceHinter(runtime, element){
html = Mustache.render(template, data); html = Mustache.render(template, data);
}); });
$(this).append(html); $(this).append(html);
// $(this).append("<div class=\"csh_hint_value\" value=\"There are no answer-specific hints for this answer.\"></div>");
} }
}); });
} }
...@@ -191,7 +190,6 @@ function CrowdsourceHinter(runtime, element){ ...@@ -191,7 +190,6 @@ function CrowdsourceHinter(runtime, element){
html = Mustache.render(template, data); html = Mustache.render(template, data);
}); });
$(this).append(html); $(this).append(html);
//$(this).append("<p><input type=\"text\" name=\"studentinput\" class=\"csh_student_text_input\" size=\"40\"><input answer=\""+student_answer+"\" type=\"button\" class=\"csh_submit_new\" value=\"Submit Hint\"> </p>");
} }
}); });
}) })
...@@ -224,8 +222,8 @@ function CrowdsourceHinter(runtime, element){ ...@@ -224,8 +222,8 @@ function CrowdsourceHinter(runtime, element){
$(element).on('click', '.csh_rate_hint', function(){ $(element).on('click', '.csh_rate_hint', function(){
//Click event to change the rating/flag a hint. The attribute 'data-rate' within each .rate_hint button is used //Click event to change the rating/flag a hint. The attribute 'data-rate' within each .rate_hint button is used
//to determine whether the student is upvoting, downvoting, or flagging the hint. //to determine whether the student is upvoting, downvoting, or flagging the hint.
hint = $(this).parent().find(".csh_hint").text(); hint = $(this).parent().parent().find(".csh_hint").text();
student_answer = $(this).parent().parent().find("span").text(); student_answer = $(this).parent().parent().parent().find("span").text();
Logger.log('crowd_hinter.rate_hint.click.event', {"hint": hint, "student_answer": student_answer, "rating": $(this).attr('data-rate')}); Logger.log('crowd_hinter.rate_hint.click.event', {"hint": hint, "student_answer": student_answer, "rating": $(this).attr('data-rate')});
$.ajax({ $.ajax({
type: "POST", type: "POST",
...@@ -233,13 +231,14 @@ function CrowdsourceHinter(runtime, element){ ...@@ -233,13 +231,14 @@ function CrowdsourceHinter(runtime, element){
data: JSON.stringify({"student_rating": $(this).attr('data-rate'), "hint": hint, "student_answer": student_answer}), data: JSON.stringify({"student_rating": $(this).attr('data-rate'), "hint": hint, "student_answer": student_answer}),
success: function (result){ success: function (result){
if(result.rating == "flagged"){ if(result.rating == "flagged"){
$(this).parent().hide(); //hide hint if it was flagged by the student
$(this).parent().remove(); $(this).parent().parent().hide();
$(this).parent().parent().remove();
} }
else if(result.rating != "voted"){ else if(result.rating != "voted"){
$(".csh_hint", element).each(function(){ $(".csh_hint", element).each(function(){
if ($(this).parent().find(".csh_hint").text() == hint && $(this).parent().parent().find("span").text() == student_answer){ if ($(this).parent().parent().find(".csh_hint").text() == hint && $(this).parent().parent().parent().find("span").text() == student_answer){
$(this).parent().find('.csh_rating').text(result.rating); $(this).parent().parent().find('.csh_rating').text(result.rating);
} }
}) })
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment