Commit 5f53a0f5 by Sola

modifications made to correct hint giving/rating systems. now can clear all user…

modifications made to correct hint giving/rating systems. now can clear all user side temporary dict/lists so that after you submit/vote on new hints you can go back and test changes. overall better.
parent 4bb3802d
......@@ -12,8 +12,8 @@ log = logging.getLogger(__name__)
#get_hint and get_feedback are in
class CrowdXBlock(XBlock):
hints = Dict(default={"1": {"hint1":10, "hint2":0, "hint3":0, "hint4":0}, "2": {"hint12":10, "hint22":0, "hints32":0}}, scope=Scope.content) #All hints. sorted by type of mistake. type_of_incorrect_answer{"hint":rating, "hint":rating}
correctanswer = String(default="42", scope=Scope.content)
hints = Dict(default={"75": {"hint12":10, "hint22":0, "hints32":0}, "1": {"hint1":1, "hint2":1, "hint3":0}, "roflcopter": {"HighFyve":1000}}, scope=Scope.content) #All hints. sorted by type of mistake. type_of_incorrect_answer{"hint":rating, "hint":rating}
HintsToUse = Dict(default={}, scope=Scope.user_state) #Dict of hints to provide 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
......@@ -34,24 +34,25 @@ class CrowdXBlock(XBlock):
@XBlock.json_handler
def get_hint(self, data, suffix=''): #get hints into HintsToUse dict, pass on to user
answer = data["submittedanswer"]
if data["submittedanswer"] not in self.WrongAnswers:
self.WrongAnswers.append(data["submittedanswer"]) #add user's incorrect answer to WrongAnswers
if str(data["submittedanswer"]) not in self.hints:
self.hints[data["submittedanswer"]] = {} #add user's incorrect answer to WrongAnswers
answer = str(data["submittedanswer"])
if str(data["submittedanswer"]) == self.correctanswer:
return{"correct": 1}
hintsarehere = 0
self.WrongAnswers.append(str(data["submittedanswer"])) #add user's incorrect answer to WrongAnswers
for key in self.hints:
try:
temphints = str(self.hints[str(key)[0]]) #perhaps a better way to do this exists, but for now this works
if str(key) == str(data["submittedanswer"]):
self.HintsToUse = {}
self.HintsToUse.update(ast.literal_eval(temphints))
except:
temphints = str(self.hints[str(key)]) #perhaps a better way to do this exists, but for now this works
if str(key) == str(data["submittedanswer"]):
print("HI HEllO")
self.HintsToUse = {}
self.HintsToUse.update(self.DefaultHints)
if len(self.HintsToUse) <= 2: #incorrect answer to HintsToUse
self.HintsToUse.update(ast.literal_eval(temphints))
for key in self.HintsToUse:
if key not in self.Used:
hintsarehere = 1
if hintsarehere == 0:
print("PLSDONTHAPPENDOE")
self.HintsToUse.update(self.DefaultHints) #Use DefaultHints if there aren't enough other hints
#else:
# self.HintsToUse = self.DefaultHints.copy()
if str(data["submittedanswer"]) not in self.hints:
self.hints[str(data["submittedanswer"])] = {} #add user's incorrect answer to WrongAnswers
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]}
......@@ -79,8 +80,14 @@ class CrowdXBlock(XBlock):
@XBlock.json_handler #add 1 or -1 to rating of a hint
def rate_hint(self, data, suffix=''):
if self.Voted == 0:
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
print str(self.DefaultHints)
return
for key in self.hints:
tempdict = str(self.hints[str(key)[0]]) #rate hint that is in hints
tempdict = str(self.hints[str(key)]) #rate hint that is in hints
tempdict = (ast.literal_eval(tempdict))
if str(key) == str(self.WrongAnswers[data['ansnum']]): #ansnum will the the answer/hint pair that is selected
tempdict[self.Used[int(data['ansnum'])]] += int(data["rating"])
......@@ -89,10 +96,6 @@ class CrowdXBlock(XBlock):
print("hints are " + str(self.hints[str(key)]))
print("otherstuff " + str(self.hints))
self.Voted = 1
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
def give_hint(self, data, suffix=''): #add student-made hint into hints
......@@ -100,15 +103,25 @@ class CrowdXBlock(XBlock):
for key in self.hints:
if str(key) == str(self.WrongAnswers[0]):
if str(data['submission']) not in self.hints[str(key)]:
tempdict = str(self.hints[str(key)[0]]) #rate hint that is in hints
tempdict = str(self.hints[str(key)]) #rate hint that is in hints
tempdict = (ast.literal_eval(tempdict))
tempdict.update({data['submission']: 0})
self.hints[str(key)] = tempdict
self.Voted = 1
print("TESTING AGAIN HI")
print("hints are " + str(self.hints[str(key)]))
print("otherstuff " + str(self.hints))
else:
self.hints[str(key)[str(data['submission'])]] += 1
self.Voted = 1
@XBlock.json_handler
def clear_states(self, data, suffix=''):
self.Used = []
self.HintsToUse = {}
self.Voted = 0
self.WrongAnswers = []
@staticmethod
def workbench_scenarios():
"""A canned scenario for display in the workbench."""
......
......@@ -12,12 +12,13 @@ log = logging.getLogger(__name__)
#get_hint and get_feedback are in
class CrowdXBlock(XBlock):
hints = Dict(default={"1": {"hint1":10, "hint2":0, "hint3":0, "hint4":0}, "2": {"hint12":10, "hint22":0, "hints32":0}}, scope=Scope.content) #All hints. sorted by type of mistake. type_of_incorrect_answer{"hint":rating, "hint":rating}
correctanswer = String(default="42", scope=Scope.content)
hints = Dict(default={"75": {"hint12":10, "hint22":0, "hints32":0}, "1": {"hint1":1, "hint2":1, "hint3":0}, "roflcopter": {"HighFyve":1000}}, scope=Scope.content) #All hints. sorted by type of mistake. type_of_incorrect_answer{"hint":rating, "hint":rating}
HintsToUse = Dict(default={}, scope=Scope.user_state) #Dict of hints to provide 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
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):
html = self.resource_string("static/html/crowdxblock.html")
......@@ -33,24 +34,25 @@ class CrowdXBlock(XBlock):
@XBlock.json_handler
def get_hint(self, data, suffix=''): #get hints into HintsToUse dict, pass on to user
answer = data["submittedanswer"]
if data["submittedanswer"] not in self.WrongAnswers:
self.WrongAnswers.append(data["submittedanswer"]) #add user's incorrect answer to WrongAnswers
if str(data["submittedanswer"]) not in self.hints:
self.hints[data["submittedanswer"]] = {} #add user's incorrect answer to WrongAnswers
answer = str(data["submittedanswer"])
if str(data["submittedanswer"]) == self.correctanswer:
return{"correct": 1}
hintsarehere = 0
self.WrongAnswers.append(str(data["submittedanswer"])) #add user's incorrect answer to WrongAnswers
for key in self.hints:
try:
temphints = str(self.hints[str(key)[0]]) #perhaps a better way to do this exists, but for now this works
if str(key) == str(data["submittedanswer"]):
self.HintsToUse = {}
self.HintsToUse.update(ast.literal_eval(temphints))
except:
temphints = str(self.hints[str(key)]) #perhaps a better way to do this exists, but for now this works
if str(key) == str(data["submittedanswer"]):
print("HI HEllO")
self.HintsToUse = {}
self.HintsToUse.update(self.DefaultHints)
if len(self.HintsToUse) <= 2: #incorrect answer to HintsToUse
self.HintsToUse.update(ast.literal_eval(temphints))
for key in self.HintsToUse:
if key not in self.Used:
hintsarehere = 1
if hintsarehere == 0:
print("PLSDONTHAPPENDOE")
self.HintsToUse.update(self.DefaultHints) #Use DefaultHints if there aren't enough other hints
#else:
# self.HintsToUse = self.DefaultHints.copy()
if str(data["submittedanswer"]) not in self.hints:
self.hints[str(data["submittedanswer"])] = {} #add user's incorrect answer to WrongAnswers
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]}
......@@ -77,30 +79,48 @@ class CrowdXBlock(XBlock):
@XBlock.json_handler #add 1 or -1 to rating of a hint
def rate_hint(self, data, suffix=''):
for key in self.hints:
tempdict = str(self.hints[str(key)[0]]) #rate hint that is in hints
tempdict = (ast.literal_eval(tempdict))
if str(key) == str(self.WrongAnswers[data['ansnum']]): #ansnum will the the answer/hint pair that is selected
tempdict[self.Used[int(data['ansnum'])]] += int(data["rating"])
self.hints[str(key)] = tempdict
print("TESTING AGAIN HI")
print("hints are " + self.hints[str(key)])
print("otherstuff " + self.hints)
for key in self.DefaultHints:
if key == self.Used[int(data['ansnum'])]: #rating for hints in DefaultHints
self.DefaultHints[str(key)] += int(data["rating"])
if self.Voted == 0:
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
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[data['ansnum']]): #ansnum will the the answer/hint pair that is selected
tempdict[self.Used[int(data['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
@XBlock.json_handler
def give_hint(self, data, suffix=''): #add student-made hint into hints
for key in self.hints:
if str(key) == str(self.WrongAnswers[0]):
if str(data['submission']) not in self.hints[str(key)]:
tempdict = str(self.hints[str(key)[0]]) #rate hint that is in hints
tempdict = (ast.literal_eval(tempdict))
tempdict.update({data['submission']: 0})
self.hints[str(key)] = tempdict
else:
self.hints[str(key)[str(data['submission'])]] += 1
if self.Voted == 0:
for key in self.hints:
if str(key) == str(self.WrongAnswers[0]):
if str(data['submission']) not in self.hints[str(key)]:
tempdict = str(self.hints[str(key)]) #rate hint that is in hints
tempdict = (ast.literal_eval(tempdict))
tempdict.update({data['submission']: 0})
self.hints[str(key)] = tempdict
self.Voted = 1
print("TESTING AGAIN HI")
print("hints are " + str(self.hints[str(key)]))
print("otherstuff " + str(self.hints))
else:
self.hints[str(key)[str(data['submission'])]] += 1
self.Voted = 1
@XBlock.json_handler
def debugclearstates(self, data, suffix=''):
self.Used = []
self.HintsToUse = {}
self.Voted = 0
self.WrongAnswers = []
@staticmethod
def workbench_scenarios():
......
......@@ -4,7 +4,7 @@
font-weight: bold;
}
.crowdxblock_block p {
.crowdxblock_block button {
cursor: pointer;
}
......
/* CSS for CrowdXBlock */
/*
.crowdxblock_block .count {
font-weight: bold;
}
......
<div class="crowdxblock_block"> <!--most stuff just for testing purposes-->
<p>CrowdXBlock: hints here? <span class='HintsToUse'>{self.HintsToUse}</span>
<p>CrowdXBlock: HINT! <span class='HintsToUse'>{self.HintsToUse}</span>
</p>
<span><br><span> Dummy Answer Input Here</span></span>
<section id="studentinput" class="textinput">
<input type="text" name="studentanswer" id="studentsubmit" class="math" size="40">
<input id="studentanswer" type="button" value="Submit Answer">
</div>
<div class="crowdxblock_block">
<p>CrowdXBlock: Your last answer:
</p>
<h2 class="problem-header">
Numerical Input
</h2>
<section class="correct"></section>
<p>
......@@ -38,6 +37,10 @@
<p>
<span class='HintUsed3'></span>
</p> </div>
<p>
<input id="cu" type="button" value="clearUsed"><input id="cw" type="button" value="clearWrong"><input id="cv" type="button" value="clearVoted"><input id="ch" type="button" value="clearHintsToUse">
<input id="caus" type="button" value="clearAllUserState">
</p>
<section class="solution-span"><span id="solution_i4x-Me-19_002-problem-Numerical_Input_solution_1"></span></section></div>
......@@ -50,8 +53,8 @@
<section id="studentinput" class="textinput">
<input type="text" name="studentinput" id="answer" class="math" size="40">
<input id="submit" type="button" value="Submit Hint">
</div></section></span>
</div></section></span>
</section>
</section>
......
<div class="crowdxblock_block"> <!--most stuff just for testing purposes-->
<p>CrowdXBlock: hints here? <span class='HintsToUse'>{self.HintsToUse}</span>
<p>CrowdXBlock: HINT! <span class='HintsToUse'>{self.HintsToUse}</span>
</p>
<span><br><span> Dummy Answer Input Here</span></span>
<section id="studentinput" class="textinput">
<input type="text" name="studentanswer" id="studentsubmit" class="math" size="40">
<input id="studentanswer" type="button" value="Submit Answer">
</div>
<div class="crowdxblock_block">
<p>CrowdXBlock: Your last answer:
</p>
<h2 class="problem-header">
Numerical Input
</h2>
<section class="correct"></section>
<p>
......@@ -45,15 +44,16 @@
<section class="action">
<input type="hidden" name="problem_id" value="Numerical Input">
<input id="upvote" type="button" value="Upvote">
<input id="downvote" type="button" value="Downvote">
<section class="problem">
<span><br><span> Enter and submit your own hint!</span></span>
<section id="studentinput" class="textinput">
<input type="text" name="studentinput" id="answer" class="math" size="40">
<input id="submit" type="button" value="Submit Hint">
</div></section></span>
</div></section></span><p>
<input id="cu" type="button" value="clearUsed"><input id="cw" type="button" value="clearWrong"><input id="cv" type="button" value="clearVoted"><input id="ch" type="button" value="clearHintsToUse">
<input id="caus" type="button" value="clearAllUserState">
</p>
</section>
</section>
......
......@@ -10,21 +10,22 @@
response = data[1];*/ //use this snippet for actual code? maybe?
function CrowdXBlock(runtime, element){
var a = 0 //test
var howmany = 0.0;
var whichanswer = 0.0;
var WrongAnswer = [];
var HintUsed = [];
$("#pair0").hide();
$("#pair3").hide();
$("#pair2").hide();
$("#pair1").hide();
$("#answer").hide();
$(".problem").hide();
function seehint(result){//use html to show these results somewhere i guess
$('.HintsToUse', element).text(result.HintsToUse); //text(result.self.hints?)
}
function getfeedback(result){
$("#answer").show();
$(".problem").show();
if(result.wngans0 != undefined){
$("#pair0").show();
}if(result.wngans1 != undefined){
......@@ -81,6 +82,15 @@ function CrowdXBlock(runtime, element){
data: JSON.stringify({"submission": $('#answer').val()}), //give hin for first incorrect answer
success: finish
});})
$('#caus', element).click(function(eventObject) {
console.debug("ca working");
$.ajax({
type: "POST",
url: runtime.handlerUrl(element, 'clear_states'),
data: JSON.stringify({"hello": "world"}), //give hin for first incorrect answer
success: clearstates
});})
function finish(){
$("#pair0").hide();
$("#pair3").hide();
......@@ -89,17 +99,47 @@ function CrowdXBlock(runtime, element){
$('.Thankyou', element).text("Thankyou for your help!");
$('.correct', element).hide();
}
function clearstates(){
$("#pair0").hide();
$("#pair3").hide();
$("#pair2").hide();
$("#pair1").hide();
$("#answer").hide();
$(".problem").hide();
$('.WrongAnswer0', element).text();
$('.HintUsed0', element).text();
$('.WrongAnswer1', element).text();
$('.HintUsed1', element).text();
$('.WrongAnswer2', element).text();
$('.HintUsed2', element).text();
$('.WrongAnswer3', element).text();
$('.HintUsed3', element).text();
}
$('p', element).click(function(eventObject) { //for test
a += 1
if (a != 4) { //when answer is incorrect /*response.search(/class="correct/) === -1*/
function checkreply(result){
if(result.correct == 1){
console.debug("yay");
$('.correct', element).text("You're correct! Please choose the best hint, or provide us with one of your own!");
$.ajax({
type: "POST",
url: runtime.handlerUrl(element, 'get_feedback'),
data: JSON.stringify({"hello": "world"}),
success: getfeedback
});
}else{
console.debug("nay");
seehint(result)
}
}
$('#studentanswer', element).click(function(eventObject) { //for test //when answer is incorrect /*response.search(/class="correct/) === -1*/
console.debug($('#studentsubmit').val()); //currently data is passed to python and then returned whether it is correct or not
$.ajax({ //that probably will be changed once i use response.search or something?
type: "POST", //if/when that is changed, remove checkreply and uncomment the else statement below
url: runtime.handlerUrl(element, 'get_hint'),
data: JSON.stringify({"submittedanswer": a}), //return student's incorrect answer here
success: seehint
data: JSON.stringify({"submittedanswer": $('#studentsubmit').val()}), //return student's incorrect answer here
success: checkreply
});
} else { //answer is correct
/* } else { //answer is correct
$('.correct', element).text("You're correct! Please choose the best hint, or provide us with one of your own!");
$.ajax({
type: "POST",
......@@ -107,6 +147,6 @@ function CrowdXBlock(runtime, element){
data: JSON.stringify({"hello": "world"}),
success: getfeedback
});
};
};*/
}
)}
......@@ -10,21 +10,22 @@
response = data[1];*/ //use this snippet for actual code? maybe?
function CrowdXBlock(runtime, element){
var a = 0 //test
var howmany = 0.0;
var whichanswer = 0.0;
var WrongAnswer = [];
var HintUsed = [];
$("#pair0").hide();
$("#pair3").hide();
$("#pair2").hide();
$("#pair1").hide();
$("#answer").hide();
$(".problem").hide();
function seehint(result){//use html to show these results somewhere i guess
$('.HintsToUse', element).text(result.HintsToUse); //text(result.self.hints?)
}
function getfeedback(result){
$("#answer").show();
$(".problem").show();
if(result.wngans0 != undefined){
$("#pair0").show();
}if(result.wngans1 != undefined){
......@@ -78,9 +79,17 @@ function CrowdXBlock(runtime, element){
$.ajax({
type: "POST",
url: runtime.handlerUrl(element, 'give_hint'),
data: JSON.stringify({"submission": $('#answer').val(), "ansnum": 0}), //give hin for first incorrect answer
data: JSON.stringify({"submission": $('#answer').val()}), //give hin for first incorrect answer
success: finish
});})
$('#caus', element).click(function(eventObject) {
console.debug("ca working");
$.ajax({
type: "POST",
url: runtime.handlerUrl(element, 'clear_states'),
data: JSON.stringify({"hello": "world"}), //give hin for first incorrect answer
success: clearstates
});})
function finish(){
$("#pair0").hide();
$("#pair3").hide();
......@@ -89,17 +98,47 @@ function CrowdXBlock(runtime, element){
$('.Thankyou', element).text("Thankyou for your help!");
$('.correct', element).hide();
}
function clearstates(){
$("#pair0").hide();
$("#pair3").hide();
$("#pair2").hide();
$("#pair1").hide();
$("#answer").hide();
$(".problem").hide();
$('.WrongAnswer0', element).text();
$('.HintUsed0', element).text();
$('.WrongAnswer1', element).text();
$('.HintUsed1', element).text();
$('.WrongAnswer2', element).text();
$('.HintUsed2', element).text();
$('.WrongAnswer3', element).text();
$('.HintUsed3', element).text();
}
$('p', element).click(function(eventObject) { //for test
a += 1
if (a != 4) { //when answer is incorrect /*response.search(/class="correct/) === -1*/
function checkreply(result){
if(result.correct == 1){
console.debug("yay");
$('.correct', element).text("You're correct! Please choose the best hint, or provide us with one of your own!");
$.ajax({
type: "POST",
url: runtime.handlerUrl(element, 'get_feedback'),
data: JSON.stringify({"hello": "world"}),
success: getfeedback
});
}else{
console.debug("nay");
seehint(result)
}
}
$('#studentanswer', element).click(function(eventObject) { //for test //when answer is incorrect /*response.search(/class="correct/) === -1*/
console.debug($('#studentsubmit').val()); //currently data is passed to python and then returned whether it is correct or not
$.ajax({ //that probably will be changed once i use response.search or something?
type: "POST", //if/when that is changed, remove checkreply and uncomment the else statement below
url: runtime.handlerUrl(element, 'get_hint'),
data: JSON.stringify({"submittedanswer": a}), //return student's incorrect answer here
success: seehint
data: JSON.stringify({"submittedanswer": $('#studentsubmit').val()}), //return student's incorrect answer here
success: checkreply
});
} else { //answer is correct
/* } else { //answer is correct
$('.correct', element).text("You're correct! Please choose the best hint, or provide us with one of your own!");
$.ajax({
type: "POST",
......@@ -107,6 +146,6 @@ function CrowdXBlock(runtime, element){
data: JSON.stringify({"hello": "world"}),
success: getfeedback
});
};
};*/
}
)}
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