From d4b632f1de908b805620524c41c3184a04477934 Mon Sep 17 00:00:00 2001 From: Amir Qayyum Khan Date: Thu, 4 Jun 2015 16:13:31 +0500 Subject: [PATCH] Fixed weight ignore issue on grade calculation --- edx_sga/sga.py | 6 ++++++ .../staff_graded_assignment/show.html | 13 +++++++++--- edx_sga/tests/integration_tests.py | 20 +++++++++++++------ 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/edx_sga/sga.py b/edx_sga/sga.py index 93aa680d..53c09d12 100644 --- a/edx_sga/sga.py +++ b/edx_sga/sga.py @@ -439,6 +439,9 @@ def enter_grade(self, request, suffix=''): state['staff_score'] = score state['comment'] = request.params.get('comment', '') module.state = json.dumps(state) + # to fix score on edx progress page + module.grade = score + module.max_grade = self.max_score() module.save() log.info( "enter_grade for course:%s module:%s student:%s", @@ -463,6 +466,7 @@ def remove_grade(self, request, suffix=''): self.block_id ) module = self.get_student_module(request.params['module_id']) + module.grade = 0 state = json.loads(module.state) state['staff_score'] = None state['comment'] = '' @@ -790,6 +794,7 @@ def student_state(self): "max_score": self.max_score(), "upload_allowed": self.upload_allowed(submission_data=submission), "solution": solution, + 'weight': self.weight, "base_asset_url": StaticContent.get_base_url_path_for_course_assets(self.location.course_key), } @@ -846,6 +851,7 @@ def get_student_data(): return { 'assignments': list(get_student_data()), 'max_score': self.max_score(), + 'weight': self.weight, 'display_name': force_text(self.display_name) } diff --git a/edx_sga/templates/staff_graded_assignment/show.html b/edx_sga/templates/staff_graded_assignment/show.html index 5715414e..6c788f56 100644 --- a/edx_sga/templates/staff_graded_assignment/show.html +++ b/edx_sga/templates/staff_graded_assignment/show.html @@ -29,7 +29,11 @@

<% if (graded) { %> - {% blocktrans %}Your score is <%= graded.score %> / <%= max_score %>{% endblocktrans %}
+ <% if (weight > 0) { %> + {% blocktrans %}Your score is <%= (graded.score / max_score) * weight %> / <%= weight %>{% endblocktrans %}
+ <% } else { %> + {% blocktrans %}Your score is <%= graded.score %> / <%= max_score %>{% endblocktrans %}
+ <% } %> <% if (graded.comment) { %> {% trans "Instructor comment" %} <%= graded.comment %>
<% } %> @@ -100,8 +104,11 @@ <% if (assignment.score !== null) { %> - <%= assignment.score %> / - <%= max_score %> + <% if (weight > 0) { %> + <%= (assignment.score / max_score) * weight %> / <%= weight %> + <% } else { %> + <%= assignment.score %> / <%= max_score %> + <% } %> <% if (! assignment.approved) { %> ({% trans "Awaiting instructor approval" %}) <% } %> diff --git a/edx_sga/tests/integration_tests.py b/edx_sga/tests/integration_tests.py index 26495d10..827668b2 100644 --- a/edx_sga/tests/integration_tests.py +++ b/edx_sga/tests/integration_tests.py @@ -112,6 +112,7 @@ def make_one(self, display_name=None, **kw): """ Creates a XBlock SGA for testing purpose. """ + weight = kw.get('weight', 0) field_data = DictFieldData(kw) block = StaffGradedAssignmentXBlock(self.runtime, field_data, self.scope_ids) block.location = Location( @@ -126,6 +127,7 @@ def make_one(self, display_name=None, **kw): block.display_name = display_name block.start = datetime.datetime(2010, 5, 12, 2, 42, tzinfo=pytz.utc) + block.weight = weight modulestore().create_item( self.staff.username, block.location.course_key, block.location.block_type, block.location.block_id ) @@ -231,7 +233,7 @@ def test_student_view(self, fragment, render_template): """ Test student view renders correctly. """ - block = self.make_one("Custom name") + block = self.make_one("Custom name", weight=12) self.personalize(block, **self.make_student(block, 'fred')) fragment = block.student_view() render_template.assert_called_once() @@ -254,6 +256,7 @@ def test_student_view(self, fragment, render_template): self.assertEqual(student_state['upload_allowed'], True) self.assertEqual(student_state['max_score'], 100) self.assertEqual(student_state['graded'], None) + assert student_state['weight'] == 12 fragment.add_css.assert_called_once_with( DummyResource("static/css/edx_sga.css")) fragment.initialize_js.assert_called_once_with( @@ -385,7 +388,7 @@ def point_positive_int_test(): block.save_sga(mock.Mock(body='{}')) self.assertEqual(block.display_name, "Staff Graded Assignment") self.assertEqual(block.points, 100) - self.assertEqual(block.weight, None) + self.assertEqual(block.weight, 0) block.save_sga(mock.Mock(method="POST", body=json.dumps({ "display_name": "Test Block", "points": str(orig_score), @@ -661,7 +664,7 @@ def test_get_staff_grading_data(self): """ Test fetch grading data for staff members. """ - block = self.make_one() + block = self.make_one(weight=15) barney = self.make_student( block, "barney", filename="foo.txt", @@ -672,6 +675,7 @@ def test_get_staff_grading_data(self): block, "fred", filename="bar.txt") data = block.get_staff_grading_data(None).json_body # lint-amnesty, pylint: disable=redefined-outer-name + assert data['weight'] == 15 assignments = sorted(data['assignments'], key=lambda x: x['username']) barney_assignment, fred_assignment = assignments @@ -757,8 +761,10 @@ def test_enter_grade_staff(self): 'submission_id': fred['submission']['uuid'], 'grade': 9, 'comment': "Good!"})) - state = json.loads(StudentModule.objects.get( - pk=fred['module'].id).state) + student_module = StudentModule.objects.get(pk=fred['module'].id) + state = json.loads(student_module.state) + assert student_module.grade == 9 + assert student_module.max_grade == block.max_score() self.assertEqual(state['comment'], 'Good!') self.assertEqual(state['staff_score'], 9) @@ -802,7 +808,9 @@ def test_remove_grade(self): 'student_id': item.student_id, }) block.remove_grade(request) - state = json.loads(StudentModule.objects.get(pk=module.id).state) + student_module = StudentModule.objects.get(pk=module.id) + state = json.loads(student_module.state) + assert student_module.grade == 0 self.assertEqual(block.get_score(item.student_id), None) self.assertEqual(state['comment'], '')