Commit bd777f90 by Sola

version with error in trying to get ID. just uploading for reference.

parent ff636ee3
......@@ -13,10 +13,10 @@ log = logging.getLogger(__name__)
#get_hint and get_feedback are in
class CrowdXBlock(XBlock):
correctanswer = String(default="42", scope=Scope.content) #should be irrelevant for completed version
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}
hints = Dict(default={"2": {"hint1for2":0, "hint2for2":0, "hints3for22":0}, "1": {"hint1for1":0, "hint2for1":0, "hint3for1":0}, "3": {"hint1for3":0, "hint2for3":0, "hint3for3":0}}, 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
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
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
......@@ -73,15 +73,17 @@ class CrowdXBlock(XBlock):
for i in range(0, len(self.Used)):
ans = str('wngans' + str(i))
hnt = str('hntusd' + str(i))
feedbackdict[ans] = str(self.WrongAnswers[i])
feedbackdict[hnt] = str(self.Used[i])
feedbackdict[str(self.Used[i])] = str(self.WrongAnswers[i])
print 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" + ansnum)
if self.Voted == 0:
for key in self.DefaultHints:
if key == self.Used[int(data['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.Voted = 1
print str(self.DefaultHints)
......@@ -89,8 +91,8 @@ class CrowdXBlock(XBlock):
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"])
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)]))
......
......@@ -13,12 +13,12 @@ log = logging.getLogger(__name__)
#get_hint and get_feedback are in
class CrowdXBlock(XBlock):
correctanswer = String(default="42", scope=Scope.content) #should be irrelevant for completed version
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}
hints = Dict(default={"2": {"hint1for2":0, "hint2for2":0, "hints3for22":0}, "1": {"hint1for1":0, "hint2for1":0, "hint3for1":0}, "3": {"hint1for3":0, "hint2for3":0, "hint3for3":0}}, 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
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
Used = List(default=[], scope=Scope.user_state)#List of used hints from HintsToUse
Voted = Integer(default=0, scope=Scope.user_state)
Voted = Integer(default=0, scope=Scope.user_state)#prevent multiple votes/hint submission
def student_view(self, context=None):
html = self.resource_string("static/html/crowdxblock.html")
......@@ -73,15 +73,17 @@ class CrowdXBlock(XBlock):
for i in range(0, len(self.Used)):
ans = str('wngans' + str(i))
hnt = str('hntusd' + str(i))
feedbackdict[ans] = str(self.WrongAnswers[i])
feedbackdict[hnt] = str(self.Used[i])
feedbackdict[str(self.Used[i])] = str(self.WrongAnswers[i])
print 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
if self.Voted == 0:
for key in self.DefaultHints:
if key == self.Used[int(data['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.Voted = 1
print str(self.DefaultHints)
......@@ -89,8 +91,8 @@ class CrowdXBlock(XBlock):
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"])
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)]))
......
<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>
......@@ -13,30 +14,11 @@
<p>
<span class='Thankyou'></span>
</p>
<div id="pair0" style="background-color:#FFA500;height:60px;width:400px"> <p>
<span class='WrongAnswer0'></span>
</p>
<p>
<span class='HintUsed0'></span>
</p> </div>
<div id="pair1" style="background-color:#FFA500;height:60px;width:400px"><p>
<span class='WrongAnswer1'></span>
</p>
<p>
<span class='HintUsed1'></span>
</p> </div>
<div id="pair2" style="background-color:#FFA500;height:60px;width:400px"><p>
<span class='WrongAnswer2'></span>
</p>
<p>
<span class='HintUsed2'></span>
</p> </div>
<div id="pair3" style="background-color:#FFA500;height:60px;width:400px"><p>
<span class='WrongAnswer3'></span>
</p>
<p>
<span class='HintUsed3'></span>
</p> </div>
<div class="hintansarea">
</div>
<p>
<input id="caus" type="button" class="button" value="clearAllUserState">
</p>
......
<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>
<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">
<input id="studentanswer" type="button" class="button" value="Submit Answer">
</div>
<div class="crowdxblock_block">
......@@ -13,32 +14,14 @@
<p>
<span class='Thankyou'></span>
</p>
<div id="pair0" style="background-color:#FFA500;height:60px;width:400px"> <p>
<span class='WrongAnswer0'></span>
</p>
<p>
<span class='HintUsed0'></span>
</p> </div>
<div id="pair1" style="background-color:#FFA500;height:60px;width:400px"><p>
<span class='WrongAnswer1'></span>
</p>
<p>
<span class='HintUsed1'></span>
</p> </div>
<div id="pair2" style="background-color:#FFA500;height:60px;width:400px"><p>
<span class='WrongAnswer2'></span>
</p>
<p>
<span class='HintUsed2'></span>
</p> </div>
<div id="pair3" style="background-color:#FFA500;height:60px;width:400px"><p>
<span class='WrongAnswer3'></span>
</p>
<p>
<span class='HintUsed3'></span>
</p> </div>
<script id="feedback">
var hintused = []
var wronganswer = []
</script>
<p>
<input id="caus" type="button" value="clearAllUserState">
<input id="caus" type="button" class="button" value="clearAllUserState">
</p>
......@@ -51,7 +34,7 @@
<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">
<input id="submit" type="button" class="button" value="Submit Hint">
</div></section></span>
</section>
......
......@@ -18,6 +18,7 @@ function CrowdXBlock(runtime, element){
$("#pair1").hide();
$("#answer").hide();
$(".problem").hide();
$("#feedback").hide();
function seehint(result){//use html to show these results somewhere i guess
$('.HintsToUse', element).text(result.HintsToUse); //text(result.self.hints?)
......@@ -26,53 +27,21 @@ function CrowdXBlock(runtime, element){
function getfeedback(result){
$("#answer").show();
$(".problem").show();
if(result.wngans0 != undefined){
$("#pair0").show();
}if(result.wngans1 != undefined){
$("#pair1").show();
}if(result.wngans2 != undefined){
$("#pair2").show();
}if(result.wngans3 != undefined){
$("#pair3").show();
}
$('.WrongAnswer0', element).text("For your incorrect answer of: " + result.wngans0);
$('.HintUsed0', element).text("You recieved the hint: " + result.hntusd0);
$('.WrongAnswer1', element).text("For your incorrect answer of: " + result.wngans1);
$('.HintUsed1', element).text("You recieved the hint: " + result.hntusd1);
$('.WrongAnswer2', element).text("For your incorrect answer of: " + result.wngans2);
$('.HintUsed2', element).text("You recieved the hint: " + result.hntusd2);
$('.WrongAnswer3', element).text("For your incorrect answer of: " + result.wngans3);
$('.HintUsed3', element).text("You recieved the hint: " + result.hntusd3);
}
$("#feedback").show();
$.each(result, function(index, value) {
console.log( index + ": " + value );
$('.hintansarea').append("<p> 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>");
});
};
$('#pair0', element).click(function(eventObject) { //upvote pair0
$.ajax({
type: "POST",
url: runtime.handlerUrl(element, 'rate_hint'),
data: JSON.stringify({"rating": 1, "ansnum": 0}),
success: finish
});})
$('#pair1', element).click(function(eventObject) { //upvote pair0
$.ajax({
type: "POST",
url: runtime.handlerUrl(element, 'rate_hint'),
data: JSON.stringify({"rating": 1, "ansnum": 1}),
success: finish
});})
$('#pair2', element).click(function(eventObject) { //upvote pair0
$.ajax({
type: "POST",
url: runtime.handlerUrl(element, 'rate_hint'),
data: JSON.stringify({"rating": 1, "ansnum": 2}),
success: finish
});})
$('#pair3', element).click(function(eventObject) { //upvote pair0
$(document).on('click', '.hintbutton', function(){ //upvote
console.log("please show me something");
id = this.id;
console.log($(this).id());
$.ajax({
type: "POST",
url: runtime.handlerUrl(element, 'rate_hint'),
data: JSON.stringify({"rating": 1, "ansnum": 3}),
data: JSON.stringify({"rating": 1, "ansnum": $(this).attr('id')}),
success: finish
});})
$('#submit', element).click(function(eventObject) {
......
......@@ -18,6 +18,7 @@ function CrowdXBlock(runtime, element){
$("#pair1").hide();
$("#answer").hide();
$(".problem").hide();
$("#feedback").hide();
function seehint(result){//use html to show these results somewhere i guess
$('.HintsToUse', element).text(result.HintsToUse); //text(result.self.hints?)
......@@ -26,53 +27,21 @@ function CrowdXBlock(runtime, element){
function getfeedback(result){
$("#answer").show();
$(".problem").show();
if(result.wngans0 != undefined){
$("#pair0").show();
}if(result.wngans1 != undefined){
$("#pair1").show();
}if(result.wngans2 != undefined){
$("#pair2").show();
}if(result.wngans3 != undefined){
$("#pair3").show();
}
$('.WrongAnswer0', element).text("For your incorrect answer of: " + result.wngans0);
$('.HintUsed0', element).text("You recieved the hint: " + result.hntusd0);
$('.WrongAnswer1', element).text("For your incorrect answer of: " + result.wngans1);
$('.HintUsed1', element).text("You recieved the hint: " + result.hntusd1);
$('.WrongAnswer2', element).text("For your incorrect answer of: " + result.wngans2);
$('.HintUsed2', element).text("You recieved the hint: " + result.hntusd2);
$('.WrongAnswer3', element).text("For your incorrect answer of: " + result.wngans3);
$('.HintUsed3', element).text("You recieved the hint: " + result.hntusd3);
}
$("#feedback").show();
$.each(result, function(index, value) {
console.log( index + ": " + value );
$('.hintansarea').append("<p> 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>");
});
};
$('#pair0', element).click(function(eventObject) { //upvote pair0
$.ajax({
type: "POST",
url: runtime.handlerUrl(element, 'rate_hint'),
data: JSON.stringify({"rating": 1, "ansnum": 0}),
success: finish
});})
$('#pair1', element).click(function(eventObject) { //upvote pair0
$.ajax({
type: "POST",
url: runtime.handlerUrl(element, 'rate_hint'),
data: JSON.stringify({"rating": 1, "ansnum": 1}),
success: finish
});})
$('#pair2', element).click(function(eventObject) { //upvote pair0
$.ajax({
type: "POST",
url: runtime.handlerUrl(element, 'rate_hint'),
data: JSON.stringify({"rating": 1, "ansnum": 2}),
success: finish
});})
$('#pair3', element).click(function(eventObject) { //upvote pair0
$(document).on('click', '.hintbutton', function(){ //upvote
console.log("please show me something");
id = this.id;
console.log($(this).attr('value'));
$.ajax({
type: "POST",
url: runtime.handlerUrl(element, 'rate_hint'),
data: JSON.stringify({"rating": 1, "ansnum": 3}),
data: JSON.stringify({"rating": 1, "ansnum": $(this).attr('id')}),
success: finish
});})
$('#submit', element).click(function(eventObject) {
......
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