Commit 169f86cb by solashirai

progress of fixing issues

parent 58e51cdd
...@@ -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)
frag.initialize_js('CrowdsourceHinterStudio', frag.initialize_js('CrowdsourceHinterStudio',
{'initial': str(self.initial_hints), {'initial': json.dumps(self.initial_hints),
'generic': str(self.generic_hints), 'generic': json.dumps(self.generic_hints),
'target_problem': self.target_problem}) 'target_problem': self.target_problem})
return frag return frag
...@@ -126,11 +126,7 @@ class CrowdsourceHinter(XBlock): ...@@ -126,11 +126,7 @@ class CrowdsourceHinter(XBlock):
'error' : 'Initial hints should be a dict.'} 'error' : 'Initial hints should be a dict.'}
self.initial_hints = initial_hints self.initial_hints = initial_hints
for answers in self.initial_hints:
for hints in self.initial_hints[answers]:
self.initial_hints[answers][hints] = {"upvotes": 0, "downvotes": 0}
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}
...@@ -160,7 +156,8 @@ class CrowdsourceHinter(XBlock): ...@@ -160,7 +156,8 @@ 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]
print answers
return dict(answers) return dict(answers)
@XBlock.json_handler @XBlock.json_handler
...@@ -189,8 +186,9 @@ class CrowdsourceHinter(XBlock): ...@@ -189,8 +186,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]: {"upvotes": 0, "downvotes": 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"])
...@@ -286,16 +284,16 @@ class CrowdsourceHinter(XBlock): ...@@ -286,16 +284,16 @@ 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[self.used[0]] = 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] = self.incorrect_answers[0]
used_hint_answer_text[None] = self.incorrect_answers[index]
self.incorrect_answers = [] self.incorrect_answers = []
self.used = [] self.used = []
print used_hint_answer_text
return used_hint_answer_text return used_hint_answer_text
@XBlock.json_handler @XBlock.json_handler
...@@ -361,6 +359,7 @@ class CrowdsourceHinter(XBlock): ...@@ -361,6 +359,7 @@ class CrowdsourceHinter(XBlock):
""" """
submission = data['new_hint_submission'] submission = data['new_hint_submission']
answer = data['answer'] answer = data['answer']
print answer, submission
# If we don't have the hint already, add it # If we don't have the hint already, add it
if submission not in self.hint_database[answer]: if submission not in self.hint_database[answer]:
......
...@@ -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}}"/>
......
...@@ -170,7 +170,7 @@ function CrowdsourceHinter(runtime, element, data){ ...@@ -170,7 +170,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(value);
student_answer = value; student_answer = encodeURI(value);
hint = index; hint = index;
//hints return null if no answer-specific hints exist //hints return null if no answer-specific hints exist
if(hint === "null") { if(hint === "null") {
......
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_target_problem', element).val(data.target_problem); $('.csh_target_problem', element).val(data.target_problem);
......
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