Commit dcdb7f36 by Sola Committed by Piotr Mitros

adding isstaff feedback

parent 05e46b62
......@@ -21,10 +21,8 @@ class CrowdXBlock(XBlock):
"""
# Database of hints. hints are stored as such: {"incorrect_answer": {"hint": rating}}. each key (incorrect answer)
# has a corresponding dictionary (in which hints are keys and the hints' ratings are the values).
hint_database = Dict(default={'answer': {'Try doing something new': 5, 'you should go review that lesson again': 0}}, scope=Scope.user_state_summary)
# This is a dictionary of hints that will be used to determine what hints to show a student.
# flagged hints are not included in this dictionary of hints
HintsToUse = Dict({}, scope=Scope.user_state)
# TODO: Remove default values once done testing
hint_database = Dict(default={'answer': {'Try doing something new': 5, 'you should go review that lesson again': 0}, "answer2": {'new answer hint': 3, "You should go look in your notes": 6, "This is a hint that should be flagged": -4}}, scope=Scope.user_state_summary)
# This is a list of incorrect answer submissions made by the student. this list is mostly used for
# feedback, to find which incorrect answer's hint a student voted on.
WrongAnswers = List([], scope=Scope.user_state)
......@@ -32,7 +30,7 @@ class CrowdXBlock(XBlock):
# student's incorrect answer within the hint_database dictionary (i.e. no students have made hints for the
# particular incorrect answer)
DefaultHints = Dict(default={'default_hint': 0}, scope=Scope.content)
# List of which hints from the HintsToUse dictionary have been shown to the student
# List of which hints have been shown to the student
# this list is used to prevent the same hint from showing up to a student (if they submit the same incorrect answers
# multiple times)
Used = List([], scope=Scope.user_state)
......@@ -43,11 +41,16 @@ class CrowdXBlock(XBlock):
# This is a dictionary of hints that have been flagged. the keys 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
# incorrect answer, i believe that the hint will still be able to show for a student
Flagged = Dict(default={}, scope=Scope.user_state_summary)
Flagged = Dict(default={"answer2": "THis is a hint that should be flagged"}, scope=Scope.user_state_summary)
# 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.
# Details on operation when set to 'False' are to be finalized.
# TODO: make this into a boolean instead of a dict
show_best = Dict(default={'showbest': 'True'}, scope=Scope.user_state_summary)
# This Dict determine whether or not the user is staff. This in turn will influence whether or not flagged hints
# will be shown. The method to actually determine whether or not the user is staff is not currently implemented.
# TODO: make this into a boolean instead of a dict
isStaff = Dict(default={'isStaff': 'true'}, scope=Scope.user_state_summary)
def student_view(self, context=None):
"""
......@@ -161,9 +164,7 @@ class CrowdXBlock(XBlock):
isflagged = []
isused = 0
testvar = 0
self.WrongAnswers.append(str(answer)) # add the student's input to the temporary list, for later use
# add hints to the self.HintsToUse dictionary. Will likely be replaced
# soon by simply looking within the self.hint_database for hints.
self.WrongAnswers.append(str(answer)) # add the student's input to the temporary list
if str(answer) not in self.hint_database:
# add incorrect answer to hint_database if no precedent exists
self.hint_database[str(answer)] = {}
......@@ -192,12 +193,15 @@ class CrowdXBlock(XBlock):
for the question, all the hints the student recieved, as well as two
more random hints that exist for an incorrect answer in the hint_database
"""
feedback_data = {}
# feedback_data is a dictionary of hints (or lack thereof) used for a
# specific answer, as well as 2 other random hints that exist for each answer
# that were not used. The keys are the used hints, the values are the
# corresponding incorrect answer
feedback_data = {}
number_of_hints = 0
if self.isStaff['isStaff'] == 'true':
feedback_data = get_staff_feedback()
return feedback_data
if len(self.WrongAnswers) == 0:
return
else:
......@@ -237,8 +241,31 @@ class CrowdXBlock(XBlock):
This function is used when no hints exist for an answer. The feedback_data within
get_feedback is set to "there are no hints for" + " " + str(self.WrongAnswers[index])
"""
self.WrongAnswers.append(str(self.WrongAnswers[index]))
self.Used.append(str("There are no hints for" + " " + str(self.WrongAnswers[index])))
for answer_keys in self.hint_database:
if str(len(self.hint_database[str(answer_keys)])) != str(0):
hint_key = self.hint_database[str(answer_keys)].keys()
for hints in hint_key:
if str(hints) not in self.Flagged.keys():
feedback_data[str(hints)] = str(answer_keys)
else:
feedback_data[str(hints)] = str("Flagged Hint")
else:
feedback_data[str("There are no hints for" + " " + str(hint_key))] = str(answer_keys)
self.WrongAnswers=[]
self.Used=[]
return feedback_data
def get_staff_feedback(self, index):
"""
This function is the alternative to get_feedback if the user is staff.
The method to determine whether or not the user is staff has not yet been implemented.
"""
# feedback_data is a dictionary of hints and corresponding answers
# The keys are the used hints, the values are the corresponding incorrect answer
# For flagged hints, the keys are used hints and the values are "flagged"
feedback_data = {}
@XBlock.json_handler
def get_ratings(self, data, suffix=''):
......
......@@ -12,7 +12,7 @@
<span class='Thankyou'></span>
</p>
<div class="hintansarea">
<div class="feedback">
</div>
......
......@@ -5,19 +5,22 @@ var issubmitting = 0;
var issubmittinghint = 0;
function CrowdXBlock(runtime, element){
var WrongAnswer = [];
var HintUsed = [];
var HintShown = [];
$("#answer").hide();
$(".problem").hide();
$("#feedback").hide();
var_element = String;
var_event_type = String;
var_data = String;
//$(".HintsToUse", element).text("Hints are enabled for this problem!");
$(".HintsToUse", element).text("");
clearvariables();
//repeat counter is used to counteract a bug caused by switching units
//after switching units all logger.listen events would trigger multiple times
repeatcounter += 1;
console.debug(repeatcounter);
//use to determine whether or not to initialize hint feedback
var hasReceivedHint = false;
var is_staff = false;
var check_staff = $('#staffstatus').val();
if(check_staff == 'staff view');
{
console.log(check_staff);
console.log("is_staff");
is_staff = true;
}
Logger.listen('seq_next', null, clearingvariables);
Logger.listen('seq_goto', null, clearingvariables);
......@@ -26,22 +29,18 @@ function CrowdXBlock(runtime, element){
}
function clearvariables(data){
HintUsed = [];
WrongAnswer = [];
repeating = 0;
}
Logger.listen('problem_graded', null, dostuff);
function dostuff(event_type, data, 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){
repeating += 1;
if(repeating != repeatcounter){
console.debug(repeating);
}else{
$("#studentsubmit").val('');
var_element = element;
var_event_type = event_type;
var_data = data;
senddata(var_event_type, var_data, var_element);
check_correct(event_type, data, element);
}
}
......@@ -49,144 +48,118 @@ function CrowdXBlock(runtime, element){
repeating = 0;
});
function senddata(var_event_type, var_data, var_element){
function check_correct(var_event_type, var_data, var_element){
//check that problem wasn't correctly answered
if (var_data[1].search(/class="correct/) === -1){
$.ajax({ //that probably will be changed once i use response.search or something?
type: "POST", //if/when that is changed, remove checkreply and uncomment the else statement below
url: runtime.handlerUrl(element, 'get_hint'),
data: JSON.stringify({"submittedanswer": var_data[0]}), //return student's incorrect answer here
//from var_data[1] check id (long thing) and get class (correct or incorrect)
success: seehint
});
}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!");
$(".HintsToUse", element).text(" ");
$.ajax({
type: "POST",
url: runtime.handlerUrl(element, 'get_feedback'),
data: JSON.stringify({"hello": "world"}),
success: getfeedback
});}
}
$.ajax({
type: "POST",
url: runtime.handlerUrl(element, 'studiodata'),
data: JSON.stringify({"hello": "world"}),
success: studiodata
});
function studiodata(result){
$(".xblock-editor").append("confirm_working");
if($(".xblock-editor").length != 0){
$.each(result, function(index, value) {
console.debug(index);
$('.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\">");
});
}
$.ajax({
type: "POST",
url: runtime.handlerUrl(element, 'get_hint'),
data: JSON.stringify({"submittedanswer": var_data[0]}),
success: seehint
});
hasReceivedHint = true;
}else if(hasReceivedHint == true){
$('.correct', element).show();
$('.correct', element).text("You're correct! Please help us improve our hints by voting on them, or submit your own hint!");
$(".HintsToUse", element).text(" ");
//send empty data for ajax call because not having a data field causes error
$.ajax({
type: "POST",
url: runtime.handlerUrl(element, 'get_feedback'),
data: JSON.stringify(""),
success: getFeedback
});
}else{
$(".HintsToUse", element).text("");
}
}
$(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}),
});
});
function seehint(result){//use html to show these results somewhere i guess
console.debug('seehint');
HintUsed.push(result.HintsToUse);
function seehint(result){
//show hint to student
$('.HintsToUse', element).text(result.HintsToUse);
}
function getfeedback(result){
$("#answer").show();
$(".problem").show();
$("#feedback").show();
function getFeedback(result){
$.each(result, function(index, value) {
student_answer = value.replace(/\./g, 'ddeecciimmaallppooiinntt');
hint_used = index.replace(/\./g, 'ddeecciimmaallppooiinntt');
student_answer = student_answer.replace(/\:/g, 'ccoolloonn');
hint_used = hint_used.replace(/\:/g, 'ccoolloonn');
student_answer = student_answer.replace(/\;/g, 'sseemmiiccoolloonn');
hint_used = hint_used.replace(/\;/g, 'sseemmiiccoolloonn');
student_answer = student_answer.replace(/\=/g, 'eeqquuaallss');
hint_used = hint_used.replace(/\=/g, 'eeqquuaallss');
if($("#submit"+student_answer).length == 0){
$('.hintansarea').append("<p id=\"submit" + student_answer + "\" class=\"hintsarea\"> </p>");
$('#submit'+student_answer).append("<p> </p><b>Answer-specific hints for \b" + " " + student_answer + "<p> <p id=\"hintstoshow" + student_answer + "\"> </p></div>");
}
if(hint_used.slice(0,22) != "There are no hints for"){
$('#hintstoshow'+student_answer).append("<p \" id =\"thisparagraph" + hint_used + "\">" + "<div data-value=\"" + student_answer + "\" id=\"" + hint_used + "\" role=\"button\" class=\"upvote_hint\" data-rate=\"1\" data-icon=\"arrow-u\" aria-label=\"upvote\"><b>↑</b></div> <div class = \"" + hint_used + "rating\">" + hint_used + "</div> <div data-value=\"" + student_answer + "\" id=\"" + hint_used + "\" role=\"button\" class=\"downvote_hint\" data-rate=\"-1\" aria-label=\"downvote\"><b>↓</b></div> </p>");
//<div data-value=\"" + student_answer + "\" id=\"" + hint_used + "\" role=\"button\" class=\"flag_hint\" data-rate=\"0\" aria-label=\"report\"><b>!</b></div>
$.ajax({
type: "POST",
url: runtime.handlerUrl(element, 'get_ratings'),
data: JSON.stringify({"student_answer": student_answer, "hint_used": hint_used}),
success: show_ratings
});
HintShown.push(index);
}else{
$('#hintstoshow'+student_answer).empty();
$('#hintstoshow'+student_answer).append("<p id=\"hintstoshow" + student_answer + "\"data-value=\"" + student_answer + "\"> <b>No hints exist in the database. (You received a default hint)</p> <p id=\"" + hint_used + "\"data-value=\"" + student_answer + "\" </p>");
}
//data of student answer and hints are stored in the paragraphs/buttons
//so that when a button is clicked, the answer and hint can be sent to the python script
student_answer = value;
hint_used = index;
if($(".submit"+student_answer).length == 0){
$('.feedback', element).append("<p class=\"submit" + student_answer + "\"</p>");
$(".submit"+student_answer, element).append("<b>Answer-specific hints for \b" + " " + student_answer + "<p><input id=\"submitbuttonfor" + student_answer + "\" style=\"float: right; float: top;\" type=\"button\" class=\"submitbutton\" value=\"Submit a hint\"><p class=\"showHintsFor" + student_answer + "\"> </p></div>");
}
if(hint_used.slice(0,22) != "There are no hints for"){
$('.showHintsFor'+student_answer, element).append(
"<p \" class =\"votingFor" + hint_used + "\">" +
"<div data-value=\"" + student_answer + "\" id=\"" + hint_used +"\" role=\"button\" class=\"upvote_hint\"" +
"data-rate=\"1\" data-icon=\"arrow-u\" aria-label=\"upvote\"><b>↑</b></div>" +
"<div class = \"" + hint_used + "rating\">" + hint_used + "</div>" +
"<div data-value=\"" + student_answer + "\" id=\"" + hint_used + "\" role=\"button\" class=\"downvote_hint\"" +
"data-rate=\"-1\" aria-label=\"downvote\"><b>↓</b>" +
"</div> </p>");
$.ajax({
type: "POST",
url: runtime.handlerUrl(element, 'get_ratings'),
data: JSON.stringify({"student_answer": student_answer, "hint_used": hint_used}),
success: show_ratings
});
}else{
$('.showHintsFor'+student_answer).empty();
$('.showHintsFor'+student_answer).append("<p class=\".showHintsFor" + student_answer + "\"data-value=\"" + student_answer + "\"> <b>No hints exist in the database. (You received a default hint)</p> <p id=\"" + hint_used + "\"data-value=\"" + student_answer + "\" </p>");
}
});
}
function show_ratings(result) {
$.each(result, function(index, value) {
console.log(index)
$("."+index+"rating").prepend(value + " ");})
console.log(index);
console.log(value);
$("."+index+"rating").append(value + " " + index);
})
}
$(document).on('click', '.submitbutton', function(){ //upvote
issubmittinghint = 0;
issubmitting += 1;
if(issubmitting == repeatcounter){
id = this.id;
id = id.slice(15);
//value = document.getElementById(id).getAttribute('data-value');
$('.submitbutton').show();
$('.math').remove();
$('#submit').remove();
$(this).hide();
$('#hintstoshow' + id).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>");
}})
id = this.id;
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', function(){
issubmittinghint += 1;
if(issubmittinghint == repeatcounter){
if($('.math').val() != null){
var answerdata = String;
var valueid = String;
issubmitting = 0;
$('#submit').each(function(){
answerdata = $('.math').attr('id');
});
$('.submitbutton').show();
$.ajax({
type: "POST",
url: runtime.handlerUrl(element, 'give_hint'),
data: JSON.stringify({"submission": $('.math').val(), "answer": answerdata}), //give hin for first incorrect answer
//success: finish
});
$("#answer").val('');
//data_value = document.getElementById(valueid).getAttribute('data-value');
data_value = String('hintstoshow' + answerdata);
$(this).remove();
$('.math').remove();
document.getElementById("submitbuttonfor" + answerdata).remove();
$('#submitbuttonfor' + answerdata).remove();
$('#'+answerdata).remove();
//value = document.getElementById(id).getAttribute('data-value');
//$('#hintstoshow' + value).prepend("<p> Thankyou! </p>");
$('#submit'+answerdata).prepend('Thankyou for your hint!');
}}})
var answerdata = String;
issubmitting = 0;
$('#submit').each(function(){
answerdata = $('.math').attr('id');
});
$('.submitbutton').show();
$.ajax({
type: "POST",
url: runtime.handlerUrl(element, 'give_hint'),
data: JSON.stringify({"submission": $('.math').val(), "answer": answerdata}), //give hin for first incorrect answer
//success: finish
});
$("#answer").val('');
$(this).remove();
$('.math').remove();
document.getElementById("submitbuttonfor" + answerdata).remove();
$('#submitbuttonfor' + answerdata).remove();
$('#'+answerdata).remove();
$('#submit'+answerdata).prepend('Thankyou for your hint!');
}
}
})
$(document).on('click', '.upvote_hint', function(){ //upvote
canhint = 0;
......@@ -202,6 +175,7 @@ function CrowdXBlock(runtime, element){
data: JSON.stringify({"student_rating": $(this).attr('data-rate'), "used_hint": $(this).attr('id'), "student_answer": $(this).attr('data-value')}),
success: finish
});})
$(document).on('click', '.downvote_hint', function(){ //upvote
canhint = 0;
id = this.id;
......@@ -216,6 +190,7 @@ function CrowdXBlock(runtime, element){
data: JSON.stringify({"student_rating": $(this).attr('data-rate'), "used_hint": $(this).attr('id'), "student_answer": $(this).attr('data-value')}),
success: finish
});})
$(document).on('click', '.flag_hint', function(){ //upvote
canhint = 0;
id = this.id;
......@@ -236,17 +211,13 @@ function CrowdXBlock(runtime, element){
if(canhint == 0){
canhint = 1;
$('.Thankyou', element).text("Thankyou for your help!");
idtouse = String('thisparagraph' + result.used_hint);
idtouse = String('votingFor' + result.used_hint);
hint_rating = result.rating;
if(result.rating == "zzeerroo"){
hint_rating = 0;
}if(result.rating == "thiswasflagged"){
hint_rating = 999;
}
//idtouse = idtouse.replace('ddeecciimmaallppooiinntt', /\./g);
//idtouse = idtouse.replace('ccoolloonn', /\:/g);
//idtouse = idtouse.replace('sseemmiiccoolloonn', /\;/g);
//idtouse = idtouse.replace('eeqquuaallss', /\=/g);
$('p').each(function(){
if($(this).attr('id') == idtouse){
if(hint_rating != "You have already voted on this hint!" && hint_rating != 999){
......@@ -263,7 +234,32 @@ function CrowdXBlock(runtime, element){
}
});}
}
}
$.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