Commit b1842e38 by Sola Committed by Piotr Mitros

removed HintsToUse

parent 5d62edf6
...@@ -95,7 +95,7 @@ class CrowdXBlock(XBlock): ...@@ -95,7 +95,7 @@ class CrowdXBlock(XBlock):
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
hints_used = 0 remaining_hints = int(0)
# the string returned by the event problem_graded is very messy and is different # the string returned by the event problem_graded is very messy and is different
# for each problem, but after all of the numbers/letters there is an equal sign, after which the # for each problem, but after all of the numbers/letters there is an equal sign, after which the
# student's input is shown. I use the function below to remove everything before the first equal # student's input is shown. I use the function below to remove everything before the first equal
...@@ -105,33 +105,39 @@ class CrowdXBlock(XBlock): ...@@ -105,33 +105,39 @@ class CrowdXBlock(XBlock):
found_equal_sign = 1 found_equal_sign = 1
eqplace = answer.index("=") + 1 eqplace = answer.index("=") + 1
answer = answer[eqplace:] answer = answer[eqplace:]
self.find_hints(answer) remaining_hints = int(self.find_hints(answer))
# add hints to the self.HintsToUse dictionary. Will likely be replaced if remaining_hints != int(0):
# soon by simply looking within the self.hint_database for hints. if max(self.hint_database[str(answer)].iteritems(), key=operator.itemgetter(1))[0] not in self.Used:
if str(answer) not in self.hint_database: # choose highest rated hint for the incorrect answer
# add incorrect answer to hint_database if no precedent exists if max(self.hint_database[str(answer)].iteritems(), key=operator.itemgetter(1))[0] not in self.Flagged.keys():
self.hint_database[str(answer)] = {} self.Used.append(max(self.hint_database[str(answer)].iteritems(), key=operator.itemgetter(1))[0])
self.HintsToUse.clear() return {'HintsToUse': max(self.hint_database[str(answer)].iteritems(), key=operator.itemgetter(1))[0]}
self.HintsToUse.update(self.DefaultHints) else:
if max(self.HintsToUse.iteritems(), key=operator.itemgetter(1))[0] not in self.Used: # choose another random hint for the answer.
# choose highest rated hint for the incorrect answer temporary_hints_list = []
if max(self.HintsToUse.iteritems(), key=operator.itemgetter(1))[0] not in self.Flagged.keys(): for hint_keys in self.hint_database[str(answer)]:
self.Used.append(max(self.HintsToUse.iteritems(), key=operator.itemgetter(1))[0]) if hint_keys not in self.Used and hint_keys not in self.Flagged:
return {'HintsToUse': max(self.HintsToUse.iteritems(), key=operator.itemgetter(1))[0]} temporary_hints_list.append(str(hint_keys))
not_used = random.choice(temporary_hints_list)
else: else:
# choose another random hint for the answer. if max(self.DefaultHints.iteritems(), key=operator.itemgetter(1))[0] not in self.Used:
temporary_hints_list = [] # choose highest rated hint for the incorrect answer
for hint_keys in self.HintsToUse: if max(self.DefaultHints.iteritems(), key=operator.itemgetter(1))[0] not in self.Flagged.keys():
if hint_keys not in self.Used and hint_keys not in self.Flagged: self.Used.append(max(self.DefaultHints.iteritems(), key=operator.itemgetter(1))[0])
temporary_hints_list.append(str(hint_keys)) return {'HintsToUse': max(self.DefaultHints.iteritems(), key=operator.itemgetter(1))[0]}
if len(temporary_hints_list) != 0:
not_used = random.choice(temporary_hints_list)
else: else:
# if there are no more hints left in either the database or defaults temporary_hitns_list = []
self.Used.append(str("There are no hints for" + " " + answer)) for hint_keys in self.DefaultHints:
return {'HintsToUse': "Sorry, there are no more hints for this answer."} if hint_keys not in self.Used:
self.Used.append(not_used) temporary_hints_list.append(str(hint_keys))
return {'HintsToUse': not_used} if len(temporary_hints_list) != 0:
not_used = random.choice(temporary_hints_list)
else:
# if there are no more hints left in either the database or defaults
self.Used.append(str("There are no hints for" + " " + answer))
return {'HintsToUse': "Sorry, there are no more hints for this answer."}
self.Used.append(not_used)
return {'HintsToUse': not_used}
def find_hints(self, answer): def find_hints(self, answer):
""" """
...@@ -141,28 +147,25 @@ class CrowdXBlock(XBlock): ...@@ -141,28 +147,25 @@ class CrowdXBlock(XBlock):
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
""" """
hints_exist = 0
isflagged = [] isflagged = []
isused = 0
self.WrongAnswers.append(str(answer)) # add the student's input to the temporary list, for later use self.WrongAnswers.append(str(answer)) # add the student's input to the temporary list, for later use
for answer_keys in self.hint_database: # add hints to the self.HintsToUse dictionary. Will likely be replaced
# look through answer keys to find a match with the student's answer, and add # soon by simply looking within the self.hint_database for hints.
# the hints that exist for said answer into the HintsToUse dict. if str(answer) not in self.hint_database:
hints = str(self.hint_database[str(answer_keys)]) # add incorrect answer to hint_database if no precedent exists
if str(answer_keys) == str(answer): self.hint_database[str(answer)] = {}
self.HintsToUse.clear() return str(0)
self.HintsToUse.update(ast.literal_eval(hints)) for hint_keys in self.hint_database[str(answer)]:
for hint_keys in self.HintsToUse:
for flagged_keys in self.Flagged: for flagged_keys in self.Flagged:
if str(hint_keys) == str(flagged_keys): if str(hint_keys) == str(flagged_keys):
isflagged.append(hint_keys) isflagged.append(hint_keys)
for flagged_keys in isflagged: if str(hint_keys) in self.Used:
# remove flagged keys from the HintsToUse isused += 1
del self.HintsToUse[flagged_keys] if (len(self.hint_database[str(answer)]) - len(isflagged) - isused) > 0:
for answer_keys in self.HintsToUse: return str(1)
if answer_keys not in self.Used: else:
hints_exist = 1 return str(0)
if hints_exist == 0:
self.HintsToUse.update(self.DefaultHints)
@XBlock.json_handler @XBlock.json_handler
def get_feedback(self, data, suffix=''): def get_feedback(self, data, suffix=''):
......
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