Merge remote-tracking branch 'origin/master' into feature/alex/poll-merged
Conflicts: cms/djangoapps/contentstore/tests/test_contentstore.py cms/djangoapps/contentstore/views.py common/lib/xmodule/xmodule/combined_open_ended_module.py common/lib/xmodule/xmodule/open_ended_grading_classes/combined_open_ended_modulev1.py common/lib/xmodule/xmodule/open_ended_grading_classes/open_ended_module.py common/lib/xmodule/xmodule/open_ended_grading_classes/openendedchild.py common/lib/xmodule/xmodule/peer_grading_module.py common/lib/xmodule/xmodule/tests/test_combined_open_ended.py common/lib/xmodule/xmodule/tests/test_self_assessment.py lms/djangoapps/open_ended_grading/tests.py
This commit is contained in:
@@ -38,14 +38,15 @@ ACCEPT_FILE_UPLOAD = False
|
||||
TRUE_DICT = ["True", True, "TRUE", "true"]
|
||||
|
||||
HUMAN_TASK_TYPE = {
|
||||
'selfassessment' : "Self Assessment",
|
||||
'openended' : "edX Assessment",
|
||||
}
|
||||
'selfassessment': "Self Assessment",
|
||||
'openended': "edX Assessment",
|
||||
}
|
||||
|
||||
#Default value that controls whether or not to skip basic spelling checks in the controller
|
||||
#Metadata overrides this
|
||||
SKIP_BASIC_CHECKS = False
|
||||
|
||||
|
||||
class CombinedOpenEndedV1Module():
|
||||
"""
|
||||
This is a module that encapsulates all open ended grading (self assessment, peer assessment, etc).
|
||||
@@ -81,7 +82,7 @@ class CombinedOpenEndedV1Module():
|
||||
TEMPLATE_DIR = "combinedopenended"
|
||||
|
||||
def __init__(self, system, location, definition, descriptor,
|
||||
instance_state=None, shared_state=None, metadata = None, static_data = None, **kwargs):
|
||||
instance_state=None, shared_state=None, metadata=None, static_data=None, **kwargs):
|
||||
|
||||
"""
|
||||
Definition file should have one or many task blocks, a rubric block, and a prompt block:
|
||||
@@ -120,7 +121,7 @@ class CombinedOpenEndedV1Module():
|
||||
|
||||
self.instance_state = instance_state
|
||||
self.display_name = instance_state.get('display_name', "Open Ended")
|
||||
self.rewrite_content_links = static_data.get('rewrite_content_links',"")
|
||||
self.rewrite_content_links = static_data.get('rewrite_content_links', "")
|
||||
|
||||
#We need to set the location here so the child modules can use it
|
||||
system.set('location', location)
|
||||
@@ -168,10 +169,10 @@ class CombinedOpenEndedV1Module():
|
||||
'rubric': definition['rubric'],
|
||||
'display_name': self.display_name,
|
||||
'accept_file_upload': self.accept_file_upload,
|
||||
'close_date' : self.timeinfo.close_date,
|
||||
's3_interface' : self.system.s3_interface,
|
||||
'skip_basic_checks' : self.skip_basic_checks,
|
||||
}
|
||||
'close_date': self.timeinfo.close_date,
|
||||
's3_interface': self.system.s3_interface,
|
||||
'skip_basic_checks': self.skip_basic_checks,
|
||||
}
|
||||
|
||||
self.task_xml = definition['task_xml']
|
||||
self.location = location
|
||||
@@ -214,15 +215,15 @@ class CombinedOpenEndedV1Module():
|
||||
child_modules = {
|
||||
'openended': open_ended_module.OpenEndedModule,
|
||||
'selfassessment': self_assessment_module.SelfAssessmentModule,
|
||||
}
|
||||
}
|
||||
child_descriptors = {
|
||||
'openended': open_ended_module.OpenEndedDescriptor,
|
||||
'selfassessment': self_assessment_module.SelfAssessmentDescriptor,
|
||||
}
|
||||
}
|
||||
children = {
|
||||
'modules': child_modules,
|
||||
'descriptors': child_descriptors,
|
||||
}
|
||||
}
|
||||
return children
|
||||
|
||||
def setup_next_task(self, reset=False):
|
||||
@@ -258,7 +259,8 @@ class CombinedOpenEndedV1Module():
|
||||
self.current_task_parsed_xml = self.current_task_descriptor.definition_from_xml(etree_xml, self.system)
|
||||
if current_task_state is None and self.current_task_number == 0:
|
||||
self.current_task = child_task_module(self.system, self.location,
|
||||
self.current_task_parsed_xml, self.current_task_descriptor, self.static_data)
|
||||
self.current_task_parsed_xml, self.current_task_descriptor,
|
||||
self.static_data)
|
||||
self.task_states.append(self.current_task.get_instance_state())
|
||||
self.state = self.ASSESSING
|
||||
elif current_task_state is None and self.current_task_number > 0:
|
||||
@@ -271,18 +273,20 @@ class CombinedOpenEndedV1Module():
|
||||
'child_attempts': 0,
|
||||
'child_created': True,
|
||||
'child_history': [{'answer': last_response}],
|
||||
})
|
||||
})
|
||||
self.current_task = child_task_module(self.system, self.location,
|
||||
self.current_task_parsed_xml, self.current_task_descriptor, self.static_data,
|
||||
instance_state=current_task_state)
|
||||
self.current_task_parsed_xml, self.current_task_descriptor,
|
||||
self.static_data,
|
||||
instance_state=current_task_state)
|
||||
self.task_states.append(self.current_task.get_instance_state())
|
||||
self.state = self.ASSESSING
|
||||
else:
|
||||
if self.current_task_number > 0 and not reset:
|
||||
current_task_state = self.overwrite_state(current_task_state)
|
||||
self.current_task = child_task_module(self.system, self.location,
|
||||
self.current_task_parsed_xml, self.current_task_descriptor, self.static_data,
|
||||
instance_state=current_task_state)
|
||||
self.current_task_parsed_xml, self.current_task_descriptor,
|
||||
self.static_data,
|
||||
instance_state=current_task_state)
|
||||
|
||||
return True
|
||||
|
||||
@@ -298,8 +302,8 @@ class CombinedOpenEndedV1Module():
|
||||
last_response_data = self.get_last_response(self.current_task_number - 1)
|
||||
current_response_data = self.get_current_attributes(self.current_task_number)
|
||||
|
||||
if(current_response_data['min_score_to_attempt'] > last_response_data['score']
|
||||
or current_response_data['max_score_to_attempt'] < last_response_data['score']):
|
||||
if (current_response_data['min_score_to_attempt'] > last_response_data['score']
|
||||
or current_response_data['max_score_to_attempt'] < last_response_data['score']):
|
||||
self.state = self.DONE
|
||||
self.ready_to_reset = True
|
||||
|
||||
@@ -325,8 +329,8 @@ class CombinedOpenEndedV1Module():
|
||||
'display_name': self.display_name,
|
||||
'accept_file_upload': self.accept_file_upload,
|
||||
'location': self.location,
|
||||
'legend_list' : LEGEND_LIST,
|
||||
}
|
||||
'legend_list': LEGEND_LIST,
|
||||
}
|
||||
|
||||
return context
|
||||
|
||||
@@ -395,7 +399,7 @@ class CombinedOpenEndedV1Module():
|
||||
|
||||
task_parsed_xml = task_descriptor.definition_from_xml(etree_xml, self.system)
|
||||
task = children['modules'][task_type](self.system, self.location, task_parsed_xml, task_descriptor,
|
||||
self.static_data, instance_state=task_state)
|
||||
self.static_data, instance_state=task_state)
|
||||
last_response = task.latest_answer()
|
||||
last_score = task.latest_score()
|
||||
last_post_assessment = task.latest_post_assessment(self.system)
|
||||
@@ -417,10 +421,10 @@ class CombinedOpenEndedV1Module():
|
||||
rubric_scores = rubric_data['rubric_scores']
|
||||
grader_types = rubric_data['grader_types']
|
||||
feedback_items = rubric_data['feedback_items']
|
||||
feedback_dicts = rubric_data['feedback_dicts']
|
||||
feedback_dicts = rubric_data['feedback_dicts']
|
||||
grader_ids = rubric_data['grader_ids']
|
||||
submission_ids = rubric_data['submission_ids']
|
||||
elif task_type== "selfassessment":
|
||||
submission_ids = rubric_data['submission_ids']
|
||||
elif task_type == "selfassessment":
|
||||
rubric_scores = last_post_assessment
|
||||
grader_types = ['SA']
|
||||
feedback_items = ['']
|
||||
@@ -437,7 +441,7 @@ class CombinedOpenEndedV1Module():
|
||||
human_state = task.HUMAN_NAMES[state]
|
||||
else:
|
||||
human_state = state
|
||||
if len(grader_types)>0:
|
||||
if len(grader_types) > 0:
|
||||
grader_type = grader_types[0]
|
||||
else:
|
||||
grader_type = "IN"
|
||||
@@ -459,15 +463,15 @@ class CombinedOpenEndedV1Module():
|
||||
'correct': last_correctness,
|
||||
'min_score_to_attempt': min_score_to_attempt,
|
||||
'max_score_to_attempt': max_score_to_attempt,
|
||||
'rubric_scores' : rubric_scores,
|
||||
'grader_types' : grader_types,
|
||||
'feedback_items' : feedback_items,
|
||||
'grader_type' : grader_type,
|
||||
'human_grader_type' : human_grader_name,
|
||||
'feedback_dicts' : feedback_dicts,
|
||||
'grader_ids' : grader_ids,
|
||||
'submission_ids' : submission_ids,
|
||||
}
|
||||
'rubric_scores': rubric_scores,
|
||||
'grader_types': grader_types,
|
||||
'feedback_items': feedback_items,
|
||||
'grader_type': grader_type,
|
||||
'human_grader_type': human_grader_name,
|
||||
'feedback_dicts': feedback_dicts,
|
||||
'grader_ids': grader_ids,
|
||||
'submission_ids': submission_ids,
|
||||
}
|
||||
return last_response_dict
|
||||
|
||||
def update_task_states(self):
|
||||
@@ -510,20 +514,27 @@ class CombinedOpenEndedV1Module():
|
||||
Output: Dictionary to be rendered via ajax that contains the result html.
|
||||
"""
|
||||
all_responses = []
|
||||
loop_up_to_task = self.current_task_number+1
|
||||
for i in xrange(0,loop_up_to_task):
|
||||
loop_up_to_task = self.current_task_number + 1
|
||||
for i in xrange(0, loop_up_to_task):
|
||||
all_responses.append(self.get_last_response(i))
|
||||
rubric_scores = [all_responses[i]['rubric_scores'] for i in xrange(0,len(all_responses)) if len(all_responses[i]['rubric_scores'])>0 and all_responses[i]['grader_types'][0] in HUMAN_GRADER_TYPE.keys()]
|
||||
grader_types = [all_responses[i]['grader_types'] for i in xrange(0,len(all_responses)) if len(all_responses[i]['grader_types'])>0 and all_responses[i]['grader_types'][0] in HUMAN_GRADER_TYPE.keys()]
|
||||
feedback_items = [all_responses[i]['feedback_items'] for i in xrange(0,len(all_responses)) if len(all_responses[i]['feedback_items'])>0 and all_responses[i]['grader_types'][0] in HUMAN_GRADER_TYPE.keys()]
|
||||
rubric_html = self.rubric_renderer.render_combined_rubric(stringify_children(self.static_data['rubric']), rubric_scores,
|
||||
grader_types, feedback_items)
|
||||
rubric_scores = [all_responses[i]['rubric_scores'] for i in xrange(0, len(all_responses)) if
|
||||
len(all_responses[i]['rubric_scores']) > 0 and all_responses[i]['grader_types'][
|
||||
0] in HUMAN_GRADER_TYPE.keys()]
|
||||
grader_types = [all_responses[i]['grader_types'] for i in xrange(0, len(all_responses)) if
|
||||
len(all_responses[i]['grader_types']) > 0 and all_responses[i]['grader_types'][
|
||||
0] in HUMAN_GRADER_TYPE.keys()]
|
||||
feedback_items = [all_responses[i]['feedback_items'] for i in xrange(0, len(all_responses)) if
|
||||
len(all_responses[i]['feedback_items']) > 0 and all_responses[i]['grader_types'][
|
||||
0] in HUMAN_GRADER_TYPE.keys()]
|
||||
rubric_html = self.rubric_renderer.render_combined_rubric(stringify_children(self.static_data['rubric']),
|
||||
rubric_scores,
|
||||
grader_types, feedback_items)
|
||||
|
||||
response_dict = all_responses[-1]
|
||||
context = {
|
||||
'results': rubric_html,
|
||||
'task_name' : 'Scored Rubric',
|
||||
'class_name' : 'combined-rubric-container'
|
||||
'task_name': 'Scored Rubric',
|
||||
'class_name': 'combined-rubric-container'
|
||||
}
|
||||
html = self.system.render_template('{0}/combined_open_ended_results.html'.format(self.TEMPLATE_DIR), context)
|
||||
return {'html': html, 'success': True}
|
||||
@@ -535,8 +546,8 @@ class CombinedOpenEndedV1Module():
|
||||
Output: Dictionary to be rendered via ajax that contains the result html.
|
||||
"""
|
||||
context = {
|
||||
'legend_list' : LEGEND_LIST,
|
||||
}
|
||||
'legend_list': LEGEND_LIST,
|
||||
}
|
||||
html = self.system.render_template('{0}/combined_open_ended_legend.html'.format(self.TEMPLATE_DIR), context)
|
||||
return {'html': html, 'success': True}
|
||||
|
||||
@@ -547,15 +558,16 @@ class CombinedOpenEndedV1Module():
|
||||
Output: Dictionary to be rendered via ajax that contains the result html.
|
||||
"""
|
||||
self.update_task_states()
|
||||
loop_up_to_task = self.current_task_number+1
|
||||
all_responses =[]
|
||||
for i in xrange(0,loop_up_to_task):
|
||||
loop_up_to_task = self.current_task_number + 1
|
||||
all_responses = []
|
||||
for i in xrange(0, loop_up_to_task):
|
||||
all_responses.append(self.get_last_response(i))
|
||||
context_list = []
|
||||
for ri in all_responses:
|
||||
for i in xrange(0,len(ri['rubric_scores'])):
|
||||
feedback = ri['feedback_dicts'][i].get('feedback','')
|
||||
rubric_data = self.rubric_renderer.render_rubric(stringify_children(self.static_data['rubric']), ri['rubric_scores'][i])
|
||||
for i in xrange(0, len(ri['rubric_scores'])):
|
||||
feedback = ri['feedback_dicts'][i].get('feedback', '')
|
||||
rubric_data = self.rubric_renderer.render_rubric(stringify_children(self.static_data['rubric']),
|
||||
ri['rubric_scores'][i])
|
||||
if rubric_data['success']:
|
||||
rubric_html = rubric_data['html']
|
||||
else:
|
||||
@@ -563,23 +575,23 @@ class CombinedOpenEndedV1Module():
|
||||
context = {
|
||||
'rubric_html': rubric_html,
|
||||
'grader_type': ri['grader_type'],
|
||||
'feedback' : feedback,
|
||||
'grader_id' : ri['grader_ids'][i],
|
||||
'submission_id' : ri['submission_ids'][i],
|
||||
'feedback': feedback,
|
||||
'grader_id': ri['grader_ids'][i],
|
||||
'submission_id': ri['submission_ids'][i],
|
||||
}
|
||||
context_list.append(context)
|
||||
feedback_table = self.system.render_template('{0}/open_ended_result_table.html'.format(self.TEMPLATE_DIR), {
|
||||
'context_list' : context_list,
|
||||
'grader_type_image_dict' : GRADER_TYPE_IMAGE_DICT,
|
||||
'human_grader_types' : HUMAN_GRADER_TYPE,
|
||||
'context_list': context_list,
|
||||
'grader_type_image_dict': GRADER_TYPE_IMAGE_DICT,
|
||||
'human_grader_types': HUMAN_GRADER_TYPE,
|
||||
'rows': 50,
|
||||
'cols': 50,
|
||||
})
|
||||
context = {
|
||||
'results': feedback_table,
|
||||
'task_name' : "Feedback",
|
||||
'class_name' : "result-container",
|
||||
}
|
||||
'task_name': "Feedback",
|
||||
'class_name': "result-container",
|
||||
}
|
||||
html = self.system.render_template('{0}/combined_open_ended_results.html'.format(self.TEMPLATE_DIR), context)
|
||||
return {'html': html, 'success': True}
|
||||
|
||||
@@ -608,8 +620,8 @@ class CombinedOpenEndedV1Module():
|
||||
'reset': self.reset,
|
||||
'get_results': self.get_results,
|
||||
'get_combined_rubric': self.get_rubric,
|
||||
'get_status' : self.get_status_ajax,
|
||||
'get_legend' : self.get_legend,
|
||||
'get_status': self.get_status_ajax,
|
||||
'get_legend': self.get_legend,
|
||||
}
|
||||
|
||||
if dispatch not in handlers:
|
||||
@@ -672,7 +684,7 @@ class CombinedOpenEndedV1Module():
|
||||
'task_states': self.task_states,
|
||||
'student_attempts': self.student_attempts,
|
||||
'ready_to_reset': self.ready_to_reset,
|
||||
}
|
||||
}
|
||||
|
||||
return json.dumps(state)
|
||||
|
||||
@@ -690,11 +702,12 @@ class CombinedOpenEndedV1Module():
|
||||
|
||||
context = {
|
||||
'status_list': status,
|
||||
'grader_type_image_dict' : GRADER_TYPE_IMAGE_DICT,
|
||||
'legend_list' : LEGEND_LIST,
|
||||
'render_via_ajax' : render_via_ajax,
|
||||
'grader_type_image_dict': GRADER_TYPE_IMAGE_DICT,
|
||||
'legend_list': LEGEND_LIST,
|
||||
'render_via_ajax': render_via_ajax,
|
||||
}
|
||||
status_html = self.system.render_template("{0}/combined_open_ended_status.html".format(self.TEMPLATE_DIR), context)
|
||||
status_html = self.system.render_template("{0}/combined_open_ended_status.html".format(self.TEMPLATE_DIR),
|
||||
context)
|
||||
|
||||
return status_html
|
||||
|
||||
@@ -727,7 +740,7 @@ class CombinedOpenEndedV1Module():
|
||||
score_dict = {
|
||||
'score': score,
|
||||
'total': max_score,
|
||||
}
|
||||
}
|
||||
|
||||
return score_dict
|
||||
|
||||
@@ -787,7 +800,9 @@ class CombinedOpenEndedV1Descriptor():
|
||||
for child in expected_children:
|
||||
if len(xml_object.xpath(child)) == 0:
|
||||
#This is a staff_facing_error
|
||||
raise ValueError("Combined Open Ended definition must include at least one '{0}' tag. Contact the learning sciences group for assistance.".format(child))
|
||||
raise ValueError(
|
||||
"Combined Open Ended definition must include at least one '{0}' tag. Contact the learning sciences group for assistance.".format(
|
||||
child))
|
||||
|
||||
def parse_task(k):
|
||||
"""Assumes that xml_object has child k"""
|
||||
|
||||
@@ -4,24 +4,26 @@ from lxml import etree
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
GRADER_TYPE_IMAGE_DICT = {
|
||||
'SA' : '/static/images/self_assessment_icon.png',
|
||||
'PE' : '/static/images/peer_grading_icon.png',
|
||||
'ML' : '/static/images/ml_grading_icon.png',
|
||||
'IN' : '/static/images/peer_grading_icon.png',
|
||||
'BC' : '/static/images/ml_grading_icon.png',
|
||||
}
|
||||
'SA': '/static/images/self_assessment_icon.png',
|
||||
'PE': '/static/images/peer_grading_icon.png',
|
||||
'ML': '/static/images/ml_grading_icon.png',
|
||||
'IN': '/static/images/peer_grading_icon.png',
|
||||
'BC': '/static/images/ml_grading_icon.png',
|
||||
}
|
||||
|
||||
HUMAN_GRADER_TYPE = {
|
||||
'SA' : 'Self-Assessment',
|
||||
'PE' : 'Peer-Assessment',
|
||||
'IN' : 'Instructor-Assessment',
|
||||
'ML' : 'AI-Assessment',
|
||||
'BC' : 'AI-Assessment',
|
||||
}
|
||||
'SA': 'Self-Assessment',
|
||||
'PE': 'Peer-Assessment',
|
||||
'IN': 'Instructor-Assessment',
|
||||
'ML': 'AI-Assessment',
|
||||
'BC': 'AI-Assessment',
|
||||
}
|
||||
|
||||
DO_NOT_DISPLAY = ['BC', 'IN']
|
||||
|
||||
LEGEND_LIST = [{'name' : HUMAN_GRADER_TYPE[k], 'image' : GRADER_TYPE_IMAGE_DICT[k]} for k in GRADER_TYPE_IMAGE_DICT.keys() if k not in DO_NOT_DISPLAY ]
|
||||
LEGEND_LIST = [{'name': HUMAN_GRADER_TYPE[k], 'image': GRADER_TYPE_IMAGE_DICT[k]} for k in GRADER_TYPE_IMAGE_DICT.keys()
|
||||
if k not in DO_NOT_DISPLAY]
|
||||
|
||||
|
||||
class RubricParsingError(Exception):
|
||||
def __init__(self, msg):
|
||||
@@ -29,15 +31,14 @@ class RubricParsingError(Exception):
|
||||
|
||||
|
||||
class CombinedOpenEndedRubric(object):
|
||||
|
||||
TEMPLATE_DIR = "combinedopenended/openended"
|
||||
|
||||
def __init__ (self, system, view_only = False):
|
||||
def __init__(self, system, view_only=False):
|
||||
self.has_score = False
|
||||
self.view_only = view_only
|
||||
self.system = system
|
||||
|
||||
def render_rubric(self, rubric_xml, score_list = None):
|
||||
def render_rubric(self, rubric_xml, score_list=None):
|
||||
'''
|
||||
render_rubric: takes in an xml string and outputs the corresponding
|
||||
html for that xml, given the type of rubric we're generating
|
||||
@@ -50,11 +51,11 @@ class CombinedOpenEndedRubric(object):
|
||||
success = False
|
||||
try:
|
||||
rubric_categories = self.extract_categories(rubric_xml)
|
||||
if score_list and len(score_list)==len(rubric_categories):
|
||||
for i in xrange(0,len(rubric_categories)):
|
||||
if score_list and len(score_list) == len(rubric_categories):
|
||||
for i in xrange(0, len(rubric_categories)):
|
||||
category = rubric_categories[i]
|
||||
for j in xrange(0,len(category['options'])):
|
||||
if score_list[i]==j:
|
||||
for j in xrange(0, len(category['options'])):
|
||||
if score_list[i] == j:
|
||||
rubric_categories[i]['options'][j]['selected'] = True
|
||||
rubric_scores = [cat['score'] for cat in rubric_categories]
|
||||
max_scores = map((lambda cat: cat['options'][-1]['points']), rubric_categories)
|
||||
@@ -63,19 +64,20 @@ class CombinedOpenEndedRubric(object):
|
||||
if self.view_only:
|
||||
rubric_template = '{0}/open_ended_view_only_rubric.html'.format(self.TEMPLATE_DIR)
|
||||
html = self.system.render_template(rubric_template,
|
||||
{'categories': rubric_categories,
|
||||
'has_score': self.has_score,
|
||||
'view_only': self.view_only,
|
||||
'max_score': max_score,
|
||||
'combined_rubric' : False
|
||||
})
|
||||
{'categories': rubric_categories,
|
||||
'has_score': self.has_score,
|
||||
'view_only': self.view_only,
|
||||
'max_score': max_score,
|
||||
'combined_rubric': False
|
||||
})
|
||||
success = True
|
||||
except:
|
||||
#This is a staff_facing_error
|
||||
error_message = "[render_rubric] Could not parse the rubric with xml: {0}. Contact the learning sciences group for assistance.".format(rubric_xml)
|
||||
error_message = "[render_rubric] Could not parse the rubric with xml: {0}. Contact the learning sciences group for assistance.".format(
|
||||
rubric_xml)
|
||||
log.exception(error_message)
|
||||
raise RubricParsingError(error_message)
|
||||
return {'success' : success, 'html' : html, 'rubric_scores' : rubric_scores}
|
||||
return {'success': success, 'html': html, 'rubric_scores': rubric_scores}
|
||||
|
||||
def check_if_rubric_is_parseable(self, rubric_string, location, max_score_allowed, max_score):
|
||||
rubric_dict = self.render_rubric(rubric_string)
|
||||
@@ -83,7 +85,8 @@ class CombinedOpenEndedRubric(object):
|
||||
rubric_feedback = rubric_dict['html']
|
||||
if not success:
|
||||
#This is a staff_facing_error
|
||||
error_message = "Could not parse rubric : {0} for location {1}. Contact the learning sciences group for assistance.".format(rubric_string, location.url())
|
||||
error_message = "Could not parse rubric : {0} for location {1}. Contact the learning sciences group for assistance.".format(
|
||||
rubric_string, location.url())
|
||||
log.error(error_message)
|
||||
raise RubricParsingError(error_message)
|
||||
|
||||
@@ -101,7 +104,7 @@ class CombinedOpenEndedRubric(object):
|
||||
if int(total) != int(max_score):
|
||||
#This is a staff_facing_error
|
||||
error_msg = "The max score {0} for problem {1} does not match the total number of points in the rubric {2}. Contact the learning sciences group for assistance.".format(
|
||||
max_score, location, total)
|
||||
max_score, location, total)
|
||||
log.error(error_msg)
|
||||
raise RubricParsingError(error_msg)
|
||||
|
||||
@@ -123,12 +126,13 @@ class CombinedOpenEndedRubric(object):
|
||||
for category in element:
|
||||
if category.tag != 'category':
|
||||
#This is a staff_facing_error
|
||||
raise RubricParsingError("[extract_categories] Expected a <category> tag: got {0} instead. Contact the learning sciences group for assistance.".format(category.tag))
|
||||
raise RubricParsingError(
|
||||
"[extract_categories] Expected a <category> tag: got {0} instead. Contact the learning sciences group for assistance.".format(
|
||||
category.tag))
|
||||
else:
|
||||
categories.append(self.extract_category(category))
|
||||
return categories
|
||||
|
||||
|
||||
def extract_category(self, category):
|
||||
'''
|
||||
construct an individual category
|
||||
@@ -150,13 +154,17 @@ class CombinedOpenEndedRubric(object):
|
||||
# if we are missing the score tag and we are expecting one
|
||||
elif self.has_score:
|
||||
#This is a staff_facing_error
|
||||
raise RubricParsingError("[extract_category] Category {0} is missing a score. Contact the learning sciences group for assistance.".format(descriptionxml.text))
|
||||
raise RubricParsingError(
|
||||
"[extract_category] Category {0} is missing a score. Contact the learning sciences group for assistance.".format(
|
||||
descriptionxml.text))
|
||||
|
||||
|
||||
# parse description
|
||||
if descriptionxml.tag != 'description':
|
||||
#This is a staff_facing_error
|
||||
raise RubricParsingError("[extract_category]: expected description tag, got {0} instead. Contact the learning sciences group for assistance.".format(descriptionxml.tag))
|
||||
raise RubricParsingError(
|
||||
"[extract_category]: expected description tag, got {0} instead. Contact the learning sciences group for assistance.".format(
|
||||
descriptionxml.tag))
|
||||
|
||||
description = descriptionxml.text
|
||||
|
||||
@@ -167,7 +175,9 @@ class CombinedOpenEndedRubric(object):
|
||||
for option in optionsxml:
|
||||
if option.tag != 'option':
|
||||
#This is a staff_facing_error
|
||||
raise RubricParsingError("[extract_category]: expected option tag, got {0} instead. Contact the learning sciences group for assistance.".format(option.tag))
|
||||
raise RubricParsingError(
|
||||
"[extract_category]: expected option tag, got {0} instead. Contact the learning sciences group for assistance.".format(
|
||||
option.tag))
|
||||
else:
|
||||
pointstr = option.get("points")
|
||||
if pointstr:
|
||||
@@ -177,13 +187,16 @@ class CombinedOpenEndedRubric(object):
|
||||
points = int(pointstr)
|
||||
except ValueError:
|
||||
#This is a staff_facing_error
|
||||
raise RubricParsingError("[extract_category]: expected points to have int, got {0} instead. Contact the learning sciences group for assistance.".format(pointstr))
|
||||
raise RubricParsingError(
|
||||
"[extract_category]: expected points to have int, got {0} instead. Contact the learning sciences group for assistance.".format(
|
||||
pointstr))
|
||||
elif autonumbering:
|
||||
# use the generated one if we're in the right mode
|
||||
points = cur_points
|
||||
cur_points = cur_points + 1
|
||||
else:
|
||||
raise Exception("[extract_category]: missing points attribute. Cannot continue to auto-create points values after a points value is explicitly defined.")
|
||||
raise Exception(
|
||||
"[extract_category]: missing points attribute. Cannot continue to auto-create points values after a points value is explicitly defined.")
|
||||
|
||||
selected = score == points
|
||||
optiontext = option.text
|
||||
@@ -193,34 +206,34 @@ class CombinedOpenEndedRubric(object):
|
||||
options = sorted(options, key=lambda option: option['points'])
|
||||
CombinedOpenEndedRubric.validate_options(options)
|
||||
|
||||
return {'description': description, 'options': options, 'score' : score}
|
||||
return {'description': description, 'options': options, 'score': score}
|
||||
|
||||
def render_combined_rubric(self,rubric_xml,scores,score_types,feedback_types):
|
||||
success, score_tuples = CombinedOpenEndedRubric.reformat_scores_for_rendering(scores,score_types,feedback_types)
|
||||
def render_combined_rubric(self, rubric_xml, scores, score_types, feedback_types):
|
||||
success, score_tuples = CombinedOpenEndedRubric.reformat_scores_for_rendering(scores, score_types,
|
||||
feedback_types)
|
||||
rubric_categories = self.extract_categories(rubric_xml)
|
||||
max_scores = map((lambda cat: cat['options'][-1]['points']), rubric_categories)
|
||||
max_score = max(max_scores)
|
||||
for i in xrange(0,len(rubric_categories)):
|
||||
for i in xrange(0, len(rubric_categories)):
|
||||
category = rubric_categories[i]
|
||||
for j in xrange(0,len(category['options'])):
|
||||
for j in xrange(0, len(category['options'])):
|
||||
rubric_categories[i]['options'][j]['grader_types'] = []
|
||||
for tuple in score_tuples:
|
||||
if tuple[1] == i and tuple[2] ==j:
|
||||
if tuple[1] == i and tuple[2] == j:
|
||||
for grader_type in tuple[3]:
|
||||
rubric_categories[i]['options'][j]['grader_types'].append(grader_type)
|
||||
|
||||
html = self.system.render_template('{0}/open_ended_combined_rubric.html'.format(self.TEMPLATE_DIR),
|
||||
{'categories': rubric_categories,
|
||||
'has_score': True,
|
||||
'view_only': True,
|
||||
'max_score': max_score,
|
||||
'combined_rubric' : True,
|
||||
'grader_type_image_dict' : GRADER_TYPE_IMAGE_DICT,
|
||||
'human_grader_types' : HUMAN_GRADER_TYPE,
|
||||
})
|
||||
{'categories': rubric_categories,
|
||||
'has_score': True,
|
||||
'view_only': True,
|
||||
'max_score': max_score,
|
||||
'combined_rubric': True,
|
||||
'grader_type_image_dict': GRADER_TYPE_IMAGE_DICT,
|
||||
'human_grader_types': HUMAN_GRADER_TYPE,
|
||||
})
|
||||
return html
|
||||
|
||||
|
||||
@staticmethod
|
||||
def validate_options(options):
|
||||
'''
|
||||
@@ -228,14 +241,16 @@ class CombinedOpenEndedRubric(object):
|
||||
'''
|
||||
if len(options) == 0:
|
||||
#This is a staff_facing_error
|
||||
raise RubricParsingError("[extract_category]: no options associated with this category. Contact the learning sciences group for assistance.")
|
||||
raise RubricParsingError(
|
||||
"[extract_category]: no options associated with this category. Contact the learning sciences group for assistance.")
|
||||
if len(options) == 1:
|
||||
return
|
||||
prev = options[0]['points']
|
||||
for option in options[1:]:
|
||||
if prev == option['points']:
|
||||
#This is a staff_facing_error
|
||||
raise RubricParsingError("[extract_category]: found duplicate point values between two different options. Contact the learning sciences group for assistance.")
|
||||
raise RubricParsingError(
|
||||
"[extract_category]: found duplicate point values between two different options. Contact the learning sciences group for assistance.")
|
||||
else:
|
||||
prev = option['points']
|
||||
|
||||
@@ -250,7 +265,7 @@ class CombinedOpenEndedRubric(object):
|
||||
@return:
|
||||
"""
|
||||
success = False
|
||||
if len(scores)==0:
|
||||
if len(scores) == 0:
|
||||
#This is a dev_facing_error
|
||||
log.error("Score length is 0 when trying to reformat rubric scores for rendering.")
|
||||
return success, ""
|
||||
@@ -264,25 +279,25 @@ class CombinedOpenEndedRubric(object):
|
||||
score_lists = []
|
||||
score_type_list = []
|
||||
feedback_type_list = []
|
||||
for i in xrange(0,len(scores)):
|
||||
for i in xrange(0, len(scores)):
|
||||
score_cont_list = scores[i]
|
||||
for j in xrange(0,len(score_cont_list)):
|
||||
for j in xrange(0, len(score_cont_list)):
|
||||
score_list = score_cont_list[j]
|
||||
score_lists.append(score_list)
|
||||
score_type_list.append(score_types[i][j])
|
||||
feedback_type_list.append(feedback_types[i][j])
|
||||
|
||||
score_list_len = len(score_lists[0])
|
||||
for i in xrange(0,len(score_lists)):
|
||||
for i in xrange(0, len(score_lists)):
|
||||
score_list = score_lists[i]
|
||||
if len(score_list)!=score_list_len:
|
||||
if len(score_list) != score_list_len:
|
||||
return success, ""
|
||||
|
||||
score_tuples = []
|
||||
for i in xrange(0,len(score_lists)):
|
||||
for j in xrange(0,len(score_lists[i])):
|
||||
tuple = [1,j,score_lists[i][j],[],[]]
|
||||
score_tuples, tup_ind = CombinedOpenEndedRubric.check_for_tuple_matches(score_tuples,tuple)
|
||||
for i in xrange(0, len(score_lists)):
|
||||
for j in xrange(0, len(score_lists[i])):
|
||||
tuple = [1, j, score_lists[i][j], [], []]
|
||||
score_tuples, tup_ind = CombinedOpenEndedRubric.check_for_tuple_matches(score_tuples, tuple)
|
||||
score_tuples[tup_ind][0] += 1
|
||||
score_tuples[tup_ind][3].append(score_type_list[i])
|
||||
score_tuples[tup_ind][4].append(feedback_type_list[i])
|
||||
@@ -302,18 +317,12 @@ class CombinedOpenEndedRubric(object):
|
||||
category = tuple[1]
|
||||
score = tuple[2]
|
||||
tup_ind = -1
|
||||
for t in xrange(0,len(tuples)):
|
||||
for t in xrange(0, len(tuples)):
|
||||
if tuples[t][1] == category and tuples[t][2] == score:
|
||||
tup_ind = t
|
||||
break
|
||||
|
||||
if tup_ind == -1:
|
||||
tuples.append([0,category,score,[],[]])
|
||||
tup_ind = len(tuples)-1
|
||||
tuples.append([0, category, score, [], []])
|
||||
tup_ind = len(tuples) - 1
|
||||
return tuples, tup_ind
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ class ControllerQueryService(GradingService):
|
||||
"""
|
||||
Interface to staff grading backend.
|
||||
"""
|
||||
|
||||
def __init__(self, config, system):
|
||||
config['system'] = system
|
||||
super(ControllerQueryService, self).__init__(config)
|
||||
@@ -59,7 +60,7 @@ class ControllerQueryService(GradingService):
|
||||
def get_flagged_problem_list(self, course_id):
|
||||
params = {
|
||||
'course_id': course_id,
|
||||
}
|
||||
}
|
||||
|
||||
response = self.get(self.flagged_problem_list_url, params)
|
||||
return response
|
||||
@@ -70,20 +71,21 @@ class ControllerQueryService(GradingService):
|
||||
'student_id': student_id,
|
||||
'submission_id': submission_id,
|
||||
'action_type': action_type
|
||||
}
|
||||
}
|
||||
|
||||
response = self.post(self.take_action_on_flags_url, params)
|
||||
return response
|
||||
|
||||
|
||||
def convert_seconds_to_human_readable(seconds):
|
||||
if seconds < 60:
|
||||
human_string = "{0} seconds".format(seconds)
|
||||
elif seconds < 60 * 60:
|
||||
human_string = "{0} minutes".format(round(seconds/60,1))
|
||||
elif seconds < (24*60*60):
|
||||
human_string = "{0} hours".format(round(seconds/(60*60),1))
|
||||
human_string = "{0} minutes".format(round(seconds / 60, 1))
|
||||
elif seconds < (24 * 60 * 60):
|
||||
human_string = "{0} hours".format(round(seconds / (60 * 60), 1))
|
||||
else:
|
||||
human_string = "{0} days".format(round(seconds/(60*60*24),1))
|
||||
human_string = "{0} days".format(round(seconds / (60 * 60 * 24), 1))
|
||||
|
||||
eta_string = "{0}".format(human_string)
|
||||
return eta_string
|
||||
|
||||
@@ -19,6 +19,7 @@ class GradingService(object):
|
||||
"""
|
||||
Interface to staff grading backend.
|
||||
"""
|
||||
|
||||
def __init__(self, config):
|
||||
self.username = config['username']
|
||||
self.password = config['password']
|
||||
@@ -34,8 +35,8 @@ class GradingService(object):
|
||||
Returns the decoded json dict of the response.
|
||||
"""
|
||||
response = self.session.post(self.login_url,
|
||||
{'username': self.username,
|
||||
'password': self.password, })
|
||||
{'username': self.username,
|
||||
'password': self.password, })
|
||||
|
||||
response.raise_for_status()
|
||||
|
||||
@@ -47,7 +48,7 @@ class GradingService(object):
|
||||
"""
|
||||
try:
|
||||
op = lambda: self.session.post(url, data=data,
|
||||
allow_redirects=allow_redirects)
|
||||
allow_redirects=allow_redirects)
|
||||
r = self._try_with_login(op)
|
||||
except (RequestException, ConnectionError, HTTPError) as err:
|
||||
# reraise as promised GradingServiceError, but preserve stacktrace.
|
||||
@@ -63,8 +64,8 @@ class GradingService(object):
|
||||
"""
|
||||
log.debug(params)
|
||||
op = lambda: self.session.get(url,
|
||||
allow_redirects=allow_redirects,
|
||||
params=params)
|
||||
allow_redirects=allow_redirects,
|
||||
params=params)
|
||||
try:
|
||||
r = self._try_with_login(op)
|
||||
except (RequestException, ConnectionError, HTTPError) as err:
|
||||
@@ -92,7 +93,7 @@ class GradingService(object):
|
||||
r = self._login()
|
||||
if r and not r.get('success'):
|
||||
log.warning("Couldn't log into staff_grading backend. Response: %s",
|
||||
r)
|
||||
r)
|
||||
# try again
|
||||
response = operation()
|
||||
response.raise_for_status()
|
||||
|
||||
@@ -5,6 +5,7 @@ to send them to S3.
|
||||
|
||||
try:
|
||||
from PIL import Image
|
||||
|
||||
ENABLE_PIL = True
|
||||
except:
|
||||
ENABLE_PIL = False
|
||||
@@ -51,6 +52,7 @@ class ImageProperties(object):
|
||||
"""
|
||||
Class to check properties of an image and to validate if they are allowed.
|
||||
"""
|
||||
|
||||
def __init__(self, image_data):
|
||||
"""
|
||||
Initializes class variables
|
||||
@@ -92,7 +94,7 @@ class ImageProperties(object):
|
||||
g = rgb[1]
|
||||
b = rgb[2]
|
||||
check_r = (r > 60)
|
||||
check_g = (r * 0.4) < g < (r * 0.85)
|
||||
check_g = (r * 0.4) < g < (r * 0.85)
|
||||
check_b = (r * 0.2) < b < (r * 0.7)
|
||||
colors_okay = check_r and check_b and check_g
|
||||
except:
|
||||
@@ -141,6 +143,7 @@ class URLProperties(object):
|
||||
Checks to see if a URL points to acceptable content. Added to check if students are submitting reasonable
|
||||
links to the peer grading image functionality of the external grading service.
|
||||
"""
|
||||
|
||||
def __init__(self, url_string):
|
||||
self.url_string = url_string
|
||||
|
||||
@@ -212,7 +215,7 @@ def run_image_tests(image):
|
||||
success = image_properties.run_tests()
|
||||
except:
|
||||
log.exception("Cannot run image tests in combined open ended xmodule. May be an issue with a particular image,"
|
||||
"or an issue with the deployment configuration of PIL/Pillow")
|
||||
"or an issue with the deployment configuration of PIL/Pillow")
|
||||
return success
|
||||
|
||||
|
||||
@@ -252,7 +255,8 @@ def upload_to_s3(file_to_upload, keyname, s3_interface):
|
||||
return True, public_url
|
||||
except:
|
||||
#This is a dev_facing_error
|
||||
error_message = "Could not connect to S3 to upload peer grading image. Trying to utilize bucket: {0}".format(bucketname.lower())
|
||||
error_message = "Could not connect to S3 to upload peer grading image. Trying to utilize bucket: {0}".format(
|
||||
bucketname.lower())
|
||||
log.error(error_message)
|
||||
return False, error_message
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import logging
|
||||
from lxml import etree
|
||||
import capa.xqueue_interface as xqueue_interface
|
||||
|
||||
from xmodule.capa_module import ComplexEncoder
|
||||
from xmodule.capa_module import ComplexEncoder
|
||||
from xmodule.editing_module import EditingDescriptor
|
||||
from xmodule.progress import Progress
|
||||
from xmodule.stringify import stringify_children
|
||||
@@ -77,7 +77,6 @@ class OpenEndedModule(openendedchild.OpenEndedChild):
|
||||
self.send_to_grader(self.latest_answer(), system)
|
||||
self.child_created = False
|
||||
|
||||
|
||||
def _parse(self, oeparam, prompt, rubric, system):
|
||||
'''
|
||||
Parse OpenEndedResponse XML:
|
||||
@@ -104,7 +103,9 @@ class OpenEndedModule(openendedchild.OpenEndedChild):
|
||||
# response types)
|
||||
except TypeError, ValueError:
|
||||
#This is a dev_facing_error
|
||||
log.exception("Grader payload from external open ended grading server is not a json object! Object: {0}".format(grader_payload))
|
||||
log.exception(
|
||||
"Grader payload from external open ended grading server is not a json object! Object: {0}".format(
|
||||
grader_payload))
|
||||
|
||||
self.initial_display = find_with_default(oeparam, 'initial_display', '')
|
||||
self.answer = find_with_default(oeparam, 'answer_display', 'No answer given.')
|
||||
@@ -148,7 +149,9 @@ class OpenEndedModule(openendedchild.OpenEndedChild):
|
||||
for tag in ['feedback', 'submission_id', 'grader_id', 'score']:
|
||||
if tag not in survey_responses:
|
||||
#This is a student_facing_error
|
||||
return {'success': False, 'msg': "Could not find needed tag {0} in the survey responses. Please try submitting again.".format(tag)}
|
||||
return {'success': False,
|
||||
'msg': "Could not find needed tag {0} in the survey responses. Please try submitting again.".format(
|
||||
tag)}
|
||||
try:
|
||||
submission_id = int(survey_responses['submission_id'])
|
||||
grader_id = int(survey_responses['grader_id'])
|
||||
@@ -188,7 +191,7 @@ class OpenEndedModule(openendedchild.OpenEndedChild):
|
||||
}
|
||||
|
||||
(error, msg) = qinterface.send_to_queue(header=xheader,
|
||||
body=json.dumps(contents))
|
||||
body=json.dumps(contents))
|
||||
|
||||
#Convert error to a success value
|
||||
success = True
|
||||
@@ -222,8 +225,8 @@ class OpenEndedModule(openendedchild.OpenEndedChild):
|
||||
str(len(self.child_history)))
|
||||
|
||||
xheader = xqueue_interface.make_xheader(lms_callback_url=system.xqueue['callback_url'],
|
||||
lms_key=queuekey,
|
||||
queue_name=self.queue_name)
|
||||
lms_key=queuekey,
|
||||
queue_name=self.queue_name)
|
||||
|
||||
contents = self.payload.copy()
|
||||
|
||||
@@ -241,7 +244,7 @@ class OpenEndedModule(openendedchild.OpenEndedChild):
|
||||
|
||||
# Submit request. When successful, 'msg' is the prior length of the queue
|
||||
(error, msg) = qinterface.send_to_queue(header=xheader,
|
||||
body=json.dumps(contents))
|
||||
body=json.dumps(contents))
|
||||
|
||||
# State associated with the queueing request
|
||||
queuestate = {'key': queuekey,
|
||||
@@ -266,7 +269,6 @@ class OpenEndedModule(openendedchild.OpenEndedChild):
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def get_answers(self):
|
||||
"""
|
||||
Gets and shows the answer for this problem.
|
||||
@@ -300,7 +302,7 @@ class OpenEndedModule(openendedchild.OpenEndedChild):
|
||||
|
||||
# We want to display available feedback in a particular order.
|
||||
# This dictionary specifies which goes first--lower first.
|
||||
priorities = { # These go at the start of the feedback
|
||||
priorities = {# These go at the start of the feedback
|
||||
'spelling': 0,
|
||||
'grammar': 1,
|
||||
# needs to be after all the other feedback
|
||||
@@ -400,7 +402,7 @@ class OpenEndedModule(openendedchild.OpenEndedChild):
|
||||
|
||||
if not response_items['success']:
|
||||
return system.render_template("{0}/open_ended_error.html".format(self.TEMPLATE_DIR),
|
||||
{'errors': feedback})
|
||||
{'errors': feedback})
|
||||
|
||||
feedback_template = system.render_template("{0}/open_ended_feedback.html".format(self.TEMPLATE_DIR), {
|
||||
'grader_type': response_items['grader_type'],
|
||||
@@ -411,7 +413,6 @@ class OpenEndedModule(openendedchild.OpenEndedChild):
|
||||
|
||||
return feedback_template, rubric_scores
|
||||
|
||||
|
||||
def _parse_score_msg(self, score_msg, system, join_feedback=True):
|
||||
"""
|
||||
Grader reply is a JSON-dump of the following dict
|
||||
@@ -437,13 +438,13 @@ class OpenEndedModule(openendedchild.OpenEndedChild):
|
||||
'valid': False,
|
||||
'score': 0,
|
||||
'feedback': '',
|
||||
'rubric_scores' : [[0]],
|
||||
'grader_types' : [''],
|
||||
'feedback_items' : [''],
|
||||
'feedback_dicts' : [{}],
|
||||
'grader_ids' : [0],
|
||||
'submission_ids' : [0],
|
||||
}
|
||||
'rubric_scores': [[0]],
|
||||
'grader_types': [''],
|
||||
'feedback_items': [''],
|
||||
'feedback_dicts': [{}],
|
||||
'grader_ids': [0],
|
||||
'submission_ids': [0],
|
||||
}
|
||||
try:
|
||||
score_result = json.loads(score_msg)
|
||||
except (TypeError, ValueError):
|
||||
@@ -470,7 +471,7 @@ class OpenEndedModule(openendedchild.OpenEndedChild):
|
||||
log.error(error_message)
|
||||
fail['feedback'] = error_message
|
||||
return fail
|
||||
#This is to support peer grading
|
||||
#This is to support peer grading
|
||||
if isinstance(score_result['score'], list):
|
||||
feedback_items = []
|
||||
rubric_scores = []
|
||||
@@ -527,12 +528,12 @@ class OpenEndedModule(openendedchild.OpenEndedChild):
|
||||
'valid': True,
|
||||
'score': score,
|
||||
'feedback': feedback,
|
||||
'rubric_scores' : rubric_scores,
|
||||
'grader_types' : grader_types,
|
||||
'feedback_items' : feedback_items,
|
||||
'feedback_dicts' : feedback_dicts,
|
||||
'grader_ids' : grader_ids,
|
||||
'submission_ids' : submission_ids,
|
||||
'rubric_scores': rubric_scores,
|
||||
'grader_types': grader_types,
|
||||
'feedback_items': feedback_items,
|
||||
'feedback_dicts': feedback_dicts,
|
||||
'grader_ids': grader_ids,
|
||||
'submission_ids': submission_ids,
|
||||
}
|
||||
|
||||
def latest_post_assessment(self, system, short_feedback=False, join_feedback=True):
|
||||
@@ -545,7 +546,7 @@ class OpenEndedModule(openendedchild.OpenEndedChild):
|
||||
return ""
|
||||
|
||||
feedback_dict = self._parse_score_msg(self.child_history[-1].get('post_assessment', ""), system,
|
||||
join_feedback=join_feedback)
|
||||
join_feedback=join_feedback)
|
||||
if not short_feedback:
|
||||
return feedback_dict['feedback'] if feedback_dict['valid'] else ''
|
||||
if feedback_dict['valid']:
|
||||
@@ -585,7 +586,7 @@ class OpenEndedModule(openendedchild.OpenEndedChild):
|
||||
#This is a dev_facing_error
|
||||
log.error("Cannot find {0} in handlers in handle_ajax function for open_ended_module.py".format(dispatch))
|
||||
#This is a dev_facing_error
|
||||
return json.dumps({'error': 'Error handling action. Please try again.', 'success' : False})
|
||||
return json.dumps({'error': 'Error handling action. Please try again.', 'success': False})
|
||||
|
||||
before = self.get_progress()
|
||||
d = handlers[dispatch](get, system)
|
||||
@@ -679,7 +680,6 @@ class OpenEndedModule(openendedchild.OpenEndedChild):
|
||||
correct = ""
|
||||
previous_answer = self.initial_display
|
||||
|
||||
|
||||
context = {
|
||||
'prompt': self.child_prompt,
|
||||
'previous_answer': previous_answer,
|
||||
@@ -692,7 +692,7 @@ class OpenEndedModule(openendedchild.OpenEndedChild):
|
||||
'child_type': 'openended',
|
||||
'correct': correct,
|
||||
'accept_file_upload': self.accept_file_upload,
|
||||
'eta_message' : eta_string,
|
||||
'eta_message': eta_string,
|
||||
}
|
||||
html = system.render_template('{0}/open_ended.html'.format(self.TEMPLATE_DIR), context)
|
||||
return html
|
||||
@@ -726,7 +726,9 @@ class OpenEndedDescriptor():
|
||||
for child in ['openendedparam']:
|
||||
if len(xml_object.xpath(child)) != 1:
|
||||
#This is a staff_facing_error
|
||||
raise ValueError("Open Ended definition must include exactly one '{0}' tag. Contact the learning sciences group for assistance.".format(child))
|
||||
raise ValueError(
|
||||
"Open Ended definition must include exactly one '{0}' tag. Contact the learning sciences group for assistance.".format(
|
||||
child))
|
||||
|
||||
def parse(k):
|
||||
"""Assumes that xml_object has child k"""
|
||||
|
||||
@@ -100,7 +100,8 @@ class OpenEndedChild(object):
|
||||
# completion (doesn't matter if you self-assessed correct/incorrect).
|
||||
if system.open_ended_grading_interface:
|
||||
self.peer_gs = PeerGradingService(system.open_ended_grading_interface, system)
|
||||
self.controller_qs = controller_query_service.ControllerQueryService(system.open_ended_grading_interface,system)
|
||||
self.controller_qs = controller_query_service.ControllerQueryService(system.open_ended_grading_interface,
|
||||
system)
|
||||
else:
|
||||
self.peer_gs = MockPeerGradingService()
|
||||
self.controller_qs = None
|
||||
@@ -142,7 +143,9 @@ class OpenEndedChild(object):
|
||||
return True, {
|
||||
'success': False,
|
||||
#This is a student_facing_error
|
||||
'error': 'You have attempted this problem {0} times. You are allowed {1} attempts.'.format(self.child_attempts, self.max_attempts)
|
||||
'error': 'You have attempted this problem {0} times. You are allowed {1} attempts.'.format(
|
||||
self.child_attempts, self.max_attempts
|
||||
)
|
||||
}
|
||||
else:
|
||||
return False, {}
|
||||
@@ -170,8 +173,8 @@ class OpenEndedChild(object):
|
||||
try:
|
||||
answer = autolink_html(answer)
|
||||
cleaner = Cleaner(style=True, links=True, add_nofollow=False, page_structure=True, safe_attrs_only=True,
|
||||
host_whitelist=open_ended_image_submission.TRUSTED_IMAGE_DOMAINS,
|
||||
whitelist_tags=set(['embed', 'iframe', 'a', 'img']))
|
||||
host_whitelist=open_ended_image_submission.TRUSTED_IMAGE_DOMAINS,
|
||||
whitelist_tags=set(['embed', 'iframe', 'a', 'img']))
|
||||
clean_html = cleaner.clean_html(answer)
|
||||
clean_html = re.sub(r'</p>$', '', re.sub(r'^<p>', '', clean_html))
|
||||
except:
|
||||
@@ -272,7 +275,7 @@ class OpenEndedChild(object):
|
||||
"""
|
||||
#This is a dev_facing_error
|
||||
log.warning("Open ended child state out sync. state: %r, get: %r. %s",
|
||||
self.child_state, get, msg)
|
||||
self.child_state, get, msg)
|
||||
#This is a student_facing_error
|
||||
return {'success': False,
|
||||
'error': 'The problem state got out-of-sync. Please try reloading the page.'}
|
||||
@@ -298,7 +301,7 @@ class OpenEndedChild(object):
|
||||
@return: Boolean correct.
|
||||
"""
|
||||
correct = False
|
||||
if(isinstance(score, (int, long, float, complex))):
|
||||
if (isinstance(score, (int, long, float, complex))):
|
||||
score_ratio = int(score) / float(self.max_score())
|
||||
correct = (score_ratio >= 0.66)
|
||||
return correct
|
||||
@@ -332,7 +335,8 @@ class OpenEndedChild(object):
|
||||
|
||||
try:
|
||||
image_data.seek(0)
|
||||
success, s3_public_url = open_ended_image_submission.upload_to_s3(image_data, image_key, self.s3_interface)
|
||||
success, s3_public_url = open_ended_image_submission.upload_to_s3(image_data, image_key,
|
||||
self.s3_interface)
|
||||
except:
|
||||
log.exception("Could not upload image to S3.")
|
||||
|
||||
@@ -394,9 +398,9 @@ class OpenEndedChild(object):
|
||||
#In this case, an image was submitted by the student, but the image could not be uploaded to S3. Likely
|
||||
#a config issue (development vs deployment). For now, just treat this as a "success"
|
||||
log.exception("Student AJAX post to combined open ended xmodule indicated that it contained an image, "
|
||||
"but the image was not able to be uploaded to S3. This could indicate a config"
|
||||
"issue with this deployment, but it could also indicate a problem with S3 or with the"
|
||||
"student image itself.")
|
||||
"but the image was not able to be uploaded to S3. This could indicate a config"
|
||||
"issue with this deployment, but it could also indicate a problem with S3 or with the"
|
||||
"student image itself.")
|
||||
overall_success = True
|
||||
elif not has_file_to_upload:
|
||||
#If there is no file to upload, probably the student has embedded the link in the answer text
|
||||
@@ -435,7 +439,7 @@ class OpenEndedChild(object):
|
||||
response = {}
|
||||
#This is a student_facing_error
|
||||
error_string = ("You need to peer grade {0} more in order to make another submission. "
|
||||
"You have graded {1}, and {2} are required. You have made {3} successful peer grading submissions.")
|
||||
"You have graded {1}, and {2} are required. You have made {3} successful peer grading submissions.")
|
||||
try:
|
||||
response = self.peer_gs.get_data_for_location(self.location_string, student_id)
|
||||
count_graded = response['count_graded']
|
||||
@@ -444,16 +448,18 @@ class OpenEndedChild(object):
|
||||
success = True
|
||||
except:
|
||||
#This is a dev_facing_error
|
||||
log.error("Could not contact external open ended graders for location {0} and student {1}".format(self.location_string,student_id))
|
||||
log.error("Could not contact external open ended graders for location {0} and student {1}".format(
|
||||
self.location_string, student_id))
|
||||
#This is a student_facing_error
|
||||
error_message = "Could not contact the graders. Please notify course staff."
|
||||
return success, allowed_to_submit, error_message
|
||||
if count_graded>=count_required:
|
||||
if count_graded >= count_required:
|
||||
return success, allowed_to_submit, ""
|
||||
else:
|
||||
allowed_to_submit = False
|
||||
#This is a student_facing_error
|
||||
error_message = error_string.format(count_required-count_graded, count_graded, count_required, student_sub_count)
|
||||
error_message = error_string.format(count_required - count_graded, count_graded, count_required,
|
||||
student_sub_count)
|
||||
return success, allowed_to_submit, error_message
|
||||
|
||||
def get_eta(self):
|
||||
@@ -468,7 +474,7 @@ class OpenEndedChild(object):
|
||||
|
||||
success = response['success']
|
||||
if isinstance(success, basestring):
|
||||
success = (success.lower()=="true")
|
||||
success = (success.lower() == "true")
|
||||
|
||||
if success:
|
||||
eta = controller_query_service.convert_seconds_to_human_readable(response['eta'])
|
||||
@@ -477,6 +483,3 @@ class OpenEndedChild(object):
|
||||
eta_string = ""
|
||||
|
||||
return eta_string
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ class PeerGradingService(GradingService):
|
||||
"""
|
||||
Interface with the grading controller for peer grading
|
||||
"""
|
||||
|
||||
def __init__(self, config, system):
|
||||
config['system'] = system
|
||||
super(PeerGradingService, self).__init__(config)
|
||||
@@ -36,10 +37,11 @@ class PeerGradingService(GradingService):
|
||||
|
||||
def get_next_submission(self, problem_location, grader_id):
|
||||
response = self.get(self.get_next_submission_url,
|
||||
{'location': problem_location, 'grader_id': grader_id})
|
||||
{'location': problem_location, 'grader_id': grader_id})
|
||||
return self.try_to_decode(self._render_rubric(response))
|
||||
|
||||
def save_grade(self, location, grader_id, submission_id, score, feedback, submission_key, rubric_scores, submission_flagged):
|
||||
def save_grade(self, location, grader_id, submission_id, score, feedback, submission_key, rubric_scores,
|
||||
submission_flagged):
|
||||
data = {'grader_id': grader_id,
|
||||
'submission_id': submission_id,
|
||||
'score': score,
|
||||
@@ -89,6 +91,7 @@ class PeerGradingService(GradingService):
|
||||
pass
|
||||
return text
|
||||
|
||||
|
||||
"""
|
||||
This is a mock peer grading service that can be used for unit tests
|
||||
without making actual service calls to the grading controller
|
||||
@@ -122,7 +125,7 @@ class MockPeerGradingService(object):
|
||||
'max_score': 4})
|
||||
|
||||
def save_calibration_essay(self, problem_location, grader_id,
|
||||
calibration_essay_id, submission_key, score,
|
||||
calibration_essay_id, submission_key, score,
|
||||
feedback, rubric_scores):
|
||||
return {'success': True, 'actual_score': 2}
|
||||
|
||||
|
||||
@@ -75,7 +75,6 @@ class SelfAssessmentModule(openendedchild.OpenEndedChild):
|
||||
html = system.render_template('{0}/self_assessment_prompt.html'.format(self.TEMPLATE_DIR), context)
|
||||
return html
|
||||
|
||||
|
||||
def handle_ajax(self, dispatch, get, system):
|
||||
"""
|
||||
This is called by courseware.module_render, to handle an AJAX call.
|
||||
@@ -97,7 +96,7 @@ class SelfAssessmentModule(openendedchild.OpenEndedChild):
|
||||
#This is a dev_facing_error
|
||||
log.error("Cannot find {0} in handlers in handle_ajax function for open_ended_module.py".format(dispatch))
|
||||
#This is a dev_facing_error
|
||||
return json.dumps({'error': 'Error handling action. Please try again.', 'success' : False})
|
||||
return json.dumps({'error': 'Error handling action. Please try again.', 'success': False})
|
||||
|
||||
before = self.get_progress()
|
||||
d = handlers[dispatch](get, system)
|
||||
@@ -161,7 +160,6 @@ class SelfAssessmentModule(openendedchild.OpenEndedChild):
|
||||
|
||||
return system.render_template('{0}/self_assessment_hint.html'.format(self.TEMPLATE_DIR), context)
|
||||
|
||||
|
||||
def save_answer(self, get, system):
|
||||
"""
|
||||
After the answer is submitted, show the rubric.
|
||||
@@ -226,7 +224,7 @@ class SelfAssessmentModule(openendedchild.OpenEndedChild):
|
||||
try:
|
||||
score = int(get['assessment'])
|
||||
score_list = get.getlist('score_list[]')
|
||||
for i in xrange(0,len(score_list)):
|
||||
for i in xrange(0, len(score_list)):
|
||||
score_list[i] = int(score_list[i])
|
||||
except ValueError:
|
||||
#This is a dev_facing_error
|
||||
@@ -270,7 +268,7 @@ class SelfAssessmentModule(openendedchild.OpenEndedChild):
|
||||
'allow_reset': self._allow_reset()}
|
||||
|
||||
def latest_post_assessment(self, system):
|
||||
latest_post_assessment = super(SelfAssessmentModule, self).latest_post_assessment(system)
|
||||
latest_post_assessment = super(SelfAssessmentModule, self).latest_post_assessment(system)
|
||||
try:
|
||||
rubric_scores = json.loads(latest_post_assessment)
|
||||
except:
|
||||
@@ -310,7 +308,9 @@ class SelfAssessmentDescriptor():
|
||||
for child in expected_children:
|
||||
if len(xml_object.xpath(child)) != 1:
|
||||
#This is a staff_facing_error
|
||||
raise ValueError("Self assessment definition must include exactly one '{0}' tag. Contact the learning sciences group for assistance.".format(child))
|
||||
raise ValueError(
|
||||
"Self assessment definition must include exactly one '{0}' tag. Contact the learning sciences group for assistance.".format(
|
||||
child))
|
||||
|
||||
def parse(k):
|
||||
"""Assumes that xml_object has child k"""
|
||||
|
||||
Reference in New Issue
Block a user