Commit 500b4baa by solashirai Committed by Piotr Mitros

added parsexml

parent 9e40db62
...@@ -21,7 +21,6 @@ class CrowdsourceHinter(XBlock): ...@@ -21,7 +21,6 @@ class CrowdsourceHinter(XBlock):
""" """
# Database of hints. hints are stored as such: {"incorrect_answer": {"hint": rating}}. each key (incorrect answer) # Database of hints. hints are stored as such: {"incorrect_answer": {"hint": rating}}. each key (incorrect answer)
# has a corresponding dictionary (in which hints are keys and the hints' ratings are the values). # has a corresponding dictionary (in which hints are keys and the hints' ratings are the values).
# TODO: Remove default values once done testing
hint_database = Dict(default={}, scope=Scope.user_state_summary) hint_database = Dict(default={}, scope=Scope.user_state_summary)
# 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
# feedback, to find which incorrect answer's hint a student voted on. # feedback, to find which incorrect answer's hint a student voted on.
...@@ -29,7 +28,8 @@ class CrowdsourceHinter(XBlock): ...@@ -29,7 +28,8 @@ class CrowdsourceHinter(XBlock):
# A dictionary of default hints. default hints will be shown to students when there are no matches with the # A dictionary of default hints. default hints will be shown to students when there are no matches with the
# 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)
DefaultHints = Dict(default={}, scope=Scope.content) #
DefaultHints = 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
# multiple times) # multiple times)
...@@ -154,11 +154,8 @@ class CrowdsourceHinter(XBlock): ...@@ -154,11 +154,8 @@ class CrowdsourceHinter(XBlock):
self.Used.append(not_used) self.Used.append(not_used)
return {'HintsToUse': not_used, "StudentAnswer": answer} return {'HintsToUse': not_used, "StudentAnswer": answer}
else: else:
temporary_hints_list = [] if len(self.DefaultHints) != 0:
for hint_keys in self.DefaultHints: not_used = random.choice(self.DefaultHints)
temporary_hints_list.append(str(hint_keys))
if len(temporary_hints_list) != 0:
not_used = random.choice(temporary_hints_list)
self.Used.append(not_used) self.Used.append(not_used)
return {'HintsToUse': not_used, "StudentAnswer": answer} return {'HintsToUse': not_used, "StudentAnswer": answer}
else: else:
...@@ -259,6 +256,7 @@ class CrowdsourceHinter(XBlock): ...@@ -259,6 +256,7 @@ class CrowdsourceHinter(XBlock):
hint_rating['student_answer'] = data['student_answer'] hint_rating['student_answer'] = data['student_answer']
hint_rating['hint'] = data['hint'] hint_rating['hint'] = data['hint']
print(hint_rating) print(hint_rating)
print(str(self.hint_database))
return hint_rating return hint_rating
@XBlock.json_handler @XBlock.json_handler
...@@ -329,15 +327,15 @@ class CrowdsourceHinter(XBlock): ...@@ -329,15 +327,15 @@ class CrowdsourceHinter(XBlock):
else: else:
temporary_dictionary[str(data_hint)] -= 1 temporary_dictionary[str(data_hint)] -= 1
self.hint_database[str(answer_data)] = temporary_dictionary self.hint_database[str(answer_data)] = temporary_dictionary
print(self.hint_database) print(str(self.hint_database))
return str(temporary_dictionary[str(data_hint)]) return str(temporary_dictionary[str(data_hint)])
@XBlock.json_handler @XBlock.json_handler
def moderate_hint(self, data, suffix=''): def moderate_hint(self, data, suffix=''):
""" """
UNDER CONSTRUCTION, intended to be used for instructors to remove hints from the database after hints Under construction?
have been flagged.
""" """
print("this is being used")
flagged_hints = {} flagged_hints = {}
flagged_hints = self.Flagged flagged_hints = self.Flagged
if data['rating'] == "dismiss": if data['rating'] == "dismiss":
...@@ -372,17 +370,18 @@ class CrowdsourceHinter(XBlock): ...@@ -372,17 +370,18 @@ class CrowdsourceHinter(XBlock):
# self.hint_database equal to it due to being unable to directly # self.hint_database equal to it due to being unable to directly
# edit self.hint_databse. Most likely scope error # edit self.hint_databse. Most likely scope error
self.hint_database[str(answer)] = temporary_dictionary self.hint_database[str(answer)] = temporary_dictionary
print(str(self.hint_database))
return return
else: else:
# if the hint exists already, simply upvote the previously entered hint # if the hint exists already, simply upvote the previously entered hint
if str(submission) in self.DefaultHints: if str(submission) in self.DefaultHints:
self.DefaultHints[str(submission)] += 1
return return
else: else:
temporary_dictionary = str(self.hint_database[str(answer)]) temporary_dictionary = str(self.hint_database[str(answer)])
temporary_dictionary = (ast.literal_eval(temporary_dictionary)) temporary_dictionary = (ast.literal_eval(temporary_dictionary))
temporary_dictionary[str(submission)] += 1 temporary_dictionary[str(submission)] += 1
self.hint_database[str(answer)] = temporary_dictionary self.hint_database[str(answer)] = temporary_dictionary
print(str(self.hint_database))
return return
@XBlock.json_handler @XBlock.json_handler
...@@ -410,9 +409,6 @@ class CrowdsourceHinter(XBlock): ...@@ -410,9 +409,6 @@ class CrowdsourceHinter(XBlock):
""" """
A minimal working test for parse_xml A minimal working test for parse_xml
""" """
print("parse xml is working")
block = runtime.construct_xblock_from_class(cls, keys) block = runtime.construct_xblock_from_class(cls, keys)
print node.text, (node.text == "Hello!") block.DefaultHints = ["Make sure to check your answer for basic mistakes like spelling!"]
block.show_best = (node.text == "Hello!")
block.hint_databawse = {"answer": {"xml test hint": 3}}
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