Commit ee466418 by solashirai Committed by Piotr Mitros

fixed xml, fixed initial hint setting

parent 387171bc
...@@ -23,9 +23,10 @@ class CrowdsourceHinter(XBlock): ...@@ -23,9 +23,10 @@ class CrowdsourceHinter(XBlock):
# #
# Example: {"computerr": {"You misspelled computer, remove the last r.": 5}} # Example: {"computerr": {"You misspelled computer, remove the last r.": 5}}
hint_database = Dict(default={}, scope=Scope.user_state_summary) hint_database = Dict(default={}, scope=Scope.user_state_summary)
# Database of initial hints, set by the course instructor. If initial hints are set by the instructor, hint_database's contents # Database of initial hints, set by the course instructor. hint_database will receive the hints inputted
# will become identical to initial_hints. The datastructure for initial_hints is the same as for hint_databsae, # in initial_hints. Initial hints have a default rating of 0.
# {"incorrect_answer": {"hint": rating}} #
# Example: {"Jeorge Washington": "You spelled his first name wrong."}
initial_hints = Dict(default={}, scope=Scope.content) initial_hints = Dict(default={}, scope=Scope.content)
# This is a list of incorrect answer submissions made by the student. this list is mostly used for # This is a list of incorrect answer submissions made by the student. this list is mostly used for
# when the student starts rating hints, to find which incorrect answer's hint a student voted on. # when the student starts rating hints, to find which incorrect answer's hint a student voted on.
...@@ -79,33 +80,13 @@ class CrowdsourceHinter(XBlock): ...@@ -79,33 +80,13 @@ class CrowdsourceHinter(XBlock):
""" """
initial = ast.literal_eval(str(data['initial_hints'])) initial = ast.literal_eval(str(data['initial_hints']))
generic = ast.literal_eval(str(data['generic_hints'])) generic = ast.literal_eval(str(data['generic_hints']))
if self.check_valid_settings(initial, generic): if(type(generic) is list and type(initial) is dict):
self.initial_hints = initial self.initial_hints = initial
self.generic_hints = generic self.generic_hints = generic
self.Element = str(data['element']) self.Element = str(data['element'])
return {'success': True} return {'success': True}
return {'success': False} return {'success': False}
def check_valid_settings(self, initial, generic):
"""
Check the settings being applied to the hinter by the staff to make sure they are
in the correct format.
Args:
initial: the hints attempted to be set for self.initial_hints
generic: the hints attempted to be set for self.generic_hints
returns:
True if generic is a list and initial is a dict and contains proper
answer-hint-rating format
"""
if(type(generic) is list and type(initial) is dict):
for answer in initial:
if (type(initial[answer]) is not dict):
return False
return True
return False
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.
...@@ -139,21 +120,22 @@ class CrowdsourceHinter(XBlock): ...@@ -139,21 +120,22 @@ class CrowdsourceHinter(XBlock):
""" """
Returns hints to students. Hints with the highest rating are shown to students unless the student has already Returns hints to students. Hints with the highest rating are shown to students unless the student has already
submitted the same incorrect answer previously. submitted the same incorrect answer previously.
Args: Args:
data['submittedanswer']: The string of text that the student submits for a problem. data['submittedanswer']: The string of text that the student submits for a problem.
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 hints for this answer.' if no 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): for answers in self.initial_hints:
self.hint_database = copy.copy(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})
#self.hint_database = copy.copy(self.initial_hints)
answer = str(data["submittedanswer"]) answer = str(data["submittedanswer"])
answer = answer.lower() # for analyzing the student input string I make it lower case. answer = answer.lower() # for analyzing the student input string I make it lower case.
found_equal_sign = 0 found_equal_sign = 0
...@@ -193,10 +175,8 @@ class CrowdsourceHinter(XBlock): ...@@ -193,10 +175,8 @@ class CrowdsourceHinter(XBlock):
""" """
This function is used to check that an incorrect answer has available hints to show. This function is used to check that an incorrect answer has available hints to show.
It will also add the incorrect answer test to self.incorrect_answers. It will also add the incorrect answer test to self.incorrect_answers.
Args: Args:
answer: This is equal to answer from get_hint, the answer the student submitted answer: This is equal to answer from get_hint, the answer the student submitted
Returns 0 if no hints to show exist Returns 0 if no hints to show exist
""" """
isreported = [] isreported = []
...@@ -221,7 +201,6 @@ class CrowdsourceHinter(XBlock): ...@@ -221,7 +201,6 @@ class CrowdsourceHinter(XBlock):
Specifically this function is used to send necessary data to JS about incorrect answer Specifically this function is used to send necessary data to JS about incorrect answer
submissions and hints. It also will return hints that have been reported, although this submissions and hints. It also will return hints that have been reported, although this
is only for Staff. is only for Staff.
Returns: Returns:
used_hint_answer_text: This dicitonary contains reported hints/answers (if the user is staff) and the used_hint_answer_text: This dicitonary contains reported hints/answers (if the user is staff) and the
first hint/answer pair that the student submitted for a problem. first hint/answer pair that the student submitted for a problem.
...@@ -232,8 +211,6 @@ class CrowdsourceHinter(XBlock): ...@@ -232,8 +211,6 @@ class CrowdsourceHinter(XBlock):
# corresponding incorrect answer # corresponding incorrect answer
used_hint_answer_text = {} used_hint_answer_text = {}
if self.get_user_is_staff(): if self.get_user_is_staff():
print len(self.reported_hints)
print str(self.reported_hints)
for key in self.reported_hints: for key in self.reported_hints:
used_hint_answer_text[key] = str("Reported") used_hint_answer_text[key] = str("Reported")
if len(self.incorrect_answers) == 0: if len(self.incorrect_answers) == 0:
...@@ -261,14 +238,11 @@ class CrowdsourceHinter(XBlock): ...@@ -261,14 +238,11 @@ class CrowdsourceHinter(XBlock):
def rate_hint(self, data, suffix=''): def rate_hint(self, data, suffix=''):
""" """
Used to facilitate hint rating by students. Used to facilitate hint rating by students.
Hint ratings in hint_database are updated and the resulting hint rating (or reported status) is returned to JS. Hint ratings in hint_database are updated and the resulting hint rating (or reported status) is returned to JS.
Args: Args:
data['student_answer']: The incorrect answer that corresponds to the hint that is being rated data['student_answer']: The incorrect answer that corresponds to the hint that is being rated
data['hint']: The hint that is being rated data['hint']: The hint that is being rated
data['student_rating']: The rating chosen by the student. data['student_rating']: The rating chosen by the student.
Returns: Returns:
'rating': the new rating of the hint, or the string 'reported' if the hint was reported 'rating': the new rating of the hint, or the string 'reported' if the hint was reported
'hint': the hint that had its rating changed 'hint': the hint that had its rating changed
...@@ -301,12 +275,10 @@ class CrowdsourceHinter(XBlock): ...@@ -301,12 +275,10 @@ class CrowdsourceHinter(XBlock):
This function is used to change the rating of a hint when students vote on its helpfulness. This function is used to change the rating of a hint when students vote on its helpfulness.
Initiated by rate_hint. The temporary_dictionary is manipulated to be used Initiated by rate_hint. The temporary_dictionary is manipulated to be used
in self.rate_hint in self.rate_hint
Args: Args:
data_hint: This is equal to the data['hint'] in self.rate_hint data_hint: This is equal to the data['hint'] in self.rate_hint
data_rating: This is equal to the data['student_rating'] in self.rate_hint data_rating: This is equal to the data['student_rating'] in self.rate_hint
answer_data: This is equal to the data['student_answer'] in self.rate_hint answer_data: This is equal to the data['student_answer'] in self.rate_hint
Returns: Returns:
The rating associated with the hint is returned. This rating is identical The rating associated with the hint is returned. This rating is identical
to what would be found under self.hint_database[answer_string[hint_string]] to what would be found under self.hint_database[answer_string[hint_string]]
...@@ -324,7 +296,6 @@ class CrowdsourceHinter(XBlock): ...@@ -324,7 +296,6 @@ class CrowdsourceHinter(XBlock):
def add_new_hint(self, data, suffix=''): def add_new_hint(self, data, suffix=''):
""" """
This function adds a new hint submitted by the student into the hint_database. This function adds a new hint submitted by the student into the hint_database.
Args: Args:
data['submission']: This is the text of the new hint that the student has submitted. data['submission']: This is the text of the new hint that the student has submitted.
data['answer']: This is the incorrect answer for which the student is submitting a new hint. data['answer']: This is the incorrect answer for which the student is submitting a new hint.
...@@ -358,7 +329,7 @@ class CrowdsourceHinter(XBlock): ...@@ -358,7 +329,7 @@ class CrowdsourceHinter(XBlock):
""" """
<verticaldemo> <verticaldemo>
<crowdsourcehinter> <crowdsourcehinter>
{"generic_hints": "Make sure to check for basic mistakes like typos", "initial_hints": {"michiganp": {"remove the p at the end", 0}, "michigann": {"too many Ns on there": 0}}, "hinting_element": "i4x://edX/DemoX/problem/Text_Input"} {"generic_hints": "Make sure to check for basic mistakes like typos", "initial_hints": {"michiganp": "remove the p at the end."}, "michigann": "too many Ns on there."}, "hinting_element": "i4x://edX/DemoX/problem/Text_Input"}
</crowdsourcehinter> </crowdsourcehinter>
</verticaldemo> </verticaldemo>
""" """
...@@ -372,7 +343,8 @@ class CrowdsourceHinter(XBlock): ...@@ -372,7 +343,8 @@ class CrowdsourceHinter(XBlock):
""" """
block = runtime.construct_xblock_from_class(cls, keys) block = runtime.construct_xblock_from_class(cls, keys)
xmlText = ast.literal_eval(str(node.text)) xmlText = ast.literal_eval(str(node.text))
block.generic_hints.append(str(xmlText["generic_hints"])) if xmlText:
block.initial_hints = copy.copy(xmlText["initial_hints"]) block.generic_hints.append(str(xmlText["generic_hints"]))
block.Element = str(xmlText["hinting_element"]) block.initial_hints = copy.copy(xmlText["initial_hints"])
block.Element = str(xmlText["hinting_element"])
return block return block
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