Commit b92754a1 by Sola

most recent changes.

parent ba55f575
...@@ -12,12 +12,12 @@ log = logging.getLogger(__name__) ...@@ -12,12 +12,12 @@ 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) #should be irrelevant for completed version correctanswer = String(default="2.0", scope=Scope.content) #should be irrelevant for completed version
hints = Dict(default={"2": {"hint1for2":0, "hint2for2":0, "hint3for2":0}, "1": {"hint1for1":0, "hint2for1":0, "hint3for1":0}, "3": {"hint1for3":0, "hint2for3":0, "hint3for3":0}}, scope=Scope.content) hints = Dict(default={"2": {"Keep significant figures in mind.":1, "So close yet so far.":0, "Try adding a .0.":0}, "8.6": {"You might have added all of the horizontal forces together to equal a total of 21 for the horizontal component of this object's force; the two forces are facing opposite direction, so you need to subtract them.":1, "Try 12-9 for the total horizontal force.":0}, "1.2": {"Did you remember to add in the vertical component of force for this object?":0},"1.0":{"dummy hint for debugs":0}, "one":{"dummy hint again for debugs":0}}, scope=Scope.content)
#All hints. sorted by type of mistake. type_of_incorrect_answer{"hint":rating, "hint":rating} #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={"defaulthint1": 0, "defaulthint2": 0, "defaulthint3": 0, "defaulthint4": 0, "defaulthint5": 0, "bestdefaulthint": 3}, scope=Scope.content) #Default hints in case no incorrect answers in hints match the user's mistake DefaultHints = Dict(default={"Start with the equation F=ma":2, "This object has horizontal and vertical components of force. Solve for the total force in each direction, then compare it to the final acceleration":1, "A small example: If an object has a force of 10N applied to it in an upward direction and it's acceleration is 1m/s^2, the mass of that object is 10.0 kg. F=ma, 10N=m*(1m/s^2), m=10/1, m=10.":1}, 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)#prevent multiple votes/hint submission Voted = Integer(default=0, scope=Scope.user_state)#prevent multiple votes/hint submission
...@@ -43,13 +43,11 @@ class CrowdXBlock(XBlock): ...@@ -43,13 +43,11 @@ class CrowdXBlock(XBlock):
for key in self.hints: for key in self.hints:
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)]) #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))
for key in self.HintsToUse: for key in self.HintsToUse:
if key not in self.Used: if key not in self.Used:
hintsarehere = 1 hintsarehere = 1
print("hints are here doe")
if hintsarehere == 0: if hintsarehere == 0:
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:
...@@ -107,7 +105,7 @@ class CrowdXBlock(XBlock): ...@@ -107,7 +105,7 @@ class CrowdXBlock(XBlock):
feedbacklist = [] feedbacklist = []
if str(self.WrongAnswers[i]) not in self.hints: if str(self.WrongAnswers[i]) not in self.hints:
feedbackdict[str(random.choice(self.DefaultHints.keys()))] = str(self.WrongAnswers[i]) feedbackdict[str(random.choice(self.DefaultHints.keys()))] = str(self.WrongAnswers[i])
print ("feedback : " + str(feedbackdict)) print("feedbackdict is: " + 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
...@@ -115,13 +113,11 @@ class CrowdXBlock(XBlock): ...@@ -115,13 +113,11 @@ class CrowdXBlock(XBlock):
for usdkey in self.Used: for usdkey in self.Used:
if str(usdkey) == str(data['ansnum']): if str(usdkey) == str(data['ansnum']):
ansnum = self.Used.index(str(data['ansnum'])) ansnum = self.Used.index(str(data['ansnum']))
print("ansnum is" + str(ansnum))
if self.Voted == 0: if self.Voted == 0:
for key in self.DefaultHints: for key in self.DefaultHints:
if key == self.Used[int(ansnum)]: #rating for hints in DefaultHints if key == self.Used[int(ansnum)]: #rating for hints in DefaultHints
self.DefaultHints[str(key)] += int(data["rating"]) self.DefaultHints[str(key)] += int(data["rating"])
self.Voted = 1 self.Voted = 1
print str(self.DefaultHints)
return return
for key in self.hints: for key in self.hints:
tempdict = str(self.hints[str(key)]) #rate hint that is in hints tempdict = str(self.hints[str(key)]) #rate hint that is in hints
...@@ -129,9 +125,6 @@ class CrowdXBlock(XBlock): ...@@ -129,9 +125,6 @@ class CrowdXBlock(XBlock):
if str(key) == str(self.WrongAnswers[ansnum]): #ansnum will the the answer/hint pair that is selected 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"]) tempdict[self.Used[int(ansnum)]] += int(data["rating"])
self.hints[str(key)] = tempdict 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 self.Voted = 1
return return
for key in self.hints: for key in self.hints:
...@@ -159,16 +152,12 @@ class CrowdXBlock(XBlock): ...@@ -159,16 +152,12 @@ class CrowdXBlock(XBlock):
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:
ansnum = self.Used.index(data['submission']) ansnum = self.Used.index(data['submission'])
for key in self.DefaultHints: for key in self.DefaultHints:
if key == self.Used[int(ansnum)]: #rating for hints in DefaultHints if key == self.Used[int(ansnum)]: #rating for hints in DefaultHints
self.DefaultHints[str(key)] += int(1) self.DefaultHints[str(key)] += int(1)
self.Voted = 1 self.Voted = 1
print str(self.DefaultHints)
return return
for key in self.hints: for key in self.hints:
tempdict = str(self.hints[str(key)]) #rate hint that is in hints tempdict = str(self.hints[str(key)]) #rate hint that is in hints
...@@ -176,17 +165,10 @@ class CrowdXBlock(XBlock): ...@@ -176,17 +165,10 @@ class CrowdXBlock(XBlock):
if str(key) == str(self.WrongAnswers[int(ansnum)]): #ansnum will the the answer/hint pair that is selected if str(key) == str(self.WrongAnswers[int(ansnum)]): #ansnum will the the answer/hint pair that is selected
tempdict[self.Used[int(ansnum)]] += int(1) tempdict[self.Used[int(ansnum)]] += int(1)
self.hints[str(key)] = tempdict 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 self.Voted = 1
@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
......
...@@ -12,12 +12,12 @@ log = logging.getLogger(__name__) ...@@ -12,12 +12,12 @@ 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) #should be irrelevant for completed version correctanswer = String(default="2.0", scope=Scope.content) #should be irrelevant for completed version
hints = Dict(default={"2": {"hint6for2":0, "hint5for2":0, "hint4for2":0, "hint1for2":0, "hint2for2":0, "hint3for2":0}, "1": {"hint1for1":0, "hint2for1":0, "hint3for1":0}, "3": {"hint1for3":0, "hint2for3":0, "hint3for3":0}}, scope=Scope.content) hints = Dict(default={"2": {"Keep significant figures in mind.":1, "So close yet so far.":0, "Try adding a .0.":0}, "8.6": {"You might have added all of the horizontal forces together to equal a total of 21 for the horizontal component of this object's force; the two forces are facing opposite direction, so you need to subtract them.":1, "Try 12-9 for the total horizontal force.":0}, "1.2": {"Did you remember to add in the vertical component of force for this object?":0},"1.0":{"dummy hint for debugs":0}, "one":{"dummy hint again for debugs":0}}, scope=Scope.content)
#All hints. sorted by type of mistake. type_of_incorrect_answer{"hint":rating, "hint":rating} #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={"defaulthint1": 0, "defaulthint2": 0, "defaulthint3": 0, "defaulthint4": 0, "defaulthint5": 0, "bestdefaulthint": 3}, scope=Scope.content) #Default hints in case no incorrect answers in hints match the user's mistake DefaultHints = Dict(default={"Start with the equation F=ma":2, "This object has horizontal and vertical components of force. Solve for the total force in each direction, then compare it to the final acceleration":1, "A small example: If an object has a force of 10N applied to it in an upward direction and it's acceleration is 1m/s^2, the mass of that object is 10.0 kg. F=ma, 10N=m*(1m/s^2), m=10/1, m=10.":1}, 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)#prevent multiple votes/hint submission Voted = Integer(default=0, scope=Scope.user_state)#prevent multiple votes/hint submission
...@@ -43,13 +43,11 @@ class CrowdXBlock(XBlock): ...@@ -43,13 +43,11 @@ class CrowdXBlock(XBlock):
for key in self.hints: for key in self.hints:
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)]) #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))
for key in self.HintsToUse: for key in self.HintsToUse:
if key not in self.Used: if key not in self.Used:
hintsarehere = 1 hintsarehere = 1
print("hints are here doe")
if hintsarehere == 0: if hintsarehere == 0:
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:
...@@ -107,7 +105,7 @@ class CrowdXBlock(XBlock): ...@@ -107,7 +105,7 @@ class CrowdXBlock(XBlock):
feedbacklist = [] feedbacklist = []
if str(self.WrongAnswers[i]) not in self.hints: if str(self.WrongAnswers[i]) not in self.hints:
feedbackdict[str(random.choice(self.DefaultHints.keys()))] = str(self.WrongAnswers[i]) feedbackdict[str(random.choice(self.DefaultHints.keys()))] = str(self.WrongAnswers[i])
print ("feedback : " + str(feedbackdict)) print("feedbackdict is: " + 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
...@@ -115,13 +113,11 @@ class CrowdXBlock(XBlock): ...@@ -115,13 +113,11 @@ class CrowdXBlock(XBlock):
for usdkey in self.Used: for usdkey in self.Used:
if str(usdkey) == str(data['ansnum']): if str(usdkey) == str(data['ansnum']):
ansnum = self.Used.index(str(data['ansnum'])) ansnum = self.Used.index(str(data['ansnum']))
print("ansnum is" + str(ansnum))
if self.Voted == 0: if self.Voted == 0:
for key in self.DefaultHints: for key in self.DefaultHints:
if key == self.Used[int(ansnum)]: #rating for hints in DefaultHints if key == self.Used[int(ansnum)]: #rating for hints in DefaultHints
self.DefaultHints[str(key)] += int(data["rating"]) self.DefaultHints[str(key)] += int(data["rating"])
self.Voted = 1 self.Voted = 1
print str(self.DefaultHints)
return return
for key in self.hints: for key in self.hints:
tempdict = str(self.hints[str(key)]) #rate hint that is in hints tempdict = str(self.hints[str(key)]) #rate hint that is in hints
...@@ -129,9 +125,6 @@ class CrowdXBlock(XBlock): ...@@ -129,9 +125,6 @@ class CrowdXBlock(XBlock):
if str(key) == str(self.WrongAnswers[ansnum]): #ansnum will the the answer/hint pair that is selected 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"]) tempdict[self.Used[int(ansnum)]] += int(data["rating"])
self.hints[str(key)] = tempdict 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 self.Voted = 1
return return
for key in self.hints: for key in self.hints:
...@@ -159,16 +152,12 @@ class CrowdXBlock(XBlock): ...@@ -159,16 +152,12 @@ class CrowdXBlock(XBlock):
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:
ansnum = self.Used.index(data['submission']) ansnum = self.Used.index(data['submission'])
for key in self.DefaultHints: for key in self.DefaultHints:
if key == self.Used[int(ansnum)]: #rating for hints in DefaultHints if key == self.Used[int(ansnum)]: #rating for hints in DefaultHints
self.DefaultHints[str(key)] += int(1) self.DefaultHints[str(key)] += int(1)
self.Voted = 1 self.Voted = 1
print str(self.DefaultHints)
return return
for key in self.hints: for key in self.hints:
tempdict = str(self.hints[str(key)]) #rate hint that is in hints tempdict = str(self.hints[str(key)]) #rate hint that is in hints
...@@ -176,17 +165,10 @@ class CrowdXBlock(XBlock): ...@@ -176,17 +165,10 @@ class CrowdXBlock(XBlock):
if str(key) == str(self.WrongAnswers[int(ansnum)]): #ansnum will the the answer/hint pair that is selected if str(key) == str(self.WrongAnswers[int(ansnum)]): #ansnum will the the answer/hint pair that is selected
tempdict[self.Used[int(ansnum)]] += int(1) tempdict[self.Used[int(ansnum)]] += int(1)
self.hints[str(key)] = tempdict 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 self.Voted = 1
@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
...@@ -198,13 +180,13 @@ class CrowdXBlock(XBlock): ...@@ -198,13 +180,13 @@ class CrowdXBlock(XBlock):
return [ return [
("CrowdXBlock", ("CrowdXBlock",
"""<vertical_demo> """<vertical_demo>
<crowdxblock/> <crowdxblock/>
</vertical_demo> </vertical_demo>
"""), """),
] ]
''' '''
print ("answer" + str(data["submittedanswer"])) print ("answer" + str(data["submittedanswer"]))
for keys in self.hints[key]: for keys in self.hints[key]:
print ("other key" + y) print ("other key" + y)
self.HintsToUse[keys] = self.hints[key[keys]] #If the user's incorrect answre has precedence in hints, add hints listed under self.HintsToUse[keys] = self.hints[key[keys]] #If the user's incorrect answre has precedence in hints, add hints listed under
print("hintstouse: " + str(self.HintsToUse[keys]))''' print("hintstouse: " + str(self.HintsToUse[keys]))'''
<div class="crowdxblock_block"> <!--most stuff just for testing purposes--> <div class="crowdxblock_block"> <!--most stuff just for testing purposes-->
<p>It's Hintin' Time! Here's your hint! <span class='HintsToUse'>{self.HintsToUse}</span> <p> <img src="demoproblem.png">
</p> </p>
<span><br><span> Dummy Answer Input Here</span></span> <p> <span class='HintsToUse'>{self.HintsToUse}</span>
</p>
<span><br><span> Dummy answer submission below: </span></span>
<section id="studentinput" class="textinput"> <section id="studentinput" class="textinput">
<input type="text" name="studentanswer" id="studentsubmit" class="notmath" size="40"> <input type="text" name="studentanswer" id="studentsubmit" class="notmath" size="40">
<input id="studentanswer" type="button" class="button" value="Submit Answer"> <input id="studentanswer" type="button" class="button" value="Submit Answer">
......
<div class="crowdxblock_block"> <!--most stuff just for testing purposes--> <div class="crowdxblock_block"> <!--most stuff just for testing purposes-->
<p>It's Hintin' Time! Here's your hint! <span class='HintsToUse'>{self.HintsToUse}</span> <p> <img src="demoproblem.png">
</p> </p>
<span><br><span> Dummy Answer Input Here</span></span> <p> <span class='HintsToUse'>{self.HintsToUse}</span>
</p>
<span><br><span> Dummy answer submission below: </span></span>
<section id="studentinput" class="textinput"> <section id="studentinput" class="textinput">
<input type="text" name="studentanswer" id="studentsubmit" class="notmath" size="40"> <input type="text" name="studentanswer" id="studentsubmit" class="notmath" size="40">
<input id="studentanswer" type="button" class="button" value="Submit Answer"> <input id="studentanswer" type="button" class="button" value="Submit Answer">
...@@ -23,9 +25,6 @@ ...@@ -23,9 +25,6 @@
<input id="caus" type="button" class="button" value="clearAllUserState"> <input id="caus" type="button" class="button" value="clearAllUserState">
</p> </p>
<section class="solution-span"><span id="solution_i4x-Me-19_002-problem-Numerical_Input_solution_1"></span></section></div>
<section class="action"> <section class="action">
<input type="hidden" name="problem_id" value="Numerical Input"> <input type="hidden" name="problem_id" value="Numerical Input">
......
...@@ -12,10 +12,6 @@ response = data[1];*/ //use this snippet for actual code? maybe? ...@@ -12,10 +12,6 @@ response = data[1];*/ //use this snippet for actual code? maybe?
function CrowdXBlock(runtime, element){ function CrowdXBlock(runtime, element){
var WrongAnswer = []; var WrongAnswer = [];
var HintUsed = []; var HintUsed = [];
$("#pair0").hide();
$("#pair3").hide();
$("#pair2").hide();
$("#pair1").hide();
$("#answer").hide(); $("#answer").hide();
$(".problem").hide(); $(".problem").hide();
$("#feedback").hide(); $("#feedback").hide();
...@@ -27,61 +23,65 @@ function CrowdXBlock(runtime, element){ ...@@ -27,61 +23,65 @@ function CrowdXBlock(runtime, element){
function getfeedback(result){ function getfeedback(result){
$("#answer").show(); $("#answer").show();
$(".problem").show(); $(".problem").show();
$("#feedback").show(); $("#feedback").show();
$.each(result, function(index, value) { $.each(result, function(index, value) {
console.log( index + ": " + value ); console.log("the type of value is" + ' '+ typeof(value));
if($("#submit"+value).length == 0){ if($("#submit"+value).length == 0){
$('.hintansarea').append("<p id=\"submit" + value + "\" class=\"hintsarea\"> </p>"); console.log("#submit"+value);
$('#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\">"); $('.hintansarea').append("<p id=\"submit" + value + "\" class=\"hintsarea\"> </p>");
}$('#hintstoshow'+value).append("<p>" + index + "<input data-value=\"" + value + "\" id=\"" + index + "\" type=\"button\" class=\"hintbutton\" value=\"Upvote this Hint\"></p>"); console.log('hintsarea made for ' + value);
}); $('#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>");
console.log("the value is " + value);
});
}; };
$(document).on('click', '.hintbutton', function(){ //upvote $(document).on('click', '.hintbutton', function(){ //upvote
console.log("the first id" + this.id); console.log("the first id" + this.id);
id = this.id; id = this.id;
console.log($(this).attr('id')); console.log($(this).attr('id'));
$.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'), "value": $(this).attr('data-value')}), 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'); value = $('#'+id).attr('data-value');
console.log("this id " + $(this).attr('id')); console.log("this id " + $(this).attr('id'));
$('#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>");}) $('#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'));
$.ajax({ $.ajax({
type: "POST", type: "POST",
url: runtime.handlerUrl(element, 'give_hint'), url: runtime.handlerUrl(element, 'give_hint'),
data: JSON.stringify({"submission": $('.math').val(), "id": $(".math").attr('id')}), //give hin for first incorrect answer data: JSON.stringify({"submission": $('.math').val(), "id": $(".math").attr('id')}), //give hin for first incorrect answer
success: finish success: finish
}); });
$("#answer").val('');}) $("#answer").val('');})
$('#caus', element).click(function(eventObject) { $('#caus', element).click(function(eventObject) {
console.debug("ca working"); console.debug("ca working this is edited");
$.ajax({ $.ajax({
type: "POST", type: "POST",
url: runtime.handlerUrl(element, 'clear_states'), url: runtime.handlerUrl(element, 'clear_states'),
data: JSON.stringify({"hello": "world"}), //give hin for first incorrect answer data: JSON.stringify({"hello": "world"}), //give hin for first incorrect answer
success: clearstates success: clearstates
}); });
$("#studentsubmit").val(''); $("#studentsubmit").val('');
$("#answer").val('');}) $("#answer").val('');})
function finish(){ function finish(){
$('.Thankyou', element).text("Thankyou for your help!"); $('.Thankyou', element).text("Thankyou for your help!");
$('.correct', element).hide(); $('.correct', element).hide();
$( ".hintansarea" ).empty(); $( ".hintansarea" ).empty();
} }
function clearstates(){ function clearstates(){
$('.Thankyou', element).text(); $('.Thankyou', element).text();
$('.correct', element).hide(); $('.correct', element).hide();
$( ".hintansarea" ).empty(); $( ".hintansarea" ).empty();
$("#answer").hide(); $("#answer").hide();
$(".problem").hide(); $(".problem").hide();
...@@ -91,8 +91,8 @@ $('.correct', element).hide(); ...@@ -91,8 +91,8 @@ $('.correct', element).hide();
if(result.correct == 1){ if(result.correct == 1){
console.debug("yay"); console.debug("yay");
$('.correct', element).show(); $('.correct', element).show();
$('.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",
url: runtime.handlerUrl(element, 'get_feedback'), url: runtime.handlerUrl(element, 'get_feedback'),
...@@ -100,12 +100,12 @@ $('.correct', element).text("You're correct! Please choose the best hint, or pro ...@@ -100,12 +100,12 @@ $('.correct', element).text("You're correct! Please choose the best hint, or pro
success: getfeedback success: getfeedback
}); });
}else{ }else{
console.debug("nay"); console.debug("nay");
seehint(result) seehint(result)
} }
} }
$('#studentanswer', element).click(function(eventObject) { //for test //when answer is incorrect /*response.search(/class="correct/) === -1*/ $('#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 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? $.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 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'),
......
//my coding attemps start here i guess //my coding attemps start here i guess
/*this.url = this.el.data('url'); /*this.url = this.el.data('url');
Logger.listen('problem_graded', this.el.data('child-id'), this.capture_problem); Logger.listen('problem_graded', this.el.data('child-id'), this.capture_problem);
this.render();*/ this.render();*/
/*function capture_problem(event_type, data, element) { /*function capture_problem(event_type, data, element) {
var answers, response, var answers, response,
_this = this; _this = this;
answers = data[0]; answers = data[0];
response = data[1];*/ //use this snippet for actual code? maybe? response = data[1];*/ //use this snippet for actual code? maybe?
//**FOR CHECKING ANSWER CORRECT/NOT**
//check for event problem_check
//Check for success == "incorrect" or success == "correct" to determine? I think?
function CrowdXBlock(runtime, element){ function CrowdXBlock(runtime, element){
var WrongAnswer = []; var WrongAnswer = [];
...@@ -30,11 +25,14 @@ function CrowdXBlock(runtime, element){ ...@@ -30,11 +25,14 @@ function CrowdXBlock(runtime, element){
$(".problem").show(); $(".problem").show();
$("#feedback").show(); $("#feedback").show();
$.each(result, function(index, value) { $.each(result, function(index, value) {
console.log( index + ": " + value ); console.log("the type of value is" + ' '+ typeof(value));
if($("#submit"+value).length == 0){ if($("#submit"+value).length == 0){
$('.hintansarea').append("<p id=\"submit" + value + "\" class=\"hintsarea\"> </p>"); $('.hintansarea').append("<p id=\"submit" + value + "\" class=\"hintsarea\"> </p>");
console.log('hintsarea made for ' + value);
$('#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\">"); $('#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>"); }
$('#hintstoshow'+value).append("<p>" + index + "<input data-value=\"" + value + "\" id=\"" + index + "\" type=\"button\" class=\"hintbutton\" value=\"Upvote this Hint\"></p>");
console.log("the value is " + value);
}); });
}; };
...@@ -66,7 +64,7 @@ function CrowdXBlock(runtime, element){ ...@@ -66,7 +64,7 @@ function CrowdXBlock(runtime, element){
$("#answer").val('');}) $("#answer").val('');})
$('#caus', element).click(function(eventObject) { $('#caus', element).click(function(eventObject) {
console.debug("ca working"); console.debug("ca working this is edited");
$.ajax({ $.ajax({
type: "POST", type: "POST",
url: runtime.handlerUrl(element, 'clear_states'), url: runtime.handlerUrl(element, 'clear_states'),
...@@ -90,7 +88,7 @@ function CrowdXBlock(runtime, element){ ...@@ -90,7 +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();
$('.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!");
...@@ -115,13 +113,13 @@ function CrowdXBlock(runtime, element){ ...@@ -115,13 +113,13 @@ function CrowdXBlock(runtime, element){
}); });
$("#studentsubmit").val(''); $("#studentsubmit").val('');
/* } 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",
url: runtime.handlerUrl(element, 'get_feedback'), url: runtime.handlerUrl(element, 'get_feedback'),
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