Commit 8077ad8f by Sola Committed by Piotr Mitros

mutliple hints show for voting after correct is reached.

parent daa364f4
...@@ -51,10 +51,11 @@ class CrowdXBlock(XBlock): ...@@ -51,10 +51,11 @@ class CrowdXBlock(XBlock):
hintsarehere = 1 hintsarehere = 1
print("hints are here doe") print("hints are here doe")
if hintsarehere == 0: if hintsarehere == 0:
print("PLSDONTHAPPENDOE")
self.HintsToUse.update(self.DefaultHints) #Use DefaultHints if there aren't enough other hints self.HintsToUse.update(self.DefaultHints) #Use DefaultHints if there aren't enough other hints
if str(data["submittedanswer"]) not in self.hints: if str(data["submittedanswer"]) not in self.hints:
self.hints[str(data["submittedanswer"])] = {} #add user's incorrect answer to WrongAnswers self.hints[str(data["submittedanswer"])] = {} #add user's incorrect answer to WrongAnswers
self.HintsToUse = {}
self.HintsToUse.update(self.DefaultHints)
if max(self.HintsToUse.iteritems(), key=operator.itemgetter(1))[0] not in self.Used: if max(self.HintsToUse.iteritems(), key=operator.itemgetter(1))[0] not in self.Used:
self.Used.append(max(self.HintsToUse.iteritems(), key=operator.itemgetter(1))[0]) #Highest rated hint is shown first self.Used.append(max(self.HintsToUse.iteritems(), key=operator.itemgetter(1))[0]) #Highest rated hint is shown first
return {'HintsToUse': max(self.HintsToUse.iteritems(), key=operator.itemgetter(1))[0]} return {'HintsToUse': max(self.HintsToUse.iteritems(), key=operator.itemgetter(1))[0]}
...@@ -66,13 +67,14 @@ class CrowdXBlock(XBlock): ...@@ -66,13 +67,14 @@ class CrowdXBlock(XBlock):
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 return {'HintsToUse': random.choice(self.HintsToUse.keys())}
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
@XBlock.json_handler @XBlock.json_handler
def get_feedback(self, data, suffix=''): #start feedback, sent hint/answer data def get_feedback(self, data, suffix=''): #start feedback, sent hint/answer data
feedbackdict = {} feedbackdict = {}
feedbacklist = []
if len(self.WrongAnswers) == 0: if len(self.WrongAnswers) == 0:
return #Do nothing if no mistakes were made return #Do nothing if no mistakes were made
else: #lenth of Used will be used to dictate flow of feedback else: #lenth of Used will be used to dictate flow of feedback
...@@ -80,30 +82,69 @@ class CrowdXBlock(XBlock): ...@@ -80,30 +82,69 @@ class CrowdXBlock(XBlock):
ans = str('wngans' + str(i)) ans = str('wngans' + str(i))
hnt = str('hntusd' + str(i)) hnt = str('hntusd' + str(i))
feedbackdict[str(self.Used[i])] = str(self.WrongAnswers[i]) feedbackdict[str(self.Used[i])] = str(self.WrongAnswers[i])
print str(feedbackdict) feedbacklist.append(str(self.Used[i]))
for key in self.hints:
if str(key) == str(self.WrongAnswers[i]):
if len(self.hints[str(key)]) > 2:
thiskeycount = 0
while thiskeycount < 2:
nextkey = random.choice(self.hints[key].keys())
if str(nextkey) not in feedbacklist:
thiskeycount += 1
feedbacklist.append(str(nextkey))
feedbackdict[str(nextkey)] = str(self.WrongAnswers[i])
if thiskeycount == 2:
feedbacklist = []
else:
thiskeycount = 0
while thiskeycount < 2:
nextkey = random.choice(self.DefaultHints.keys())
if str(nextkey) not in feedbacklist:
thiskeycount += 1
feedbacklist.append(str(nextkey))
feedbackdict[str(nextkey)] = str(self.WrongAnswers[i])
if thiskeycount == 2:
feedbacklist = []
if str(self.WrongAnswers[i]) not in self.hints:
feedbackdict[str(random.choice(self.DefaultHints.keys()))] = str(self.WrongAnswers[i])
print ("feedback : " + str(feedbackdict))
return feedbackdict return feedbackdict
@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=''):
ansnum = self.Used.index(str(data['ansnum'])) for usdkey in self.Used:
print("ansnum is" + str(ansnum)) if str(usdkey) == str(data['ansnum']):
if self.Voted == 0: ansnum = self.Used.index(str(data['ansnum']))
for key in self.DefaultHints: print("ansnum is" + str(ansnum))
if key == self.Used[int(ansnum)]: #rating for hints in DefaultHints if self.Voted == 0:
self.DefaultHints[str(key)] += int(data["rating"]) for key in self.DefaultHints:
self.Voted = 1 if key == self.Used[int(ansnum)]: #rating for hints in DefaultHints
print str(self.DefaultHints) self.DefaultHints[str(key)] += int(data["rating"])
return self.Voted = 1
for key in self.hints: print str(self.DefaultHints)
tempdict = str(self.hints[str(key)]) #rate hint that is in hints return
tempdict = (ast.literal_eval(tempdict)) for key in self.hints:
if str(key) == str(self.WrongAnswers[ansnum]): #ansnum will the the answer/hint pair that is selected tempdict = str(self.hints[str(key)]) #rate hint that is in hints
tempdict[self.Used[int(ansnum)]] += int(data["rating"]) tempdict = (ast.literal_eval(tempdict))
self.hints[str(key)] = tempdict if str(key) == str(self.WrongAnswers[ansnum]): #ansnum will the the answer/hint pair that is selected
print("TESTING AGAIN HI") tempdict[self.Used[int(ansnum)]] += int(data["rating"])
print("hints are " + str(self.hints[str(key)])) self.hints[str(key)] = tempdict
print("otherstuff " + str(self.hints)) print("TESTING AGAIN HI")
self.Voted = 1 print("hints are " + str(self.hints[str(key)]))
print("otherstuff " + str(self.hints))
self.Voted = 1
return
for key in self.hints:
if str(key) == str(data['value']):
for nextkey in self.hints[key]:
if str(nextkey) == str(data['ansnum']):
ansnum = self.hints[str(key)[str(nextkey)]]
tempdict = str(self.hints[str(key)]) #rate hint that is in hints
tempdict = (ast.literal_eval(tempdict))
tempdict[self.hints[str(key)[ansnum]]] += 1
selff.hints[str(key)] = tempdict
self.Voted = 1
return
@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
...@@ -142,6 +183,10 @@ class CrowdXBlock(XBlock): ...@@ -142,6 +183,10 @@ class CrowdXBlock(XBlock):
@XBlock.json_handler @XBlock.json_handler
def clear_states(self, data, suffix=''): def clear_states(self, data, suffix=''):
print("used: " + str(self.Used))
print("wronganswers: " + str(self.WrongAnswers))
print("hints: " + str(self.hints))
print("defaults: " + str(self.DefaultHints))
self.Used = [] self.Used = []
self.HintsToUse = {} self.HintsToUse = {}
self.Voted = 0 self.Voted = 0
......
...@@ -51,10 +51,11 @@ class CrowdXBlock(XBlock): ...@@ -51,10 +51,11 @@ class CrowdXBlock(XBlock):
hintsarehere = 1 hintsarehere = 1
print("hints are here doe") print("hints are here doe")
if hintsarehere == 0: if hintsarehere == 0:
print("PLSDONTHAPPENDOE")
self.HintsToUse.update(self.DefaultHints) #Use DefaultHints if there aren't enough other hints self.HintsToUse.update(self.DefaultHints) #Use DefaultHints if there aren't enough other hints
if str(data["submittedanswer"]) not in self.hints: if str(data["submittedanswer"]) not in self.hints:
self.hints[str(data["submittedanswer"])] = {} #add user's incorrect answer to WrongAnswers self.hints[str(data["submittedanswer"])] = {} #add user's incorrect answer to WrongAnswers
self.HintsToUse = {}
self.HintsToUse.update(self.DefaultHints)
if max(self.HintsToUse.iteritems(), key=operator.itemgetter(1))[0] not in self.Used: if max(self.HintsToUse.iteritems(), key=operator.itemgetter(1))[0] not in self.Used:
self.Used.append(max(self.HintsToUse.iteritems(), key=operator.itemgetter(1))[0]) #Highest rated hint is shown first self.Used.append(max(self.HintsToUse.iteritems(), key=operator.itemgetter(1))[0]) #Highest rated hint is shown first
return {'HintsToUse': max(self.HintsToUse.iteritems(), key=operator.itemgetter(1))[0]} return {'HintsToUse': max(self.HintsToUse.iteritems(), key=operator.itemgetter(1))[0]}
...@@ -73,6 +74,7 @@ class CrowdXBlock(XBlock): ...@@ -73,6 +74,7 @@ class CrowdXBlock(XBlock):
@XBlock.json_handler @XBlock.json_handler
def get_feedback(self, data, suffix=''): #start feedback, sent hint/answer data def get_feedback(self, data, suffix=''): #start feedback, sent hint/answer data
feedbackdict = {} feedbackdict = {}
feedbacklist = []
if len(self.WrongAnswers) == 0: if len(self.WrongAnswers) == 0:
return #Do nothing if no mistakes were made return #Do nothing if no mistakes were made
else: #lenth of Used will be used to dictate flow of feedback else: #lenth of Used will be used to dictate flow of feedback
...@@ -80,30 +82,69 @@ class CrowdXBlock(XBlock): ...@@ -80,30 +82,69 @@ class CrowdXBlock(XBlock):
ans = str('wngans' + str(i)) ans = str('wngans' + str(i))
hnt = str('hntusd' + str(i)) hnt = str('hntusd' + str(i))
feedbackdict[str(self.Used[i])] = str(self.WrongAnswers[i]) feedbackdict[str(self.Used[i])] = str(self.WrongAnswers[i])
print str(feedbackdict) feedbacklist.append(str(self.Used[i]))
for key in self.hints:
if str(key) == str(self.WrongAnswers[i]):
if len(self.hints[str(key)]) > 2:
thiskeycount = 0
while thiskeycount < 2:
nextkey = random.choice(self.hints[key].keys())
if str(nextkey) not in feedbacklist:
thiskeycount += 1
feedbacklist.append(str(nextkey))
feedbackdict[str(nextkey)] = str(self.WrongAnswers[i])
if thiskeycount == 2:
feedbacklist = []
else:
thiskeycount = 0
while thiskeycount < 2:
nextkey = random.choice(self.DefaultHints.keys())
if str(nextkey) not in feedbacklist:
thiskeycount += 1
feedbacklist.append(str(nextkey))
feedbackdict[str(nextkey)] = str(self.WrongAnswers[i])
if thiskeycount == 2:
feedbacklist = []
if str(self.WrongAnswers[i]) not in self.hints:
feedbackdict[str(random.choice(self.DefaultHints.keys()))] = str(self.WrongAnswers[i])
print ("feedback : " + str(feedbackdict))
return feedbackdict return feedbackdict
@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=''):
ansnum = self.Used.index(str(data['ansnum'])) for usdkey in self.Used:
print("ansnum is" + str(ansnum)) if str(usdkey) == str(data['ansnum']):
if self.Voted == 0: ansnum = self.Used.index(str(data['ansnum']))
for key in self.DefaultHints: print("ansnum is" + str(ansnum))
if key == self.Used[int(ansnum)]: #rating for hints in DefaultHints if self.Voted == 0:
self.DefaultHints[str(key)] += int(data["rating"]) for key in self.DefaultHints:
self.Voted = 1 if key == self.Used[int(ansnum)]: #rating for hints in DefaultHints
print str(self.DefaultHints) self.DefaultHints[str(key)] += int(data["rating"])
return self.Voted = 1
for key in self.hints: print str(self.DefaultHints)
tempdict = str(self.hints[str(key)]) #rate hint that is in hints return
tempdict = (ast.literal_eval(tempdict)) for key in self.hints:
if str(key) == str(self.WrongAnswers[ansnum]): #ansnum will the the answer/hint pair that is selected tempdict = str(self.hints[str(key)]) #rate hint that is in hints
tempdict[self.Used[int(ansnum)]] += int(data["rating"]) tempdict = (ast.literal_eval(tempdict))
self.hints[str(key)] = tempdict if str(key) == str(self.WrongAnswers[ansnum]): #ansnum will the the answer/hint pair that is selected
print("TESTING AGAIN HI") tempdict[self.Used[int(ansnum)]] += int(data["rating"])
print("hints are " + str(self.hints[str(key)])) self.hints[str(key)] = tempdict
print("otherstuff " + str(self.hints)) print("TESTING AGAIN HI")
self.Voted = 1 print("hints are " + str(self.hints[str(key)]))
print("otherstuff " + str(self.hints))
self.Voted = 1
return
for key in self.hints:
if str(key) == str(data['value']):
for nextkey in self.hints[key]:
if str(nextkey) == str(data['ansnum']):
ansnum = self.hints[str(key)[str(nextkey)]]
tempdict = str(self.hints[str(key)]) #rate hint that is in hints
tempdict = (ast.literal_eval(tempdict))
tempdict[self.hints[str(key)[ansnum]]] += 1
selff.hints[str(key)] = tempdict
self.Voted = 1
return
@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
...@@ -142,6 +183,10 @@ class CrowdXBlock(XBlock): ...@@ -142,6 +183,10 @@ class CrowdXBlock(XBlock):
@XBlock.json_handler @XBlock.json_handler
def clear_states(self, data, suffix=''): def clear_states(self, data, suffix=''):
print("used: " + str(self.Used))
print("wronganswers: " + str(self.WrongAnswers))
print("hints: " + str(self.hints))
print("defaults: " + str(self.DefaultHints))
self.Used = [] self.Used = []
self.HintsToUse = {} self.HintsToUse = {}
self.Voted = 0 self.Voted = 0
......
...@@ -29,3 +29,12 @@ ...@@ -29,3 +29,12 @@
padding-bottom: 0px !important; padding-bottom: 0px !important;
} }
.crowdxblock_block .hintbutton {
background: rgb(230, 250,230);
}
.crowdxblock_block .hintsarea {
width: 300px;
padding: 10px;
border: 5px solid gray;
margin: 0px;
}
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
.crowdxblock_block button { .crowdxblock_block button {
cursor: pointer; cursor: pointer;
background: rgb(0,0,200);
} }
.crowdxblock_block .crowdsource-wrapper { .crowdxblock_block .crowdsource-wrapper {
...@@ -28,3 +29,12 @@ ...@@ -28,3 +29,12 @@
padding-bottom: 0px !important; padding-bottom: 0px !important;
} }
.crowdxblock_block .hintbutton {
background: rgb(230, 250,230);
}
.crowdxblock_block .hintsarea {
width: 220px;
padding: 10px;
border: 5px solid gray;
margin: 0px;
}
...@@ -30,7 +30,10 @@ function CrowdXBlock(runtime, element){ ...@@ -30,7 +30,10 @@ function CrowdXBlock(runtime, element){
$("#feedback").show(); $("#feedback").show();
$.each(result, function(index, value) { $.each(result, function(index, value) {
console.log( index + ": " + value ); console.log( index + ": " + value );
$('.hintansarea').append("<p id=\"submit" + index + "\"> For your incorrect answer of:" + " " + value + "</p> <p> You received the hint:" + " " + index + " <input id=\"" + index + "\" type=\"button\" class=\"hintbutton\" value=\"Upvote this Hint\"> </p><p> <input id=\"" + index + "\" type=\"button\" class=\"submitbutton\" value=\"Submit a hint for this problem\">"); if($("#submit"+value).length == 0){
$('.hintansarea').append("<p id=\"submit" + value + "\" class=\"hintsarea\"> </p>");
$('#submit'+value).append("For your incorrect answer of:" + " " + value + " <p id=\"hintstoshow" + value + "\"> The following hints exist: </p><p> <input id=\"" + index + "\" type=\"button\" class=\"submitbutton\" value=\"Submit a hint for this problem\">");
}$('#hintstoshow'+value).append("<p>" + index + "<input data-value=\"" + value + "\" id=\"" + index + "\" type=\"button\" class=\"hintbutton\" value=\"Upvote this Hint\"></p>");
}); });
}; };
...@@ -41,14 +44,15 @@ function CrowdXBlock(runtime, element){ ...@@ -41,14 +44,15 @@ function CrowdXBlock(runtime, element){
$.ajax({ $.ajax({
type: "POST", type: "POST",
url: runtime.handlerUrl(element, 'rate_hint'), url: runtime.handlerUrl(element, 'rate_hint'),
data: JSON.stringify({"rating": 1, "ansnum": $(this).attr('id')}), data: JSON.stringify({"rating": 1, "ansnum": $(this).attr('id'), "value": $(this).attr('data-value')}),
success: finish success: finish
});}) });})
$(document).on('click', '.submitbutton', function(){ //upvote $(document).on('click', '.submitbutton', function(){ //upvote
console.log("submitbutton hit"); console.log("submitbutton hit");
id = this.id; id = this.id;
value = $('#'+id).attr('data-value');
console.log("this id " + $(this).attr('id')); console.log("this id " + $(this).attr('id'));
$('#submit' + id).append("<p><input type=\"text\" name=\"studentinput\" id=\"" + id + "\" class=\"math\" size=\"40\"><<input id=\"submit\" type=\"button\" class=\"button\" value=\"Submit Hint\"> </p>");}) $('#submit' + value).append("<p><input type=\"text\" name=\"studentinput\" id=\"" + id + "\" class=\"math\" size=\"40\"><<input id=\"submit\" type=\"button\" class=\"button\" value=\"Submit Hint\"> </p>");})
$(document).on('click', '#submit', function(){ $(document).on('click', '#submit', function(){
console.log("the other id thing" + this.id); console.log("the other id thing" + this.id);
console.log("thisthing" + $(".math").attr('id')); console.log("thisthing" + $(".math").attr('id'));
......
...@@ -30,7 +30,10 @@ function CrowdXBlock(runtime, element){ ...@@ -30,7 +30,10 @@ function CrowdXBlock(runtime, element){
$("#feedback").show(); $("#feedback").show();
$.each(result, function(index, value) { $.each(result, function(index, value) {
console.log( index + ": " + value ); console.log( index + ": " + value );
$('.hintansarea').append("<p id=\"submit" + index + "\"> For your incorrect answer of:" + " " + value + "</p> <p> You received the hint:" + " " + index + " <input id=\"" + index + "\" type=\"button\" class=\"hintbutton\" value=\"Upvote this Hint\"> </p><p> <input id=\"" + index + "\" type=\"button\" class=\"submitbutton\" value=\"Submit a hint for this problem\">"); if($("#submit"+value).length == 0){
$('.hintansarea').append("<p id=\"submit" + value + "\"> class=\"hintsarea\" </p>");
$('#submit'+value).append("For your incorrect answer of:" + " " + value + " <p id=\"hintstoshow" + value + "\"> The following hints exist: </p><p> <input id=\"" + index + "\" type=\"button\" class=\"submitbutton\" value=\"Submit a hint for this problem\">");
}$('#hintstoshow'+value).append("<p>" + index + "<input data-value=\"" + value + "\" id=\"" + index + "\" type=\"button\" class=\"hintbutton\" value=\"Upvote this Hint\"></p>");
}); });
}; };
...@@ -41,14 +44,15 @@ function CrowdXBlock(runtime, element){ ...@@ -41,14 +44,15 @@ function CrowdXBlock(runtime, element){
$.ajax({ $.ajax({
type: "POST", type: "POST",
url: runtime.handlerUrl(element, 'rate_hint'), url: runtime.handlerUrl(element, 'rate_hint'),
data: JSON.stringify({"rating": 1, "ansnum": $(this).attr('id')}), data: JSON.stringify({"rating": 1, "ansnum": $(this).attr('id'), "value": $(this).attr('data-value')}),
success: finish success: finish
});}) });})
$(document).on('click', '.submitbutton', function(){ //upvote $(document).on('click', '.submitbutton', function(){ //upvote
console.log("submitbutton hit"); console.log("submitbutton hit");
id = this.id; id = this.id;
value = $('#'+id).attr('data-value');
console.log("this id " + $(this).attr('id')); console.log("this id " + $(this).attr('id'));
$('#submit' + id).append("<p><input type=\"text\" name=\"studentinput\" id=\"" + id + "\" class=\"math\" size=\"40\"><<input id=\"submit\" type=\"button\" class=\"button\" value=\"Submit Hint\"> </p>");}) $('#submit' + value).append("<p><input type=\"text\" name=\"studentinput\" id=\"" + id + "\" class=\"math\" size=\"40\"><<input id=\"submit\" type=\"button\" class=\"button\" value=\"Submit Hint\"> </p>");})
$(document).on('click', '#submit', function(){ $(document).on('click', '#submit', function(){
console.log("the other id thing" + this.id); console.log("the other id thing" + this.id);
console.log("thisthing" + $(".math").attr('id')); console.log("thisthing" + $(".math").attr('id'));
...@@ -84,6 +88,7 @@ function CrowdXBlock(runtime, element){ ...@@ -84,6 +88,7 @@ function CrowdXBlock(runtime, element){
} }
function checkreply(result){ function checkreply(result){
if(result.correct == 1){ if(result.correct == 1){
console.debug("yay"); console.debug("yay");
$('.correct', element).show(); $('.correct', element).show();
......
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