Commit 16876f5a by Sola

no longer crash when hints run dry (gives "no more hints" instead)

parent e306997a
...@@ -60,11 +60,11 @@ class CrowdXBlock(XBlock): ...@@ -60,11 +60,11 @@ class CrowdXBlock(XBlock):
return {'HintsToUse': max(self.HintsToUse.iteritems(), key=operator.itemgetter(1))[0]} return {'HintsToUse': max(self.HintsToUse.iteritems(), key=operator.itemgetter(1))[0]}
else: else:
NotUsed = random.choice(self.HintsToUse.keys()) NotUsed = random.choice(self.HintsToUse.keys())
if len(self.HintsToUse) != len(self.Used): if len(self.HintsToUse) > len(self.Used):
while NotUsed in self.Used: while NotUsed in self.Used:
NotUsed = random.choice(self.HintsToUse.keys()) #Choose random hint that hasn't already been Used NotUsed = random.choice(self.HintsToUse.keys()) #Choose random hint that hasn't already been Used
elif len(self.Used) > 0: elif len(self.Used) > 0:
return {'HintsToUse': random.choice(self.HintsToUse.keys())} return {'HintsToUse': "Sorry, there are no more hints for this answer."}
self.Used.append(NotUsed) self.Used.append(NotUsed)
return {'HintsToUse': NotUsed} #note to self dont let python get into endless notused loop return {'HintsToUse': NotUsed} #note to self dont let python get into endless notused loop
...@@ -147,8 +147,6 @@ class CrowdXBlock(XBlock): ...@@ -147,8 +147,6 @@ class CrowdXBlock(XBlock):
data['id'] = data['id'].replace('ddeecciimmaallppooiinntt', '.') data['id'] = data['id'].replace('ddeecciimmaallppooiinntt', '.')
if self.Voted == 0: if self.Voted == 0:
for key in self.hints: for key in self.hints:
print(str(key))
print("still working here")
if str(key) == self.WrongAnswers[self.Used.index(str(data['id']))]: if str(key) == self.WrongAnswers[self.Used.index(str(data['id']))]:
if str(data['submission']) not in self.hints[str(key)]: if str(data['submission']) not in self.hints[str(key)]:
tempdict = str(self.hints[str(key)]) #rate hint that is in hints tempdict = str(self.hints[str(key)]) #rate hint that is in hints
......
...@@ -60,11 +60,11 @@ class CrowdXBlock(XBlock): ...@@ -60,11 +60,11 @@ class CrowdXBlock(XBlock):
return {'HintsToUse': max(self.HintsToUse.iteritems(), key=operator.itemgetter(1))[0]} return {'HintsToUse': max(self.HintsToUse.iteritems(), key=operator.itemgetter(1))[0]}
else: else:
NotUsed = random.choice(self.HintsToUse.keys()) NotUsed = random.choice(self.HintsToUse.keys())
if len(self.HintsToUse) != len(self.Used): if len(self.HintsToUse) > len(self.Used):
while NotUsed in self.Used: while NotUsed in self.Used:
NotUsed = random.choice(self.HintsToUse.keys()) #Choose random hint that hasn't already been Used NotUsed = random.choice(self.HintsToUse.keys()) #Choose random hint that hasn't already been Used
elif len(self.Used) > 0: elif len(self.Used) > 0:
return {'HintsToUse': random.choice(self.HintsToUse.keys())} return {'HintsToUse': "Sorry, there are no more hints."}
self.Used.append(NotUsed) self.Used.append(NotUsed)
return {'HintsToUse': NotUsed} #note to self dont let python get into endless notused loop return {'HintsToUse': NotUsed} #note to self dont let python get into endless notused loop
...@@ -144,11 +144,9 @@ class CrowdXBlock(XBlock): ...@@ -144,11 +144,9 @@ class CrowdXBlock(XBlock):
@XBlock.json_handler @XBlock.json_handler
def give_hint(self, data, suffix=''): #add student-made hint into hints def give_hint(self, data, suffix=''): #add student-made hint into hints
data['submission'] = data['submission'].replace('ddeecciimmaallppooiinntt', '.') data['submission'] = data['submission'].replace('ddeecciimmaallppooiinntt', '.')
data['id'] = data['id'].replace('qquueessttiioonnmmaarrkk', '?') data['id'] = data['id'].replace('ddeecciimmaallppooiinntt', '.')
if self.Voted == 0: if self.Voted == 0:
for key in self.hints: for key in self.hints:
print(str(key))
print("still working here")
if str(key) == self.WrongAnswers[self.Used.index(str(data['id']))]: if str(key) == self.WrongAnswers[self.Used.index(str(data['id']))]:
if str(data['submission']) not in self.hints[str(key)]: if str(data['submission']) not in self.hints[str(key)]:
tempdict = str(self.hints[str(key)]) #rate hint that is in hints tempdict = str(self.hints[str(key)]) #rate hint that is in hints
......
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