Commit 28295120 by solashirai Committed by Piotr Mitros

fixes to listening for events, errors exist with dict key/values being unicode

parent 76f5ee71
...@@ -108,12 +108,19 @@ class CrowdsourceHinter(XBlock): ...@@ -108,12 +108,19 @@ class CrowdsourceHinter(XBlock):
""" """
return self.xmodule_runtime.user_is_staff return self.xmodule_runtime.user_is_staff
def convert_keys_to_string(dictionary):
"""Recursively converts dictionary keys to strings."""
if not isinstance(dictionary, dict):
return dictionary
return dict((str(k), convert_keys_to_string(v))
for k, v in dictionary.items())
@XBlock.json_handler @XBlock.json_handler
def get_element(self, data, suffix=''): def get_element(self, data, suffix=''):
""" """
Returns the self.element so that the javascript Logger.listen will be using the correct element. Returns the self.element so that the javascript Logger.listen will be using the correct element.
""" """
return str(self.Element); return unicode(self.Element);
@XBlock.json_handler @XBlock.json_handler
def is_user_staff(self, _data, _suffix=''): def is_user_staff(self, _data, _suffix=''):
...@@ -145,8 +152,6 @@ class CrowdsourceHinter(XBlock): ...@@ -145,8 +152,6 @@ class CrowdsourceHinter(XBlock):
# populate hint_database with hints from initial_hints if there are no hints in hint_database. # populate hint_database with hints from initial_hints if there are no hints in hint_database.
# this probably will occur only on the very first run of a unit containing this block. # this probably will occur only on the very first run of a unit containing this block.
if not bool(self.hint_database): if not bool(self.hint_database):
#TODO: Figure out why temporarydict = self.initial_hints doesn't work.
self.hint_database = copy.copy(self.initial_hints) self.hint_database = copy.copy(self.initial_hints)
answer = str(data["submittedanswer"]) answer = str(data["submittedanswer"])
answer = answer.lower() # for analyzing the student input string I make it lower case. answer = answer.lower() # for analyzing the student input string I make it lower case.
...@@ -164,6 +169,7 @@ class CrowdsourceHinter(XBlock): ...@@ -164,6 +169,7 @@ class CrowdsourceHinter(XBlock):
answer = answer[eqplace:] answer = answer[eqplace:]
remaining_hints = str(self.find_hints(answer)) remaining_hints = str(self.find_hints(answer))
if remaining_hints != str(0): if remaining_hints != str(0):
print(self.hint_database)
best_hint = max(self.hint_database[str(answer)].iteritems(), key=operator.itemgetter(1))[0] best_hint = max(self.hint_database[str(answer)].iteritems(), key=operator.itemgetter(1))[0]
if self.show_best: if self.show_best:
# if set to show best, only the best hint will be shown. Different hitns will not be shown # if set to show best, only the best hint will be shown. Different hitns will not be shown
...@@ -385,6 +391,13 @@ class CrowdsourceHinter(XBlock): ...@@ -385,6 +391,13 @@ class CrowdsourceHinter(XBlock):
self.hint_database[str(answer)][str(submission)] += 1 self.hint_database[str(answer)][str(submission)] += 1
return return
def convert_keys_to_string(dictionary):
"""Recursively converts dictionary keys to strings."""
if not isinstance(dictionary, dict):
return dictionary
return dict((str(k), convert_keys_to_string(v))
for k, v in dictionary.items())
@XBlock.json_handler @XBlock.json_handler
def studiodata(self, data, suffix=''): def studiodata(self, data, suffix=''):
""" """
...@@ -414,8 +427,9 @@ class CrowdsourceHinter(XBlock): ...@@ -414,8 +427,9 @@ class CrowdsourceHinter(XBlock):
A minimal working test for parse_xml A minimal working test for parse_xml
""" """
block = runtime.construct_xblock_from_class(cls, keys) block = runtime.construct_xblock_from_class(cls, keys)
xmlText = ast.literal_eval((node.text).encode('utf-8')) xmlText = ast.literal_eval(str(node.text))
block.generic_hints.append(xmlText["generic_hints"]) block.generic_hints.append(str(xmlText["generic_hints"]))
block.initial_hints = copy.copy(xmlText["initial_hints"]) block.initial_hints = copy.copy(xmlText["initial_hints"])
block.Element = xmlText["hinting_element"] block.Element = str(xmlText["hinting_element"])
print block.Element, block.initial_hints
return block return block
...@@ -16,8 +16,9 @@ function CrowdsourceHinter(runtime, element){ ...@@ -16,8 +16,9 @@ function CrowdsourceHinter(runtime, element){
url: runtime.handlerUrl(element, 'get_element'), url: runtime.handlerUrl(element, 'get_element'),
data: JSON.stringify("helloworld"), data: JSON.stringify("helloworld"),
success: function(result){ success: function(result){
console.log("hinting_element being set", result); console.log("hinting_element being set", String(result));
hinting_element = result; hinting_element = String(result);
Logger.listen('problem_graded', result, get_event_data);
} }
}); });
...@@ -25,7 +26,6 @@ function CrowdsourceHinter(runtime, element){ ...@@ -25,7 +26,6 @@ function CrowdsourceHinter(runtime, element){
//This function is used to prevent a particular instance of the hinter from acting after //This function is used to prevent a particular instance of the hinter from acting after
//switching between edX course's units. //switching between edX course's units.
executeHinter = false; executeHinter = false;
console.log("executeHinter set to false");
} }
Logger.listen('seq_next', null, stopScript); Logger.listen('seq_next', null, stopScript);
Logger.listen('seq_prev', null, stopScript); Logger.listen('seq_prev', null, stopScript);
...@@ -34,18 +34,8 @@ function CrowdsourceHinter(runtime, element){ ...@@ -34,18 +34,8 @@ function CrowdsourceHinter(runtime, element){
//data about the problem obtained from Logger.listen('problem_graded') is passed on to the onStudentSubmission. //data about the problem obtained from Logger.listen('problem_graded') is passed on to the onStudentSubmission.
//directly passing data to onStudentSubmission does not appear to work //directly passing data to onStudentSubmission does not appear to work
function get_event_data(event_type, data, element){ function get_event_data(event_type, data, element){
//onStudentSubmission(data); onStudentSubmission(data);
console.log("gradedevent listen");
} }
Logger.listen('problem_graded', hinting_element, function(){console.log("test")});
Logger.listen('problem_graded', 'i4x://edX/DemoX/problem/Text_Input', function(){console.log("test2")});
function get_event_data_temp(event_type, data, element){
console.log("checkevent listen");
console.log(hinting_element);
console.log(typeof('i4x://edX/DemoX/problem/Text_Input'));
}
Logger.listen('problem_check', null, get_event_data_temp);
function onStudentSubmission(problem_graded_event_data){ function onStudentSubmission(problem_graded_event_data){
//This function will determine whether or not the student correctly answered the question. //This function will determine whether or not the student correctly answered the question.
...@@ -217,6 +207,7 @@ function CrowdsourceHinter(runtime, element){ ...@@ -217,6 +207,7 @@ function CrowdsourceHinter(runtime, element){
var answerdata = unescape($(this).attr('answer')); var answerdata = unescape($(this).attr('answer'));
var newhint = unescape($('.csh_student_text_input').val()); var newhint = unescape($('.csh_student_text_input').val());
Logger.log('crowd_hinter.submit_new.click.event', {"student_answer": answerdata, "new_hint_submission": newhint}); Logger.log('crowd_hinter.submit_new.click.event', {"student_answer": answerdata, "new_hint_submission": newhint});
console.log(answerdata, newhint);
$('.csh_submitbutton').show(); $('.csh_submitbutton').show();
$.ajax({ $.ajax({
type: "POST", type: "POST",
......
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