Commit e306997a by Sola

Now properly deals with periods. Colon/Semicolon probably will mess things up still.

parent b92754a1
......@@ -13,7 +13,7 @@ log = logging.getLogger(__name__)
#get_hint and get_feedback are in
class CrowdXBlock(XBlock):
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)
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}}, 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
......@@ -54,14 +54,13 @@ class CrowdXBlock(XBlock):
self.hints[str(data["submittedanswer"])] = {} #add user's incorrect answer to WrongAnswers
self.HintsToUse = {}
self.HintsToUse.update(self.DefaultHints)
print str(self.hints)
if max(self.HintsToUse.iteritems(), key=operator.itemgetter(1))[0] not in self.Used:
self.Used.append(max(self.HintsToUse.iteritems(), key=operator.itemgetter(1))[0]) #Highest rated hint is shown first
return {'HintsToUse': max(self.HintsToUse.iteritems(), key=operator.itemgetter(1))[0]}
else:
NotUsed = random.choice(self.HintsToUse.keys())
print(len(self.HintsToUse) + len(self.Used))
if len(self.HintsToUse) != len(self.Used):
print(len(self.HintsToUse) + len(self.Used))
while NotUsed in self.Used:
NotUsed = random.choice(self.HintsToUse.keys()) #Choose random hint that hasn't already been Used
elif len(self.Used) > 0:
......@@ -91,6 +90,7 @@ class CrowdXBlock(XBlock):
thiskeycount += 1
feedbacklist.append(str(nextkey))
feedbackdict[str(nextkey)] = str(self.WrongAnswers[i])
print(str(nextkey))
if thiskeycount == 2:
feedbacklist = []
else:
......@@ -110,6 +110,8 @@ class CrowdXBlock(XBlock):
@XBlock.json_handler #add 1 or -1 to rating of a hint
def rate_hint(self, data, suffix=''):
data['ansnum'] = data['ansnum'].replace('ddeecciimmaallppooiinntt', '.')
data['ansnum'] = data['ansnum'].replace('qquueessttiioonnmmaarrkk', '?')
for usdkey in self.Used:
if str(usdkey) == str(data['ansnum']):
ansnum = self.Used.index(str(data['ansnum']))
......@@ -141,6 +143,8 @@ class CrowdXBlock(XBlock):
@XBlock.json_handler
def give_hint(self, data, suffix=''): #add student-made hint into hints
data['submission'] = data['submission'].replace('ddeecciimmaallppooiinntt', '.')
data['id'] = data['id'].replace('ddeecciimmaallppooiinntt', '.')
if self.Voted == 0:
for key in self.hints:
print(str(key))
......@@ -152,6 +156,8 @@ class CrowdXBlock(XBlock):
tempdict.update({data['submission']: 0})
self.hints[str(key)] = tempdict
self.Voted = 1
print ('this went through fine')
return
else:
ansnum = self.Used.index(data['submission'])
for key in self.DefaultHints:
......
......@@ -13,7 +13,7 @@ log = logging.getLogger(__name__)
#get_hint and get_feedback are in
class CrowdXBlock(XBlock):
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)
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}}, 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
......@@ -54,14 +54,13 @@ class CrowdXBlock(XBlock):
self.hints[str(data["submittedanswer"])] = {} #add user's incorrect answer to WrongAnswers
self.HintsToUse = {}
self.HintsToUse.update(self.DefaultHints)
print str(self.hints)
if max(self.HintsToUse.iteritems(), key=operator.itemgetter(1))[0] not in self.Used:
self.Used.append(max(self.HintsToUse.iteritems(), key=operator.itemgetter(1))[0]) #Highest rated hint is shown first
return {'HintsToUse': max(self.HintsToUse.iteritems(), key=operator.itemgetter(1))[0]}
else:
NotUsed = random.choice(self.HintsToUse.keys())
print(len(self.HintsToUse) + len(self.Used))
if len(self.HintsToUse) != len(self.Used):
print(len(self.HintsToUse) + len(self.Used))
while NotUsed in self.Used:
NotUsed = random.choice(self.HintsToUse.keys()) #Choose random hint that hasn't already been Used
elif len(self.Used) > 0:
......@@ -91,6 +90,7 @@ class CrowdXBlock(XBlock):
thiskeycount += 1
feedbacklist.append(str(nextkey))
feedbackdict[str(nextkey)] = str(self.WrongAnswers[i])
print(str(nextkey))
if thiskeycount == 2:
feedbacklist = []
else:
......@@ -110,6 +110,8 @@ class CrowdXBlock(XBlock):
@XBlock.json_handler #add 1 or -1 to rating of a hint
def rate_hint(self, data, suffix=''):
data['ansnum'] = data['ansnum'].replace('ddeecciimmaallppooiinntt', '.')
data['ansnum'] = data['ansnum'].replace('qquueessttiioonnmmaarrkk', '?')
for usdkey in self.Used:
if str(usdkey) == str(data['ansnum']):
ansnum = self.Used.index(str(data['ansnum']))
......@@ -141,6 +143,8 @@ class CrowdXBlock(XBlock):
@XBlock.json_handler
def give_hint(self, data, suffix=''): #add student-made hint into hints
data['submission'] = data['submission'].replace('ddeecciimmaallppooiinntt', '.')
data['id'] = data['id'].replace('qquueessttiioonnmmaarrkk', '?')
if self.Voted == 0:
for key in self.hints:
print(str(key))
......@@ -152,6 +156,8 @@ class CrowdXBlock(XBlock):
tempdict.update({data['submission']: 0})
self.hints[str(key)] = tempdict
self.Voted = 1
print ('this went through fine')
return
else:
ansnum = self.Used.index(data['submission'])
for key in self.DefaultHints:
......
......@@ -25,22 +25,49 @@ function CrowdXBlock(runtime, element){
$(".problem").show();
$("#feedback").show();
$.each(result, function(index, value) {
valueid = value.replace(/\./g, 'ddeecciimmaallppooiinntt');
indexid = index.replace(/\./g, 'ddeecciimmaallppooiinntt');
// valueid = valueid.replace(/\?/g, 'qquueessttiioonnmmaarrkk');
// indexid = indexid.replace(/\?/g, 'qquueessttiioonnmmaarrkk');
console.log("the type of value is" + ' '+ typeof(value));
if($("#submit"+value).length == 0){
if($("#submit"+valueid).length == 0){
console.log("#submit"+value);
$('.hintansarea').append("<p id=\"submit" + value + "\" class=\"hintsarea\"> </p>");
$('.hintansarea').append("<p id=\"submit" + valueid + "\" 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'+valueid).append("For your incorrect answer of:" + " " + value + " <p id=\"hintstoshow" + valueid + "\"> The following hints exist: </p><p> <input id=\"" + indexid + "\" 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('indexid' + indexid);
$('#hintstoshow'+valueid).append("<p>" + index + "<input data-value=\"" + valueid + "\" id=\"" + indexid + "\" type=\"button\" class=\"hintbutton\" value=\"Upvote this Hint\"></p>");
console.log('valueid' + valueid);
console.log("the value is " + value);
});
};
}
$(document).on('click', '.submitbutton', function(){ //upvote
console.log("submitbutton hit");
console.log(this.id);
id = this.id;
value = $('#'+id).attr('data-value');
// console.log($('#'+id).attr('data-value'));
// valueid = $('#'+id).attr('data-value').replace(/\./g, 'ddeecciimmaallppooiinntt');
// indexid = index.replace(/\./g, 'ddeecciimmaallppooiinntt');
// valueid = valueid.replace(/\?/g, 'qquueessttiioonnmmaarrkk');
// indexid = indexid.replace(/\?/g, 'qquueessttiioonnmmaarrkk');
console.log("this id " + $(this).attr('id'));
$('#submit' + valueid).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('submitid' + ' ' + '#submit' + valueid);
$.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('');})
$(document).on('click', '.hintbutton', function(){ //upvote
console.log("the first id" + this.id);
id = this.id;
console.log($(this).attr('id'));
console.log("the first id" + this.id);
$.ajax({
type: "POST",
url: runtime.handlerUrl(element, 'rate_hint'),
......@@ -49,9 +76,10 @@ function CrowdXBlock(runtime, element){
});})
$(document).on('click', '.submitbutton', function(){ //upvote
console.log("submitbutton hit");
id = this.id;
id = $(this).attr('id');
value = $('#'+id).attr('data-value');
console.log("this id " + $(this).attr('id'));
console.log('#submit' + value);
$('#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);
......@@ -89,7 +117,7 @@ function CrowdXBlock(runtime, element){
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!");
......@@ -124,3 +152,6 @@ success: getfeedback
};*/
}
)}
......@@ -25,21 +25,50 @@ function CrowdXBlock(runtime, element){
$(".problem").show();
$("#feedback").show();
$.each(result, function(index, value) {
valueid = value.replace(/\./g, 'ddeecciimmaallppooiinntt');
indexid = index.replace(/\./g, 'ddeecciimmaallppooiinntt');
// valueid = valueid.replace(/\?/g, 'qquueessttiioonnmmaarrkk');
// indexid = indexid.replace(/\?/g, 'qquueessttiioonnmmaarrkk');
console.log("the type of value is" + ' '+ typeof(value));
if($("#submit"+value).length == 0){
$('.hintansarea').append("<p id=\"submit" + value + "\" class=\"hintsarea\"> </p>");
if($("#submit"+valueid).length == 0){
console.log("#submit"+value);
$('.hintansarea').append("<p id=\"submit" + valueid + "\" 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'+valueid).append("For your incorrect answer of:" + " " + value + " <p id=\"hintstoshow" + valueid + "\"> The following hints exist: </p><p> <input id=\"" + indexid + "\" 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('indexid' + indexid);
$('#hintstoshow'+valueid).append("<p>" + index + "<input data-value=\"" + valueid + "\" id=\"" + indexid + "\" type=\"button\" class=\"hintbutton\" value=\"Upvote this Hint\"></p>");
console.log('valueid' + valueid);
console.log("the value is " + value);
});
};
}
$(document).on('click', '.submitbutton', function(){ //upvote
console.log("submitbutton hit");
console.log(this.id);
id = this.id;
value = $('#'+id).attr('data-value');
// console.log($('#'+id).attr('data-value'));
// valueid = $('#'+id).attr('data-value').replace(/\./g, 'ddeecciimmaallppooiinntt');
// indexid = index.replace(/\./g, 'ddeecciimmaallppooiinntt');
// valueid = valueid.replace(/\?/g, 'qquueessttiioonnmmaarrkk');
// indexid = indexid.replace(/\?/g, 'qquueessttiioonnmmaarrkk');
console.log("this id " + $(this).attr('id'));
$('#submit' + valueid).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({
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('');})
$(document).on('click', '.hintbutton', function(){ //upvote
console.log("the first id" + this.id);
id = this.id;
console.log($(this).attr('id'));
console.log("the first id" + this.id);
$.ajax({
type: "POST",
url: runtime.handlerUrl(element, 'rate_hint'),
......@@ -48,9 +77,10 @@ function CrowdXBlock(runtime, element){
});})
$(document).on('click', '.submitbutton', function(){ //upvote
console.log("submitbutton hit");
id = this.id;
id = $(this).attr('id');
value = $('#'+id).attr('data-value');
console.log("this id " + $(this).attr('id'));
console.log('#submit' + value);
$('#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);
......@@ -88,7 +118,7 @@ function CrowdXBlock(runtime, element){
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!");
......@@ -123,3 +153,6 @@ 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