Commit ba55f575 by Sola

fixed mistakes I made with github doing stuff.

parent 41fb5594
......@@ -10,10 +10,10 @@ from xblock.fragment import Fragment
log = logging.getLogger(__name__)
#get_hint and get_feedback are in
#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": {"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": {"hint1for2":0, "hint2for2":0, "hint3for2":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
......@@ -72,12 +72,12 @@ class CrowdXBlock(XBlock):
return {'HintsToUse': NotUsed} #note to self dont let python get into endless notused loop
@XBlock.json_handler
def get_feedback(self, data, suffix=''): #start feedback, sent hint/answer data
def get_feedback(self, data, suffix=''): #start feedback, sent hint/answer data
feedbackdict = {}
feedbacklist = []
if len(self.WrongAnswers) == 0:
return #Do nothing if no mistakes were made
else: #lenth of Used will be used to dictate flow of feedback
else: #lenth of Used will be used to dictate flow of feedback
for i in range(0, len(self.Used)):
ans = str('wngans' + str(i))
hnt = str('hntusd' + str(i))
......@@ -101,7 +101,7 @@ class CrowdXBlock(XBlock):
nextkey = random.choice(self.DefaultHints.keys())
if str(nextkey) not in feedbacklist:
thiskeycount += 1
feedbacklist.append(str(nextkey))
feedbacklist.append(str(nextkey))
feedbackdict[str(nextkey)] = str(self.WrongAnswers[i])
if thiskeycount == 2:
feedbacklist = []
......@@ -115,7 +115,7 @@ 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))
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
......@@ -124,9 +124,9 @@ class CrowdXBlock(XBlock):
print str(self.DefaultHints)
return
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
tempdict = (ast.literal_eval(tempdict))
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"])
self.hints[str(key)] = tempdict
print("TESTING AGAIN HI")
......@@ -139,7 +139,7 @@ class CrowdXBlock(XBlock):
for nextkey in self.hints[key]:
if str(nextkey) == str(data['ansnum']):
ansnum = self.hints[str(key)[str(nextkey)]]
tempdict = str(self.hints[str(key)]) #rate hint that is in hints
tempdict = str(self.hints[str(key)]) #rate hint that is in hints
tempdict = (ast.literal_eval(tempdict))
tempdict[self.hints[str(key)[ansnum]]] += 1
selff.hints[str(key)] = tempdict
......@@ -154,7 +154,7 @@ class CrowdXBlock(XBlock):
print("still working here")
if str(key) == self.WrongAnswers[self.Used.index(str(data['id']))]:
if str(data['submission']) not in self.hints[str(key)]:
tempdict = str(self.hints[str(key)]) #rate hint that is in hints
tempdict = str(self.hints[str(key)]) #rate hint that is in hints
tempdict = (ast.literal_eval(tempdict))
tempdict.update({data['submission']: 0})
self.hints[str(key)] = tempdict
......@@ -171,9 +171,9 @@ class CrowdXBlock(XBlock):
print str(self.DefaultHints)
return
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
tempdict = (ast.literal_eval(tempdict))
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)
self.hints[str(key)] = tempdict
print("TESTING AGAIN HI")
......@@ -198,13 +198,13 @@ class CrowdXBlock(XBlock):
return [
("CrowdXBlock",
"""<vertical_demo>
<crowdxblock/>
</vertical_demo>
"""),
<crowdxblock/>
</vertical_demo>
"""),
]
'''
print ("answer" + str(data["submittedanswer"]))
for keys in self.hints[key]:
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
print("hintstouse: " + str(self.HintsToUse[keys]))'''
print ("answer" + str(data["submittedanswer"]))
for keys in self.hints[key]:
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
print("hintstouse: " + str(self.HintsToUse[keys]))'''
......@@ -13,7 +13,7 @@ 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)
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)
#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
......
//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 = [];
......@@ -32,100 +27,100 @@ 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( index + ": " + 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\">");
$('.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>");
});
});
};
$(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");
$.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
});
};*/
}
)}
......@@ -17,10 +17,6 @@
function CrowdXBlock(runtime, element){
var WrongAnswer = [];
var HintUsed = [];
$("#pair0").hide();
$("#pair3").hide();
$("#pair2").hide();
$("#pair1").hide();
$("#answer").hide();
$(".problem").hide();
$("#feedback").hide();
......
/* Javascript for CrowdXBlock. */
function CrowdXBlock(runtime, element) {
function Hinter(element) {
var _this = this;
this.set_bottom_links = function() {
return Hinter.prototype.set_bottom_links.apply(_this, arguments);
};
this.answer_choice_handle = function(eventObj) {
return Hinter.prototype.answer_choice_handle.apply(_this, arguments);
};
this.wizard_link_handle = function(eventObj) {
return Hinter.prototype.wizard_link_handle.apply(_this, arguments);
};
this.clear_default_text = function(eventObj) {
return Hinter.prototype.clear_default_text.apply(_this, arguments);
};
this.submit_hint = function(eventObj) {
return Hinter.prototype.submit_hint.apply(_this, arguments);
};
this.vote = function(eventObj) {
return Hinter.prototype.vote.apply(_this, arguments);
};
this.expand = function(eventObj) {
return Hinter.prototype.expand.apply(_this, arguments);
};
this.bind = function() {
return Hinter.prototype.bind.apply(_this, arguments);
};
this.capture_problem = function(event_type, data, element) {
return Hinter.prototype.capture_problem.apply(_this, arguments);
};
this.el = $(element).find('.crowdsource-wrapper');
this.url = this.el.data('url');
Logger.listen('problem_graded', this.el.data('child-id'), this.capture_problem);
this.render();
}
Hinter.prototype.capture_problem = function(event_type, data, element) {
var answers, response,
_this = this;
answers = data[0];
response = data[1];
if (response.search(/class="correct/) === -1) {
return $.postWithPrefix("" + this.url + "/get_hint", answers, function(response) {
return _this.render(response.contents);
});
} else {
return $.postWithPrefix("" + this.url + "/get_feedback", answers, function(response) {
return _this.render(response.contents);
});
}
};
Hinter.prototype.$ = function(selector) {
return $(selector, this.el);
};
Hinter.prototype.bind = function() {
this.$('input.vote').click(this.vote);
this.$('input.submit-hint').click(this.submit_hint);
this.$('.custom-hint').click(this.clear_default_text);
this.$('.expand').click(this.expand);
this.$('.wizard-link').click(this.wizard_link_handle);
return this.$('.answer-choice').click(this.answer_choice_handle);
};
Hinter.prototype.expand = function(eventObj) {
var target;
target = this.$('#' + this.$(eventObj.currentTarget).data('target'));
if (this.$(target).css('crowdxblock') === 'none') {
this.$(target).css('crowdxblock', 'block');
} else {
this.$(target).css('crowdxblock', 'none');
}
return this.set_bottom_links();
};
Hinter.prototype.submit_hint = function(eventObj) {
var post_json, textarea,
_this = this;
textarea = $('.custom-hint');f
if (this.answer === '') {
return;
}
post_json = {
'answer': this.answer,
'hint': textarea.val()
};
var post_json = {}
post_json['answer'] = this.answer;
post_json[]
JSON.stringify(post_json)
return $.postWithPrefix("" + this.url + "/submit_hint", post_json, function(response) {
return _this.render(response.contents);
});
};
/* $.ajax({
type: "POST",
url: handlerUrl,
data: JSON.stringify({"hello": "world"}),
success: updateCount
});*/
Hinter.prototype.clear_default_text = function(eventObj) {
var target;
target = this.$(eventObj.currentTarget);
if (target.data('cleared') === void 0) {
target.val('');
return target.data('cleared', true);
}
};
Hinter.prototype.wizard_link_handle = function(eventObj) {
var target;
target = this.$(eventObj.currentTarget);
return this.go_to(target.attr('dest'));
};
Hinter.prototype.answer_choice_handle = function(eventObj) {
this.answer = this.$(eventObj.target).attr('value');
this.$('#blank-answer').html(this.answer);
return this.go_to('p3');
};
Hinter.prototype.set_bottom_links = function() {
var viewbox_height;
this.$('.bottom').css('margin-top', '0px');
viewbox_height = parseInt(this.$('.wizard-viewbox').css('height'), 10);
return this.$('.bottom').each(function(index, obj) {
var view_height;
view_height = parseInt($(obj).parent().css('height'), 10);
return $(obj).css('margin-top', (viewbox_height - view_height) + 'px');
});
};
Hinter.prototype.render = function(content) {
var hints_exist, styles,
_this = this;
if (content) {
content = content.trim();
}
if (content) {
this.el.html(content);
this.el.show();
JavascriptLoader.executeModuleScripts(this.el, function() {
return _this.bind();
});
this.$('#previous-answer-0').css('crowdxblock', 'inline');
} else {
this.el.hide();
}
this.answer = '';
styles = document.body.style;
if (styles.WebkitTransform === '' || styles.transform === '') {
this.go_to = this.transform_go_to;
} else {
this.go_to = this.legacy_go_to;
}
hints_exist = this.$('#hints-exist').html() === 'True';
if (hints_exist) {
return this.go_to('p1');
} else {
return this.go_to('p2');
}
};
Hinter.prototype.transform_go_to = function(view_id) {
var id_to_index, translate_string;
id_to_index = {
'p1': 0,
'p2': 1,
'p3': 2
};
translate_string = 'translateX(' + id_to_index[view_id] * -1 * parseInt($('#' + view_id).css('width'), 10) + 'px)';
this.$('.wizard-container').css('transform', translate_string);
this.$('.wizard-container').css('-webkit-transform', translate_string);
return this.set_bottom_links();
};
Hinter.prototype.legacy_go_to = function(view_id) {
this.$('.wizard-view').css('display', 'none');
this.$('#' + view_id).css('display', 'block');
return this.set_bottom_links();
};
return Hinter;
})();
}).call(this);
/*
function updateCount(result) {
$('.count', element).text(result.count);
}
function checktheanswer(result) {
// capture the information from server and render your screen to show the submission result
$('.studentanswer', element).text(result.studentanswer);
}
var handlerUrl = runtime.handlerUrl(element, 'increment_count');
var handlerUrlcheck = runtime.handlerUrl(element, 'checkanswer');
$('#check').click(function(eventObject) {
capture what the user types
$.ajax({
type: "POST",
url: handlerUrlcheck,
data: JSON.stringify({"submittedanswer": $('#answer').val()}),
success: checktheanswer
});
$.ajax({
type: "POST",
url: handlerUrl,
data: JSON.stringify({"hello": "world"}), // pass what user types to server
success: updateCount
});
});
*/
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