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__) ...@@ -12,8 +12,8 @@ log = logging.getLogger(__name__)
#get_hint and get_feedback are in #get_hint and get_feedback are in
class CrowdXBlock(XBlock): class CrowdXBlock(XBlock):
correctanswer = String(default="42", scope=Scope.content)
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} 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 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 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
...@@ -34,24 +34,25 @@ class CrowdXBlock(XBlock): ...@@ -34,24 +34,25 @@ class CrowdXBlock(XBlock):
@XBlock.json_handler @XBlock.json_handler
def get_hint(self, data, suffix=''): #get hints into HintsToUse dict, pass on to user def get_hint(self, data, suffix=''): #get hints into HintsToUse dict, pass on to user
answer = data["submittedanswer"] answer = str(data["submittedanswer"])
if data["submittedanswer"] not in self.WrongAnswers: if str(data["submittedanswer"]) == self.correctanswer:
self.WrongAnswers.append(data["submittedanswer"]) #add user's incorrect answer to WrongAnswers return{"correct": 1}
if str(data["submittedanswer"]) not in self.hints: hintsarehere = 0
self.hints[data["submittedanswer"]] = {} #add user's incorrect answer to WrongAnswers self.WrongAnswers.append(str(data["submittedanswer"])) #add user's incorrect answer to WrongAnswers
for key in self.hints: for key in self.hints:
try: temphints = str(self.hints[str(key)]) #perhaps a better way to do this exists, but for now this works
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"]): if str(key) == str(data["submittedanswer"]):
print("HI HEllO")
self.HintsToUse = {} self.HintsToUse = {}
self.HintsToUse.update(ast.literal_eval(temphints)) self.HintsToUse.update(ast.literal_eval(temphints))
except: for key in self.HintsToUse:
self.HintsToUse = {} if key not in self.Used:
self.HintsToUse.update(self.DefaultHints) hintsarehere = 1
if len(self.HintsToUse) <= 2: #incorrect answer to HintsToUse 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
#else: if str(data["submittedanswer"]) not in self.hints:
# self.HintsToUse = self.DefaultHints.copy() 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: 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]}
...@@ -79,8 +80,14 @@ class CrowdXBlock(XBlock): ...@@ -79,8 +80,14 @@ 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=''):
if self.Voted == 0: 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: 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)) tempdict = (ast.literal_eval(tempdict))
if str(key) == str(self.WrongAnswers[data['ansnum']]): #ansnum will the the answer/hint pair that is selected 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"]) tempdict[self.Used[int(data['ansnum'])]] += int(data["rating"])
...@@ -89,10 +96,6 @@ class CrowdXBlock(XBlock): ...@@ -89,10 +96,6 @@ class CrowdXBlock(XBlock):
print("hints are " + str(self.hints[str(key)])) print("hints are " + str(self.hints[str(key)]))
print("otherstuff " + str(self.hints)) print("otherstuff " + str(self.hints))
self.Voted = 1 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 @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
...@@ -100,15 +103,25 @@ class CrowdXBlock(XBlock): ...@@ -100,15 +103,25 @@ class CrowdXBlock(XBlock):
for key in self.hints: for key in self.hints:
if str(key) == str(self.WrongAnswers[0]): if str(key) == str(self.WrongAnswers[0]):
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)[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 = (ast.literal_eval(tempdict))
tempdict.update({data['submission']: 0}) tempdict.update({data['submission']: 0})
self.hints[str(key)] = tempdict self.hints[str(key)] = tempdict
self.Voted = 1 self.Voted = 1
print("TESTING AGAIN HI")
print("hints are " + str(self.hints[str(key)]))
print("otherstuff " + str(self.hints))
else: else:
self.hints[str(key)[str(data['submission'])]] += 1 self.hints[str(key)[str(data['submission'])]] += 1
self.Voted = 1 self.Voted = 1
@XBlock.json_handler
def clear_states(self, data, suffix=''):
self.Used = []
self.HintsToUse = {}
self.Voted = 0
self.WrongAnswers = []
@staticmethod @staticmethod
def workbench_scenarios(): def workbench_scenarios():
"""A canned scenario for display in the workbench.""" """A canned scenario for display in the workbench."""
......
...@@ -12,12 +12,13 @@ log = logging.getLogger(__name__) ...@@ -12,12 +12,13 @@ log = logging.getLogger(__name__)
#get_hint and get_feedback are in #get_hint and get_feedback are in
class CrowdXBlock(XBlock): class CrowdXBlock(XBlock):
correctanswer = String(default="42", scope=Scope.content)
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} 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 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 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")
...@@ -33,24 +34,25 @@ class CrowdXBlock(XBlock): ...@@ -33,24 +34,25 @@ class CrowdXBlock(XBlock):
@XBlock.json_handler @XBlock.json_handler
def get_hint(self, data, suffix=''): #get hints into HintsToUse dict, pass on to user def get_hint(self, data, suffix=''): #get hints into HintsToUse dict, pass on to user
answer = data["submittedanswer"] answer = str(data["submittedanswer"])
if data["submittedanswer"] not in self.WrongAnswers: if str(data["submittedanswer"]) == self.correctanswer:
self.WrongAnswers.append(data["submittedanswer"]) #add user's incorrect answer to WrongAnswers return{"correct": 1}
if str(data["submittedanswer"]) not in self.hints: hintsarehere = 0
self.hints[data["submittedanswer"]] = {} #add user's incorrect answer to WrongAnswers self.WrongAnswers.append(str(data["submittedanswer"])) #add user's incorrect answer to WrongAnswers
for key in self.hints: for key in self.hints:
try: temphints = str(self.hints[str(key)]) #perhaps a better way to do this exists, but for now this works
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"]): if str(key) == str(data["submittedanswer"]):
print("HI HEllO")
self.HintsToUse = {} self.HintsToUse = {}
self.HintsToUse.update(ast.literal_eval(temphints)) self.HintsToUse.update(ast.literal_eval(temphints))
except: for key in self.HintsToUse:
self.HintsToUse = {} if key not in self.Used:
self.HintsToUse.update(self.DefaultHints) hintsarehere = 1
if len(self.HintsToUse) <= 2: #incorrect answer to HintsToUse 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
#else: if str(data["submittedanswer"]) not in self.hints:
# self.HintsToUse = self.DefaultHints.copy() 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: 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]}
...@@ -77,30 +79,48 @@ class CrowdXBlock(XBlock): ...@@ -77,30 +79,48 @@ 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=''):
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: 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)) tempdict = (ast.literal_eval(tempdict))
if str(key) == str(self.WrongAnswers[data['ansnum']]): #ansnum will the the answer/hint pair that is selected 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"]) tempdict[self.Used[int(data['ansnum'])]] += int(data["rating"])
self.hints[str(key)] = tempdict self.hints[str(key)] = tempdict
print("TESTING AGAIN HI") print("TESTING AGAIN HI")
print("hints are " + self.hints[str(key)]) print("hints are " + str(self.hints[str(key)]))
print("otherstuff " + self.hints) print("otherstuff " + str(self.hints))
for key in self.DefaultHints: self.Voted = 1
if key == self.Used[int(data['ansnum'])]: #rating for hints in DefaultHints
self.DefaultHints[str(key)] += int(data["rating"])
@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
if self.Voted == 0:
for key in self.hints: for key in self.hints:
if str(key) == str(self.WrongAnswers[0]): if str(key) == str(self.WrongAnswers[0]):
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)[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 = (ast.literal_eval(tempdict))
tempdict.update({data['submission']: 0}) tempdict.update({data['submission']: 0})
self.hints[str(key)] = tempdict 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: else:
self.hints[str(key)[str(data['submission'])]] += 1 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 @staticmethod
def workbench_scenarios(): def workbench_scenarios():
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
font-weight: bold; font-weight: bold;
} }
.crowdxblock_block p { .crowdxblock_block button {
cursor: pointer; cursor: pointer;
} }
......
/* CSS for CrowdXBlock */ /* CSS for CrowdXBlock */
/*
.crowdxblock_block .count { .crowdxblock_block .count {
font-weight: bold; font-weight: bold;
} }
......
<div class="crowdxblock_block"> <!--most stuff just for testing purposes--> <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> </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>
<div class="crowdxblock_block"> <div class="crowdxblock_block">
<p>CrowdXBlock: Your last answer:
</p>
<h2 class="problem-header">
Numerical Input
</h2>
<section class="correct"></section> <section class="correct"></section>
<p> <p>
...@@ -38,6 +37,10 @@ ...@@ -38,6 +37,10 @@
<p> <p>
<span class='HintUsed3'></span> <span class='HintUsed3'></span>
</p> </div> </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> <section class="solution-span"><span id="solution_i4x-Me-19_002-problem-Numerical_Input_solution_1"></span></section></div>
...@@ -50,8 +53,8 @@ ...@@ -50,8 +53,8 @@
<section id="studentinput" class="textinput"> <section id="studentinput" class="textinput">
<input type="text" name="studentinput" id="answer" class="math" size="40"> <input type="text" name="studentinput" id="answer" class="math" size="40">
<input id="submit" type="button" value="Submit Hint"> <input id="submit" type="button" value="Submit Hint">
</div></section></span>
</div></section></span>
</section> </section>
</section> </section>
......
<div class="crowdxblock_block"> <!--most stuff just for testing purposes--> <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> </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>
<div class="crowdxblock_block"> <div class="crowdxblock_block">
<p>CrowdXBlock: Your last answer:
</p>
<h2 class="problem-header">
Numerical Input
</h2>
<section class="correct"></section> <section class="correct"></section>
<p> <p>
...@@ -45,15 +44,16 @@ ...@@ -45,15 +44,16 @@
<section class="action"> <section class="action">
<input type="hidden" name="problem_id" value="Numerical Input"> <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"> <section class="problem">
<span><br><span> Enter and submit your own hint!</span></span> <span><br><span> Enter and submit your own hint!</span></span>
<section id="studentinput" class="textinput"> <section id="studentinput" class="textinput">
<input type="text" name="studentinput" id="answer" class="math" size="40"> <input type="text" name="studentinput" id="answer" class="math" size="40">
<input id="submit" type="button" value="Submit Hint"> <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>
</section> </section>
......
...@@ -10,21 +10,22 @@ ...@@ -10,21 +10,22 @@
response = data[1];*/ //use this snippet for actual code? maybe? response = data[1];*/ //use this snippet for actual code? maybe?
function CrowdXBlock(runtime, element){ function CrowdXBlock(runtime, element){
var a = 0 //test
var howmany = 0.0;
var whichanswer = 0.0;
var WrongAnswer = []; var WrongAnswer = [];
var HintUsed = []; var HintUsed = [];
$("#pair0").hide(); $("#pair0").hide();
$("#pair3").hide(); $("#pair3").hide();
$("#pair2").hide(); $("#pair2").hide();
$("#pair1").hide(); $("#pair1").hide();
$("#answer").hide();
$(".problem").hide();
function seehint(result){//use html to show these results somewhere i guess function seehint(result){//use html to show these results somewhere i guess
$('.HintsToUse', element).text(result.HintsToUse); //text(result.self.hints?) $('.HintsToUse', element).text(result.HintsToUse); //text(result.self.hints?)
} }
function getfeedback(result){ function getfeedback(result){
$("#answer").show();
$(".problem").show();
if(result.wngans0 != undefined){ if(result.wngans0 != undefined){
$("#pair0").show(); $("#pair0").show();
}if(result.wngans1 != undefined){ }if(result.wngans1 != undefined){
...@@ -81,6 +82,15 @@ function CrowdXBlock(runtime, element){ ...@@ -81,6 +82,15 @@ function CrowdXBlock(runtime, element){
data: JSON.stringify({"submission": $('#answer').val()}), //give hin for first incorrect answer data: JSON.stringify({"submission": $('#answer').val()}), //give hin for first incorrect answer
success: finish 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(){ function finish(){
$("#pair0").hide(); $("#pair0").hide();
$("#pair3").hide(); $("#pair3").hide();
...@@ -89,17 +99,47 @@ function CrowdXBlock(runtime, element){ ...@@ -89,17 +99,47 @@ function CrowdXBlock(runtime, element){
$('.Thankyou', element).text("Thankyou for your help!"); $('.Thankyou', element).text("Thankyou for your help!");
$('.correct', element).hide(); $('.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 function checkreply(result){
a += 1 if(result.correct == 1){
if (a != 4) { //when answer is incorrect /*response.search(/class="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({ $.ajax({
type: "POST", 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'), url: runtime.handlerUrl(element, 'get_hint'),
data: JSON.stringify({"submittedanswer": a}), //return student's incorrect answer here data: JSON.stringify({"submittedanswer": $('#studentsubmit').val()}), //return student's incorrect answer here
success: seehint 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!"); $('.correct', element).text("You're correct! Please choose the best hint, or provide us with one of your own!");
$.ajax({ $.ajax({
type: "POST", type: "POST",
...@@ -107,6 +147,6 @@ function CrowdXBlock(runtime, element){ ...@@ -107,6 +147,6 @@ function CrowdXBlock(runtime, element){
data: JSON.stringify({"hello": "world"}), data: JSON.stringify({"hello": "world"}),
success: getfeedback success: getfeedback
}); });
}; };*/
} }
)} )}
...@@ -10,21 +10,22 @@ ...@@ -10,21 +10,22 @@
response = data[1];*/ //use this snippet for actual code? maybe? response = data[1];*/ //use this snippet for actual code? maybe?
function CrowdXBlock(runtime, element){ function CrowdXBlock(runtime, element){
var a = 0 //test
var howmany = 0.0;
var whichanswer = 0.0;
var WrongAnswer = []; var WrongAnswer = [];
var HintUsed = []; var HintUsed = [];
$("#pair0").hide(); $("#pair0").hide();
$("#pair3").hide(); $("#pair3").hide();
$("#pair2").hide(); $("#pair2").hide();
$("#pair1").hide(); $("#pair1").hide();
$("#answer").hide();
$(".problem").hide();
function seehint(result){//use html to show these results somewhere i guess function seehint(result){//use html to show these results somewhere i guess
$('.HintsToUse', element).text(result.HintsToUse); //text(result.self.hints?) $('.HintsToUse', element).text(result.HintsToUse); //text(result.self.hints?)
} }
function getfeedback(result){ function getfeedback(result){
$("#answer").show();
$(".problem").show();
if(result.wngans0 != undefined){ if(result.wngans0 != undefined){
$("#pair0").show(); $("#pair0").show();
}if(result.wngans1 != undefined){ }if(result.wngans1 != undefined){
...@@ -78,9 +79,17 @@ function CrowdXBlock(runtime, element){ ...@@ -78,9 +79,17 @@ function CrowdXBlock(runtime, element){
$.ajax({ $.ajax({
type: "POST", type: "POST",
url: runtime.handlerUrl(element, 'give_hint'), 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 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(){ function finish(){
$("#pair0").hide(); $("#pair0").hide();
$("#pair3").hide(); $("#pair3").hide();
...@@ -89,17 +98,47 @@ function CrowdXBlock(runtime, element){ ...@@ -89,17 +98,47 @@ function CrowdXBlock(runtime, element){
$('.Thankyou', element).text("Thankyou for your help!"); $('.Thankyou', element).text("Thankyou for your help!");
$('.correct', element).hide(); $('.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 function checkreply(result){
a += 1 if(result.correct == 1){
if (a != 4) { //when answer is incorrect /*response.search(/class="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({ $.ajax({
type: "POST", 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'), url: runtime.handlerUrl(element, 'get_hint'),
data: JSON.stringify({"submittedanswer": a}), //return student's incorrect answer here data: JSON.stringify({"submittedanswer": $('#studentsubmit').val()}), //return student's incorrect answer here
success: seehint 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!"); $('.correct', element).text("You're correct! Please choose the best hint, or provide us with one of your own!");
$.ajax({ $.ajax({
type: "POST", type: "POST",
...@@ -107,6 +146,6 @@ function CrowdXBlock(runtime, element){ ...@@ -107,6 +146,6 @@ function CrowdXBlock(runtime, element){
data: JSON.stringify({"hello": "world"}), data: JSON.stringify({"hello": "world"}),
success: getfeedback 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