Commit 69c89f84 by Sola Committed by Piotr Mitros

fixed unit switching with hinter

parent 37753c86
......@@ -102,8 +102,7 @@ class CrowdXBlock(XBlock):
@XBlock.json_handler
def get_hint(self, data, suffix=''):
"""
Returns hints to students. Hints are placed into the HintsToUse dictionary if it is found that they
are not flagged. Hints with the highest rating are shown to students unless the student has already
Returns hints to students. Hints with the highest rating are shown to students unless the student has already
submitted the same incorrect answer previously.
Args:
......@@ -171,7 +170,7 @@ class CrowdXBlock(XBlock):
def find_hints(self, answer):
"""
This function is used to find all appropriate hints that would be provided for
an incorrect answer. Flagged hints are not added into the HintsToUse dictionary.
an incorrect answer.
Args:
answer: This is equal to answer from get_hint, the answer the student submitted
......@@ -311,18 +310,17 @@ class CrowdXBlock(XBlock):
If the hint has already been voted on, 'You have already voted on this hint!'
will be returned to JS.
"""
original_data = data['student_answer'] # original strings are saved to return later
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_hint = data['used_hint']
if str(data['student_rating']) == str(2):
if data['student_rating'] == 'unflag':
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):
if data['student_rating'] == 'remove':
for flagged_answer in self.Flagged:
if self.Flagged[flagged_answer] == data_hint:
temporary_dict = str(self.hint_database[str(flagged_answer)])
......@@ -331,30 +329,28 @@ class CrowdXBlock(XBlock):
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 data['student_rating'] == 'flag':
# add hint to
self.Flagged[str(answer_data)] = data_hint
return {"rating": 'flagged', 'used_hint': data_hint}
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
rating = self.change_rating(data_hint, 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(0), 'used_hint': data_hint}
else:
return {"rating": str(rating), 'used_hint': data_hint}
else:
return {"rating": str('voted'), 'used_hint': data_hint}
def hint_flagged(self, data_hint, answer_data):
"""
This is used to add a hint to the self.flagged dictionary. When a hint is returned with the rating
of 0, it is considered to be flagged.
Args:
data_hint: This is equal to the data['used_hint'] in self.rate_hint
answer_data: This is equal to the data['student_answer'] in self.rate_hint
"""
# def hint_flagged(self, data_hint, answer_data):
# """
# This is used to add a hint to the self.flagged dictionary. When a hint is returned with the rating
# of 0, it is considered to be flagged.
# Args:
# data_hint: This is equal to the data['used_hint'] in self.rate_hint
# answer_data: This is equal to the data['student_answer'] in self.rate_hint
# """
# for answer_keys in self.hint_database:
# if answer_keys == data_hint:
# for hint_keys in self.hint_database[str(answer_keys)]:
......@@ -378,7 +374,10 @@ class CrowdXBlock(XBlock):
"""
temporary_dictionary = str(self.hint_database[str(answer_data)])
temporary_dictionary = (ast.literal_eval(temporary_dictionary))
temporary_dictionary[str(data_hint)] += int(data_rating)
if data_rating == 'upvote':
temporary_dictionary[str(data_hint)] += 1
else:
temporary_dictionary[str(data_hint)] -= 1
self.hint_database[str(answer_data)] = temporary_dictionary
return str(temporary_dictionary[str(data_hint)])
......@@ -445,12 +444,12 @@ class CrowdXBlock(XBlock):
else:
# if the hint exists already, simply upvote the previously entered hint
if str(submission) in self.DefaultHints:
self.DefaultHints[str(submission)] += int(1)
self.DefaultHints[str(submission)] += 1
return
else:
temporary_dictionary = str(self.hint_database[str(answer)])
temporary_dictionary = (ast.literal_eval(temporary_dictionary))
temporary_dictionary[str(submission)] += int(data['rating'])
temporary_dictionary[str(submission)] += 1
self.hint_database[str(answer)] = temporary_dictionary
return
......
var canhint = 0;
function CrowdXBlock(runtime, element){
//use executionFunctions to prevent old initializations of hinter from working after switching units
var executionFunctions = true;
var isStaff = false;
$(".HintsToUse", element).text("");
//use to determine whether or not to initialize hint feedback
var hasReceivedHint = false;
function stopScript(){
executionFunctions = false;
}
Logger.listen('seq_next', null, stopScript);
Logger.listen('seq_prev', null, stopScript);
Logger.listen('seq_goto', null, stopScript);
//stop this script if units are switched to prevent data errors/duplication
function stopScript(event_type, data, element){
return;
}
function logError(details) {
$.ajax({
......@@ -22,14 +20,16 @@ function CrowdXBlock(runtime, element){
});
}
Logger.listen('problem_graded', null, get_event_data);
//read the data from the problem_graded event here
function get_event_data(event_type, data, element){
check_correct(event_type, data, element);
if(executionFunctions){
check_correct(event_type, data, element);
}
}
Logger.listen('problem_graded', null, get_event_data);
function check_correct(var_event_type, var_data, var_element){
if(executionFunctions){
//check that problem wasn't correctly answered
if (var_data[1].search(/class="correct/) === -1){
$.ajax({
......@@ -38,7 +38,6 @@ function CrowdXBlock(runtime, element){
data: JSON.stringify({"submittedanswer": unescape(var_data[0])}),
success: seehint
});
hasReceivedHint = true;
}else{
$('.correct', element).show();
$('.correct', element).text("You're correct! Please help us improve our hints by voting on them, or submit your own hint!");
......@@ -68,33 +67,37 @@ function CrowdXBlock(runtime, element){
}
});
}
}
}}
function seehint(result){
if(executionFunctions){
//show hint to student
$('.HintsToUse', element).text(result.HintsToUse);
}
}}
function appendHint(result){
$(".student_answer", element).each(function(){
if ($(this).find("span").text() == result.student_answer){
$(this).append(unescape("<div class=\"hint_value\" value = \"" + result.hint_used + "\">" +
"<div role=\"button\" class=\"rate_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=\"rate_hint\" data-rate=\"-1\" aria-label=\"downvote\"><b>↓</b></div> </div>"));
"<div role=\"button\" class=\"rate_hint\" data-rate=\"upvote\" data-icon=\"arrow-u\" aria-label=\"upvote\"><b>↑</b></div>" +
"<div role=\"button\" class=\"rate_hint\" data-rate=\"flag\" data-icon=\"flag\" aria-label=\"flag\"><b>!</b></div>"+
"<div class = \"rating\">" + result.rating + "</div>"+
"<div class=\"hint_used\">" + ""+result.hint_used+"</div>" +
"<div role=\"button\" class=\"rate_hint\" data-rate=\"downvote\" aria-label=\"downvote\"><b>↓</b></div> </div>"));
}
});
}
//appendFlagged is only for staff - shows all hints that are flagged
function appendFlagged(result){
$(".flagged_hints", element).append("<div class=\"hint_value\" value = \"" + result.hint_used + "\">" +
"<div role=\"button\" class=\"staff_rate\" data-rate=\"2\" aria-label=\"unflag\"><b>O</b></div>" +
"<div role=\"button\" class=\"staff_rate\" data-rate=\"unflag\" 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>");
"<div role=\"button\" class=\"staff_rate\" data-rate=\"remove\" aria-label=\"remove\"><b>X</b></div> </div>");
}
function getFeedback(result){
console.log("feedback");
if(executionFunctions){
if(isStaff){
$('.feedback', element).append("<div class=\"flagged_hints\"><span>Flagged</span></div>");
}
......@@ -103,7 +106,7 @@ function CrowdXBlock(runtime, element){
//so that when a button is clicked, the answer and hint can be sent to the python script
student_answer = value;
hint_used = index;
//check if div for a student answer already exists (if length = 0, it doesn't)
//check if <div> for a student answer already exists, if not create the first one
if(student_answer != "Flagged"){
if($('.student_answer', element).length == 0){
$('.feedback', element).append("<div class=\"student_answer\"><span><b>"+student_answer+"</b></span>"+
......@@ -123,7 +126,8 @@ function CrowdXBlock(runtime, element){
}
}
}
//check first part of the hint to see if a hint was actually used
//if an answer doesn't have any hints to display, "There are no hints for"+student_answer is received
//as the hint. use substring to determine if that is the case.
if(hint_used.substring(0, 22) == "There are no hints for"){
$(".student_answer", element).each(function(){
if ($(this).find("span").text() == student_answer){
......@@ -131,6 +135,7 @@ function CrowdXBlock(runtime, element){
}
});
}
//flagged hints have their corresponding answer set to "Flagged"
else if(student_answer != "Flagged"){
$.ajax({
type: "POST",
......@@ -148,9 +153,11 @@ function CrowdXBlock(runtime, element){
});
}
});
}
}}
$(document).on('click', '.student_hint_creation', function(){
if(executionFunctions){
//remove all other hint inputs and replace
$('.math').remove();
$('.submit_new').remove();
student_answer = $(this).parent().parent().find("span").text();
......@@ -159,9 +166,10 @@ function CrowdXBlock(runtime, element){
$(this).prepend("<p><input type=\"text\" name=\"studentinput\" class=\"math\" size=\"40\"><input id=\""+student_answer+"\" type=\"button\" class=\"submit_new\" value=\"Submit Hint\"> </p>");
}
});
})
}})
$(document).on('click', '.submit_new', function(){
if(executionFunctions){
if($(this).parent().find('.math').val() != null){
var answerdata = unescape($(this).attr('id'));
var newhint = unescape($('.math').val());
......@@ -169,23 +177,28 @@ function CrowdXBlock(runtime, element){
$.ajax({
type: "POST",
url: runtime.handlerUrl(element, 'give_hint'),
data: JSON.stringify({"submission": newhint, "answer": answerdata}), //give hin for first incorrect answer
//success: finish
data: JSON.stringify({"submission": newhint, "answer": answerdata}),
});
$(this).parent('p').remove();
//$('.math').remove();
}
})
}
}})
$(document).on('click', '.rate_hint', function(){
if(executionFunctions){
used_hint = $(this).parent().find(".hint_used").text();
student_answer = $(this).parent().parent().find("span").text();
Logger.log('rate_hint.click.event', {"used_hint": used_hint, "student_answer": student_answer, "rating": $(this).attr('data-rate')});
$.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: function (result){
if(result.rating != "voted"){
if(result.rating == "flagged"){
console.log("flagged");
$(this).parent().hide();
$(this).parent().remove();
}
else 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);
......@@ -194,9 +207,11 @@ function CrowdXBlock(runtime, element){
}
}
});
})
}})
//staff ratings are the removal or unflagging of flagged hints from the database
$(document).on('click', '.staff_rate', function(){
if(executionFunctions){
used_hint = $(this).parent().find(".hint_used").text();
student_answer = $(this).parent().parent().find("span").text();
$.ajax({
......@@ -211,77 +226,5 @@ function CrowdXBlock(runtime, element){
});
}
});
})
$(document).on('click', '.flag_hint', function(){
canhint = 0;
id = this.id;
$('.hintbutton').each(function(){
if($(this).attr('id') == String(id)){
$(this).hide();
}
});
$.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
});
})
function finish(result){
if(canhint == 0){
canhint = 1;
$('.Thankyou', element).text("Thankyou for your help!");
idtouse = String('votingFor' + result.used_hint);
hint_rating = result.rating;
if(result.rating == "zzeerroo"){
hint_rating = 0;
}if(result.rating == "thiswasflagged"){
hint_rating = 999;
}
$('p').each(function(){
if($(this).attr('id') == idtouse){
if(hint_rating != "You have already voted on this hint!" && hint_rating != 999){
$.ajax({
type: "POST",
url: runtime.handlerUrl(element, 'get_ratings'),
data: JSON.stringify({"student_answer": student_answer, "hint_used": hint_used}),
success: show_ratings
});
}if (hint_rating == "You have already voted on this hint!"){
$(this).prepend("<div><p style=\"float: left;\"><b> You have already voted on this hint.</p></div>");
}if (hint_rating == 999){
$(this).prepend("<div><p style=\"float: left;\"><b><font color=\"red\"> This hint has been flagged for moderation.</font></p></div>");}
}
});}
}
$.ajax({
type: "POST",
url: runtime.handlerUrl(element, 'studiodata'),
data: JSON.stringify(""),
success: studiodata
});
function studiodata(result){
if($(".xblock-editor").length != 0){
$.each(result, function(index, value) {
$('.xblock-editor').append("<p id=\"" + value + "\"> The hint<b>" + " " + index + " " + "</b>was flagged for the submission<b>" + " " + value + "</b></p>");
$('#'+value).prepend("<input data-value=\"" + value + "\" id=\"" + index + "\" style=\"height:35px;padding-top: 3px;\" type=\"button\" class=\"flagbutton\" data-rate=\"dismiss\" value=\"Dismiss Hint\"><input data-value=\"" + value + "\" id=\"" + index + "\" style=\"height:35px; padding-top: 3px;\" type=\"button\" class=\"flagbutton\" data-rate=\"purge\" value=\"Purge Hint\">");
});
}
}
$(document).on('click', '.flagbutton', function(){
answer_wrong = $(this).attr('id');
hint = $(this).attr('data-value');
rating = $(this).attr('data-rate');
$.ajax({
type: "POST",
url: runtime.handlerUrl(element, 'moderate_hint'),
data: JSON.stringify({"answer_wrong":answer_wrong, "hint": hint, "rating":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