Commit 87b53fbe by solashirai

Merge pull request #6 from solashirai/sola/working

Sola/working
parents 132ad676 eecc234b
......@@ -5,6 +5,7 @@ import random
import json
import copy
import urllib
import HTMLParser
from xblock.core import 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_css(self.resource_string("static/css/crowdsourcehinter.css"))
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',
{'initial': self.initial_hints,
'generic': self.generic_hints,
{'initial': json.dumps(self.initial_hints),
'generic': json.dumps(self.generic_hints),
'target_problem': self.target_problem})
return frag
......@@ -127,7 +127,6 @@ class CrowdsourceHinter(XBlock):
self.initial_hints = initial_hints
self.generic_hints = generic_hints
print type(data['target_problem'])
if len(data['target_problem']) > 1:
self.target_problem = data['target_problem']
return {'success': True}
......@@ -157,7 +156,7 @@ class CrowdsourceHinter(XBlock):
# First, we split this into the submission
answers = [a.split('=') for a in answers.split("&")]
# 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)
@XBlock.json_handler
......@@ -186,8 +185,9 @@ class CrowdsourceHinter(XBlock):
for answers in self.initial_hints:
if answers not in self.hint_database:
self.hint_database[answers] = {}
if self.initial_hints[answers] not in self.hint_database[answers]:
self.hint_database[answers].update({self.initial_hints[answers]: 0})
for hints in self.initial_hints[answers]:
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"])
......@@ -283,14 +283,13 @@ class CrowdsourceHinter(XBlock):
if len(self.incorrect_answers) == 0:
return used_hint_answer_text
else:
for index in range(0, len(self.used)):
# each index is a hint that was used, in order of usage
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)
used_hint_answer_text[self.used[index]] = self.incorrect_answers[index]
else:
# if the student's answer had no hints (or all the hints were reported and unavailable) return None
used_hint_answer_text[None] = self.incorrect_answers[index]
# for the time being only the first answer/hint pair will be shown to the studen
if self.used[0] in self.hint_database[self.incorrect_answers[0]]:
# 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])
else:
# 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])
self.incorrect_answers = []
self.used = []
return used_hint_answer_text
......
......@@ -6,7 +6,7 @@
Generic Hints: <textarea type="text" class="csh_generic_hints" value = "{{generic}}"/>
</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>
Initial Hints: <textarea type="text" class="csh_initial_hints" value = "{{initial}}"/>
......@@ -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
</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>
<input type="button" class="csh_apply_settings" value="Apply Settings">
......
......@@ -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
* 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 == ''){
//contains workaround because the data-usage-id shows up with ";_" in place of "/" in lms
......@@ -145,7 +145,7 @@ function CrowdsourceHinter(runtime, element, data){
* @param student_answers is the text of the student's incorrect 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);
}
......@@ -169,7 +169,7 @@ function CrowdsourceHinter(runtime, element, data){
}
$.each(result, function(index, value) {
if(value != "Reported"){
showStudentSubmissionHistory(value);
showStudentSubmissionHistory($.parseJSON(value));
student_answer = value;
hint = index;
//hints return null if no answer-specific hints exist
......
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_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
* working.
*/
function apply_settings(){ return function(apply_settings_button){
var initial = unescape($('.csh_initial_hints').val());
var generic = unescape($('.csh_generic_hints').val());
var hinting_element = unescape($('.csh_hinting_element').val());
var initial = $('.csh_initial_hints').val();
var generic = $('.csh_generic_hints').val();
var target_problem = $('.csh_target_problem').val();
$.ajax({
type: "POST",
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){
if(result.success){
$('.csh_check_success', element).text('hints successfully added to the database');
} else {
$('.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