Commit d5d88a6a by Sola Committed by Piotr Mitros

added "Voted" to prevent multiple votes

parent 6d2b720e
...@@ -18,6 +18,7 @@ class CrowdXBlock(XBlock): ...@@ -18,6 +18,7 @@ class CrowdXBlock(XBlock):
WrongAnswers = List(default=[], scope=Scope.user_state) #List of mistakes made by user WrongAnswers = List(default=[], scope=Scope.user_state) #List of mistakes made by user
DefaultHints = Dict(default={"hint": 100, "hinttwo": 10, "hintthree": 0, "hintasdf": 50, "aas;dklfj?": 1000, "SuperDuperBestHint": 10000}, scope=Scope.content) #Default hints in case no incorrect answers in hints match the user's mistake DefaultHints = Dict(default={"hint": 100, "hinttwo": 10, "hintthree": 0, "hintasdf": 50, "aas;dklfj?": 1000, "SuperDuperBestHint": 10000}, scope=Scope.content) #Default hints in case no incorrect answers in hints match the user's mistake
Used = List(default=[], scope=Scope.user_state)#List of used hints from HintsToUse Used = List(default=[], scope=Scope.user_state)#List of used hints from HintsToUse
Voted = Integer(default=0, scope=Scope.user_state)
def student_view(self, context=None): def student_view(self, context=None):
html = self.resource_string("static/html/crowdxblock.html") html = self.resource_string("static/html/crowdxblock.html")
...@@ -77,30 +78,36 @@ class CrowdXBlock(XBlock): ...@@ -77,30 +78,36 @@ class CrowdXBlock(XBlock):
@XBlock.json_handler #add 1 or -1 to rating of a hint @XBlock.json_handler #add 1 or -1 to rating of a hint
def rate_hint(self, data, suffix=''): def rate_hint(self, data, suffix=''):
for key in self.hints: if self.Voted == 0:
tempdict = str(self.hints[str(key)[0]]) #rate hint that is in hints for key in self.hints:
tempdict = (ast.literal_eval(tempdict)) tempdict = str(self.hints[str(key)[0]]) #rate hint that is in hints
if str(key) == str(self.WrongAnswers[data['ansnum']]): #ansnum will the the answer/hint pair that is selected tempdict = (ast.literal_eval(tempdict))
tempdict[self.Used[int(data['ansnum'])]] += int(data["rating"]) if str(key) == str(self.WrongAnswers[data['ansnum']]): #ansnum will the the answer/hint pair that is selected
self.hints[str(key)] = tempdict tempdict[self.Used[int(data['ansnum'])]] += int(data["rating"])
print("TESTING AGAIN HI") self.hints[str(key)] = tempdict
print("hints are " + str(self.hints[str(key)])) print("TESTING AGAIN HI")
print("otherstuff " + str(self.hints)) print("hints are " + str(self.hints[str(key)]))
for key in self.DefaultHints: print("otherstuff " + str(self.hints))
if key == self.Used[int(data['ansnum'])]: #rating for hints in DefaultHints self.Voted = 1
self.DefaultHints[str(key)] += int(data["rating"]) for key in self.DefaultHints:
if key == self.Used[int(data['ansnum'])]: #rating for hints in DefaultHints
self.DefaultHints[str(key)] += int(data["rating"])
self.Voted = 1
@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
for key in self.hints: if self.Voted == 0:
if str(key) == str(self.WrongAnswers[0]): for key in self.hints:
if str(data['submission']) not in self.hints[str(key)]: if str(key) == str(self.WrongAnswers[0]):
tempdict = str(self.hints[str(key)[0]]) #rate hint that is in hints if str(data['submission']) not in self.hints[str(key)]:
tempdict = (ast.literal_eval(tempdict)) tempdict = str(self.hints[str(key)[0]]) #rate hint that is in hints
tempdict.update({data['submission']: 0}) tempdict = (ast.literal_eval(tempdict))
self.hints[str(key)] = tempdict tempdict.update({data['submission']: 0})
else: self.hints[str(key)] = tempdict
self.hints[str(key)[str(data['submission'])]] += 1 self.Voted = 1
else:
self.hints[str(key)[str(data['submission'])]] += 1
self.Voted = 1
@staticmethod @staticmethod
def workbench_scenarios(): def workbench_scenarios():
......
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