Commit 95df17df by solashirai Committed by Piotr Mitros

mostly cleanup

parent 1029ba95
...@@ -6,6 +6,7 @@ import random ...@@ -6,6 +6,7 @@ import random
import json import json
import copy import copy
from copy import deepcopy from copy import deepcopy
from eventtracking import tracker
from xblock.core import XBlock from xblock.core import XBlock
from xblock.fields import Scope, Dict, List, Boolean from xblock.fields import Scope, Dict, List, Boolean
...@@ -126,9 +127,6 @@ class CrowdsourceHinter(XBlock): ...@@ -126,9 +127,6 @@ class CrowdsourceHinter(XBlock):
or another random hint for an incorrect answer or another random hint for an incorrect answer
or 'Sorry, there are no more hints for this answer.' if no more hints exist or 'Sorry, there are no more hints for this answer.' if no more hints exist
""" """
print(str(self.hint_database))
print(str(self.initial_hints))
print(str(self.generic_hints))
# populate hint_database with hints from initial_hints if there are no hints in hint_database. # populate hint_database with hints from initial_hints if there are no hints in hint_database.
# this probably will occur only on the very first run of a unit containing this block. # this probably will occur only on the very first run of a unit containing this block.
if not bool(self.hint_database): if not bool(self.hint_database):
...@@ -157,11 +155,13 @@ class CrowdsourceHinter(XBlock): ...@@ -157,11 +155,13 @@ class CrowdsourceHinter(XBlock):
# for multiple submissions/hint requests # for multiple submissions/hint requests
if best_hint not in self.Flagged.keys(): if best_hint not in self.Flagged.keys():
self.Used.append(best_hint) self.Used.append(best_hint)
tracker.emit('get_hint', answer, best_hint, 'best hint')
return {'HintsToUse': best_hint, "StudentAnswer": answer} return {'HintsToUse': best_hint, "StudentAnswer": answer}
if best_hint not in self.Used: if best_hint not in self.Used:
# choose highest rated hint for the incorrect answer # choose highest rated hint for the incorrect answer
if best_hint not in self.Flagged.keys(): if best_hint not in self.Flagged.keys():
self.Used.append(best_hint) self.Used.append(best_hint)
tracker.emit('get_hint', answer, best_hint, 'best hint')
return {'HintsToUse': best_hint, "StudentAnswer": answer} return {'HintsToUse': best_hint, "StudentAnswer": answer}
# choose another random hint for the answer. # choose another random hint for the answer.
temporary_hints_list = [] temporary_hints_list = []
...@@ -171,11 +171,13 @@ class CrowdsourceHinter(XBlock): ...@@ -171,11 +171,13 @@ class CrowdsourceHinter(XBlock):
temporary_hints_list.append(str(hint_keys)) temporary_hints_list.append(str(hint_keys))
not_used = random.choice(temporary_hints_list) not_used = random.choice(temporary_hints_list)
self.Used.append(not_used) self.Used.append(not_used)
tracker.emit('get_hint', answer, not_used, 'unused hint')
return {'HintsToUse': not_used, "StudentAnswer": answer} return {'HintsToUse': not_used, "StudentAnswer": answer}
else: else:
if len(self.generic_hints) != 0: if len(self.generic_hints) != 0:
not_used = random.choice(self.generic_hints) not_used = random.choice(self.generic_hints)
self.Used.append(not_used) self.Used.append(not_used)
tracker.emit('get_hint', answer, not_used, 'generic hint')
return {'HintsToUse': not_used, "StudentAnswer": answer} return {'HintsToUse': not_used, "StudentAnswer": answer}
else: else:
# if there are no more hints left in either the database or defaults # if there are no more hints left in either the database or defaults
...@@ -304,27 +306,28 @@ class CrowdsourceHinter(XBlock): ...@@ -304,27 +306,28 @@ class CrowdsourceHinter(XBlock):
answer_data = data['student_answer'] answer_data = data['student_answer']
data_rating = data['student_rating'] data_rating = data['student_rating']
data_hint = data['hint'] data_hint = data['hint']
print answer_data, data_rating, data_hint
print (str(self.hint_database))
print (str(self.Flagged))
if data['student_rating'] == 'unflag': if data['student_rating'] == 'unflag':
for flagged_hints in self.Flagged: for flagged_hints in self.Flagged:
if flagged_hints == data_hint: if flagged_hints == data_hint:
self.Flagged.pop(data_hint, None) self.Flagged.pop(data_hint, None)
tracker.emit('rate_hint', data, 'unflagged')
return {'rating': 'unflagged'} return {'rating': 'unflagged'}
if data['student_rating'] == 'remove': if data['student_rating'] == 'remove':
for flagged_hints in self.Flagged: for flagged_hints in self.Flagged:
if data_hint == flagged_hints: if data_hint == flagged_hints:
self.hint_database[self.Flagged[data_hint]].pop(data_hint, None) self.hint_database[self.Flagged[data_hint]].pop(data_hint, None)
self.Flagged.pop(data_hint, None) self.Flagged.pop(data_hint, None)
tracker.emit('rate_hint', data, 'removed')
return {'rating': 'removed'} return {'rating': 'removed'}
if data['student_rating'] == 'flag': if data['student_rating'] == 'flag':
# add hint to Flagged dictionary # add hint to Flagged dictionary
self.Flagged[str(data_hint)] = answer_data self.Flagged[str(data_hint)] = answer_data
tracker.emit('rate_hint', data, 'flagged')
return {"rating": 'flagged', 'hint': data_hint} return {"rating": 'flagged', 'hint': data_hint}
if str(data_hint) not in self.Voted: if str(data_hint) not in self.Voted:
self.Voted.append(str(data_hint)) # add data to Voted to prevent multiple votes self.Voted.append(str(data_hint)) # add data to Voted to prevent multiple votes
rating = self.change_rating(data_hint, data_rating, answer_data) # change hint rating rating = self.change_rating(data_hint, data_rating, answer_data) # change hint rating
tracker.emit('rate_hint', data, 'rating changed')
if str(rating) == str(0): if str(rating) == str(0):
return {"rating": str(0), 'hint': data_hint} return {"rating": str(0), 'hint': data_hint}
else: else:
...@@ -334,7 +337,7 @@ class CrowdsourceHinter(XBlock): ...@@ -334,7 +337,7 @@ class CrowdsourceHinter(XBlock):
def change_rating(self, data_hint, data_rating, answer_data): def change_rating(self, data_hint, data_rating, answer_data):
""" """
This function is used to change the rating of a hint when it is voted on. This function is used to change the rating of a hint when students vote on its helpfulness.
Initiated by rate_hint. The temporary_dictionary is manipulated to be used Initiated by rate_hint. The temporary_dictionary is manipulated to be used
in self.rate_hint in self.rate_hint
...@@ -364,6 +367,7 @@ class CrowdsourceHinter(XBlock): ...@@ -364,6 +367,7 @@ class CrowdsourceHinter(XBlock):
""" """
submission = data['submission'] submission = data['submission']
answer = data['answer'] answer = data['answer']
tracker.emit('give_hint', answer, submission)
if str(submission) not in self.hint_database[str(answer)]: if str(submission) not in self.hint_database[str(answer)]:
self.hint_database[str(answer)].update({submission: 0}) self.hint_database[str(answer)].update({submission: 0})
return return
...@@ -406,7 +410,7 @@ class CrowdsourceHinter(XBlock): ...@@ -406,7 +410,7 @@ class CrowdsourceHinter(XBlock):
A minimal working test for parse_xml A minimal working test for parse_xml
""" """
block = runtime.construct_xblock_from_class(cls, keys) block = runtime.construct_xblock_from_class(cls, keys)
#import pdb; pdb.set_trace() import pdb; pdb.set_trace()
#['__class__', '__contains__', '__copy__', '__deepcopy__', '__delattr__', '__delitem__', '__doc__', '__format__', '__getattribute__', '__getitem__', '__hash__', '__init__', '__iter__', '__len__', '__module__', '__new__', '__nonzero__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__setattr__', '__setitem__', '__sizeof__', '__slots__', '__str__', '__subclasshook__', '_filter', '_init', 'addnext', 'addprevious', 'append', 'attrib', 'base', 'blacklist', 'clear', 'extend', 'find', 'findall', 'findtext', 'get', 'getchildren', 'getiterator', 'getnext', 'getparent', 'getprevious', 'getroottree', 'index', 'insert', 'items', 'iter', 'iterancestors', 'iterchildren', 'iterdescendants', 'iterfind', 'itersiblings', 'itertext', 'keys', 'makeelement', 'nsmap', 'prefix', 'remove', 'replace', 'set', 'sourceline', 'tag', 'tail', 'text', 'values', 'xpath'] #['__class__', '__contains__', '__copy__', '__deepcopy__', '__delattr__', '__delitem__', '__doc__', '__format__', '__getattribute__', '__getitem__', '__hash__', '__init__', '__iter__', '__len__', '__module__', '__new__', '__nonzero__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__setattr__', '__setitem__', '__sizeof__', '__slots__', '__str__', '__subclasshook__', '_filter', '_init', 'addnext', 'addprevious', 'append', 'attrib', 'base', 'blacklist', 'clear', 'extend', 'find', 'findall', 'findtext', 'get', 'getchildren', 'getiterator', 'getnext', 'getparent', 'getprevious', 'getroottree', 'index', 'insert', 'items', 'iter', 'iterancestors', 'iterchildren', 'iterdescendants', 'iterfind', 'itersiblings', 'itertext', 'keys', 'makeelement', 'nsmap', 'prefix', 'remove', 'replace', 'set', 'sourceline', 'tag', 'tail', 'text', 'values', 'xpath']
print(node.tag) print(node.tag)
......
...@@ -92,3 +92,7 @@ div[data-rate="downvote"] { ...@@ -92,3 +92,7 @@ div[data-rate="downvote"] {
flex-direction: colomn; flex-direction: colomn;
} }
.csh_student_text_input{
width: 100%;
}
...@@ -30,7 +30,10 @@ ...@@ -30,7 +30,10 @@
</script> </script>
<script type="x-tmpl/mustache" id="student_hint_creation"> <script type="x-tmpl/mustache" id="student_hint_creation">
<p><textarea type="text" name="studentinput" class="csh_student_text_input"></textarea> <p>
<textarea type="text" name="studentinput" class="csh_student_text_input"></textarea>
</p>
<p>
<input answer="{{student_answer}}" type="button" class="csh_submit_new" value="Submit Hint"> <input answer="{{student_answer}}" type="button" class="csh_submit_new" value="Submit Hint">
</p> </p>
</script> </script>
...@@ -42,7 +45,8 @@ ...@@ -42,7 +45,8 @@
<script type="x-tmpl/mustache" id="show_answer_feedback"> <script type="x-tmpl/mustache" id="show_answer_feedback">
<div class="csh_student_answer"> <div class="csh_student_answer">
<h class="csh_answer_text" answer={{answer}}><i> Your answer: {{answer}}</i></h> <h class="csh_answer_text" answer={{answer}}>
<i> Your original answer: {{answer}} <br> The hint you viewed: </i></h>
</div> </div>
</script> </script>
......
...@@ -20,7 +20,7 @@ function CrowdsourceHinter(runtime, element){ ...@@ -20,7 +20,7 @@ function CrowdsourceHinter(runtime, element){
Logger.listen('seq_goto', null, stopScript); Logger.listen('seq_goto', null, stopScript);
//data about the problem obtained from Logger.listen('problem_graded') is passed on to the onStudentSubmission. //data about the problem obtained from Logger.listen('problem_graded') is passed on to the onStudentSubmission.
//directly passing data to onStudentSubmission does not work for unknown reasons (to be fixed?) //directly passing data to onStudentSubmission does not appear to work
function get_event_data(event_type, data, element){ function get_event_data(event_type, data, element){
onStudentSubmission(data); onStudentSubmission(data);
} }
...@@ -72,6 +72,8 @@ function CrowdsourceHinter(runtime, element){ ...@@ -72,6 +72,8 @@ function CrowdsourceHinter(runtime, element){
$('.csh_HintsToUse', element).attr('student_answer', result.StudentAnswer); $('.csh_HintsToUse', element).attr('student_answer', result.StudentAnswer);
$('.csh_HintsToUse', element).attr('hint_received', result.HintsToUse); $('.csh_HintsToUse', element).attr('hint_received', result.HintsToUse);
$('.csh_HintsToUse', element).text("Hint: " + result.HintsToUse); $('.csh_HintsToUse', element).text("Hint: " + result.HintsToUse);
Logger.log('crowd_hinter.seehint', {"student_answer": result.StudentAnswer, "hint_received": result.HintsToUse});
} }
function showHintFeedback(hint, student_answer){ function showHintFeedback(hint, student_answer){
...@@ -233,6 +235,7 @@ function CrowdsourceHinter(runtime, element){ ...@@ -233,6 +235,7 @@ function CrowdsourceHinter(runtime, element){
//to determine whether to unflag or delete the hint. //to determine whether to unflag or delete the hint.
hint = $(this).parent().find(".csh_hint").text(); hint = $(this).parent().find(".csh_hint").text();
student_answer = "Flagged"; student_answer = "Flagged";
Logger.log('crowd_hinter.staff_rate_hint.click.event', {"hint": hint, "student_answer": student_answer, "rating": $(this).attr('data-rate')});
$.ajax({ $.ajax({
type: "POST", type: "POST",
url: runtime.handlerUrl(element, 'rate_hint'), url: runtime.handlerUrl(element, 'rate_hint'),
......
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