Commit 87b53fbe by solashirai

Merge pull request #6 from solashirai/sola/working

Sola/working
parents 132ad676 eecc234b
...@@ -5,6 +5,7 @@ import random ...@@ -5,6 +5,7 @@ import random
import json import json
import copy import copy
import urllib
import HTMLParser import HTMLParser
from xblock.core import XBlock from xblock.core import XBlock
...@@ -96,10 +97,9 @@ class CrowdsourceHinter(XBlock): ...@@ -96,10 +97,9 @@ class CrowdsourceHinter(XBlock):
frag.add_javascript_url('//cdnjs.cloudflare.com/ajax/libs/mustache.js/0.8.1/mustache.min.js') frag.add_javascript_url('//cdnjs.cloudflare.com/ajax/libs/mustache.js/0.8.1/mustache.min.js')
frag.add_css(self.resource_string("static/css/crowdsourcehinter.css")) frag.add_css(self.resource_string("static/css/crowdsourcehinter.css"))
frag.add_javascript(self.resource_string("static/js/src/crowdsourcehinter_studio.js")) frag.add_javascript(self.resource_string("static/js/src/crowdsourcehinter_studio.js"))
print type(self.initial_hints), type(self.target_problem), type(self.generic_hints), str
frag.initialize_js('CrowdsourceHinterStudio', frag.initialize_js('CrowdsourceHinterStudio',
{'initial': self.initial_hints, {'initial': json.dumps(self.initial_hints),
'generic': self.generic_hints, 'generic': json.dumps(self.generic_hints),
'target_problem': self.target_problem}) 'target_problem': self.target_problem})
return frag return frag
...@@ -127,7 +127,6 @@ class CrowdsourceHinter(XBlock): ...@@ -127,7 +127,6 @@ class CrowdsourceHinter(XBlock):
self.initial_hints = initial_hints self.initial_hints = initial_hints
self.generic_hints = generic_hints self.generic_hints = generic_hints
print type(data['target_problem'])
if len(data['target_problem']) > 1: if len(data['target_problem']) > 1:
self.target_problem = data['target_problem'] self.target_problem = data['target_problem']
return {'success': True} return {'success': True}
...@@ -157,7 +156,7 @@ class CrowdsourceHinter(XBlock): ...@@ -157,7 +156,7 @@ class CrowdsourceHinter(XBlock):
# First, we split this into the submission # First, we split this into the submission
answers = [a.split('=') for a in answers.split("&")] answers = [a.split('=') for a in answers.split("&")]
# Next, we decode the HTML escapes # Next, we decode the HTML escapes
answers = [(a[0], html_parser.unescape(a[1])) for a in answers] answers = [(a[0], urllib.unquote_plus(a[1])) for a in answers]
return dict(answers) return dict(answers)
@XBlock.json_handler @XBlock.json_handler
...@@ -186,8 +185,9 @@ class CrowdsourceHinter(XBlock): ...@@ -186,8 +185,9 @@ class CrowdsourceHinter(XBlock):
for answers in self.initial_hints: for answers in self.initial_hints:
if answers not in self.hint_database: if answers not in self.hint_database:
self.hint_database[answers] = {} self.hint_database[answers] = {}
if self.initial_hints[answers] not in self.hint_database[answers]: for hints in self.initial_hints[answers]:
self.hint_database[answers].update({self.initial_hints[answers]: 0}) if hints not in self.hint_database[answers]:
self.hint_database[answers].update({hints: {"upvotes": 0, "downvotes": 0}})
answer = self.extract_student_answers(data["submittedanswer"]) answer = self.extract_student_answers(data["submittedanswer"])
...@@ -283,14 +283,13 @@ class CrowdsourceHinter(XBlock): ...@@ -283,14 +283,13 @@ class CrowdsourceHinter(XBlock):
if len(self.incorrect_answers) == 0: if len(self.incorrect_answers) == 0:
return used_hint_answer_text return used_hint_answer_text
else: else:
for index in range(0, len(self.used)): # for the time being only the first answer/hint pair will be shown to the studen
# each index is a hint that was used, in order of usage if self.used[0] in self.hint_database[self.incorrect_answers[0]]:
if self.used[index] in self.hint_database[self.incorrect_answers[index]]: # add new key (hint) to used_hint_answer_text with a value (incorrect answer)
# add new key (hint) to used_hint_answer_text with a value (incorrect answer) used_hint_answer_text[json.dumps(self.used[0])] = json.dumps(self.incorrect_answers[0])
used_hint_answer_text[self.used[index]] = self.incorrect_answers[index] else:
else: # if the student's answer had no hints (or all the hints were reported and unavailable) return None
# if the student's answer had no hints (or all the hints were reported and unavailable) return None used_hint_answer_text[None] = json.dumps(self.incorrect_answers[0])
used_hint_answer_text[None] = self.incorrect_answers[index]
self.incorrect_answers = [] self.incorrect_answers = []
self.used = [] self.used = []
return used_hint_answer_text return used_hint_answer_text
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
Generic Hints: <textarea type="text" class="csh_generic_hints" value = "{{generic}}"/> Generic Hints: <textarea type="text" class="csh_generic_hints" value = "{{generic}}"/>
</p> </p>
<p> <p>
Initial hints should be a python dictionary, with keys representing anticipated incorrect answers and values being hints. e.x {"incorrect answer example 1": "hint for incorrect answer 1"}. The rating of initial hints defaults to 0. Initial hints should be a python dictionary, in the following format - {"mistake1": {"hint1": {"upvotes": 0, "downvotes": 0}}, "mistake2": {"hint2": {"upvotes": 0, "downvotes": 0}}}. Upvotes and downvotes can be set to desired values for varying results (e.x. set high downvotes to make new student-made hints have priority over your initial hint).
</p> </p>
<p> <p>
Initial Hints: <textarea type="text" class="csh_initial_hints" value = "{{initial}}"/> Initial Hints: <textarea type="text" class="csh_initial_hints" value = "{{initial}}"/>
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
This is the element of the problem for which the hinter is working. This is the "data-usage-id" of the problem block. It should look something like i4x://edX/DemoX/problem/f958789435cf47218ff32f0d600f1184 This is the element of the problem for which the hinter is working. This is the "data-usage-id" of the problem block. It should look something like i4x://edX/DemoX/problem/f958789435cf47218ff32f0d600f1184
</p> </p>
<p> <p>
Problem Element: <textarea type="text" class="csh_hinting_element" value = "{{hinting_element}}"/> Target Problem: <textarea type="text" class="csh_target_problem" value = "{{target_problem}}"/>
</p> </p>
<p> <p>
<input type="button" class="csh_apply_settings" value="Apply Settings"> <input type="button" class="csh_apply_settings" value="Apply Settings">
......
...@@ -88,7 +88,7 @@ function CrowdsourceHinter(runtime, element, data){ ...@@ -88,7 +88,7 @@ function CrowdsourceHinter(runtime, element, data){
/** /**
* Set the target problem for which to listen for the problem_graded event. Set target to first * Set the target problem for which to listen for the problem_graded event. Set target to first
* problem block if no hinting element has been manually entered. * problem block if no target element has been manually entered.
*/ */
if(data.target_problem == undefined || data.target_problem == ''){ if(data.target_problem == undefined || data.target_problem == ''){
//contains workaround because the data-usage-id shows up with ";_" in place of "/" in lms //contains workaround because the data-usage-id shows up with ";_" in place of "/" in lms
...@@ -145,7 +145,7 @@ function CrowdsourceHinter(runtime, element, data){ ...@@ -145,7 +145,7 @@ function CrowdsourceHinter(runtime, element, data){
* @param student_answers is the text of the student's incorrect answer * @param student_answers is the text of the student's incorrect answer
*/ */
function showStudentSubmissionHistory(student_answer){ function showStudentSubmissionHistory(student_answer){
var showStudentSubmissionTemplate = $(Mustache.render($('#show_student_submission').html(), {answer: student_answer})); var showStudentSubmissionTemplate = $(Mustache.render($('#show_student_submission').html(), {answer:student_answer}));
$('.csh_student_submission', element).append(showStudentSubmissionTemplate); $('.csh_student_submission', element).append(showStudentSubmissionTemplate);
} }
...@@ -169,7 +169,7 @@ function CrowdsourceHinter(runtime, element, data){ ...@@ -169,7 +169,7 @@ function CrowdsourceHinter(runtime, element, data){
} }
$.each(result, function(index, value) { $.each(result, function(index, value) {
if(value != "Reported"){ if(value != "Reported"){
showStudentSubmissionHistory(value); showStudentSubmissionHistory($.parseJSON(value));
student_answer = value; student_answer = value;
hint = index; hint = index;
//hints return null if no answer-specific hints exist //hints return null if no answer-specific hints exist
......
function CrowdsourceHinterStudio(runtime, element, data){ function CrowdsourceHinterStudio(runtime, element, data){
//set text area values to be what is currently in the hinter. to be replaced by above code. //set text area values to be what is currently in the hinter
$('.csh_initial_hints', element).val(data.initial); $('.csh_initial_hints', element).val(data.initial);
$('.csh_generic_hints', element).val(data.generic); $('.csh_generic_hints', element).val(data.generic);
$('.csh_hinting_element', element).val(data.element); $('.csh_target_problem', element).val(data.target_problem);
/** /**
* Apply settings for initial hints, generic hints, and the element for which the hinter is * Apply settings for initial hints, generic hints, and the element for which the hinter is
* working. * working.
*/ */
function apply_settings(){ return function(apply_settings_button){ function apply_settings(){ return function(apply_settings_button){
var initial = unescape($('.csh_initial_hints').val()); var initial = $('.csh_initial_hints').val();
var generic = unescape($('.csh_generic_hints').val()); var generic = $('.csh_generic_hints').val();
var hinting_element = unescape($('.csh_hinting_element').val()); var target_problem = $('.csh_target_problem').val();
$.ajax({ $.ajax({
type: "POST", type: "POST",
url: runtime.handlerUrl(element, 'set_initial_settings'), url: runtime.handlerUrl(element, 'set_initial_settings'),
data: JSON.stringify({"initial_hints": initial, "generic_hints": generic, "element": hinting_element}), data: JSON.stringify({"initial_hints": initial, "generic_hints": generic, "target_problem": target_problem}),
success: function(result){ success: function(result){
if(result.success){ if(result.success){
$('.csh_check_success', element).text('hints successfully added to the database'); $('.csh_check_success', element).text('hints successfully added to the database');
} else { } else {
$('.csh_check_success', element).text('there was a problem adding your hints to the database. check the format on your hints.'); $('.csh_check_success', element).text('there was a problem adding your hints to the database. check the format on your hints.');
} }
Logger.log('crowd_hinter.staff_edit_hinter', {"generic_hints": generic, "initial_hint": initial, "element": hinting_element, "successfully_set_hints": result.success}); Logger.log('crowd_hinter.staff_edit_hinter', {"generic_hints": generic, "initial_hint": initial, "target_problem": target_problem, "successfully_set_hints": result.success});
} }
}); });
}} }}
......
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