Commit b92754a1 by Sola

most recent changes.

parent ba55f575
......@@ -12,12 +12,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={"2": {"hint1for2":0, "hint2for2":0, "hint3for2":0}, "1": {"hint1for1":0, "hint2for1":0, "hint3for1":0}, "3": {"hint1for3":0, "hint2for3":0, "hint3for3":0}}, scope=Scope.content)
correctanswer = String(default="2.0", scope=Scope.content) #should be irrelevant for completed version
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}
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={"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
Voted = Integer(default=0, scope=Scope.user_state)#prevent multiple votes/hint submission
......@@ -43,13 +43,11 @@ class CrowdXBlock(XBlock):
for key in self.hints:
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(ast.literal_eval(temphints))
for key in self.HintsToUse:
if key not in self.Used:
hintsarehere = 1
print("hints are here doe")
if hintsarehere == 0:
self.HintsToUse.update(self.DefaultHints) #Use DefaultHints if there aren't enough other hints
if str(data["submittedanswer"]) not in self.hints:
......@@ -107,7 +105,7 @@ class CrowdXBlock(XBlock):
feedbacklist = []
if str(self.WrongAnswers[i]) not in self.hints:
feedbackdict[str(random.choice(self.DefaultHints.keys()))] = str(self.WrongAnswers[i])
print ("feedback : " + str(feedbackdict))
print("feedbackdict is: " + str(feedbackdict))
return feedbackdict
@XBlock.json_handler #add 1 or -1 to rating of a hint
......@@ -115,13 +113,11 @@ class CrowdXBlock(XBlock):
for usdkey in self.Used:
if str(usdkey) == str(data['ansnum']):
ansnum = self.Used.index(str(data['ansnum']))
print("ansnum is" + str(ansnum))
if self.Voted == 0:
for key in self.DefaultHints:
if key == self.Used[int(ansnum)]: #rating for hints in DefaultHints
self.DefaultHints[str(key)] += int(data["rating"])
self.Voted = 1
print str(self.DefaultHints)
return
for key in self.hints:
tempdict = str(self.hints[str(key)]) #rate hint that is in hints
......@@ -129,9 +125,6 @@ class CrowdXBlock(XBlock):
if str(key) == str(self.WrongAnswers[ansnum]): #ansnum will the the answer/hint pair that is selected
tempdict[self.Used[int(ansnum)]] += int(data["rating"])
self.hints[str(key)] = tempdict
print("TESTING AGAIN HI")
print("hints are " + str(self.hints[str(key)]))
print("otherstuff " + str(self.hints))
self.Voted = 1
return
for key in self.hints:
......@@ -159,16 +152,12 @@ class CrowdXBlock(XBlock):
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:
ansnum = self.Used.index(data['submission'])
for key in self.DefaultHints:
if key == self.Used[int(ansnum)]: #rating for hints in DefaultHints
self.DefaultHints[str(key)] += int(1)
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
......@@ -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
tempdict[self.Used[int(ansnum)]] += int(1)
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 clear_states(self, data, suffix=''):
print("used: " + str(self.Used))
print("wronganswers: " + str(self.WrongAnswers))
print("hints: " + str(self.hints))
print("defaults: " + str(self.DefaultHints))
self.Used = []
self.HintsToUse = {}
self.Voted = 0
......
<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>
<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">
<input type="text" name="studentanswer" id="studentsubmit" class="notmath" size="40">
<input id="studentanswer" type="button" class="button" value="Submit Answer">
......
<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>
<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">
<input type="text" name="studentanswer" id="studentsubmit" class="notmath" size="40">
<input id="studentanswer" type="button" class="button" value="Submit Answer">
......@@ -23,9 +25,6 @@
<input id="caus" type="button" class="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="action">
<input type="hidden" name="problem_id" value="Numerical Input">
......
......@@ -12,10 +12,6 @@ response = data[1];*/ //use this snippet for actual code? maybe?
function CrowdXBlock(runtime, element){
var WrongAnswer = [];
var HintUsed = [];
$("#pair0").hide();
$("#pair3").hide();
$("#pair2").hide();
$("#pair1").hide();
$("#answer").hide();
$(".problem").hide();
$("#feedback").hide();
......@@ -27,61 +23,65 @@ function CrowdXBlock(runtime, element){
function getfeedback(result){
$("#answer").show();
$(".problem").show();
$("#feedback").show();
$.each(result, function(index, value) {
console.log( index + ": " + value );
$("#feedback").show();
$.each(result, function(index, value) {
console.log("the type of value is" + ' '+ typeof(value));
if($("#submit"+value).length == 0){
$('.hintansarea').append("<p id=\"submit" + value + "\" class=\"hintsarea\"> </p>");
$('#submit'+value).append("For your incorrect answer of:" + " " + value + " <p id=\"hintstoshow" + value + "\"> The following hints exist: </p><p> <input id=\"" + index + "\" type=\"button\" class=\"submitbutton\" value=\"Submit a hint for this problem\">");
}$('#hintstoshow'+value).append("<p>" + index + "<input data-value=\"" + value + "\" id=\"" + index + "\" type=\"button\" class=\"hintbutton\" value=\"Upvote this Hint\"></p>");
});
console.log("#submit"+value);
$('.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\">");
}
$('#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
console.log("the first id" + this.id);
id = this.id;
console.log($(this).attr('id'));
$.ajax({
console.log("the first id" + this.id);
id = this.id;
console.log($(this).attr('id'));
$.ajax({
type: "POST",
url: runtime.handlerUrl(element, 'rate_hint'),
data: JSON.stringify({"rating": 1, "ansnum": $(this).attr('id'), "value": $(this).attr('data-value')}),
success: finish
});})
$(document).on('click', '.submitbutton', function(){ //upvote
console.log("submitbutton hit");
id = this.id;
console.log("submitbutton hit");
id = this.id;
value = $('#'+id).attr('data-value');
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>");})
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>");})
$(document).on('click', '#submit', function(){
console.log("the other id thing" + this.id);
console.log("thisthing" + $(".math").attr('id'));
$.ajax({
$.ajax({
type: "POST",
url: runtime.handlerUrl(element, 'give_hint'),
data: JSON.stringify({"submission": $('.math').val(), "id": $(".math").attr('id')}), //give hin for first incorrect answer
success: finish
});
$("#answer").val('');})
$("#answer").val('');})
$('#caus', element).click(function(eventObject) {
console.debug("ca working");
$.ajax({
console.debug("ca working this is edited");
$.ajax({
type: "POST",
url: runtime.handlerUrl(element, 'clear_states'),
data: JSON.stringify({"hello": "world"}), //give hin for first incorrect answer
success: clearstates
});
$("#studentsubmit").val('');
$("#answer").val('');})
$("#studentsubmit").val('');
$("#answer").val('');})
function finish(){
$('.Thankyou', element).text("Thankyou for your help!");
$('.correct', element).hide();
$('.Thankyou', element).text("Thankyou for your help!");
$('.correct', element).hide();
$( ".hintansarea" ).empty();
}
function clearstates(){
$('.Thankyou', element).text();
$('.correct', element).hide();
$('.Thankyou', element).text();
$('.correct', element).hide();
$( ".hintansarea" ).empty();
$("#answer").hide();
$(".problem").hide();
......@@ -91,8 +91,8 @@ $('.correct', element).hide();
if(result.correct == 1){
console.debug("yay");
$('.correct', element).show();
$('.correct', element).text("You're correct! Please choose the best hint, or provide us with one of your own!");
$('.correct', element).show();
$('.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'),
......@@ -100,12 +100,12 @@ $('.correct', element).text("You're correct! Please choose the best hint, or pro
success: getfeedback
});
}else{
console.debug("nay");
seehint(result)
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
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'),
......
//my coding attemps start here i guess
/*this.url = this.el.data('url');
Logger.listen('problem_graded', this.el.data('child-id'), this.capture_problem);
this.render();*/
Logger.listen('problem_graded', this.el.data('child-id'), this.capture_problem);
this.render();*/
/*function capture_problem(event_type, data, element) {
var answers, response,
_this = this;
answers = data[0];
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?
var answers, response,
_this = this;
answers = data[0];
response = data[1];*/ //use this snippet for actual code? maybe?
function CrowdXBlock(runtime, element){
var WrongAnswer = [];
......@@ -28,100 +23,103 @@ function CrowdXBlock(runtime, element){
function getfeedback(result){
$("#answer").show();
$(".problem").show();
$("#feedback").show();
$.each(result, function(index, value) {
console.log( index + ": " + value );
$("#feedback").show();
$.each(result, function(index, value) {
console.log("the type of value is" + ' '+ typeof(value));
if($("#submit"+value).length == 0){
$('.hintansarea').append("<p id=\"submit" + value + "\" class=\"hintsarea\"> </p>");
$('#submit'+value).append("For your incorrect answer of:" + " " + value + " <p id=\"hintstoshow" + value + "\"> The following hints exist: </p><p> <input id=\"" + index + "\" type=\"button\" class=\"submitbutton\" value=\"Submit a hint for this problem\">");
}$('#hintstoshow'+value).append("<p>" + index + "<input data-value=\"" + value + "\" id=\"" + index + "\" type=\"button\" class=\"hintbutton\" value=\"Upvote this Hint\"></p>");
});
$('.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\">");
}
$('#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
console.log("the first id" + this.id);
id = this.id;
console.log($(this).attr('id'));
$.ajax({
console.log("the first id" + this.id);
id = this.id;
console.log($(this).attr('id'));
$.ajax({
type: "POST",
url: runtime.handlerUrl(element, 'rate_hint'),
data: JSON.stringify({"rating": 1, "ansnum": $(this).attr('id'), "value": $(this).attr('data-value')}),
success: finish
});})
$(document).on('click', '.submitbutton', function(){ //upvote
console.log("submitbutton hit");
id = this.id;
console.log("submitbutton hit");
id = this.id;
value = $('#'+id).attr('data-value');
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>");})
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>");})
$(document).on('click', '#submit', function(){
console.log("the other id thing" + this.id);
console.log("thisthing" + $(".math").attr('id'));
$.ajax({
$.ajax({
type: "POST",
url: runtime.handlerUrl(element, 'give_hint'),
data: JSON.stringify({"submission": $('.math').val(), "id": $(".math").attr('id')}), //give hin for first incorrect answer
success: finish
});
$("#answer").val('');})
$("#answer").val('');})
$('#caus', element).click(function(eventObject) {
console.debug("ca working");
$.ajax({
console.debug("ca working this is edited");
$.ajax({
type: "POST",
url: runtime.handlerUrl(element, 'clear_states'),
data: JSON.stringify({"hello": "world"}), //give hin for first incorrect answer
success: clearstates
});
$("#studentsubmit").val('');
$("#answer").val('');})
$("#studentsubmit").val('');
$("#answer").val('');})
function finish(){
$('.Thankyou', element).text("Thankyou for your help!");
$('.correct', element).hide();
$('.Thankyou', element).text("Thankyou for your help!");
$('.correct', element).hide();
$( ".hintansarea" ).empty();
}
function clearstates(){
$('.Thankyou', element).text();
$('.correct', element).hide();
$('.Thankyou', element).text();
$('.correct', element).hide();
$( ".hintansarea" ).empty();
$("#answer").hide();
$(".problem").hide();
}
function checkreply(result){
if(result.correct == 1){
if(result.correct == 1){
console.debug("yay");
$('.correct', element).show();
$('.correct', element).text("You're correct! Please choose the best hint, or provide us with one of your own!");
$('.correct', element).show();
$('.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"}),
data: JSON.stringify({"hello": "world"}),
success: getfeedback
});
}else{
console.debug("nay");
seehint(result)
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
$('#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": $('#studentsubmit').val()}), //return student's incorrect answer here
success: checkreply
});
$("#studentsubmit").val('');
/* } 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",
url: runtime.handlerUrl(element, 'get_feedback'),
data: JSON.stringify({"hello": "world"}),
success: getfeedback
});
};*/
$('.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
});
};*/
}
)}
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