Commit 17ea55ee by solashirai Committed by Piotr Mitros

added automatic setting for problem element

parent bad2ab67
...@@ -13,7 +13,7 @@ To bring the crowd sourced hinter into a demo course: ...@@ -13,7 +13,7 @@ To bring the crowd sourced hinter into a demo course:
Follow https://github.com/edx/edx-platform/wiki/Installing-a-new-XBlock for basic xblock installation. The name of the module to set in the advanced settings tab is "crowdsourcehinter". Follow https://github.com/edx/edx-platform/wiki/Installing-a-new-XBlock for basic xblock installation. The name of the module to set in the advanced settings tab is "crowdsourcehinter".
In studio view, edit the hinter so that the "Problem Element" is set to the "data-usage-id" of the problem block (findable by inspecting element of the problem block). This allows for multiple problems each with their own corresponding hinters to exist on a single page. While setting the Problem Element is crucial, the hinter can function without setting Initial hints or Generic hints. In studio view, edit the hinter so that the "Problem Element" is set to the "data-usage-id" of the problem block (findable by inspecting element of the problem block). If no problem element is set manually, the hinter will default to respond to the first problem block on the page.
![CrowdSourceHinter Installation Screenshot](crowdsourcehinter_setup.png) ![CrowdSourceHinter Installation Screenshot](crowdsourcehinter_setup.png)
......
...@@ -36,7 +36,7 @@ class CrowdsourceHinter(XBlock): ...@@ -36,7 +36,7 @@ class CrowdsourceHinter(XBlock):
# student's incorrect answer within the hint_database dictionary (i.e. no students have made hints for the # student's incorrect answer within the hint_database dictionary (i.e. no students have made hints for the
# particular incorrect answer) # particular incorrect answer)
# #
# Example: ["Make sure to check your answer for simple mistakes, like spelling or spaces!"] # Example: ["Make sure to check your answer for simple mistakes like typos!"]
generic_hints = List(default=[], scope=Scope.content) generic_hints = List(default=[], scope=Scope.content)
# List of which hints have been shown to the student # List of which hints have been shown to the student
# this list is used to prevent the same hint from showing up to a student (if they submit the same incorrect answers # this list is used to prevent the same hint from showing up to a student (if they submit the same incorrect answers
...@@ -106,6 +106,10 @@ class CrowdsourceHinter(XBlock): ...@@ -106,6 +106,10 @@ class CrowdsourceHinter(XBlock):
return True return True
return False return False
@XBlock.json_handler
def auto_set_problem_element(self, data, suffix=''):
self.Element = str(data["hintingElement"])
def resource_string(self, path): def resource_string(self, path):
""" """
This function is used to get the path of static resources. This function is used to get the path of static resources.
...@@ -146,9 +150,10 @@ class CrowdsourceHinter(XBlock): ...@@ -146,9 +150,10 @@ class CrowdsourceHinter(XBlock):
returns: returns:
'BestHint': the highest rated hint for an incorrect answer 'BestHint': the highest rated hint for an incorrect answer
or another random hint for an incorrect answer or another random hint for an incorrect answer
or 'Sorry, there are no more hints for this answer.' if no more hints exist or 'Sorry, there are no hints for this answer.' if no hints exist
'StudentAnswer': the student's incorrect answer 'StudentAnswer': the student's incorrect answer
""" """
# 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):
...@@ -273,6 +278,8 @@ class CrowdsourceHinter(XBlock): ...@@ -273,6 +278,8 @@ class CrowdsourceHinter(XBlock):
answer_data = data['student_answer'] answer_data = data['student_answer']
data_rating = data['student_rating'] data_rating = data['student_rating']
data_hint = data['hint'] data_hint = data['hint']
if data_hint == 'Sorry, there are no hints for this answer.':
return {"rating": None, 'hint': data_hint}
if data['student_rating'] == 'unreport': if data['student_rating'] == 'unreport':
for reported_hints in self.reported_hints: for reported_hints in self.reported_hints:
if reported_hints == data_hint: if reported_hints == data_hint:
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
Initial Hints: <textarea type="text" class="csh_initial_hints" value = "{{initial}}"/> Initial Hints: <textarea type="text" class="csh_initial_hints" value = "{{initial}}"/>
</p> </p>
<p> <p>
This is the element of the problem for which the hinter is working. This is the "data-usage-id" of the problem block. e.x. i4x://edX/DemoX/problem/Text_Input 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}}"/> Problem Element: <textarea type="text" class="csh_hinting_element" value = "{{hinting_element}}"/>
......
...@@ -2,6 +2,8 @@ function CrowdsourceHinter(runtime, element, data){ ...@@ -2,6 +2,8 @@ function CrowdsourceHinter(runtime, element, data){
var onHinterPage = true; //We don't do hinter logic if we're on a differ tab in a sequential. var onHinterPage = true; //We don't do hinter logic if we're on a differ tab in a sequential.
var problemElement = '';
$(".crowdsourcehinter_block", element).hide(); $(".crowdsourcehinter_block", element).hide();
if(!onHinterPage){ if(!onHinterPage){
...@@ -22,7 +24,7 @@ function CrowdsourceHinter(runtime, element, data){ ...@@ -22,7 +24,7 @@ function CrowdsourceHinter(runtime, element, data){
Logger.listen('seq_goto', null, stopScript); Logger.listen('seq_goto', null, stopScript);
/** /**
* Get a hint from the server to show to the student after incorrectly answering a * Get a hint from the server to show to the student after inc-orrectly answering a
* question. On success, continue to showHint. * question. On success, continue to showHint.
* @param problemGradedEvent is data generated by the problem_graded event * @param problemGradedEvent is data generated by the problem_graded event
*/ */
...@@ -85,11 +87,18 @@ function CrowdsourceHinter(runtime, element, data){ ...@@ -85,11 +87,18 @@ function CrowdsourceHinter(runtime, element, data){
getHint(data); getHint(data);
} }
}} }}
//IMPORTANT
//Comment out the listener for "problem_check" and uncomment "problem_graded" on the lavash devstack release. /**
//problem_check is used in the birch release to detect answer submission * Set the target problem for which to listen for the problem_graded event. Set target to first
//Logger.listen('problem_check', null, onStudentSubmission()); * problem block if no hinting element has been manually entered.
Logger.listen('problem_graded', data.hinting_element, onStudentSubmission()); */
if(data.hinting_element == undefined || data.hinting_element == ''){
hintingElement = ($('.xblock[data-block-type="problem"]').first().attr('data-usage-id')).replace(/;_/g, '/');
} else {
hintingElement = data.hinting_element;
}
Logger.listen('problem_graded', hintingElement, onStudentSubmission());
/** /**
* Modify csh_hint_text attributes to show hint to the student. * Modify csh_hint_text attributes to show hint to the student.
......
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