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):
"""
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
def get_element(self, data, suffix=''):
"""
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
def is_user_staff(self, _data, _suffix=''):
......@@ -145,8 +152,6 @@ class CrowdsourceHinter(XBlock):
# 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.
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)
answer = str(data["submittedanswer"])
answer = answer.lower() # for analyzing the student input string I make it lower case.
......@@ -164,6 +169,7 @@ class CrowdsourceHinter(XBlock):
answer = answer[eqplace:]
remaining_hints = str(self.find_hints(answer))
if remaining_hints != str(0):
print(self.hint_database)
best_hint = max(self.hint_database[str(answer)].iteritems(), key=operator.itemgetter(1))[0]
if self.show_best:
# 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):
self.hint_database[str(answer)][str(submission)] += 1
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
def studiodata(self, data, suffix=''):
"""
......@@ -414,8 +427,9 @@ class CrowdsourceHinter(XBlock):
A minimal working test for parse_xml
"""
block = runtime.construct_xblock_from_class(cls, keys)
xmlText = ast.literal_eval((node.text).encode('utf-8'))
block.generic_hints.append(xmlText["generic_hints"])
xmlText = ast.literal_eval(str(node.text))
block.generic_hints.append(str(xmlText["generic_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
......@@ -16,8 +16,9 @@ function CrowdsourceHinter(runtime, element){
url: runtime.handlerUrl(element, 'get_element'),
data: JSON.stringify("helloworld"),
success: function(result){
console.log("hinting_element being set", result);
hinting_element = result;
console.log("hinting_element being set", String(result));
hinting_element = String(result);
Logger.listen('problem_graded', result, get_event_data);
}
});
......@@ -25,7 +26,6 @@ function CrowdsourceHinter(runtime, element){
//This function is used to prevent a particular instance of the hinter from acting after
//switching between edX course's units.
executeHinter = false;
console.log("executeHinter set to false");
}
Logger.listen('seq_next', null, stopScript);
Logger.listen('seq_prev', null, stopScript);
......@@ -34,18 +34,8 @@ function CrowdsourceHinter(runtime, element){
//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
function get_event_data(event_type, data, element){
//onStudentSubmission(data);
console.log("gradedevent listen");
onStudentSubmission(data);
}
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){
//This function will determine whether or not the student correctly answered the question.
......@@ -217,6 +207,7 @@ function CrowdsourceHinter(runtime, element){
var answerdata = unescape($(this).attr('answer'));
var newhint = unescape($('.csh_student_text_input').val());
Logger.log('crowd_hinter.submit_new.click.event', {"student_answer": answerdata, "new_hint_submission": newhint});
console.log(answerdata, newhint);
$('.csh_submitbutton').show();
$.ajax({
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