From dadb128bf8c78523fb03d33c8c2bcd9c8e3b859d Mon Sep 17 00:00:00 2001 From: Vik Paruchuri Date: Fri, 12 Jul 2013 15:29:01 -0400 Subject: [PATCH 1/6] Simplify save_grade and pass through answer_unknown --- .../peer_grading_service.py | 17 ++++---------- .../xmodule/xmodule/peer_grading_module.py | 23 ++++++------------- .../xmodule/tests/test_peer_grading.py | 1 + 3 files changed, 12 insertions(+), 29 deletions(-) diff --git a/common/lib/xmodule/xmodule/open_ended_grading_classes/peer_grading_service.py b/common/lib/xmodule/xmodule/open_ended_grading_classes/peer_grading_service.py index 56bd1ec0a8..7721c3b96c 100644 --- a/common/lib/xmodule/xmodule/open_ended_grading_classes/peer_grading_service.py +++ b/common/lib/xmodule/xmodule/open_ended_grading_classes/peer_grading_service.py @@ -40,17 +40,9 @@ class PeerGradingService(GradingService): {'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): - data = {'grader_id': grader_id, - 'submission_id': submission_id, - 'score': score, - 'feedback': feedback, - 'submission_key': submission_key, - 'location': location, - 'rubric_scores': rubric_scores, - 'rubric_scores_complete': True, - 'submission_flagged': submission_flagged} + def save_grade(self, **kwargs): + data = kwargs + data.update({'rubric_scores_complete' : True}) return self.try_to_decode(self.post(self.save_grade_url, data)) def is_student_calibrated(self, problem_location, grader_id): @@ -108,8 +100,7 @@ class MockPeerGradingService(object): 'rubric': 'fake rubric', 'max_score': 4} - def save_grade(self, location, grader_id, submission_id, - score, feedback, submission_key, rubric_scores, submission_flagged): + def save_grade(self,**kwargs): return {'success': True} def is_student_calibrated(self, problem_location, grader_id): diff --git a/common/lib/xmodule/xmodule/peer_grading_module.py b/common/lib/xmodule/xmodule/peer_grading_module.py index 09cac9a6b4..c6c5d2e3f2 100644 --- a/common/lib/xmodule/xmodule/peer_grading_module.py +++ b/common/lib/xmodule/xmodule/peer_grading_module.py @@ -308,31 +308,22 @@ class PeerGradingModule(PeerGradingFields, XModule): error: if there was an error in the submission, this is the error message """ - required = set(['location', 'submission_id', 'submission_key', 'score', 'feedback', 'rubric_scores[]', - 'submission_flagged']) + required = set(['location', 'submission_id', 'submission_key', 'score', 'feedback', 'rubric_scores[]', 'submission_flagged', 'answer_unknown']) success, message = self._check_required(data, required) if not success: return self._err_response(message) - grader_id = self.system.anonymous_student_id - location = data.get('location') - submission_id = data.get('submission_id') - score = data.get('score') - feedback = data.get('feedback') - submission_key = data.get('submission_key') - rubric_scores = data.getlist('rubric_scores[]') - submission_flagged = data.get('submission_flagged') + data_dict = {k:data.get(k) for k in required} + data_dict['rubric_scores'] = data_dict['rubric_scores[]'] + data_dict['grader_id'] = self.system.anonymous_student_id try: - response = self.peer_gs.save_grade(location, grader_id, submission_id, - score, feedback, submission_key, rubric_scores, submission_flagged) + response = self.peer_gs.save_grade(**data_dict) return response except GradingServiceError: # This is a dev_facing_error - log.exception("""Error saving grade to open ended grading service. server url: {0}, location: {1}, submission_id:{2}, - submission_key: {3}, score: {4}""" - .format(self.peer_gs.url, - location, submission_id, submission_key, score) + log.exception("""Error saving grade to open ended grading service. server url: {0}""" + .format(self.peer_gs.url) ) # This is a student_facing_error return { diff --git a/common/lib/xmodule/xmodule/tests/test_peer_grading.py b/common/lib/xmodule/xmodule/tests/test_peer_grading.py index c386f77e9b..fcdb0bb1ac 100644 --- a/common/lib/xmodule/xmodule/tests/test_peer_grading.py +++ b/common/lib/xmodule/xmodule/tests/test_peer_grading.py @@ -28,6 +28,7 @@ class PeerGradingModuleTest(unittest.TestCase, DummyModulestore): 'feedback': "", 'rubric_scores[]': [0, 1], 'submission_flagged': False, + 'answer_unknown' : False, }) def setUp(self): From 018601777b397af048991b6b2dc9ed4dfd3dce41 Mon Sep 17 00:00:00 2001 From: Vik Paruchuri Date: Fri, 12 Jul 2013 15:42:19 -0400 Subject: [PATCH 2/6] Simplify peer grading service calibration --- .../peer_grading_service.py | 17 ++++------------- .../lib/xmodule/xmodule/peer_grading_module.py | 17 +++++------------ 2 files changed, 9 insertions(+), 25 deletions(-) diff --git a/common/lib/xmodule/xmodule/open_ended_grading_classes/peer_grading_service.py b/common/lib/xmodule/xmodule/open_ended_grading_classes/peer_grading_service.py index 7721c3b96c..81c24bc021 100644 --- a/common/lib/xmodule/xmodule/open_ended_grading_classes/peer_grading_service.py +++ b/common/lib/xmodule/xmodule/open_ended_grading_classes/peer_grading_service.py @@ -54,16 +54,9 @@ class PeerGradingService(GradingService): response = self.get(self.show_calibration_essay_url, params) return self.try_to_decode(self._render_rubric(response)) - def save_calibration_essay(self, problem_location, grader_id, calibration_essay_id, submission_key, - score, feedback, rubric_scores): - data = {'location': problem_location, - 'student_id': grader_id, - 'calibration_essay_id': calibration_essay_id, - 'submission_key': submission_key, - 'score': score, - 'feedback': feedback, - 'rubric_scores[]': rubric_scores, - 'rubric_scores_complete': True} + def save_calibration_essay(self, **kwargs): + data = kwargs + data.update({'rubric_scores_complete' : True}) return self.try_to_decode(self.post(self.save_calibration_essay_url, data)) def get_problem_list(self, course_id, grader_id): @@ -115,9 +108,7 @@ class MockPeerGradingService(object): 'rubric': 'fake rubric', 'max_score': 4} - def save_calibration_essay(self, problem_location, grader_id, - calibration_essay_id, submission_key, score, - feedback, rubric_scores): + def save_calibration_essay(self, **kwargs): return {'success': True, 'actual_score': 2} def get_problem_list(self, course_id, grader_id): diff --git a/common/lib/xmodule/xmodule/peer_grading_module.py b/common/lib/xmodule/xmodule/peer_grading_module.py index c6c5d2e3f2..c97ec0c4f0 100644 --- a/common/lib/xmodule/xmodule/peer_grading_module.py +++ b/common/lib/xmodule/xmodule/peer_grading_module.py @@ -442,27 +442,20 @@ class PeerGradingModule(PeerGradingFields, XModule): success, message = self._check_required(data, required) if not success: return self._err_response(message) - grader_id = self.system.anonymous_student_id - location = data.get('location') - calibration_essay_id = data.get('submission_id') - submission_key = data.get('submission_key') - score = data.get('score') - feedback = data.get('feedback') - rubric_scores = data.getlist('rubric_scores[]') + data_dict = {k:data.get(k) for k in required} + data_dict['rubric_scores'] = data_dict['rubric_scores[]'] + data_dict['grader_id'] = self.system.anonymous_student_id try: - response = self.peer_gs.save_calibration_essay(location, grader_id, calibration_essay_id, - submission_key, score, feedback, rubric_scores) + response = self.peer_gs.save_calibration_essay(**data_dict) if 'actual_rubric' in response: rubric_renderer = combined_open_ended_rubric.CombinedOpenEndedRubric(self.system, True) response['actual_rubric'] = rubric_renderer.render_rubric(response['actual_rubric'])['html'] return response except GradingServiceError: # This is a dev_facing_error - log.exception( - "Error saving calibration grade, location: {0}, submission_key: {1}, grader_id: {2}".format( - location, submission_key, grader_id)) + log.exception("Error saving calibration grade") # This is a student_facing_error return self._err_response('There was an error saving your score. Please notify course staff.') From 306649f6addf91ff31b3f872cb4ab54d21d28677 Mon Sep 17 00:00:00 2001 From: Vik Paruchuri Date: Fri, 12 Jul 2013 15:45:41 -0400 Subject: [PATCH 3/6] Fix test --- lms/djangoapps/open_ended_grading/tests.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lms/djangoapps/open_ended_grading/tests.py b/lms/djangoapps/open_ended_grading/tests.py index 556a421808..262124d667 100644 --- a/lms/djangoapps/open_ended_grading/tests.py +++ b/lms/djangoapps/open_ended_grading/tests.py @@ -205,7 +205,9 @@ class TestPeerGradingService(LoginEnrollmentTestCase): 'submission_key': 'fake key', 'score': 2, 'feedback': 'feedback', - 'submission_flagged': 'false' + 'submission_flagged': 'false', + 'answer_unknown': 'false', + 'rubric_scores_complete' : 'true' } qdict = MagicMock() From 8b228dd64b259a9818f27c17e9761f6f5d8c939a Mon Sep 17 00:00:00 2001 From: Vik Paruchuri Date: Fri, 12 Jul 2013 15:51:36 -0400 Subject: [PATCH 4/6] Fix bad key naming --- common/lib/xmodule/xmodule/peer_grading_module.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/common/lib/xmodule/xmodule/peer_grading_module.py b/common/lib/xmodule/xmodule/peer_grading_module.py index c97ec0c4f0..f693cbb98e 100644 --- a/common/lib/xmodule/xmodule/peer_grading_module.py +++ b/common/lib/xmodule/xmodule/peer_grading_module.py @@ -445,7 +445,8 @@ class PeerGradingModule(PeerGradingFields, XModule): data_dict = {k:data.get(k) for k in required} data_dict['rubric_scores'] = data_dict['rubric_scores[]'] - data_dict['grader_id'] = self.system.anonymous_student_id + data_dict['student_id'] = self.system.anonymous_student_id + data_dict['calibration_essay_id'] = data_dict['submission_id'] try: response = self.peer_gs.save_calibration_essay(**data_dict) From 62c7255ac4aec6f2d6de43348547eecc18a95151 Mon Sep 17 00:00:00 2001 From: Vik Paruchuri Date: Fri, 12 Jul 2013 16:30:21 -0400 Subject: [PATCH 5/6] Use getlist --- common/lib/xmodule/xmodule/peer_grading_module.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/lib/xmodule/xmodule/peer_grading_module.py b/common/lib/xmodule/xmodule/peer_grading_module.py index f693cbb98e..254af404d5 100644 --- a/common/lib/xmodule/xmodule/peer_grading_module.py +++ b/common/lib/xmodule/xmodule/peer_grading_module.py @@ -314,7 +314,7 @@ class PeerGradingModule(PeerGradingFields, XModule): return self._err_response(message) data_dict = {k:data.get(k) for k in required} - data_dict['rubric_scores'] = data_dict['rubric_scores[]'] + data_dict['rubric_scores'] = data.getlist('rubric_scores[]') data_dict['grader_id'] = self.system.anonymous_student_id try: @@ -444,7 +444,7 @@ class PeerGradingModule(PeerGradingFields, XModule): return self._err_response(message) data_dict = {k:data.get(k) for k in required} - data_dict['rubric_scores'] = data_dict['rubric_scores[]'] + data_dict['rubric_scores'] = data.getlist('rubric_scores[]') data_dict['student_id'] = self.system.anonymous_student_id data_dict['calibration_essay_id'] = data_dict['submission_id'] From c9ddcd78687ed66bb210e8cbccaac0b03b41696d Mon Sep 17 00:00:00 2001 From: Vik Paruchuri Date: Fri, 19 Jul 2013 11:56:00 -0400 Subject: [PATCH 6/6] Fix some pep8 violations --- .../peer_grading_service.py | 31 ++++++++++++------- .../xmodule/xmodule/peer_grading_module.py | 21 ++++++++----- 2 files changed, 32 insertions(+), 20 deletions(-) diff --git a/common/lib/xmodule/xmodule/open_ended_grading_classes/peer_grading_service.py b/common/lib/xmodule/xmodule/open_ended_grading_classes/peer_grading_service.py index 81c24bc021..3c25b301ab 100644 --- a/common/lib/xmodule/xmodule/open_ended_grading_classes/peer_grading_service.py +++ b/common/lib/xmodule/xmodule/open_ended_grading_classes/peer_grading_service.py @@ -36,13 +36,18 @@ class PeerGradingService(GradingService): return self.try_to_decode(response) def get_next_submission(self, problem_location, grader_id): - response = self.get(self.get_next_submission_url, - {'location': problem_location, 'grader_id': grader_id}) + response = self.get( + self.get_next_submission_url, + { + 'location': problem_location, + 'grader_id': grader_id + } + ) return self.try_to_decode(self._render_rubric(response)) def save_grade(self, **kwargs): data = kwargs - data.update({'rubric_scores_complete' : True}) + data.update({'rubric_scores_complete': True}) return self.try_to_decode(self.post(self.save_grade_url, data)) def is_student_calibrated(self, problem_location, grader_id): @@ -56,7 +61,7 @@ class PeerGradingService(GradingService): def save_calibration_essay(self, **kwargs): data = kwargs - data.update({'rubric_scores_complete' : True}) + data.update({'rubric_scores_complete': True}) return self.try_to_decode(self.post(self.save_calibration_essay_url, data)) def get_problem_list(self, course_id, grader_id): @@ -85,15 +90,17 @@ without making actual service calls to the grading controller class MockPeerGradingService(object): def get_next_submission(self, problem_location, grader_id): - return {'success': True, - 'submission_id': 1, - 'submission_key': "", - 'student_response': 'fake student response', - 'prompt': 'fake submission prompt', - 'rubric': 'fake rubric', - 'max_score': 4} + return { + 'success': True, + 'submission_id': 1, + 'submission_key': "", + 'student_response': 'fake student response', + 'prompt': 'fake submission prompt', + 'rubric': 'fake rubric', + 'max_score': 4 + } - def save_grade(self,**kwargs): + def save_grade(self, **kwargs): return {'success': True} def is_student_calibrated(self, problem_location, grader_id): diff --git a/common/lib/xmodule/xmodule/peer_grading_module.py b/common/lib/xmodule/xmodule/peer_grading_module.py index 254af404d5..c8770cf785 100644 --- a/common/lib/xmodule/xmodule/peer_grading_module.py +++ b/common/lib/xmodule/xmodule/peer_grading_module.py @@ -23,6 +23,7 @@ log = logging.getLogger(__name__) EXTERNAL_GRADER_NO_CONTACT_ERROR = "Failed to contact external graders. Please notify course staff." + class PeerGradingFields(object): use_for_single_location = Boolean( display_name="Show Single Problem", @@ -68,9 +69,11 @@ class PeerGradingFields(object): scope=Scope.settings, default="Peer Grading Interface" ) - data = String(help="Html contents to display for this module", + data = String( + help="Html contents to display for this module", default='', - scope=Scope.content) + scope=Scope.content + ) class PeerGradingModule(PeerGradingFields, XModule): @@ -79,11 +82,14 @@ class PeerGradingModule(PeerGradingFields, XModule): """ _VERSION = 1 - js = {'coffee': [resource_string(__name__, 'js/src/peergrading/peer_grading.coffee'), - resource_string(__name__, 'js/src/peergrading/peer_grading_problem.coffee'), - resource_string(__name__, 'js/src/collapsible.coffee'), - resource_string(__name__, 'js/src/javascript_loader.coffee'), - ]} + js = { + 'coffee': [ + resource_string(__name__, 'js/src/peergrading/peer_grading.coffee'), + resource_string(__name__, 'js/src/peergrading/peer_grading_problem.coffee'), + resource_string(__name__, 'js/src/collapsible.coffee'), + resource_string(__name__, 'js/src/javascript_loader.coffee'), + ] + } js_module_name = "PeerGrading" css = {'scss': [resource_string(__name__, 'css/combinedopenended/display.scss')]} @@ -134,7 +140,6 @@ class PeerGradingModule(PeerGradingFields, XModule): return True return False - def _err_response(self, msg): """ Return a HttpResponse with a json dump with success=False, and the given error message.