Commit e61f2c64 by solashirai

small code cleanup

parent 2de82982
......@@ -12,6 +12,7 @@ from xblock.fragment import Fragment
log = logging.getLogger(__name__)
class CrowdsourceHinter(XBlock):
"""
This is the Crowdsource Hinter XBlock. This Xblock seeks to provide students with hints
......@@ -80,7 +81,7 @@ class CrowdsourceHinter(XBlock):
"""
initial = ast.literal_eval(str(data['initial_hints']))
generic = ast.literal_eval(str(data['generic_hints']))
if(type(generic) is list and type(initial) is dict):
if type(generic) is list and type(initial) is dict:
self.initial_hints = initial
self.generic_hints = generic
self.Element = str(data['element'])
......@@ -135,9 +136,10 @@ class CrowdsourceHinter(XBlock):
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 = answer.lower() # for analyzing the student input string I make it lower case.
# put the student's answer to lower case so that differences in capitalization don't make
# different groups of hints. this is sloppy and the execution should probably be changed.
answer = answer.lower()
found_equal_sign = 0
remaining_hints = int(0)
best_hint = ""
......@@ -156,8 +158,8 @@ class CrowdsourceHinter(XBlock):
if remaining_hints != str(0):
for hint in self.hint_database[str(answer)]:
if hint not in self.reported_hints.keys():
#if best_hint hasn't been set yet or the rating of hints is greater than the rating of best_hint
if (best_hint == "" or self.hint_database[str(answer)][hint] > self.hint_database[str(answer)][str(best_hint)]):
# if best_hint hasn't been set yet or the rating of hints is greater than the rating of best_hint
if best_hint == "" or self.hint_database[str(answer)][hint] > self.hint_database[str(answer)][str(best_hint)]:
best_hint = hint
self.used.append(best_hint)
return {'BestHint': best_hint, "StudentAnswer": answer}
......@@ -180,7 +182,7 @@ class CrowdsourceHinter(XBlock):
Returns 0 if no hints to show exist
"""
isreported = []
self.incorrect_answers.append(str(answer)) # add the student's input to the temporary list
self.incorrect_answers.append(str(answer))
if str(answer) not in self.hint_database:
# add incorrect answer to hint_database if no precedent exists
self.hint_database[str(answer)] = {}
......@@ -230,8 +232,8 @@ class CrowdsourceHinter(XBlock):
self.incorrect_answers = []
self.used = []
return used_hint_answer_text
self.incorrect_answers=[]
self.used=[]
self.incorrect_answers = []
self.used = []
return used_hint_answer_text
@XBlock.json_handler
......@@ -267,7 +269,7 @@ class CrowdsourceHinter(XBlock):
# add hint to Reported dictionary
self.reported_hints[str(data_hint)] = answer_data
return {"rating": 'reported', 'hint': data_hint}
rating = self.change_rating(data_hint, data_rating, answer_data) # change hint rating
rating = self.change_rating(data_hint, data_rating, answer_data)
return {"rating": str(rating), 'hint': data_hint}
def change_rating(self, data_hint, data_rating, answer_data):
......@@ -333,7 +335,7 @@ class CrowdsourceHinter(XBlock):
</crowdsourcehinter>
</verticaldemo>
"""
),
)
]
@classmethod
......
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