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):
hintsarehere = 1
print("hints are here doe")
if hintsarehere == 0:
print("PLSDONTHAPPENDOE")
self.HintsToUse.update(self.DefaultHints) #Use DefaultHints if there aren't enough other hints
if str(data["submittedanswer"]) not in self.hints:
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:
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]}
......@@ -66,13 +67,14 @@ class CrowdXBlock(XBlock):
while NotUsed in self.Used:
NotUsed = random.choice(self.HintsToUse.keys()) #Choose random hint that hasn't already been Used
elif len(self.Used) > 0:
return
return {'HintsToUse': random.choice(self.HintsToUse.keys())}
self.Used.append(NotUsed)
return {'HintsToUse': NotUsed} #note to self dont let python get into endless notused loop
@XBlock.json_handler
def get_feedback(self, data, suffix=''): #start feedback, sent hint/answer data
feedbackdict = {}
feedbacklist = []
if len(self.WrongAnswers) == 0:
return #Do nothing if no mistakes were made
else: #lenth of Used will be used to dictate flow of feedback
......@@ -80,30 +82,69 @@ class CrowdXBlock(XBlock):
ans = str('wngans' + str(i))
hnt = str('hntusd' + str(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
@XBlock.json_handler #add 1 or -1 to rating of a hint
def rate_hint(self, data, suffix=''):
ansnum = self.Used.index(str(data['ansnum']))
print("ansnum is" + str(ansnum))
if self.Voted == 0:
for key in self.DefaultHints:
if key == self.Used[int(ansnum)]: #rating for hints in DefaultHints
self.DefaultHints[str(key)] += int(data["rating"])
self.Voted = 1
print str(self.DefaultHints)
return
for key in self.hints:
tempdict = str(self.hints[str(key)]) #rate hint that is in hints
tempdict = (ast.literal_eval(tempdict))
if str(key) == str(self.WrongAnswers[ansnum]): #ansnum will the the answer/hint pair that is selected
tempdict[self.Used[int(ansnum)]] += int(data["rating"])
self.hints[str(key)] = tempdict
print("TESTING AGAIN HI")
print("hints are " + str(self.hints[str(key)]))
print("otherstuff " + str(self.hints))
self.Voted = 1
for usdkey in self.Used:
if str(usdkey) == str(data['ansnum']):
ansnum = self.Used.index(str(data['ansnum']))
print("ansnum is" + str(ansnum))
if self.Voted == 0:
for key in self.DefaultHints:
if key == self.Used[int(ansnum)]: #rating for hints in DefaultHints
self.DefaultHints[str(key)] += int(data["rating"])
self.Voted = 1
print str(self.DefaultHints)
return
for key in self.hints:
tempdict = str(self.hints[str(key)]) #rate hint that is in hints
tempdict = (ast.literal_eval(tempdict))
if str(key) == str(self.WrongAnswers[ansnum]): #ansnum will the the answer/hint pair that is selected
tempdict[self.Used[int(ansnum)]] += int(data["rating"])
self.hints[str(key)] = tempdict
print("TESTING AGAIN HI")
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
def give_hint(self, data, suffix=''): #add student-made hint into hints
......@@ -142,6 +183,10 @@ class CrowdXBlock(XBlock):
@XBlock.json_handler
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.HintsToUse = {}
self.Voted = 0
......
......@@ -51,10 +51,11 @@ class CrowdXBlock(XBlock):
hintsarehere = 1
print("hints are here doe")
if hintsarehere == 0:
print("PLSDONTHAPPENDOE")
self.HintsToUse.update(self.DefaultHints) #Use DefaultHints if there aren't enough other hints
if str(data["submittedanswer"]) not in self.hints:
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:
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]}
......@@ -73,6 +74,7 @@ class CrowdXBlock(XBlock):
@XBlock.json_handler
def get_feedback(self, data, suffix=''): #start feedback, sent hint/answer data
feedbackdict = {}
feedbacklist = []
if len(self.WrongAnswers) == 0:
return #Do nothing if no mistakes were made
else: #lenth of Used will be used to dictate flow of feedback
......@@ -80,30 +82,69 @@ class CrowdXBlock(XBlock):
ans = str('wngans' + str(i))
hnt = str('hntusd' + str(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
@XBlock.json_handler #add 1 or -1 to rating of a hint
def rate_hint(self, data, suffix=''):
ansnum = self.Used.index(str(data['ansnum']))
print("ansnum is" + str(ansnum))
if self.Voted == 0:
for key in self.DefaultHints:
if key == self.Used[int(ansnum)]: #rating for hints in DefaultHints
self.DefaultHints[str(key)] += int(data["rating"])
self.Voted = 1
print str(self.DefaultHints)
return
for key in self.hints:
tempdict = str(self.hints[str(key)]) #rate hint that is in hints
tempdict = (ast.literal_eval(tempdict))
if str(key) == str(self.WrongAnswers[ansnum]): #ansnum will the the answer/hint pair that is selected
tempdict[self.Used[int(ansnum)]] += int(data["rating"])
self.hints[str(key)] = tempdict
print("TESTING AGAIN HI")
print("hints are " + str(self.hints[str(key)]))
print("otherstuff " + str(self.hints))
self.Voted = 1
for usdkey in self.Used:
if str(usdkey) == str(data['ansnum']):
ansnum = self.Used.index(str(data['ansnum']))
print("ansnum is" + str(ansnum))
if self.Voted == 0:
for key in self.DefaultHints:
if key == self.Used[int(ansnum)]: #rating for hints in DefaultHints
self.DefaultHints[str(key)] += int(data["rating"])
self.Voted = 1
print str(self.DefaultHints)
return
for key in self.hints:
tempdict = str(self.hints[str(key)]) #rate hint that is in hints
tempdict = (ast.literal_eval(tempdict))
if str(key) == str(self.WrongAnswers[ansnum]): #ansnum will the the answer/hint pair that is selected
tempdict[self.Used[int(ansnum)]] += int(data["rating"])
self.hints[str(key)] = tempdict
print("TESTING AGAIN HI")
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
def give_hint(self, data, suffix=''): #add student-made hint into hints
......@@ -142,6 +183,10 @@ class CrowdXBlock(XBlock):
@XBlock.json_handler
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.HintsToUse = {}
self.Voted = 0
......
......@@ -29,3 +29,12 @@
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 @@
.crowdxblock_block button {
cursor: pointer;
background: rgb(0,0,200);
}
.crowdxblock_block .crowdsource-wrapper {
......@@ -28,3 +29,12 @@
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){
$("#feedback").show();
$.each(result, function(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){
$.ajax({
type: "POST",
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
});})
$(document).on('click', '.submitbutton', function(){ //upvote
console.log("submitbutton hit");
id = this.id;
value = $('#'+id).attr('data-value');
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(){
console.log("the other id thing" + this.id);
console.log("thisthing" + $(".math").attr('id'));
......
......@@ -30,7 +30,10 @@ function CrowdXBlock(runtime, element){
$("#feedback").show();
$.each(result, function(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){
$.ajax({
type: "POST",
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
});})
$(document).on('click', '.submitbutton', function(){ //upvote
console.log("submitbutton hit");
id = this.id;
value = $('#'+id).attr('data-value');
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(){
console.log("the other id thing" + this.id);
console.log("thisthing" + $(".math").attr('id'));
......@@ -84,6 +88,7 @@ function CrowdXBlock(runtime, element){
}
function checkreply(result){
if(result.correct == 1){
console.debug("yay");
$('.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